Aude has submitted this change and it was merged.

Change subject: Fix comparison of objects in ClaimDiffer
......................................................................


Fix comparison of objects in ClaimDiffer

ClaimDiffer was detecting changes in the mainsnak even if nothing was
changed. This was due to a wrong comparison method used for comparing snak 
objects.

REQUIRES: I2653426355 in DataModel to pass PHPSTRICT

Change-Id: I2f3273596731276770c66695ac839aa6912f133d
(cherry picked from commit 0990b878d20ddbf83b0e3649118119c47dcf284e)
---
M lib/includes/ClaimDiffer.php
1 file changed, 15 insertions(+), 6 deletions(-)

Approvals:
  Aude: Verified; Looks good to me, approved



diff --git a/lib/includes/ClaimDiffer.php b/lib/includes/ClaimDiffer.php
index 5b42066..1577f0b 100644
--- a/lib/includes/ClaimDiffer.php
+++ b/lib/includes/ClaimDiffer.php
@@ -5,6 +5,7 @@
 use Diff\Diff;
 use Diff\Differ;
 use Diff\DiffOpChange;
+use Wikibase\DataModel\Internal\ObjectComparer;
 
 /**
  * Class for generating a ClaimDifference given two claims.
@@ -69,7 +70,9 @@
        private function diffMainSnaks( $oldClaim, $newClaim ) {
                $oldClaimMainSnak = $oldClaim === null ? null : 
$oldClaim->getMainSnak();
                $newClaimMainSnak = $newClaim === null ? null : 
$newClaim->getMainSnak();
-               if( $oldClaimMainSnak !== $newClaimMainSnak ){
+
+               $mainSnakComparer = new ObjectComparer();
+               if( !$mainSnakComparer->dataEquals( $oldClaimMainSnak, 
$newClaimMainSnak ) ) {
                        return new DiffOpChange( $oldClaimMainSnak, 
$newClaimMainSnak );
                }
                return null;
@@ -79,12 +82,14 @@
         * @param Claim $oldClaim
         * @param Claim $newClaim
         *
-        * @return DiffOpChange|null
+        * @return Diff
         */
        private function diffQualifiers( $oldClaim, $newClaim ) {
                $oldQualifiers = $oldClaim === null ? array() : 
iterator_to_array( $oldClaim->getQualifiers() );
                $newQualifiers = $newClaim === null ? array() : 
iterator_to_array( $newClaim->getQualifiers() );
-               if( $oldQualifiers !== $newQualifiers ){
+
+               $qualifierComparer = new ObjectComparer();
+               if (  !$qualifierComparer->dataEquals( $oldQualifiers, 
$newQualifiers ) ) {
                        return new Diff( $this->listDiffer->doDiff( 
$oldQualifiers, $newQualifiers ), false );
                }
                return null;
@@ -99,7 +104,9 @@
        private function diffRank( $oldClaim, $newClaim ) {
                $oldRank = $oldClaim === null ? null : $oldClaim->getRank();
                $newRank = $newClaim === null ? null : $newClaim->getRank();
-               if( $oldRank !== $newRank ){
+
+               $rankComparer = new ObjectComparer();
+               if( !$rankComparer->dataEquals( $oldRank, $newRank ) ){
                        return new DiffOpChange( $oldRank, $newRank );
                }
                return null;
@@ -109,12 +116,14 @@
         * @param Statement $oldClaim
         * @param Statement $newClaim
         *
-        * @return DiffOpChange|null
+        * @return Diff
         */
        private function diffReferences( $oldClaim, $newClaim ) {
                $oldReferences = $oldClaim === null ? array() : 
iterator_to_array( $oldClaim->getReferences() );
                $newReferences = $newClaim === null ? array() : 
iterator_to_array( $newClaim->getReferences() );
-               if( $oldReferences !== $newReferences ){
+
+               $referenceComparer = new ObjectComparer();
+               if ( !$referenceComparer->dataEquals( $oldReferences, 
$newReferences ) ) {
                        return new Diff( $this->listDiffer->doDiff( 
$oldReferences, $newReferences ), false );
                }
                return null;

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I2f3273596731276770c66695ac839aa6912f133d
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: mw1.23-wmf3
Gerrit-Owner: Aude <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>

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

Reply via email to