Bene has uploaded a new change for review.
https://gerrit.wikimedia.org/r/277582
Change subject: Only use numeric ids on supported entity types
......................................................................
Only use numeric ids on supported entity types
Change-Id: I84933393456c60cc1175b667440a5dac25981fad
---
M lib/tests/phpunit/MockRepository.php
1 file changed, 24 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/82/277582/1
diff --git a/lib/tests/phpunit/MockRepository.php
b/lib/tests/phpunit/MockRepository.php
index 215868b..b04c1c4 100644
--- a/lib/tests/phpunit/MockRepository.php
+++ b/lib/tests/phpunit/MockRepository.php
@@ -2,6 +2,7 @@
namespace Wikibase\Test;
+use InvalidArgumentException;
use Status;
use User;
use Wikibase\DataModel\Entity\EntityDocument;
@@ -257,7 +258,10 @@
$revisionId = ++$this->maxRevisionId;
}
- $this->maxEntityId = max( $this->maxEntityId,
$entity->getId()->getNumericId() );
+ if ( $this->supportsNumericIds( $entity->getType() ) ) {
+ $this->maxEntityId = max( $this->maxEntityId,
$entity->getId()->getNumericId() );
+ }
+
$this->maxRevisionId = max( $this->maxRevisionId, $revisionId );
$revision = new EntityRevision(
@@ -306,7 +310,10 @@
$revisionId = ++$this->maxRevisionId;
}
- $this->maxEntityId = max( $this->maxEntityId,
$redirect->getTargetId()->getNumericId() );
+ if ( $this->supportsNumericIds(
$redirect->getTargetId()->getEntityType() ) ) {
+ $this->maxEntityId = max( $this->maxEntityId,
$redirect->getTargetId()->getNumericId() );
+ }
+
$this->maxRevisionId = max( $this->maxRevisionId, $revisionId );
$this->redirects[$key] = new RedirectRevision(
@@ -622,9 +629,13 @@
* @throws StorageException
*/
public function assignFreshId( EntityDocument $entity ) {
- //TODO: Find a canonical way to generate an EntityId from the
maxId number.
- //XXX: Using setId() with an integer argument is deprecated!
+ if ( !$this->supportsNumericIds( $entity->getType() ) ) {
+ throw new InvalidArgumentException( "The given entity
doesn't support numeric ids." );
+ }
+
$numericId = ++$this->maxEntityId;
+
+ /** @var Item|Property $entity */
$entity->setId( $numericId );
}
@@ -748,4 +759,13 @@
throw new EntityRedirectLookupException( $entityId );
}
+ /**
+ * @param string $entityType
+ *
+ * @return bool
+ */
+ private function supportsNumericIds( $entityType ) {
+ return in_array( $entityType, array( 'item', 'property' ) );
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/277582
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I84933393456c60cc1175b667440a5dac25981fad
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Bene <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits