WMDE-leszek has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/364228 )
Change subject: Handle storage exception from custom entities in
EntityStorageHelper
......................................................................
Handle storage exception from custom entities in EntityStorageHelper
Also changes the exception thrown by WikiPageEntityStore::assignFreshId
when entity that already hsa an ID is provided. This method expects
an entity without the ID set, so when it is provided something other,
the caller must have been wrong.
All existing callers already make sure the entity passed to that
method actually is the one with the "empty" ID.
Change-Id: Ic78b4db0d24cc230197b7e17691c22ae013a79ba
---
M repo/includes/Api/EntitySavingHelper.php
M repo/includes/Store/Sql/WikiPageEntityStore.php
M repo/tests/phpunit/includes/Api/EditEntityTest.php
3 files changed, 18 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/28/364228/1
diff --git a/repo/includes/Api/EntitySavingHelper.php
b/repo/includes/Api/EntitySavingHelper.php
index a94f5cf..51d488a 100644
--- a/repo/includes/Api/EntitySavingHelper.php
+++ b/repo/includes/Api/EntitySavingHelper.php
@@ -16,6 +16,7 @@
use Wikibase\EntityFactory;
use Wikibase\Lib\Store\EntityRevisionLookup;
use Wikibase\Lib\Store\EntityStore;
+use Wikibase\Lib\Store\StorageException;
use Wikibase\Summary;
use Wikibase\SummaryFormatter;
@@ -265,8 +266,18 @@
$entity->setId( $customId );
} else {
- // NOTE: We need to assign an ID early, for things like
the ClaimIdGenerator.
- $this->entityStore->assignFreshId( $entity );
+ try {
+ // NOTE: We need to assign an ID early, for
things like the ClaimIdGenerator.
+ $this->entityStore->assignFreshId( $entity );
+ } catch ( StorageException $e ) {
+ $this->errorReporter->dieError(
+ 'Cannot automatically assign ID: ' .
$e->getMessage(),
+ 'no-automatic-entity-id'
+ );
+
+ throw new LogicException(
'ApiErrorReporter::dieError did not throw an exception' );
+ }
+
}
return $entity;
diff --git a/repo/includes/Store/Sql/WikiPageEntityStore.php
b/repo/includes/Store/Sql/WikiPageEntityStore.php
index 99a0cbc..cdcfddd 100644
--- a/repo/includes/Store/Sql/WikiPageEntityStore.php
+++ b/repo/includes/Store/Sql/WikiPageEntityStore.php
@@ -74,10 +74,11 @@
* @param EntityDocument $entity
*
* @throws StorageException
+ * @throws InvalidArgumentException
*/
public function assignFreshId( EntityDocument $entity ) {
if ( $entity->getId() !== null ) {
- throw new StorageException( 'This entity already has an
ID: ' . $entity->getId() . '!' );
+ throw new InvalidArgumentException( 'This entity
already has an ID: ' . $entity->getId() . '!' );
}
$type = $entity->getType();
diff --git a/repo/tests/phpunit/includes/Api/EditEntityTest.php
b/repo/tests/phpunit/includes/Api/EditEntityTest.php
index 9b39ed9..c6742d0 100644
--- a/repo/tests/phpunit/includes/Api/EditEntityTest.php
+++ b/repo/tests/phpunit/includes/Api/EditEntityTest.php
@@ -862,8 +862,9 @@
'create mediainfo with automatic id' => [
'p' => [ 'new' => 'mediainfo', 'data' => '{}' ],
'e' => [ 'exception' => [
- 'type' => StorageException::class,
- 'message' => 'mediainfo entities do not
support automatic IDs'
+ 'type' => ApiUsageException::class,
+ 'message' => 'Cannot automatically
assign ID: mediainfo entities do not support automatic IDs',
+ 'code' => 'no-automatic-entity-id',
] ],
'requires' => 'mediainfo' // skip if MediaInfo
is not configured
],
--
To view, visit https://gerrit.wikimedia.org/r/364228
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic78b4db0d24cc230197b7e17691c22ae013a79ba
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: WMDE-leszek <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits