jenkins-bot has submitted this change and it was merged. Change subject: Refactor string references to SiteLinkTable::compareSiteLinks ......................................................................
Refactor string references to SiteLinkTable::compareSiteLinks Change-Id: Iacc9852a35f131327b3afbc2c890bab7faf7b977 --- M lib/includes/store/sql/SiteLinkTable.php M lib/tests/phpunit/store/Sql/SiteLinkTableTest.php 2 files changed, 19 insertions(+), 19 deletions(-) Approvals: Hoo man: 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/includes/store/sql/SiteLinkTable.php b/lib/includes/store/sql/SiteLinkTable.php index f224e49..1dc19e7 100644 --- a/lib/includes/store/sql/SiteLinkTable.php +++ b/lib/includes/store/sql/SiteLinkTable.php @@ -63,25 +63,25 @@ } /** - * @param SiteLink $a - * @param SiteLink $b + * @param SiteLink[] $siteLinks1 + * @param SiteLink[] $siteLinks2 * - * @return int + * @return SiteLink[] */ - public function compareSiteLinks( SiteLink $a, SiteLink $b ) { - $siteComp = strcmp( $a->getSiteId(), $b->getSiteId() ); + public function diffSiteLinks( array $siteLinks1, array $siteLinks2 ) { + return array_udiff( + $siteLinks1, + $siteLinks2, + function( SiteLink $a, SiteLink $b ) { + $result = strcmp( $a->getSiteId(), $b->getSiteId() ); - if ( $siteComp !== 0 ) { - return $siteComp; - } + if ( $result === 0 ) { + $result = strcmp( $a->getPageName(), $b->getPageName() ); + } - $pageComp = strcmp( $a->getPageName(), $b->getPageName() ); - - if ( $pageComp !== 0 ) { - return $pageComp; - } - - return 0; + return $result; + } + ); } /** @@ -98,8 +98,8 @@ $newLinks = $item->getSiteLinkList()->toArray(); $oldLinks = $this->getSiteLinksForItem( $item->getId() ); - $linksToInsert = array_udiff( $newLinks, $oldLinks, array( $this, 'compareSiteLinks' ) ); - $linksToDelete = array_udiff( $oldLinks, $newLinks, array( $this, 'compareSiteLinks' ) ); + $linksToInsert = $this->diffSiteLinks( $newLinks, $oldLinks ); + $linksToDelete = $this->diffSiteLinks( $oldLinks, $newLinks ); if ( !$linksToInsert && !$linksToDelete ) { wfDebugLog( __CLASS__, __FUNCTION__ . ": links did not change, returning." ); diff --git a/lib/tests/phpunit/store/Sql/SiteLinkTableTest.php b/lib/tests/phpunit/store/Sql/SiteLinkTableTest.php index 5dbef22..25bd099 100644 --- a/lib/tests/phpunit/store/Sql/SiteLinkTableTest.php +++ b/lib/tests/phpunit/store/Sql/SiteLinkTableTest.php @@ -97,8 +97,8 @@ $actualLinks = $this->siteLinkTable->getSiteLinksForItem( $item->getId() ); $expectedLinks = $item->getSiteLinkList()->toArray(); - $missingLinks = array_udiff( $expectedLinks, $actualLinks, array( $this->siteLinkTable, 'compareSiteLinks' ) ); - $extraLinks = array_udiff( $actualLinks, $expectedLinks, array( $this->siteLinkTable, 'compareSiteLinks' ) ); + $missingLinks = $this->siteLinkTable->diffSiteLinks( $expectedLinks, $actualLinks ); + $extraLinks = $this->siteLinkTable->diffSiteLinks( $actualLinks, $expectedLinks ); $this->assertEmpty( $missingLinks, 'Missing links' ); $this->assertEmpty( $extraLinks, 'Extra links' ); -- To view, visit https://gerrit.wikimedia.org/r/257855 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Iacc9852a35f131327b3afbc2c890bab7faf7b977 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com> Gerrit-Reviewer: Aude <aude.w...@gmail.com> Gerrit-Reviewer: Hoo man <h...@online.de> Gerrit-Reviewer: Jeroen De Dauw <jeroended...@gmail.com> Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits