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); $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('code_paths', '*', array('cp_rev_id' => $revisions, 'cp_repo_id' => $repo->getId()), __METHOD__); $dbw = wfGetDB(DB_MASTER); $dbw->begin(); foreach ($res as $row) { $fragments = CodeRevision::getPathFragments(array(array('path' => $row->cp_path, 'action' => $row->cp_action))); CodeRevision::insertPaths($dbw, $fragments, $repo->getId(), $row->cp_rev_id); $this->output("r{$row->cp_rev_id}, path: " . $row->cp_path . " Fragments: " . count($fragments) . "\n"); } $dbw->commit(); $this->output("Done!\n"); }
/** * @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(); }