[MediaWiki-commits] [Gerrit] mediawiki...WikimediaMaintenance[master]: Remove migrateWlmUploads.php
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/384087 ) Change subject: Remove migrateWlmUploads.php .. Remove migrateWlmUploads.php It was a one-off script to move a bunch of files across wikis for a very specific use case. It served its purpose so it can go. Change-Id: Ie339aa7695137454e16449c649afc42db8eebfdd --- D migrateWlmUploads.php 1 file changed, 0 insertions(+), 200 deletions(-) Approvals: Krinkle: Looks good to me, approved jenkins-bot: Verified diff --git a/migrateWlmUploads.php b/migrateWlmUploads.php deleted file mode 100644 index 0a1e51c..000 --- a/migrateWlmUploads.php +++ /dev/null @@ -1,200 +0,0 @@ -http://www.gnu.org/copyleft/gpl.html - * - * @file - * @ingroup Maintenance - * @ingroup Wikimedia - */ - -require_once __DIR__ . '/WikimediaMaintenance.php'; - -class MigrateWlmUploads extends Maintenance { - private $dryRun, - $testerUsernames = [ - 'Jdlrobson', - 'Tfinc', - 'Brion VIBBER', - 'Awjrichards', - 'Philinje', - ], - $home, - $logFiles = [ 'found', 'done', 'exists', 'nouser' ], - $tmpDir, - $deletingUser; - - /* @var IDatabase */ - private $commonsDbw; - - public function __construct() { - parent::__construct(); - $this->addDescription( 'Migrate botched up uploads from testwiki to Commons' ); - $this->addOption( 'do-it', 'Actually perform the migration (otherwise a dry run will be performed)' ); - } - - public function execute() { - global $wgDBname; - if ( $wgDBname != 'testwiki' ) { - $this->error( 'This script must be run on testwiki', 1 ); - } - - wfSuppressWarnings(); - // Make an empty temp directory - $this->tmpDir = wfTempDir() . '/wlmcleanup'; - unlink( $this->tmpDir ); - mkdir( $this->tmpDir ); - // Delete all log files from previous runs - foreach ( $this->logFiles as $file ) { - unlink( $this->fileName( $file ) ); - } - wfRestoreWarnings(); - - $this->home = getenv( 'HOME' ); - $this->dryRun = !$this->hasOption( 'do-it' ); - - $dbw = $this->getDB( DB_MASTER ); - $this->commonsDbw = $this->getDB( DB_MASTER, [], 'commonswiki' ); - $wlmTemplate = Title::newFromText( 'Template:Uploaded with WLM Mobile' ); - $this->deletingUser = User::newFromName( 'Maintenance script' ); - - $res = $dbw->select( - [ 'templatelinks', 'page', 'image' ], - [ 'page_title', 'img_user_text', 'img_timestamp' ], - [ - 'tl_namespace' => $wlmTemplate->getNamespace(), - 'tl_title' => $wlmTemplate->getDBkey(), - 'tl_from = page_id', - 'page_namespace' => NS_FILE, - 'page_title = img_name', - ], - __METHOD__ - ); - - foreach ( $res as $row ) { - $title = $row->page_title; - $user = $row->img_user_text; - $timestamp = $row->img_timestamp; - - $this->logToFile( 'found', [ $title, $user ] ); - $this->output( "$title by $user uploaded at $timestamp\n" ); - if ( in_array( $user, $this->testerUsernames ) ) { - $this->output( " ...this user is an app tester, rejecting\n" ); - continue; - } - $this->migrateFile( $title, $user, $timestamp ); - } - - if ( $this->dryRun ) { - $this->output( "\nDry run complete\n" ); - } - - wfSuppressWarnings(); - rmdir( $this->tmpDir ); - wfRestoreWarnings(); - } - - private function fileName( $group ) { - return "{$this->home}/{$group}.log"; - } - - /** -* @param string $name: Name of file to log to, relative to user's home directory -* @param string|array $what: What to log -*/ - private function logToFile( $name, $what ) { - if ( !in_array( $name, $this->logFiles ) ) { - throw new MWException( "Unexpected logging group '$name'!" ); - } - - $file = fopen( $this->fileName( $name ), 'at' ); - if ( is_array(
[MediaWiki-commits] [Gerrit] mediawiki...WikimediaMaintenance[master]: Remove migrateWlmUploads.php
MaxSem has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/384087 ) Change subject: Remove migrateWlmUploads.php .. Remove migrateWlmUploads.php It was a one-off script to move a bunch of files across wikis for a very specific use case. It served its purpose so it can go. Change-Id: Ie339aa7695137454e16449c649afc42db8eebfdd --- D migrateWlmUploads.php 1 file changed, 0 insertions(+), 200 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikimediaMaintenance refs/changes/87/384087/1 diff --git a/migrateWlmUploads.php b/migrateWlmUploads.php deleted file mode 100644 index 0a1e51c..000 --- a/migrateWlmUploads.php +++ /dev/null @@ -1,200 +0,0 @@ -http://www.gnu.org/copyleft/gpl.html - * - * @file - * @ingroup Maintenance - * @ingroup Wikimedia - */ - -require_once __DIR__ . '/WikimediaMaintenance.php'; - -class MigrateWlmUploads extends Maintenance { - private $dryRun, - $testerUsernames = [ - 'Jdlrobson', - 'Tfinc', - 'Brion VIBBER', - 'Awjrichards', - 'Philinje', - ], - $home, - $logFiles = [ 'found', 'done', 'exists', 'nouser' ], - $tmpDir, - $deletingUser; - - /* @var IDatabase */ - private $commonsDbw; - - public function __construct() { - parent::__construct(); - $this->addDescription( 'Migrate botched up uploads from testwiki to Commons' ); - $this->addOption( 'do-it', 'Actually perform the migration (otherwise a dry run will be performed)' ); - } - - public function execute() { - global $wgDBname; - if ( $wgDBname != 'testwiki' ) { - $this->error( 'This script must be run on testwiki', 1 ); - } - - wfSuppressWarnings(); - // Make an empty temp directory - $this->tmpDir = wfTempDir() . '/wlmcleanup'; - unlink( $this->tmpDir ); - mkdir( $this->tmpDir ); - // Delete all log files from previous runs - foreach ( $this->logFiles as $file ) { - unlink( $this->fileName( $file ) ); - } - wfRestoreWarnings(); - - $this->home = getenv( 'HOME' ); - $this->dryRun = !$this->hasOption( 'do-it' ); - - $dbw = $this->getDB( DB_MASTER ); - $this->commonsDbw = $this->getDB( DB_MASTER, [], 'commonswiki' ); - $wlmTemplate = Title::newFromText( 'Template:Uploaded with WLM Mobile' ); - $this->deletingUser = User::newFromName( 'Maintenance script' ); - - $res = $dbw->select( - [ 'templatelinks', 'page', 'image' ], - [ 'page_title', 'img_user_text', 'img_timestamp' ], - [ - 'tl_namespace' => $wlmTemplate->getNamespace(), - 'tl_title' => $wlmTemplate->getDBkey(), - 'tl_from = page_id', - 'page_namespace' => NS_FILE, - 'page_title = img_name', - ], - __METHOD__ - ); - - foreach ( $res as $row ) { - $title = $row->page_title; - $user = $row->img_user_text; - $timestamp = $row->img_timestamp; - - $this->logToFile( 'found', [ $title, $user ] ); - $this->output( "$title by $user uploaded at $timestamp\n" ); - if ( in_array( $user, $this->testerUsernames ) ) { - $this->output( " ...this user is an app tester, rejecting\n" ); - continue; - } - $this->migrateFile( $title, $user, $timestamp ); - } - - if ( $this->dryRun ) { - $this->output( "\nDry run complete\n" ); - } - - wfSuppressWarnings(); - rmdir( $this->tmpDir ); - wfRestoreWarnings(); - } - - private function fileName( $group ) { - return "{$this->home}/{$group}.log"; - } - - /** -* @param string $name: Name of file to log to, relative to user's home directory -* @param string|array $what: What to log -*/ - private function logToFile( $name, $what ) { - if ( !in_array( $name, $this->logFiles ) ) { - throw new MWException( "Unexpected logging group '$name'!" ); - } - - $file = fopen( $this->fileName( $name ), 'at' ); -