private function buildBindingList(AlmanacService $service)
 {
     $viewer = $this->getViewer();
     $id = $service->getID();
     $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $service, PhabricatorPolicyCapability::CAN_EDIT);
     $bindings = id(new AlmanacBindingQuery())->setViewer($viewer)->withServicePHIDs(array($service->getPHID()))->execute();
     $table = id(new AlmanacBindingTableView())->setNoDataString(pht('This service has not been bound to any device interfaces yet.'))->setUser($viewer)->setBindings($bindings);
     $header = id(new PHUIHeaderView())->setHeader(pht('Service Bindings'))->addActionLink(id(new PHUIButtonView())->setTag('a')->setHref($this->getApplicationURI("binding/edit/?serviceID={$id}"))->setWorkflow(!$can_edit)->setDisabled(!$can_edit)->setText(pht('Add Binding'))->setIcon('fa-plus'));
     return id(new PHUIObjectBoxView())->setHeader($header)->setTable($table);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $list_uri = $this->getApplicationURI('service/');
     $id = $request->getURIData('id');
     if ($id) {
         $service = id(new AlmanacServiceQuery())->setViewer($viewer)->withIDs(array($id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
         if (!$service) {
             return new Aphront404Response();
         }
         $is_new = false;
         $service_uri = $service->getURI();
         $cancel_uri = $service_uri;
         $title = pht('Edit Service');
         $save_button = pht('Save Changes');
     } else {
         $cancel_uri = $list_uri;
         $this->requireApplicationCapability(AlmanacCreateServicesCapability::CAPABILITY);
         $service_class = $request->getStr('serviceClass');
         $service_types = AlmanacServiceType::getAllServiceTypes();
         if (empty($service_types[$service_class])) {
             return $this->buildServiceTypeResponse($service_types, $cancel_uri);
         }
         $service_type = $service_types[$service_class];
         if ($service_type->isClusterServiceType()) {
             $this->requireApplicationCapability(AlmanacCreateClusterServicesCapability::CAPABILITY);
         }
         $service = AlmanacService::initializeNewService();
         $service->setServiceClass($service_class);
         $service->attachServiceType($service_type);
         $is_new = true;
         $title = pht('Create Service');
         $save_button = pht('Create Service');
     }
     $v_name = $service->getName();
     $e_name = true;
     $validation_exception = null;
     if ($is_new) {
         $v_projects = array();
     } else {
         $v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs($service->getPHID(), PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
         $v_projects = array_reverse($v_projects);
     }
     if ($request->isFormPost() && $request->getStr('edit')) {
         $v_name = $request->getStr('name');
         $v_view = $request->getStr('viewPolicy');
         $v_edit = $request->getStr('editPolicy');
         $v_projects = $request->getArr('projects');
         $type_name = AlmanacServiceTransaction::TYPE_NAME;
         $type_view = PhabricatorTransactions::TYPE_VIEW_POLICY;
         $type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY;
         $xactions = array();
         $xactions[] = id(new AlmanacServiceTransaction())->setTransactionType($type_name)->setNewValue($v_name);
         $xactions[] = id(new AlmanacServiceTransaction())->setTransactionType($type_view)->setNewValue($v_view);
         $xactions[] = id(new AlmanacServiceTransaction())->setTransactionType($type_edit)->setNewValue($v_edit);
         $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
         $xactions[] = id(new AlmanacServiceTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', $proj_edge_type)->setNewValue(array('=' => array_fuse($v_projects)));
         $editor = id(new AlmanacServiceEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true);
         try {
             $editor->applyTransactions($service, $xactions);
             $service_uri = $service->getURI();
             return id(new AphrontRedirectResponse())->setURI($service_uri);
         } catch (PhabricatorApplicationTransactionValidationException $ex) {
             $validation_exception = $ex;
             $e_name = $ex->getShortMessage($type_name);
             $service->setViewPolicy($v_view);
             $service->setEditPolicy($v_edit);
         }
     }
     $policies = id(new PhabricatorPolicyQuery())->setViewer($viewer)->setObject($service)->execute();
     $form = id(new AphrontFormView())->setUser($viewer)->addHiddenInput('edit', true)->addHiddenInput('serviceClass', $service->getServiceClass())->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Name'))->setName('name')->setValue($v_name)->setError($e_name))->appendChild(id(new AphrontFormPolicyControl())->setName('viewPolicy')->setPolicyObject($service)->setCapability(PhabricatorPolicyCapability::CAN_VIEW)->setPolicies($policies))->appendChild(id(new AphrontFormPolicyControl())->setName('editPolicy')->setPolicyObject($service)->setCapability(PhabricatorPolicyCapability::CAN_EDIT)->setPolicies($policies))->appendControl(id(new AphrontFormTokenizerControl())->setLabel(pht('Projects'))->setName('projects')->setValue($v_projects)->setDatasource(new PhabricatorProjectDatasource()))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($cancel_uri)->setValue($save_button));
     $box = id(new PHUIObjectBoxView())->setValidationException($validation_exception)->setHeaderText($title)->appendChild($form);
     $crumbs = $this->buildApplicationCrumbs();
     if ($is_new) {
         $crumbs->addTextCrumb(pht('Create Service'));
     } else {
         $crumbs->addTextCrumb($service->getName(), $service_uri);
         $crumbs->addTextCrumb(pht('Edit'));
     }
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild(array($box));
 }
 protected function newEditableObject()
 {
     $service_type = $this->getServiceType();
     return AlmanacService::initializeNewService($service_type);
 }
<?php

// Previously, Almanac services stored a "serviceClass". Migrate these to
// new "serviceType" values.
$table = new AlmanacService();
$conn_w = $table->establishConnection('w');
foreach (new LiskMigrationIterator($table) as $service) {
    $new_type = null;
    try {
        $old_type = $service->getServiceType();
        $object = newv($old_type, array());
        $new_type = $object->getServiceTypeConstant();
    } catch (Exception $ex) {
        continue;
    }
    if (!$new_type) {
        continue;
    }
    queryfx($conn_w, 'UPDATE %T SET serviceType = %s WHERE id = %d', $table->getTableName(), $new_type, $service->getID());
}
Example #5
0
 public static function initializeNewBinding(AlmanacService $service)
 {
     return id(new AlmanacBinding())->setServicePHID($service->getPHID())->attachAlmanacProperties(array());
 }
 protected function getServiceDictionary(AlmanacService $service)
 {
     return array('id' => (int) $service->getID(), 'phid' => $service->getPHID(), 'name' => $service->getName(), 'uri' => PhabricatorEnv::getProductionURI($service->getURI()), 'serviceClass' => $service->getServiceClass(), 'properties' => $this->getPropertiesDictionary($service));
 }
 public function newResultObject()
 {
     // NOTE: We need to attach a service type in order to generate custom
     // field definitions.
     return AlmanacService::initializeNewService()->attachServiceType(new AlmanacCustomServiceType());
 }