jenkins-bot has submitted this change and it was merged.

Change subject: Only use numeric ids on supported entity types
......................................................................


Only use numeric ids on supported entity types

Bug: T133044
Change-Id: I84933393456c60cc1175b667440a5dac25981fad
---
M lib/tests/phpunit/MockRepository.php
1 file changed, 15 insertions(+), 3 deletions(-)

Approvals:
  Daniel Kinzler: Looks good to me, approved
  Thiemo Mättig (WMDE): Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/lib/tests/phpunit/MockRepository.php 
b/lib/tests/phpunit/MockRepository.php
index cf150f4..eb2b684 100644
--- a/lib/tests/phpunit/MockRepository.php
+++ b/lib/tests/phpunit/MockRepository.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Lib\Tests;
 
+use InvalidArgumentException;
 use Status;
 use User;
 use Wikibase\DataModel\Entity\EntityDocument;
@@ -257,7 +258,7 @@
                        $revisionId = ++$this->maxRevisionId;
                }
 
-               $this->maxEntityId = max( $this->maxEntityId, 
$entity->getId()->getNumericId() );
+               $this->updateMaxNumericId( $entity->getId() );
                $this->maxRevisionId = max( $this->maxRevisionId, $revisionId );
 
                $revision = new EntityRevision(
@@ -306,7 +307,7 @@
                        $revisionId = ++$this->maxRevisionId;
                }
 
-               $this->maxEntityId = max( $this->maxEntityId, 
$redirect->getTargetId()->getNumericId() );
+               $this->updateMaxNumericId( $redirect->getTargetId() );
                $this->maxRevisionId = max( $this->maxRevisionId, $revisionId );
 
                $this->redirects[$key] = new RedirectRevision(
@@ -614,12 +615,23 @@
                return isset( $this->watchlist[ $user->getName() ][ 
$entityId->getSerialization() ] );
        }
 
+       private function updateMaxNumericId( EntityId $id ) {
+               if ( method_exists( $id, 'getNumericId' ) ) {
+                       $numericId = $id->getNumericId();
+               } else {
+                       // FIXME: This is a generic implementation of 
getNumericId for entities without.
+                       $numericId = (int)preg_replace( '/^\D+/', '', 
$id->getSerialization() );
+               }
+
+               $this->maxEntityId = max( $this->maxEntityId, $numericId );
+       }
+
        /**
         * @see EntityStore::assignFreshId
         *
         * @param EntityDocument $entity
         *
-        * @throws StorageException
+        * @throws InvalidArgumentException when the entity type does not 
support setting numeric ids.
         */
        public function assignFreshId( EntityDocument $entity ) {
                //TODO: Find a canonical way to generate an EntityId from the 
maxId number.

-- 
To view, visit https://gerrit.wikimedia.org/r/277582
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I84933393456c60cc1175b667440a5dac25981fad
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Bene <[email protected]>
Gerrit-Reviewer: Adrian Heine <[email protected]>
Gerrit-Reviewer: Bene <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to