Merge "Add attributes parameter to ShowSearchHitTitle"
[lhc/web/wiklou.git] / maintenance / rebuildImages.php
index 6aa1f37..8fceedb 100644 (file)
@@ -32,6 +32,8 @@
 
 require_once __DIR__ . '/Maintenance.php';
 
+use Wikimedia\Rdbms\IMaintainableDatabase;
+
 /**
  * Maintenance script to update image metadata records.
  *
@@ -40,7 +42,7 @@ require_once __DIR__ . '/Maintenance.php';
 class ImageBuilder extends Maintenance {
 
        /**
-        * @var Database
+        * @var IMaintainableDatabase
         */
        protected $dbw;
 
@@ -61,7 +63,8 @@ class ImageBuilder extends Maintenance {
                $this->dbw = $this->getDB( DB_MASTER );
                $this->dryrun = $this->hasOption( 'dry-run' );
                if ( $this->dryrun ) {
-                       $GLOBALS['wgReadOnly'] = 'Dry run mode, image upgrades are suppressed';
+                       MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode()
+                               ->setReason( 'Dry run mode, image upgrades are suppressed' );
                }
 
                if ( $this->hasOption( 'missing' ) ) {
@@ -122,12 +125,14 @@ class ImageBuilder extends Maintenance {
                flush();
        }
 
-       function buildTable( $table, $key, $callback ) {
+       function buildTable( $table, $key, $queryInfo, $callback ) {
                $count = $this->dbw->selectField( $table, 'count(*)', '', __METHOD__ );
                $this->init( $count, $table );
                $this->output( "Processing $table...\n" );
 
-               $result = $this->getDB( DB_REPLICA )->select( $table, '*', [], __METHOD__ );
+               $result = $this->getDB( DB_REPLICA )->select(
+                       $queryInfo['tables'], $queryInfo['fields'], [], __METHOD__, [], $queryInfo['joins']
+               );
 
                foreach ( $result as $row ) {
                        $update = call_user_func( $callback, $row, null );
@@ -142,7 +147,7 @@ class ImageBuilder extends Maintenance {
 
        function buildImage() {
                $callback = [ $this, 'imageCallback' ];
-               $this->buildTable( 'image', 'img_name', $callback );
+               $this->buildTable( 'image', 'img_name', LocalFile::getQueryInfo(), $callback );
        }
 
        function imageCallback( $row, $copy ) {
@@ -154,7 +159,8 @@ class ImageBuilder extends Maintenance {
        }
 
        function buildOldImage() {
-               $this->buildTable( 'oldimage', 'oi_archive_name', [ $this, 'oldimageCallback' ] );
+               $this->buildTable( 'oldimage', 'oi_archive_name', OldLocalFile::getQueryInfo(),
+                       [ $this, 'oldimageCallback' ] );
        }
 
        function oldimageCallback( $row, $copy ) {