Fix TextPassDumperDatabaseTest::testPrefetchPlain postgres failures
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 26 May 2017 21:38:07 +0000 (14:38 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Fri, 26 May 2017 21:43:17 +0000 (21:43 +0000)
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
includes/page/WikiPage.php
maintenance/backupPrefetch.inc
maintenance/dumpTextPass.php
tests/phpunit/maintenance/backupTextPassTest.php

index f84ffa9..2fe275b 100644 (file)
@@ -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;
        }
index a687900..5f8da15 100644 (file)
@@ -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 );
 
index 265800e..6a2d3bf 100644 (file)
@@ -40,6 +40,7 @@
  * @ingroup Maintenance
  */
 class BaseDump {
+       /** @var XMLReader */
        protected $reader = null;
        protected $atEnd = false;
        protected $atPageEnd = false;
index 581f0d7..c6e9aad 100644 (file)
@@ -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;
index d460401..ea5ca8d 100644 (file)
@@ -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" );
        }