Merge "maintenance: Remove cross-wiki purging from rebuildmessages.php"
[lhc/web/wiklou.git] / maintenance / Maintenance.php
index c88a1a0..130d1fb 100644 (file)
@@ -26,6 +26,7 @@ require_once __DIR__ . '/../includes/PHPVersionCheck.php';
 wfEntryPointCheck( 'text' );
 
 use MediaWiki\Shell\Shell;
+use Wikimedia\Rdbms\IResultWrapper;
 
 /**
  * @defgroup MaintenanceArchive Maintenance archives
@@ -358,7 +359,7 @@ abstract class Maintenance {
                        wfDeprecated( __METHOD__ . ' without an $argId', '1.33' );
                }
 
-               return $this->hasArg( $argId ) ? $this->mArgs[$argId] : $default;
+               return $this->mArgs[$argId] ?? $default;
        }
 
        /**
@@ -830,7 +831,7 @@ abstract class Maintenance {
                                        + $wgProfiler
                                        + [ 'threshold' => $wgProfileLimit ]
                        );
-                       $profiler->setTemplated( true );
+                       $profiler->setAllowOutput();
                        Profiler::replaceStubInstance( $profiler );
                }
 
@@ -1365,28 +1366,34 @@ abstract class Maintenance {
        }
 
        /**
-        * Returns a database to be used by current maintenance script. It can be set by setDB().
-        * If not set, wfGetDB() will be used.
-        * This function has the same parameters as wfGetDB()
+        * Returns a database to be used by current maintenance script.
+        *
+        * This uses the main LBFactory instance by default unless overriden via setDB().
+        *
+        * This function has the same parameters as LoadBalancer::getConnection().
         *
         * @param int $db DB index (DB_REPLICA/DB_MASTER)
         * @param string|string[] $groups default: empty array
-        * @param string|bool $wiki default: current wiki
+        * @param string|bool $dbDomain default: current wiki
         * @return IMaintainableDatabase
         */
-       protected function getDB( $db, $groups = [], $wiki = false ) {
+       protected function getDB( $db, $groups = [], $dbDomain = false ) {
                if ( $this->mDb === null ) {
-                       return wfGetDB( $db, $groups, $wiki );
+                       return MediaWikiServices::getInstance()
+                               ->getDBLoadBalancerFactory()
+                               ->getMainLB( $dbDomain )
+                               ->getMaintenanceConnectionRef( $db, $groups, $dbDomain );
                }
+
                return $this->mDb;
        }
 
        /**
         * Sets database object to be returned by getDB().
         *
-        * @param IDatabase $db
+        * @param IMaintainableDatabase $db
         */
-       public function setDB( IDatabase $db ) {
+       public function setDB( IMaintainableDatabase $db ) {
                $this->mDb = $db;
        }
 
@@ -1478,9 +1485,9 @@ abstract class Maintenance {
        /**
         * Perform a search index update with locking
         * @param int $maxLockTime The maximum time to keep the search index locked.
-        * @param string $callback The function that will update the function.
+        * @param callable $callback The function that will update the function.
         * @param IMaintainableDatabase $dbw
-        * @param array $results
+        * @param array|IResultWrapper $results
         */
        public function updateSearchIndex( $maxLockTime, $callback, $dbw, $results ) {
                $lockTime = time();
@@ -1528,7 +1535,7 @@ abstract class Maintenance {
                        $title = $titleObj->getPrefixedDBkey();
                        $this->output( "$title..." );
                        # Update searchindex
-                       $u = new SearchUpdate( $pageId, $titleObj->getText(), $rev->getContent() );
+                       $u = new SearchUpdate( $pageId, $titleObj, $rev->getContent() );
                        $u->doUpdate();
                        $this->output( "\n" );
                }
@@ -1724,7 +1731,7 @@ abstract class LoggedUpdateMaintenance extends Maintenance {
                        return false;
                }
 
-               $db->insert( 'updatelog', [ 'ul_key' => $key ], __METHOD__, 'IGNORE' );
+               $db->insert( 'updatelog', [ 'ul_key' => $key ], __METHOD__, [ 'IGNORE' ] );
 
                return true;
        }
@@ -1736,7 +1743,7 @@ abstract class LoggedUpdateMaintenance extends Maintenance {
        protected function updateSkippedMessage() {
                $key = $this->getUpdateKey();
 
-               return "Update '{$key}' already logged as completed.";
+               return "Update '{$key}' already logged as completed. Use --force to run it again.";
        }
 
        /**