Call resetServices() when setting globals in tests
[lhc/web/wiklou.git] / maintenance / populateArchiveRevId.php
index c03eb24..c85e194 100644 (file)
@@ -43,6 +43,15 @@ class PopulateArchiveRevId extends LoggedUpdateMaintenance {
                $this->setBatchSize( 100 );
        }
 
+       /**
+        * @param IDatabase $dbw
+        * @return bool
+        */
+       public static function isNewInstall( IDatabase $dbw ) {
+               return $dbw->selectRowCount( 'archive' ) === 0 &&
+                       $dbw->selectRowCount( 'revision' ) === 1;
+       }
+
        protected function getUpdateKey() {
                return __CLASS__;
        }
@@ -110,14 +119,14 @@ class PopulateArchiveRevId extends LoggedUpdateMaintenance {
                $ok = false;
                while ( !$ok ) {
                        try {
-                               $dbw->doAtomicSection( __METHOD__, function ( $dbw, $fname ) {
+                               $dbw->doAtomicSection( __METHOD__, function ( IDatabase $dbw, $fname ) {
                                        $dbw->insert( 'revision', self::$dummyRev, $fname );
                                        $id = $dbw->insertId();
                                        $toDelete[] = $id;
 
                                        $maxId = max(
-                                               (int)$dbw->selectField( 'archive', 'MAX(ar_rev_id)', [], __METHOD__ ),
-                                               (int)$dbw->selectField( 'slots', 'MAX(slot_revision_id)', [], __METHOD__ )
+                                               (int)$dbw->selectField( 'archive', 'MAX(ar_rev_id)', [], $fname ),
+                                               (int)$dbw->selectField( 'slots', 'MAX(slot_revision_id)', [], $fname )
                                        );
                                        if ( $id <= $maxId ) {
                                                $dbw->insert( 'revision', [ 'rev_id' => $maxId + 1 ] + self::$dummyRev, $fname );
@@ -147,7 +156,7 @@ class PopulateArchiveRevId extends LoggedUpdateMaintenance {
                        self::$dummyRev = self::makeDummyRevisionRow( $dbw );
                }
 
-               $updates = $dbw->doAtomicSection( __METHOD__, function ( $dbw, $fname ) use ( $arIds ) {
+               $updates = $dbw->doAtomicSection( __METHOD__, function ( IDatabase $dbw, $fname ) use ( $arIds ) {
                        // Create new rev_ids by inserting dummy rows into revision and then deleting them.
                        $dbw->insert( 'revision', array_fill( 0, count( $arIds ), self::$dummyRev ), $fname );
                        $revIds = $dbw->selectFieldValues(
@@ -198,7 +207,7 @@ class PopulateArchiveRevId extends LoggedUpdateMaintenance {
                $rev = null;
 
                $mainPage = Title::newMainPage();
-               $pageId = $mainPage ? $mainPage->getArticleId() : null;
+               $pageId = $mainPage ? $mainPage->getArticleID() : null;
                if ( $pageId ) {
                        $rev = $dbw->selectRow(
                                'revision',