Path: blob/master/src/applications/harbormaster/herald/HarbormasterRunBuildPlansHeraldAction.php
12256 views
<?php12final class HarbormasterRunBuildPlansHeraldAction3extends HeraldAction {45const DO_BUILD = 'do.build';67const ACTIONCONST = 'harbormaster.build';89public function getRequiredAdapterStates() {10return array(11HeraldBuildableState::STATECONST,12);13}1415public function getActionGroupKey() {16return HeraldSupportActionGroup::ACTIONGROUPKEY;17}1819public function supportsObject($object) {20$adapter = $this->getAdapter();21return ($adapter instanceof HarbormasterBuildableAdapterInterface);22}2324protected function applyBuilds(array $phids, HeraldRule $rule) {25$adapter = $this->getAdapter();2627$allowed_types = array(28HarbormasterBuildPlanPHIDType::TYPECONST,29);3031$targets = $this->loadStandardTargets($phids, $allowed_types, array());32if (!$targets) {33return;34}3536$phids = array_fuse(array_keys($targets));3738foreach ($phids as $phid) {39$request = id(new HarbormasterBuildRequest())40->setBuildPlanPHID($phid)41->setInitiatorPHID($rule->getPHID());42$adapter->queueHarbormasterBuildRequest($request);43}4445$this->logEffect(self::DO_BUILD, $phids);46}4748protected function getActionEffectMap() {49return array(50self::DO_BUILD => array(51'icon' => 'fa-play',52'color' => 'green',53'name' => pht('Building'),54),55);56}5758protected function renderActionEffectDescription($type, $data) {59switch ($type) {60case self::DO_BUILD:61return pht(62'Started %s build(s): %s.',63phutil_count($data),64$this->renderHandleList($data));65}66}6768public function getHeraldActionName() {69return pht('Run build plans');70}7172public function supportsRuleType($rule_type) {73return ($rule_type != HeraldRuleTypeConfig::RULE_TYPE_PERSONAL);74}7576public function applyEffect($object, HeraldEffect $effect) {77return $this->applyBuilds($effect->getTarget(), $effect->getRule());78}7980public function getHeraldActionStandardType() {81return self::STANDARD_PHID_LIST;82}8384protected function getDatasource() {85return new HarbormasterBuildPlanDatasource();86}8788public function renderActionDescription($value) {89return pht(90'Run build plans: %s.',91$this->renderHandleList($value));92}9394public function getPHIDsAffectedByAction(HeraldActionRecord $record) {95return $record->getTarget();96}9798public function isActionAvailable() {99return id(new PhabricatorHarbormasterApplication())->isInstalled();100}101102}103104105