Add Message test for implicit formatting
[lhc/web/wiklou.git] / maintenance / Maintenance.php
index 2216de1..208cf17 100644 (file)
@@ -104,7 +104,7 @@ abstract class Maintenance {
 
        /**
         * Used by getDB() / setDB()
-        * @var IDatabase
+        * @var Database
         */
        private $mDb = null;
 
@@ -553,8 +553,19 @@ abstract class Maintenance {
         * Set triggers like when to try to run deferred updates
         * @since 1.28
         */
-       public function setTriggers() {
+       public function setAgentAndTriggers() {
+               if ( function_exists( 'posix_getpwuid' ) ) {
+                       $agent = posix_getpwuid( posix_geteuid() )['name'];
+               } else {
+                       $agent = 'sysadmin';
+               }
+               $agent .= '@' . wfHostname();
+
                $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+               // Add a comment for easy SHOW PROCESSLIST interpretation
+               $lbFactory->setAgentName(
+                       mb_strlen( $agent ) > 15 ? mb_substr( $agent, 0, 15 ) . '...' : $agent
+               );
                self::setLBFactoryTriggers( $lbFactory );
        }
 
@@ -715,6 +726,7 @@ abstract class Maintenance {
 
                if ( is_array( $wgProfiler ) && isset( $wgProfiler['class'] ) ) {
                        $class = $wgProfiler['class'];
+                       /** @var Profiler $profiler */
                        $profiler = new $class(
                                [ 'sampling' => 1, 'output' => [ $output ] ]
                                        + $wgProfiler
@@ -1091,7 +1103,7 @@ abstract class Maintenance {
                                $wgLBFactoryConf['serverTemplate']['user'] = $wgDBuser;
                                $wgLBFactoryConf['serverTemplate']['password'] = $wgDBpassword;
                        }
-                       LBFactory::destroyInstance();
+                       MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->destroy();
                }
 
                // Per-script profiling; useful for debugging
@@ -1171,6 +1183,7 @@ abstract class Maintenance {
                $this->beginTransaction( $dbw, __METHOD__ );
 
                # Get "active" text records from the revisions table
+               $cur = [];
                $this->output( 'Searching for active text records in revisions table...' );
                $res = $dbw->select( 'revision', 'rev_text_id', [], __METHOD__, [ 'DISTINCT' ] );
                foreach ( $res as $row ) {
@@ -1230,7 +1243,7 @@ abstract class Maintenance {
         * @param integer $db DB index (DB_REPLICA/DB_MASTER)
         * @param array $groups; default: empty array
         * @param string|bool $wiki; default: current wiki
-        * @return IDatabase
+        * @return Database
         */
        protected function getDB( $db, $groups = [], $wiki = false ) {
                if ( is_null( $this->mDb ) ) {
@@ -1305,7 +1318,7 @@ abstract class Maintenance {
 
        /**
         * Lock the search index
-        * @param DatabaseBase &$db
+        * @param Database &$db
         */
        private function lockSearchindex( $db ) {
                $write = [ 'searchindex' ];
@@ -1323,7 +1336,7 @@ abstract class Maintenance {
 
        /**
         * Unlock the tables
-        * @param DatabaseBase &$db
+        * @param Database &$db
         */
        private function unlockSearchindex( $db ) {
                $db->unlockTables( __CLASS__ . '::' . __METHOD__ );
@@ -1332,7 +1345,7 @@ abstract class Maintenance {
        /**
         * Unlock and lock again
         * Since the lock is low-priority, queued reads will be able to complete
-        * @param DatabaseBase &$db
+        * @param Database &$db
         */
        private function relockSearchindex( $db ) {
                $this->unlockSearchindex( $db );
@@ -1343,7 +1356,7 @@ 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 DatabaseBase $dbw
+        * @param Database $dbw
         * @param array $results
         */
        public function updateSearchIndex( $maxLockTime, $callback, $dbw, $results ) {
@@ -1379,7 +1392,7 @@ abstract class Maintenance {
 
        /**
         * Update the searchindex table for a given pageid
-        * @param DatabaseBase $dbw A database write handle
+        * @param Database $dbw A database write handle
         * @param int $pageId The page ID to update.
         * @return null|string
         */