Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / harbormaster / management / HarbormasterManagementBuildWorkflow.php
blob2efd443a91876e0eebc4f3956a8d1872b9313183
1 <?php
3 final class HarbormasterManagementBuildWorkflow
4 extends HarbormasterManagementWorkflow {
6 protected function didConstruct() {
7 $this
8 ->setName('build')
9 ->setExamples('**build** [__options__] __buildable__ --plan __id__')
10 ->setSynopsis(pht('Run plan __id__ on __buildable__.'))
11 ->setArguments(
12 array(
13 array(
14 'name' => 'plan',
15 'param' => 'id',
16 'help' => pht('ID of build plan to run.'),
18 array(
19 'name' => 'background',
20 'help' => pht(
21 'Submit builds into the build queue normally instead of '.
22 'running them in the foreground.'),
24 array(
25 'name' => 'buildable',
26 'wildcard' => true,
28 ));
31 public function execute(PhutilArgumentParser $args) {
32 $viewer = $this->getViewer();
34 $names = $args->getArg('buildable');
35 if (count($names) != 1) {
36 throw new PhutilArgumentUsageException(
37 pht('Specify exactly one buildable object, by object name.'));
40 $name = head($names);
42 $buildable = id(new PhabricatorObjectQuery())
43 ->setViewer($viewer)
44 ->withNames($names)
45 ->executeOne();
46 if (!$buildable) {
47 throw new PhutilArgumentUsageException(
48 pht('No such buildable "%s"!', $name));
51 if (!($buildable instanceof HarbormasterBuildableInterface)) {
52 throw new PhutilArgumentUsageException(
53 pht('Object "%s" is not a buildable!', $name));
56 $plan_id = $args->getArg('plan');
57 if (!$plan_id) {
58 throw new PhutilArgumentUsageException(
59 pht(
60 'Use %s to specify a build plan to run.',
61 '--plan'));
64 $plan = id(new HarbormasterBuildPlanQuery())
65 ->setViewer($viewer)
66 ->withIDs(array($plan_id))
67 ->executeOne();
68 if (!$plan) {
69 throw new PhutilArgumentUsageException(
70 pht('Build plan "%s" does not exist.', $plan_id));
73 if (!$plan->canRunManually()) {
74 throw new PhutilArgumentUsageException(
75 pht('This build plan can not be run manually.'));
78 $console = PhutilConsole::getConsole();
80 $buildable = HarbormasterBuildable::initializeNewBuildable($viewer)
81 ->setIsManualBuildable(true)
82 ->setBuildablePHID($buildable->getHarbormasterBuildablePHID())
83 ->setContainerPHID($buildable->getHarbormasterContainerPHID())
84 ->save();
86 $buildable->sendMessage(
87 $viewer,
88 HarbormasterMessageType::BUILDABLE_BUILD,
89 false);
91 $console->writeOut(
92 "%s\n",
93 pht(
94 'Applying plan %s to new buildable %s...',
95 $plan->getID(),
96 'B'.$buildable->getID()));
98 $console->writeOut(
99 "\n %s\n\n",
100 PhabricatorEnv::getProductionURI('/B'.$buildable->getID()));
102 if (!$args->getArg('background')) {
103 PhabricatorWorker::setRunAllTasksInProcess(true);
106 if ($viewer->isOmnipotent()) {
107 $initiator = id(new PhabricatorHarbormasterApplication())->getPHID();
108 } else {
109 $initiator = $viewer->getPHID();
111 $buildable->applyPlan($plan, array(), $initiator);
113 $console->writeOut("%s\n", pht('Done.'));
115 return 0;