class MigrateFileRepoLayout extends Maintenance {
public function __construct() {
parent::__construct();
- $this->mDescription = "Copy files in repo to a different layout.";
+ $this->addDescription( 'Copy files in repo to a different layout.' );
$this->addOption( 'oldlayout', "Old layout; one of 'name' or 'sha1'", true, true );
$this->addOption( 'newlayout', "New layout; one of 'name' or 'sha1'", true, true );
$this->addOption( 'since', "Copy only files from after this timestamp", false, true );
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' );
$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 ) {
$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 ) );
}
- $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 ) {
$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 ) );
}
- $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() );
}
// 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 ) {
'/' . $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 ) );
}
- $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() );
$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 ) );
}