jenkins-bot has submitted this change and it was merged.

Change subject: Cleanups to MigrateFileRepoLayout
......................................................................


Cleanups to MigrateFileRepoLayout

* Use "bypassReadOnly" as other file backend maintenance
  scripts do.  One may want to run this while site traffic
  is off via $wgReadOnly.
* Fixed handling for when img_sha1 is not set.
* Fixed some IDEA errors.

Change-Id: I95c426c5f2082576fc9ea40282d2869750a9f3d8
---
M includes/Status.php
M includes/filerepo/file/File.php
M includes/filerepo/file/LocalFile.php
M maintenance/migrateFileRepoLayout.php
4 files changed, 19 insertions(+), 13 deletions(-)

Approvals:
  Krinkle: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Status.php b/includes/Status.php
index 28af7f5..752cc5d 100644
--- a/includes/Status.php
+++ b/includes/Status.php
@@ -361,7 +361,7 @@
         *
         * @note: this handles RawMessage poorly
         *
-        * @param string $type
+        * @param string|bool $type
         * @return array
         */
        protected function getStatusArray( $type = false ) {
diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php
index cde5e6a..9a7c21c 100644
--- a/includes/filerepo/file/File.php
+++ b/includes/filerepo/file/File.php
@@ -1444,7 +1444,7 @@
         * @param string $end Only revisions newer than $end will be returned
         * @param bool $inc Include the endpoints of the time range
         *
-        * @return array
+        * @return File[]
         */
        function getHistory( $limit = null, $start = null, $end = null, $inc = 
true ) {
                return array();
diff --git a/includes/filerepo/file/LocalFile.php 
b/includes/filerepo/file/LocalFile.php
index d1467084..0092e17 100644
--- a/includes/filerepo/file/LocalFile.php
+++ b/includes/filerepo/file/LocalFile.php
@@ -986,7 +986,7 @@
         * @param int $start Optional: Timestamp, start from
         * @param int $end Optional: Timestamp, end at
         * @param bool $inc
-        * @return array
+        * @return OldLocalFile[]
         */
        function getHistory( $limit = null, $start = null, $end = null, $inc = 
true ) {
                $dbr = $this->repo->getSlaveDB();
diff --git a/maintenance/migrateFileRepoLayout.php 
b/maintenance/migrateFileRepoLayout.php
index 78587ce..68b97e3 100644
--- a/maintenance/migrateFileRepoLayout.php
+++ b/maintenance/migrateFileRepoLayout.php
@@ -72,7 +72,8 @@
                $batch = array();
                $lastName = '';
                do {
-                       $res = $dbw->select( 'image', array( 'img_name', 
'img_sha1' ),
+                       $res = $dbw->select( 'image',
+                               array( 'img_name', 'img_sha1' ),
                                array_merge( array( 'img_name > ' . 
$dbw->addQuotes( $lastName ) ), $conds ),
                                __METHOD__,
                                array( 'LIMIT' => $this->mBatchSize, 'ORDER BY' 
=> 'img_name' )
@@ -80,12 +81,14 @@
 
                        foreach ( $res as $row ) {
                                $lastName = $row->img_name;
-                               $sha1 = $row->img_sha1;
-                               if ( !strlen( $sha1 ) ) {
-                                       $this->error( "Image SHA-1 not set for 
{$row->img_name}." );
-                               } else {
-                                       $file = $repo->newFile( $row->img_name 
);
+                               /** @var LocalFile $file */
+                               $file = $repo->newFile( $row->img_name );
+                               // Check in case SHA1 rows are not populated 
for some files
+                               $sha1 = strlen( $row->img_sha1 ) ? 
$row->img_sha1 : $file->getSha1();
 
+                               if ( !strlen( $sha1 ) ) {
+                                       $this->error( "Image SHA-1 not known 
for {$row->img_name}." );
+                               } else {
                                        if ( $oldLayout === 'sha1' ) {
                                                $spath = 
"{$origBase}/{$sha1[0]}/{$sha1[1]}/{$sha1[2]}/{$sha1}";
                                        } else {
@@ -98,7 +101,8 @@
                                                $dpath = $file->getPath();
                                        }
 
-                                       $status = $be->prepare( array( 'dir' => 
dirname( $dpath ) ) );
+                                       $status = $be->prepare( array(
+                                               'dir' => dirname( $dpath ), 
'bypassReadOnly' => 1 ) );
                                        if ( !$status->isOK() ) {
                                                $this->error( print_r( 
$status->getErrorsArray(), true ) );
                                        }
@@ -130,7 +134,8 @@
                                                $dpath = $ofile->getPath();
                                        }
 
-                                       $status = $be->prepare( array( 'dir' => 
dirname( $dpath ) ) );
+                                       $status = $be->prepare( array(
+                                               'dir' => dirname( $dpath ), 
'bypassReadOnly' => 1 ) );
                                        if ( !$status->isOK() ) {
                                                $this->error( print_r( 
$status->getErrorsArray(), true ) );
                                        }
@@ -187,7 +192,8 @@
                                                '/' . 
$repo->getDeletedHashPath( $sha1Key ) . $sha1Key;
                                }
 
-                               $status = $be->prepare( array( 'dir' => 
dirname( $dpath ) ) );
+                               $status = $be->prepare( array(
+                                       'dir' => dirname( $dpath ), 
'bypassReadOnly' => 1 ) );
                                if ( !$status->isOK() ) {
                                        $this->error( print_r( 
$status->getErrorsArray(), true ) );
                                }
@@ -219,7 +225,7 @@
                        $this->output( "\"{$op['img']}\" (dest: 
{$op['dst']})\n" );
                }
 
-               $status = $be->doOperations( $ops );
+               $status = $be->doOperations( $ops, array( 'bypassReadOnly' => 1 
) );
                if ( !$status->isOK() ) {
                        $this->output( print_r( $status->getErrorsArray(), true 
) );
                }

-- 
To view, visit https://gerrit.wikimedia.org/r/243606
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I95c426c5f2082576fc9ea40282d2869750a9f3d8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Parent5446 <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to