From 6fb5844fec8fb1ec727ada77406c6050571d2e3a Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 26 May 2017 14:38:07 -0700 Subject: [PATCH] Fix TextPassDumperDatabaseTest::testPrefetchPlain postgres failures The insertId() method was returning a string, which caused the returnValueMap not to trigger due to int/string mismatches. Also add sanity integer cast to WikiPage::insertOn(). Added a few more type docs. Bug: T75174 Change-Id: Id1090f3e3d0481272a3d13c3af8f2588f06dc912 --- includes/libs/rdbms/database/DatabasePostgres.php | 2 +- includes/page/WikiPage.php | 2 +- maintenance/backupPrefetch.inc | 1 + maintenance/dumpTextPass.php | 8 ++++++-- tests/phpunit/maintenance/backupTextPassTest.php | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/includes/libs/rdbms/database/DatabasePostgres.php b/includes/libs/rdbms/database/DatabasePostgres.php index f84ffa9b12..2fe275b5c1 100644 --- a/includes/libs/rdbms/database/DatabasePostgres.php +++ b/includes/libs/rdbms/database/DatabasePostgres.php @@ -776,7 +776,7 @@ __INDEXATTR__; $safeseq = str_replace( "'", "''", $seqName ); $res = $this->query( "SELECT nextval('$safeseq')" ); $row = $this->fetchRow( $res ); - $this->mInsertId = $row[0]; + $this->mInsertId = is_null( $row[0] ) ? null : (int)$row[0]; return $this->mInsertId; } diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index a687900431..5f8da15866 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -1177,7 +1177,7 @@ class WikiPage implements Page, IDBAccessObject { ); if ( $dbw->affectedRows() > 0 ) { - $newid = $pageId ?: $dbw->insertId(); + $newid = $pageId ? (int)$pageId : $dbw->insertId(); $this->mId = $newid; $this->mTitle->resetArticleID( $newid ); diff --git a/maintenance/backupPrefetch.inc b/maintenance/backupPrefetch.inc index 265800ec06..6a2d3bf626 100644 --- a/maintenance/backupPrefetch.inc +++ b/maintenance/backupPrefetch.inc @@ -40,6 +40,7 @@ * @ingroup Maintenance */ class BaseDump { + /** @var XMLReader */ protected $reader = null; protected $atEnd = false; protected $atPageEnd = false; diff --git a/maintenance/dumpTextPass.php b/maintenance/dumpTextPass.php index 581f0d7b4d..c6e9aad646 100644 --- a/maintenance/dumpTextPass.php +++ b/maintenance/dumpTextPass.php @@ -33,7 +33,12 @@ use Wikimedia\Rdbms\IMaintainableDatabase; * @ingroup Maintenance */ class TextPassDumper extends BackupDumper { + /** @var BaseDump */ public $prefetch = null; + /** @var string|bool */ + private $thisPage; + /** @var string|bool */ + private $thisRev; // when we spend more than maxTimeAllowed seconds on this run, we continue // processing until we write out the next complete page, then save output file(s), @@ -583,8 +588,7 @@ TEXT if ( $text === false && isset( $this->prefetch ) && $prefetchNotTried ) { $prefetchNotTried = false; $tryIsPrefetch = true; - $text = $this->prefetch->prefetch( intval( $this->thisPage ), - intval( $this->thisRev ) ); + $text = $this->prefetch->prefetch( (int)$this->thisPage, (int)$this->thisRev ); if ( $text === null ) { $text = false; diff --git a/tests/phpunit/maintenance/backupTextPassTest.php b/tests/phpunit/maintenance/backupTextPassTest.php index d460401a86..ea5ca8d847 100644 --- a/tests/phpunit/maintenance/backupTextPassTest.php +++ b/tests/phpunit/maintenance/backupTextPassTest.php @@ -103,7 +103,7 @@ class TextPassDumperDatabaseTest extends DumpTestCase { // increasing $this->assertEquals( [ $this->pageId2, $this->pageId3, $this->pageId4 ], - [ $this->pageId1 + 1, $this->pageId2 + 1, $this->pageId3 + 1 ], + [ $this->pageId1 + 1, $this->pageId1 + 2, $this->pageId1 + 3 ], "Page ids increasing without holes" ); } -- 2.20.1