r77355 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77354‎ | r77355 | r77356 >
Date:14:21, 27 November 2010
Author:reedy
Status:ok (Comments)
Tags:
Comment:
(bug 25505) Write maintenance script to bulk update status'

Actually untested (but should be feature complete), struggling to work out why all the relevant stuff isn't autoloaded. Any suggestions? :(
Modified paths:
  • /trunk/extensions/CodeReview/bulkStatusUpdate.php (added) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/bulkStatusUpdate.php
@@ -0,0 +1,83 @@
 2+<?php
 3+
 4+$IP = getenv( 'MW_INSTALL_PATH' );
 5+if ( $IP === false ) {
 6+ $IP = dirname( __FILE__ ) . '/../..';
 7+}
 8+require( "$IP/maintenance/Maintenance.php" );
 9+
 10+class BulkStatusUpdate extends Maintenance {
 11+
 12+ public function __construct() {
 13+ parent::__construct();
 14+ $this->mDescription = "Updates a range of revisions to a specific status";
 15+ $this->addArg( 'repo', 'The name of the repo. Cannot be all. Repos:'
 16+ . implode( ", ", CodeRepository::getRepoList() ) );
 17+ $this->addArg( 'revisions', "The revisions to set status for. Format: start:end" );
 18+ $this->addArg( 'status', implode( ", ", CodeRevision::getPossibleStates() ) );
 19+ $this->addArg( 'user', "Username for whom to accredit the state changes to." .
 20+ "The User needs to have the 'codereview-set-status' right" );
 21+ }
 22+
 23+ public function execute() {
 24+ $repoName = $this->getArg( 0 );
 25+
 26+ if ( $repoName == "all" ) {
 27+ $this->error( "Cannot use the 'all' repo", true );
 28+ }
 29+
 30+ $repo = CodeRepository::newFromName( $repoName );
 31+ if ( !$repo ) {
 32+ $this->error( "Repo '{$$repoName}' is not a valid Repository", true );
 33+ }
 34+
 35+ $revisions = $this->getArg( 1 );
 36+ if ( strpos( $revisions, ':' ) !== false ) {
 37+ $revisionVals = explode( ':', $revisions, 2 );
 38+ } else {
 39+ $this->error( "Invalid revision range", true );
 40+ }
 41+
 42+ $start = intval( $revisionVals[0] );
 43+ $end = intval( $revisionVals[1] );
 44+
 45+ $revisions = range( $start, $end );
 46+
 47+ $status = $this->getArg( 2 );
 48+
 49+ if ( !CodeRevision::isValidStatus( $status ) ) {
 50+ $this->error( "'{$status}' is not a valid status", true );
 51+ }
 52+
 53+ $username = $this->getArg( 3 );
 54+ $user = User::newFromName( $username );
 55+
 56+ if ( !$user ) {
 57+ $this->error( "'{$username}' is not a valid username ", true );
 58+ }
 59+
 60+ if ( !$user->isAllowed( 'codereview-set-status' ) ) {
 61+ $this->error( "'{$username}' does not have the 'codereview-set-status' right", true );
 62+ }
 63+
 64+ $dbr = wfGetDB( DB_SLAVE );
 65+
 66+ $res = $dbr->select( 'code_rev', '*', array( 'cr_id' => $revisions, 'cr_repo_id' => $repo->getId() ),
 67+ __METHOD__ );
 68+
 69+ foreach ( $res as $row ) {
 70+ $rev = CodeRevision::newFromRow( $repo, $row );
 71+
 72+ if ( $rev && $rev->setStatus( $status, $user ) ) {
 73+ $this->output( "r{$row->cr_id} updated\n" );
 74+ } else {
 75+ $this->output( "r{$row->cr_id} not updated\n" );
 76+ }
 77+ }
 78+
 79+ $this->output( "Done!\n" );
 80+ }
 81+}
 82+
 83+$maintClass = "BulkStatusUpdate";
 84+require_once( DO_MAINTENANCE );
Property changes on: trunk/extensions/CodeReview/bulkStatusUpdate.php
___________________________________________________________________
Added: svn:eol-style
185 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r77358Create instance of Maintenance class after AutoLoader and Defines...reedy15:25, 27 November 2010
r77362Seeing as we can't do that with how maintenance is setup (see bug 26143), exp...reedy17:13, 27 November 2010

Comments

#Comment by Reedy (talk | contribs)   14:24, 27 November 2010

reedy@ubuntu64-esxi:~/mediawiki/trunk/extensions/CodeReview$ php bulkStatusUpdate.php

Fatal error: Class 'CodeRepository' not found in /home/reedy/mediawiki/trunk/extensions/CodeReview/bulkStatusUpdate.php on line 15

Status & tagging log