@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 109 lines 3.0 kB view raw
1<?php 2 3final class HarbormasterStepAddController 4 extends HarbormasterPlanController { 5 6 public function handleRequest(AphrontRequest $request) { 7 $viewer = $this->getViewer(); 8 9 $plan = id(new HarbormasterBuildPlanQuery()) 10 ->setViewer($viewer) 11 ->withIDs(array($request->getURIData('id'))) 12 ->requireCapabilities( 13 array( 14 PhabricatorPolicyCapability::CAN_VIEW, 15 PhabricatorPolicyCapability::CAN_EDIT, 16 )) 17 ->executeOne(); 18 if (!$plan) { 19 return new Aphront404Response(); 20 } 21 22 $plan_id = $plan->getID(); 23 $cancel_uri = $this->getApplicationURI("plan/{$plan_id}/"); 24 $plan_title = pht('Plan %d', $plan_id); 25 26 $all = HarbormasterBuildStepImplementation::getImplementations(); 27 $all = msort($all, 'getName'); 28 29 $all_groups = HarbormasterBuildStepGroup::getAllGroups(); 30 foreach ($all as $impl) { 31 $group_key = $impl->getBuildStepGroupKey(); 32 if (empty($all_groups[$group_key])) { 33 throw new Exception( 34 pht( 35 'Build step "%s" has step group key "%s", but no step group '. 36 'with that key exists.', 37 get_class($impl), 38 $group_key)); 39 } 40 } 41 42 $groups = mgroup($all, 'getBuildStepGroupKey'); 43 $boxes = array(); 44 45 $enabled_groups = HarbormasterBuildStepGroup::getAllEnabledGroups(); 46 foreach ($enabled_groups as $group) { 47 $list = id(new PHUIObjectItemListView()) 48 ->setNoDataString( 49 pht('This group has no available build steps.')); 50 51 $steps = idx($groups, $group->getGroupKey(), array()); 52 53 foreach ($steps as $key => $impl) { 54 if ($impl->shouldRequireAutotargeting()) { 55 unset($steps[$key]); 56 continue; 57 } 58 } 59 60 if (!$steps && !$group->shouldShowIfEmpty()) { 61 continue; 62 } 63 64 foreach ($steps as $key => $impl) { 65 $class = get_class($impl); 66 67 $new_uri = $this->getApplicationURI("step/new/{$plan_id}/{$class}/"); 68 69 $item = id(new PHUIObjectItemView()) 70 ->setHeader($impl->getName()) 71 ->setHref($new_uri) 72 ->addAttribute($impl->getGenericDescription()); 73 74 $list->addItem($item); 75 } 76 77 $box = id(new PHUIObjectBoxView()) 78 ->setHeaderText($group->getGroupName()) 79 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 80 ->appendChild($list); 81 82 $boxes[] = $box; 83 } 84 85 $crumbs = $this->buildApplicationCrumbs() 86 ->addTextCrumb($plan_title, $cancel_uri) 87 ->addTextCrumb(pht('Add Build Step')) 88 ->setBorder(true); 89 90 $title = array($plan_title, pht('Add Build Step')); 91 92 $header = id(new PHUIHeaderView()) 93 ->setHeader(pht('Add Build Step')) 94 ->setHeaderIcon('fa-plus-square'); 95 96 $view = id(new PHUITwoColumnView()) 97 ->setHeader($header) 98 ->setFooter(array( 99 $boxes, 100 )); 101 102 return $this->newPage() 103 ->setTitle($title) 104 ->setCrumbs($crumbs) 105 ->appendChild($view); 106 107 } 108 109}