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 |
1 | 85 | + native |