jenkins-bot has submitted this change and it was merged. Change subject: Add null check in WikiImporter ......................................................................
Add null check in WikiImporter This is my code, and it caused fatals in production whenever anyone tried to import anything :( This should get rid of the fatals, but obviously this won't fix the underlying issue of WikiPage::getContent() sometimes returning null. See the task for more info on that issue. Bug: T94325 Change-Id: I68ce2288d7d209733bceffe42e1876c7afcd73d3 (cherry picked from commit 45788085afaa7be7b606c08ccc3cba06d224496b) --- M includes/Import.php 1 file changed, 13 insertions(+), 8 deletions(-) Approvals: MaxSem: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/Import.php b/includes/Import.php index de453b5..06355ed 100644 --- a/includes/Import.php +++ b/includes/Import.php @@ -375,14 +375,19 @@ $page = WikiPage::factory( $title ); $page->loadPageData( 'fromdbmaster' ); $content = $page->getContent(); - $editInfo = $page->prepareContentForEdit( $content ); - $countKey = 'title_' . $title->getPrefixedText(); - $countable = $page->isCountable( $editInfo ); - if ( array_key_exists( $countKey, $this->countableCache ) && - $countable != $this->countableCache[ $countKey ] ) { - DeferredUpdates::addUpdate( SiteStatsUpdate::factory( array( - 'articles' => ( (int)$countable - (int)$this->countableCache[ $countKey ] ) - ) ) ); + if ( $content === null ) { + wfDebug( __METHOD__ . ': Skipping article count adjustment for ' . $title . + ' because WikiPage::getContent() returned null' ); + } else { + $editInfo = $page->prepareContentForEdit( $content ); + $countKey = 'title_' . $title->getPrefixedText(); + $countable = $page->isCountable( $editInfo ); + if ( array_key_exists( $countKey, $this->countableCache ) && + $countable != $this->countableCache[ $countKey ] ) { + DeferredUpdates::addUpdate( SiteStatsUpdate::factory( array( + 'articles' => ( (int)$countable - (int)$this->countableCache[ $countKey ] ) + ) ) ); + } } $args = func_get_args(); -- To view, visit https://gerrit.wikimedia.org/r/200771 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I68ce2288d7d209733bceffe42e1876c7afcd73d3 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: wmf/1.25wmf23 Gerrit-Owner: TTO <at.li...@live.com.au> Gerrit-Reviewer: MaxSem <maxsem.w...@gmail.com> Gerrit-Reviewer: TTO <at.li...@live.com.au> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits