private function createRepo() { $dbw = wfGetDB(DB_MASTER); $dbw->insert('code_repo', array('repo_name' => 'Test', 'repo_path' => 'somewhere', 'repo_viewvc' => 'http://example.com/view/', 'repo_bugzilla' => 'http://www.example.com/$1'), __METHOD__); $id = $dbw->insertId(); $this->repo = CodeRepository::newFromId($id); # Now insert a revision $row = new StdClass(); $row->cr_repo_id = $this->repo->getId(); $row->cr_id = 777; $row->cr_author = 'hashar'; $row->cr_timestamp = '20110731063300'; $row->cr_message = 'I am the very first revision of this life'; $row->cr_status = ''; $row->cr_path = '/trunk/'; $rev = CodeRevision::newFromRow($this->repo, $row); $rev->save(); }
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"); }
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); $dryrun = $this->hasOption('dry-run'); $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); $affectedRevs = $rev->getUniqueAffectedRevs(); $this->output("r{$row->cr_id}: "); if (count($affectedRevs)) { $this->output("associating revs " . implode(',', $affectedRevs) . "\n"); if (!$dryrun) { $rev->addReferencesTo($affectedRevs); } } else { $this->output("no revisions followed up\n"); } } $this->output("Done!\n"); }
/** * @param $row * @param $repo CodeRepository * @param $result ApiResult * @return array */ private function formatRow($row, $repo, $result) { $item = array(); if (isset($this->props['revid'])) { $item['revid'] = intval($row->cr_id); } if (isset($this->props['status'])) { $item['status'] = $row->cr_status; } if (isset($this->props['commentcount'])) { $item['commentcount'] = $row->comments; } if (isset($this->props['path'])) { $item['path'] = $row->cr_path; } if (isset($this->props['message'])) { ApiResult::setContent($item, $row->cr_message); } if (isset($this->props['author'])) { $item['author'] = $row->cr_author; } if (isset($this->props['timestamp'])) { $item['timestamp'] = wfTimestamp(TS_ISO_8601, $row->cr_timestamp); } $rev = null; if (isset($this->props['tags'])) { $rev = CodeRevision::newFromRow($repo, $row); $item['tags'] = $rev->getTags(); $result->setIndexedTagName($item['tags'], 'tags'); } if (isset($this->props['followups'])) { if ($rev === null) { $rev = CodeRevision::newFromRow($repo, $row); } $item['followsup'] = $this->addReferenced($rev); $result->setIndexedTagName($item['followsup'], 'followsup'); } if (isset($this->props['followedup'])) { if ($rev === null) { $rev = CodeRevision::newFromRow($repo, $row); } $item['followedup'] = $this->addReferenced($rev); $result->setIndexedTagName($item['followedup'], 'followedup'); } return $item; }
/** * Load a particular revision out of the DB * @param $id int|string * @return CodeRevision */ public function getRevision($id) { if (!$this->isValidRev($id)) { return null; } $dbr = wfGetDB(DB_SLAVE); $row = $dbr->selectRow('code_rev', '*', array('cr_id' => $id, 'cr_repo_id' => $this->getId()), __METHOD__); if (!$row) { throw new MWException('Failed to load expected revision data'); } return CodeRevision::newFromRow($this, $row); }
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)); }
/** * @return void */ public function save() { $dbw = wfGetDB(DB_MASTER); $dbw->begin(); $dbw->insert('code_rev', array('cr_repo_id' => $this->repoId, 'cr_id' => $this->id, 'cr_author' => $this->author, 'cr_timestamp' => $dbw->timestamp($this->timestamp), 'cr_message' => $this->message, 'cr_status' => $this->status, 'cr_path' => $this->commonPath, 'cr_flags' => ''), __METHOD__, array('IGNORE')); // Already exists? Update the row! $newRevision = $dbw->affectedRows() > 0; if (!$newRevision) { $dbw->update('code_rev', array('cr_author' => $this->author, 'cr_timestamp' => $dbw->timestamp($this->timestamp), 'cr_message' => $this->message, 'cr_path' => $this->commonPath), array('cr_repo_id' => $this->repoId, 'cr_id' => $this->id), __METHOD__); } // Update path tracking used for output and searching if ($this->paths) { CodeRevision::insertPaths($dbw, $this->paths, $this->repoId, $this->id); } $affectedRevs = $this->getUniqueAffectedRevs(); if (count($affectedRevs)) { $this->addReferencesTo($affectedRevs); } global $wgEnableEmail; // Email the authors of revisions that this follows up on if ($wgEnableEmail && $newRevision && count($affectedRevs) > 0) { // Get committer wiki user name, or repo name at least $commitAuthor = $this->getWikiUser(); if ($commitAuthor) { $committer = $commitAuthor->getName(); $commitAuthorId = $commitAuthor->getId(); } else { $committer = htmlspecialchars($this->author); $commitAuthorId = 0; } // Get the authors of these revisions $res = $dbw->select('code_rev', array('cr_repo_id', 'cr_id', 'cr_author', 'cr_timestamp', 'cr_message', 'cr_status', 'cr_path'), array('cr_repo_id' => $this->repoId, 'cr_id' => $affectedRevs, 'cr_id < ' . intval($this->id), 'cr_author != ' . $dbw->addQuotes($this->author)), __METHOD__, array('USE INDEX' => 'PRIMARY')); // Get repo and build comment title (for url) $url = $this->getCanonicalUrl(); foreach ($res as $row) { $revision = CodeRevision::newFromRow($this->repo, $row); $users = $revision->getCommentingUsers(); $rowUrl = $revision->getCanonicalUrl(); $revisionAuthor = $revision->getWikiUser(); $revisionCommitSummary = $revision->getMessage(); //Add the followup revision author if they have not already been added as a commentor (they won't want dupe emails!) if ($revisionAuthor && !array_key_exists($revisionAuthor->getId(), $users)) { $users[$revisionAuthor->getId()] = $revisionAuthor; } //Notify commenters and revision author of followup revision foreach ($users as $user) { /** * @var $user User */ // No sense in notifying the author of this rev if they are a commenter/the author on the target rev if ($commitAuthorId == $user->getId()) { continue; } if ($user->canReceiveEmail()) { // Send message in receiver's language $lang = array('language' => $user->getGlobalPreference('language')); $user->sendMail(wfMsgExt('codereview-email-subj2', $lang, $this->repo->getName(), $this->getIdString($row->cr_id)), wfMsgExt('codereview-email-body2', $lang, $committer, $this->getIdStringUnique($row->cr_id), $url, $this->message, $rowUrl, $revisionCommitSummary)); } } } } $dbw->commit(); }