Пример #1
0
 public function execute()
 {
     $repoName = $this->getArg(0);
     if ($repoName == "all") {
         $this->error("Cannot use the 'all' repo", true);
     }
     $repo = CodeRepository::newFromName($repoName);
     if (!$repo) {
         $this->error("Repo '{$repoName}' is not a valid Repository", true);
     }
     $revisions = $this->getArg(1);
     if (strpos($revisions, ':') !== false) {
         $revisionVals = explode(':', $revisions, 2);
     } else {
         $this->error("Invalid revision range", true);
     }
     $start = intval($revisionVals[0]);
     $end = intval($revisionVals[1]);
     $revisions = range($start, $end);
     $status = $this->getArg(2);
     if (!CodeRevision::isValidStatus($status)) {
         $this->error("'{$status}' is not a valid status", true);
     }
     $username = $this->getArg(3);
     $user = User::newFromName($username);
     if (!$user) {
         $this->error("'{$username}' is not a valid username ", true);
     }
     if (!$user->isAllowed('codereview-set-status')) {
         $this->error("'{$username}' does not have the 'codereview-set-status' right", true);
     }
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select('code_rev', '*', array('cr_id' => $revisions, 'cr_repo_id' => $repo->getId()), __METHOD__);
     foreach ($res as $row) {
         $rev = CodeRevision::newFromRow($repo, $row);
         if ($rev && $rev->setStatus($status, $user)) {
             $this->output("r{$row->cr_id} updated\n");
         } else {
             $this->output("r{$row->cr_id} not updated\n");
         }
     }
     $this->output("Done!\n");
 }
Пример #2
0
 function doBatchChange()
 {
     global $wgRequest, $wgUser, $wgOut;
     $revisions = $wgRequest->getArray('wpRevisionSelected');
     $removeTags = $wgRequest->getVal('wpRemoveTag');
     $addTags = $wgRequest->getVal('wpTag');
     $status = $wgRequest->getVal('wpStatus');
     // Grab data from the DB
     $dbr = wfGetDB(DB_SLAVE);
     $revObjects = array();
     $res = $dbr->select('code_rev', '*', array('cr_id' => $revisions, 'cr_repo_id' => $this->mRepo->getId()), __METHOD__);
     foreach ($res as $row) {
         $revObjects[] = CodeRevision::newFromRow($this->mRepo, $row);
     }
     if ($wgUser->isAllowed('codereview-add-tag') && $addTags || $removeTags) {
         $addTags = array_map('trim', explode(",", $addTags));
         $removeTags = array_map('trim', explode(",", $removeTags));
         foreach ($revObjects as $rev) {
             $rev->changeTags($addTags, $removeTags, $wgUser);
         }
     }
     if ($wgUser->isAllowed('codereview-set-status') && $revObjects && CodeRevision::isValidStatus($status)) {
         foreach ($revObjects as $rev) {
             $rev->setStatus($status, $wgUser);
         }
     }
     // Automatically refresh
     // This way of getting GET parameters is horrible, but effective.
     $fields = $wgRequest->getValues();
     foreach (array_keys($fields) as $key) {
         if (substr($key, 0, 2) == 'wp' || $key == 'title') {
             unset($fields[$key]);
         }
     }
     $wgOut->redirect($this->getPager()->getTitle()->getFullURL($fields));
 }