Tobias Gritschacher has uploaded a new change for review. https://gerrit.wikimedia.org/r/61018
Change subject: Fix issues in Entity::patch ...................................................................... Fix issues in Entity::patch * The base claim list passed in did not have claim guids as keys * The MapPatcher comparison behaviour was not altered to behave correctly for Claim objects This change depends on https://gerrit.wikimedia.org/r/#/c/60870/ Change-Id: I86d158e9653724c36575d93952da9317fca0f349 --- M DataModel/DataModel/Entity/Entity.php M DataModel/tests/phpunit/Entity/EntityTest.php 2 files changed, 24 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/18/61018/1 diff --git a/DataModel/DataModel/Entity/Entity.php b/DataModel/DataModel/Entity/Entity.php index 0bc0a71..bf1ee16 100644 --- a/DataModel/DataModel/Entity/Entity.php +++ b/DataModel/DataModel/Entity/Entity.php @@ -2,7 +2,9 @@ namespace Wikibase; +use Diff\Comparer\CallbackComparer; use Diff\Differ; +use Diff\MapPatcher; use Diff\Patcher; use MWException; use Wikibase\Lib\GuidGenerator; @@ -851,22 +853,31 @@ * @since 0.4 * * @param EntityDiff $patch - * @param Patcher|null $patcher The patcher with which to apply the diff */ - public final function patch( EntityDiff $patch, Patcher $patcher = null ) { - if ( $patcher === null ) { - $patcher = new \Diff\MapPatcher(); - } + public final function patch( EntityDiff $patch ) { + $patcher = new MapPatcher(); $this->setLabels( $patcher->patch( $this->getLabels(), $patch->getLabelsDiff() ) ); $this->setDescriptions( $patcher->patch( $this->getDescriptions(), $patch->getDescriptionsDiff() ) ); $this->setAllAliases( $patcher->patch( $this->getAllAliases(), $patch->getAliasesDiff() ) ); - $claims = $patcher->patch( $this->getClaims(), $patch->getClaimsDiff() ); + $this->patchSpecificFields( $patch, $patcher ); + + $patcher->setValueComparer( new CallbackComparer( + function( Claim $firstClaim, Claim $secondClaim ) { + return $firstClaim->getHash() === $secondClaim->getHash(); + } + ) ); + + $claims = array(); + + foreach ( $this->getClaims() as $claim ) { + $claims[$claim->getGuid()] = $claim; + } + + $claims = $patcher->patch( $claims, $patch->getClaimsDiff() ); $this->setClaims( new Claims( $claims ) ); - - $this->patchSpecificFields( $patch, $patcher ); } /** diff --git a/DataModel/tests/phpunit/Entity/EntityTest.php b/DataModel/tests/phpunit/Entity/EntityTest.php index b70e36f..fd40f0e 100644 --- a/DataModel/tests/phpunit/Entity/EntityTest.php +++ b/DataModel/tests/phpunit/Entity/EntityTest.php @@ -718,6 +718,11 @@ $claim2 = new \Wikibase\Claim( new \Wikibase\PropertyValueSnak( 42, new \DataValues\StringValue( 'ohi' ) ) ); $claim3 = new \Wikibase\Claim( new \Wikibase\PropertyNoValueSnak( 1 ) ); + $claim0->setGuid( 'claim0' ); + $claim1->setGuid( 'claim1' ); + $claim2->setGuid( 'claim2' ); + $claim3->setGuid( 'claim3' ); + $argLists = array(); -- To view, visit https://gerrit.wikimedia.org/r/61018 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I86d158e9653724c36575d93952da9317fca0f349 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: mw1.22-wmf3 Gerrit-Owner: Tobias Gritschacher <tobias.gritschac...@wikimedia.de> Gerrit-Reviewer: Jeroen De Dauw <jeroended...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits