Aude has uploaded a new change for review. https://gerrit.wikimedia.org/r/218906
Change subject: Fix unhandled exception in OtherProjectsSitesGenerator ...................................................................... Fix unhandled exception in OtherProjectsSitesGenerator If the local site is not in the sites table, don't horribly break a 'connected' page on parse or save. Instead, we can log a warning and go on. Bug: T102685 Change-Id: Ib832df0fc72a4213efd600f49de3abe06c3e2dcf --- M client/includes/OtherProjectsSitesGenerator.php M client/tests/phpunit/includes/OtherProjectsSitesGeneratorTest.php 2 files changed, 17 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/06/218906/1 diff --git a/client/includes/OtherProjectsSitesGenerator.php b/client/includes/OtherProjectsSitesGenerator.php index 4ae39f7..e0e1f37 100644 --- a/client/includes/OtherProjectsSitesGenerator.php +++ b/client/includes/OtherProjectsSitesGenerator.php @@ -49,7 +49,14 @@ * @return string[] */ public function getOtherProjectsSiteIds( array $siteLinkGroups ) { - $currentGroupId = $this->getLocalSite()->getGroup(); + $localSite = $this->getLocalSite(); + + if ( $localSite === null ) { + wfWarn( 'Site not found for ' . $this->localSiteId ); + return array(); + } + + $currentGroupId = $localSite->getGroup(); $otherProjectsSiteIds = array(); $this->expandSpecialGroups( $siteLinkGroups ); @@ -58,7 +65,7 @@ continue; } - $siteToAdd = $this->getSiteForGroup( $groupId ); + $siteToAdd = $this->getSiteForGroup( $groupId, $localSite->getLanguageCode() ); if ( $siteToAdd ) { $otherProjectsSiteIds[] = $siteToAdd->getGlobalId(); } @@ -74,16 +81,16 @@ * as the current site is returned * * @param string $groupId + * @param string $currentLanguageCode * * @return Site|null */ - private function getSiteForGroup( $groupId ) { + private function getSiteForGroup( $groupId, $currentLanguageCode ) { $siteGroupList = $this->siteStore->getSites()->getGroup( $groupId ); if ( $siteGroupList->count() === 1 ) { return $siteGroupList[0]; } - $currentLanguageCode = $this->getLocalSite()->getLanguageCode(); /** @var Site $site */ foreach ( $siteGroupList as $site ) { if ( $site->getLanguageCode() === $currentLanguageCode ) { diff --git a/client/tests/phpunit/includes/OtherProjectsSitesGeneratorTest.php b/client/tests/phpunit/includes/OtherProjectsSitesGeneratorTest.php index c6e09ed..0012d29 100644 --- a/client/tests/phpunit/includes/OtherProjectsSitesGeneratorTest.php +++ b/client/tests/phpunit/includes/OtherProjectsSitesGeneratorTest.php @@ -75,6 +75,12 @@ array() ); + $tests['Unknown site'] = array( + array( 'wikipedia', 'wikisource' ), + 'kittenswiki', + array() + ); + return $tests; } -- To view, visit https://gerrit.wikimedia.org/r/218906 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib832df0fc72a4213efd600f49de3abe06c3e2dcf Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Aude <aude.w...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits