From: Aaron Schulz Date: Wed, 31 Jul 2019 02:18:11 +0000 (-0400) Subject: Clean up use of IDatabase::affectedRows() in WikiPage::updateRedirectOn() X-Git-Tag: 1.34.0-rc.0~759^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmembres/load.php?a=commitdiff_plain;h=3bd96b883843816ab2e3eca75a0b65163ff594b0;p=lhc%2Fweb%2Fwiklou.git Clean up use of IDatabase::affectedRows() in WikiPage::updateRedirectOn() Bug: T229456 Change-Id: Ibce207904375a762943dff3352db7affd13c1aaa --- diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 33fd4721d4..1ff91012ec 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -1063,6 +1063,7 @@ class WikiPage implements Page, IDBAccessObject { * Insert or update the redirect table entry for this page to indicate it redirects to $rt * @param Title $rt Redirect target * @param int|null $oldLatest Prior page_latest for check and set + * @return bool Success */ public function insertRedirectEntry( Title $rt, $oldLatest = null ) { $dbw = wfGetDB( DB_MASTER ); @@ -1089,9 +1090,14 @@ class WikiPage implements Page, IDBAccessObject { ], __METHOD__ ); + $success = true; + } else { + $success = false; } $dbw->endAtomic( __METHOD__ ); + + return $success; } /** @@ -1456,18 +1462,19 @@ class WikiPage implements Page, IDBAccessObject { } if ( $isRedirect ) { - $this->insertRedirectEntry( $redirectTitle ); + $success = $this->insertRedirectEntry( $redirectTitle ); } else { // This is not a redirect, remove row from redirect table $where = [ 'rd_from' => $this->getId() ]; $dbw->delete( 'redirect', $where, __METHOD__ ); + $success = true; } if ( $this->getTitle()->getNamespace() == NS_FILE ) { RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect( $this->getTitle() ); } - return ( $dbw->affectedRows() != 0 ); + return $success; } /** diff --git a/tests/phpunit/includes/page/WikiPageDbTestBase.php b/tests/phpunit/includes/page/WikiPageDbTestBase.php index ee6c227b60..cbafbe901a 100644 --- a/tests/phpunit/includes/page/WikiPageDbTestBase.php +++ b/tests/phpunit/includes/page/WikiPageDbTestBase.php @@ -1593,9 +1593,9 @@ more stuff public function provideUpdateRedirectOn() { yield [ '#REDIRECT [[Foo]]', true, null, true, true, 0 ]; - yield [ '#REDIRECT [[Foo]]', true, 'Foo', true, false, 1 ]; + yield [ '#REDIRECT [[Foo]]', true, 'Foo', true, true, 1 ]; yield [ 'SomeText', false, null, false, true, 0 ]; - yield [ 'SomeText', false, 'Foo', false, false, 1 ]; + yield [ 'SomeText', false, 'Foo', false, true, 1 ]; } /**