X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=maintenance%2FmigrateFileRepoLayout.php;h=f771fff73d14bf9c55174a566f0492cd115c1506;hp=77d88f57425cfff25033ff1656b0d414380cd58f;hb=f5b9af121a07ecc674a63cbc65c3a01e9fa7d785;hpb=7ed96f4de2411d21cce4572e1fac7d3a8d2d0b77 diff --git a/maintenance/migrateFileRepoLayout.php b/maintenance/migrateFileRepoLayout.php index 77d88f5742..f771fff73d 100644 --- a/maintenance/migrateFileRepoLayout.php +++ b/maintenance/migrateFileRepoLayout.php @@ -42,11 +42,11 @@ class MigrateFileRepoLayout extends Maintenance { public function execute() { $oldLayout = $this->getOption( 'oldlayout' ); - if ( !in_array( $oldLayout, array( 'name', 'sha1' ) ) ) { + if ( !in_array( $oldLayout, [ 'name', 'sha1' ] ) ) { $this->error( "Invalid old layout.", 1 ); } $newLayout = $this->getOption( 'newlayout' ); - if ( !in_array( $newLayout, array( 'name', 'sha1' ) ) ) { + if ( !in_array( $newLayout, [ 'name', 'sha1' ] ) ) { $this->error( "Invalid new layout.", 1 ); } $since = $this->getOption( 'since' ); @@ -64,19 +64,19 @@ class MigrateFileRepoLayout extends Maintenance { $startTime = wfTimestampNow(); // Do current and archived versions... - $conds = array(); + $conds = []; if ( $since ) { $conds[] = 'img_timestamp >= ' . $dbw->addQuotes( $dbw->timestamp( $since ) ); } - $batch = array(); + $batch = []; $lastName = ''; do { $res = $dbw->select( 'image', - array( 'img_name', 'img_sha1' ), - array_merge( array( 'img_name > ' . $dbw->addQuotes( $lastName ) ), $conds ), + [ 'img_name', 'img_sha1' ], + array_merge( [ 'img_name > ' . $dbw->addQuotes( $lastName ) ], $conds ), __METHOD__, - array( 'LIMIT' => $this->mBatchSize, 'ORDER BY' => 'img_name' ) + [ 'LIMIT' => $this->mBatchSize, 'ORDER BY' => 'img_name' ] ); foreach ( $res as $row ) { @@ -101,14 +101,14 @@ class MigrateFileRepoLayout extends Maintenance { $dpath = $file->getPath(); } - $status = $be->prepare( array( - 'dir' => dirname( $dpath ), 'bypassReadOnly' => 1 ) ); + $status = $be->prepare( [ + 'dir' => dirname( $dpath ), 'bypassReadOnly' => 1 ] ); if ( !$status->isOK() ) { - $this->error( print_r( $status->getErrorsArray(), true ) ); + $this->error( print_r( $status->getErrors(), true ) ); } - $batch[] = array( 'op' => 'copy', 'overwrite' => true, - 'src' => $spath, 'dst' => $dpath, 'img' => $row->img_name ); + $batch[] = [ 'op' => 'copy', 'overwrite' => true, + 'src' => $spath, 'dst' => $dpath, 'img' => $row->img_name ]; } foreach ( $file->getHistory() as $ofile ) { @@ -134,18 +134,18 @@ class MigrateFileRepoLayout extends Maintenance { $dpath = $ofile->getPath(); } - $status = $be->prepare( array( - 'dir' => dirname( $dpath ), 'bypassReadOnly' => 1 ) ); + $status = $be->prepare( [ + 'dir' => dirname( $dpath ), 'bypassReadOnly' => 1 ] ); if ( !$status->isOK() ) { - $this->error( print_r( $status->getErrorsArray(), true ) ); + $this->error( print_r( $status->getErrors(), true ) ); } - $batch[] = array( 'op' => 'copy', 'overwrite' => true, - 'src' => $spath, 'dst' => $dpath, 'img' => $ofile->getArchiveName() ); + $batch[] = [ 'op' => 'copy', 'overwrite' => true, + 'src' => $spath, 'dst' => $dpath, 'img' => $ofile->getArchiveName() ]; } if ( count( $batch ) >= $this->mBatchSize ) { $this->runBatch( $batch, $be ); - $batch = array(); + $batch = []; } } } while ( $res->numRows() ); @@ -155,18 +155,18 @@ class MigrateFileRepoLayout extends Maintenance { } // Do deleted versions... - $conds = array(); + $conds = []; if ( $since ) { $conds[] = 'fa_deleted_timestamp >= ' . $dbw->addQuotes( $dbw->timestamp( $since ) ); } - $batch = array(); + $batch = []; $lastId = 0; do { - $res = $dbw->select( 'filearchive', array( 'fa_storage_key', 'fa_id', 'fa_name' ), - array_merge( array( 'fa_id > ' . $dbw->addQuotes( $lastId ) ), $conds ), + $res = $dbw->select( 'filearchive', [ 'fa_storage_key', 'fa_id', 'fa_name' ], + array_merge( [ 'fa_id > ' . $dbw->addQuotes( $lastId ) ], $conds ), __METHOD__, - array( 'LIMIT' => $this->mBatchSize, 'ORDER BY' => 'fa_id' ) + [ 'LIMIT' => $this->mBatchSize, 'ORDER BY' => 'fa_id' ] ); foreach ( $res as $row ) { @@ -192,18 +192,18 @@ class MigrateFileRepoLayout extends Maintenance { '/' . $repo->getDeletedHashPath( $sha1Key ) . $sha1Key; } - $status = $be->prepare( array( - 'dir' => dirname( $dpath ), 'bypassReadOnly' => 1 ) ); + $status = $be->prepare( [ + 'dir' => dirname( $dpath ), 'bypassReadOnly' => 1 ] ); if ( !$status->isOK() ) { - $this->error( print_r( $status->getErrorsArray(), true ) ); + $this->error( print_r( $status->getErrors(), true ) ); } - $batch[] = array( 'op' => 'copy', 'src' => $spath, 'dst' => $dpath, - 'overwriteSame' => true, 'img' => "(ID {$row->fa_id}) {$row->fa_name}" ); + $batch[] = [ 'op' => 'copy', 'src' => $spath, 'dst' => $dpath, + 'overwriteSame' => true, 'img' => "(ID {$row->fa_id}) {$row->fa_name}" ]; if ( count( $batch ) >= $this->mBatchSize ) { $this->runBatch( $batch, $be ); - $batch = array(); + $batch = []; } } } while ( $res->numRows() ); @@ -225,9 +225,9 @@ class MigrateFileRepoLayout extends Maintenance { $this->output( "\"{$op['img']}\" (dest: {$op['dst']})\n" ); } - $status = $be->doOperations( $ops, array( 'bypassReadOnly' => 1 ) ); + $status = $be->doOperations( $ops, [ 'bypassReadOnly' => 1 ] ); if ( !$status->isOK() ) { - $this->output( print_r( $status->getErrorsArray(), true ) ); + $this->output( print_r( $status->getErrors(), true ) ); } $this->output( "Batch done\n\n" );