Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / releeph / editor / ReleephBranchEditor.php
blob0bc084223b974860f38ad44a7c6c247c746a789b
1 <?php
3 final class ReleephBranchEditor extends PhabricatorEditor {
5 private $releephProject;
6 private $releephBranch;
8 public function setReleephProject(ReleephProject $rp) {
9 $this->releephProject = $rp;
10 return $this;
13 public function setReleephBranch(ReleephBranch $branch) {
14 $this->releephBranch = $branch;
15 return $this;
18 public function newBranchFromCommit(
19 PhabricatorRepositoryCommit $cut_point,
20 $branch_date,
21 $symbolic_name = null) {
23 $template = $this->releephProject->getDetail('branchTemplate');
24 if (!$template) {
25 $template = ReleephBranchTemplate::getRequiredDefaultTemplate();
28 $cut_point_handle = id(new PhabricatorHandleQuery())
29 ->setViewer($this->requireActor())
30 ->withPHIDs(array($cut_point->getPHID()))
31 ->executeOne();
33 list($name, $errors) = id(new ReleephBranchTemplate())
34 ->setCommitHandle($cut_point_handle)
35 ->setBranchDate($branch_date)
36 ->setReleephProjectName($this->releephProject->getName())
37 ->interpolate($template);
39 $basename = last(explode('/', $name));
41 $table = id(new ReleephBranch());
42 $transaction = $table->openTransaction();
43 $branch = id(new ReleephBranch())
44 ->setName($name)
45 ->setBasename($basename)
46 ->setReleephProjectID($this->releephProject->getID())
47 ->setCreatedByUserPHID($this->requireActor()->getPHID())
48 ->setCutPointCommitPHID($cut_point->getPHID())
49 ->setIsActive(1)
50 ->setDetail('branchDate', $branch_date)
51 ->save();
53 /**
54 * Steal the symbolic name from any other branch that has it (in this
55 * project).
57 if ($symbolic_name) {
58 $others = id(new ReleephBranch())->loadAllWhere(
59 'releephProjectID = %d',
60 $this->releephProject->getID());
61 foreach ($others as $other) {
62 if ($other->getSymbolicName() == $symbolic_name) {
63 $other
64 ->setSymbolicName(null)
65 ->save();
68 $branch
69 ->setSymbolicName($symbolic_name)
70 ->save();
73 $table->saveTransaction();
74 return $branch;
77 // aka "close" and "reopen"
78 public function changeBranchAccess($is_active) {
79 $branch = $this->releephBranch;
81 $branch
82 ->setIsActive((int)$is_active)
83 ->save();