protected function execute(ConduitAPIRequest $request)
 {
     $user = $request->getUser()->getPHID();
     $phid = $request->getValue('objectPHID');
     $new = false;
     $flag = id(new PhabricatorFlag())->loadOneWhere('objectPHID = %s AND ownerPHID = %s', $phid, $user);
     if ($flag) {
         $params = $request->getAllParameters();
         if (isset($params['color'])) {
             $flag->setColor($params['color']);
         }
         if (isset($params['note'])) {
             $flag->setNote($params['note']);
         }
     } else {
         $default_color = PhabricatorFlagColor::COLOR_BLUE;
         $flag = id(new PhabricatorFlag())->setOwnerPHID($user)->setType(phid_get_type($phid))->setObjectPHID($phid)->setReasonPHID($user)->setColor($request->getValue('color', $default_color))->setNote($request->getValue('note', ''));
         $new = true;
     }
     $this->attachHandleToFlag($flag, $request->getUser());
     $flag->save();
     $ret = $this->buildFlagInfoDictionary($flag);
     $ret['new'] = $new;
     return $ret;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $id = $request->getValue('id');
     $phid = $request->getValue('phid');
     if ($id && $phid || !$id && !$phid) {
         throw new Exception(pht("Specify exactly one of '%s' and '%s'.", 'id', 'phid'));
     }
     $query = id(new ManiphestTaskQuery())->setViewer($request->getUser())->needSubscriberPHIDs(true)->needProjectPHIDs(true);
     if ($id) {
         $query->withIDs(array($id));
     } else {
         $query->withPHIDs(array($phid));
     }
     $task = $query->executeOne();
     $params = $request->getAllParameters();
     unset($params['id']);
     unset($params['phid']);
     if (call_user_func_array('coalesce', $params) === null) {
         throw new ConduitException('ERR-NO-EFFECT');
     }
     if (!$task) {
         throw new ConduitException('ERR-BAD-TASK');
     }
     $task = $this->applyRequest($task, $request, $is_new = false);
     return $this->buildTaskInfoDictionary($task);
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $results = array();
     $history = DiffusionHistoryQuery::newFromDiffusionRequest(DiffusionRequest::newFromAphrontRequestDictionary($request->getAllParameters()))->setLimit(self::RESULT_LIMIT)->needDirectChanges(true)->needChildChanges(true)->loadHistory();
     $raw_commit_identifiers = mpull($history, 'getCommitIdentifier');
     $result = array();
     foreach ($raw_commit_identifiers as $id) {
         $result[] = 'r' . $request->getValue('callsign') . $id;
     }
     return $result;
 }
 private function buildHumanReadableResponse($method, ConduitAPIRequest $request = null, $result = null)
 {
     $param_rows = array();
     $param_rows[] = array('Method', $this->renderAPIValue($method));
     if ($request) {
         foreach ($request->getAllParameters() as $key => $value) {
             $param_rows[] = array(phutil_escape_html($key), $this->renderAPIValue($value));
         }
     }
     $param_table = new AphrontTableView($param_rows);
     $param_table->setColumnClasses(array('header', 'wide'));
     $result_rows = array();
     foreach ($result as $key => $value) {
         $result_rows[] = array(phutil_escape_html($key), $this->renderAPIValue($value));
     }
     $result_table = new AphrontTableView($result_rows);
     $result_table->setColumnClasses(array('header', 'wide'));
     $param_panel = new AphrontPanelView();
     $param_panel->setHeader('Method Parameters');
     $param_panel->appendChild($param_table);
     $result_panel = new AphrontPanelView();
     $result_panel->setHeader('Method Result');
     $result_panel->appendChild($result_table);
     return $this->buildStandardPageResponse(array($param_panel, $result_panel), array('title' => 'Method Call Result'));
 }
 private function buildHumanReadableResponse($method, ConduitAPIRequest $request = null, $result = null, ConduitAPIMethod $method_implementation = null)
 {
     $param_rows = array();
     $param_rows[] = array('Method', $this->renderAPIValue($method));
     if ($request) {
         foreach ($request->getAllParameters() as $key => $value) {
             $param_rows[] = array($key, $this->renderAPIValue($value));
         }
     }
     $param_table = new AphrontTableView($param_rows);
     $param_table->setColumnClasses(array('header', 'wide'));
     $result_rows = array();
     foreach ($result as $key => $value) {
         $result_rows[] = array($key, $this->renderAPIValue($value));
     }
     $result_table = new AphrontTableView($result_rows);
     $result_table->setColumnClasses(array('header', 'wide'));
     $param_panel = new PHUIObjectBoxView();
     $param_panel->setHeaderText(pht('Method Parameters'));
     $param_panel->setTable($param_table);
     $result_panel = new PHUIObjectBoxView();
     $result_panel->setHeaderText(pht('Method Result'));
     $result_panel->setTable($result_table);
     $method_uri = $this->getApplicationURI('method/' . $method . '/');
     $crumbs = $this->buildApplicationCrumbs()->addTextCrumb($method, $method_uri)->addTextCrumb(pht('Call'));
     $example_panel = null;
     if ($request && $method_implementation) {
         $params = $request->getAllParameters();
         $example_panel = $this->renderExampleBox($method_implementation, $params);
     }
     return $this->buildApplicationPage(array($crumbs, $param_panel, $result_panel, $example_panel), array('title' => pht('Method Call Result')));
 }
 private function buildHumanReadableResponse($method, ConduitAPIRequest $request = null, $result = null, ConduitAPIMethod $method_implementation = null)
 {
     $param_rows = array();
     $param_rows[] = array('Method', $this->renderAPIValue($method));
     if ($request) {
         foreach ($request->getAllParameters() as $key => $value) {
             $param_rows[] = array($key, $this->renderAPIValue($value));
         }
     }
     $param_table = new AphrontTableView($param_rows);
     $param_table->setColumnClasses(array('header', 'wide'));
     $result_rows = array();
     foreach ($result as $key => $value) {
         $result_rows[] = array($key, $this->renderAPIValue($value));
     }
     $result_table = new AphrontTableView($result_rows);
     $result_table->setColumnClasses(array('header', 'wide'));
     $param_panel = id(new PHUIObjectBoxView())->setHeaderText(pht('Method Parameters'))->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setTable($param_table);
     $result_panel = id(new PHUIObjectBoxView())->setHeaderText(pht('Method Result'))->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setTable($result_table);
     $method_uri = $this->getApplicationURI('method/' . $method . '/');
     $crumbs = $this->buildApplicationCrumbs()->addTextCrumb($method, $method_uri)->addTextCrumb(pht('Call'))->setBorder(true);
     $example_panel = null;
     if ($request && $method_implementation) {
         $params = $request->getAllParameters();
         $example_panel = $this->renderExampleBox($method_implementation, $params);
     }
     $title = pht('Method Call Result');
     $header = id(new PHUIHeaderView())->setHeader($title)->setHeaderIcon('fa-exchange');
     $view = id(new PHUITwoColumnView())->setHeader($header)->setFooter(array($param_panel, $result_panel, $example_panel));
     $title = pht('Method Call Result');
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view);
 }
 /**
  * This method is final because most queries will need to construct a
  * @{class:DiffusionRequest} and use it. Consolidating this codepath and
  * enforcing @{method:getDiffusionRequest} works when we need it is good.
  *
  * @{method:getResult} should be overridden by subclasses as necessary, e.g.
  * there is a common operation across all version control systems that
  * should occur after @{method:getResult}, like formatting a timestamp.
  */
 protected final function execute(ConduitAPIRequest $request)
 {
     $drequest = DiffusionRequest::newFromDictionary(array('user' => $request->getUser(), 'callsign' => $request->getValue('callsign'), 'branch' => $request->getValue('branch'), 'path' => $request->getValue('path'), 'commit' => $request->getValue('commit')));
     // Figure out whether we're going to handle this request on this device,
     // or proxy it to another node in the cluster.
     // If this is a cluster request and we need to proxy, we'll explode here
     // to prevent infinite recursion.
     $is_cluster_request = $request->getIsClusterRequest();
     $repository = $drequest->getRepository();
     $client = $repository->newConduitClient($request->getUser(), $is_cluster_request);
     if ($client) {
         // We're proxying, so just make an intracluster call.
         return $client->callMethodSynchronous($this->getAPIMethodName(), $request->getAllParameters());
     } else {
         // We pass this flag on to prevent proxying of any other Conduit calls
         // which we need to make in order to respond to this one. Although we
         // could safely proxy them, we take a big performance hit in the common
         // case, and doing more proxying wouldn't exercise any additional code so
         // we wouldn't gain a testability/predictability benefit.
         $drequest->setIsClusterRequest($is_cluster_request);
         $this->setDiffusionRequest($drequest);
         return $this->getResult($request);
     }
 }
 /**
  * This method is final because most queries will need to construct a
  * @{class:DiffusionRequest} and use it. Consolidating this codepath and
  * enforcing @{method:getDiffusionRequest} works when we need it is good.
  *
  * @{method:getResult} should be overridden by subclasses as necessary, e.g.
  * there is a common operation across all version control systems that
  * should occur after @{method:getResult}, like formatting a timestamp.
  */
 protected final function execute(ConduitAPIRequest $request)
 {
     $identifier = $request->getValue('repository');
     if ($identifier === null) {
         $identifier = $request->getValue('callsign');
     }
     $drequest = DiffusionRequest::newFromDictionary(array('user' => $request->getUser(), 'repository' => $identifier, 'branch' => $request->getValue('branch'), 'path' => $request->getValue('path'), 'commit' => $request->getValue('commit')));
     if (!$drequest) {
         throw new Exception(pht('Repository "%s" is not a valid repository.', $identifier));
     }
     // Figure out whether we're going to handle this request on this device,
     // or proxy it to another node in the cluster.
     // If this is a cluster request and we need to proxy, we'll explode here
     // to prevent infinite recursion.
     $is_cluster_request = $request->getIsClusterRequest();
     $viewer = $request->getUser();
     $repository = $drequest->getRepository();
     $client = $repository->newConduitClient($viewer, $is_cluster_request);
     if ($client) {
         // We're proxying, so just make an intracluster call.
         return $client->callMethodSynchronous($this->getAPIMethodName(), $request->getAllParameters());
     } else {
         // We pass this flag on to prevent proxying of any other Conduit calls
         // which we need to make in order to respond to this one. Although we
         // could safely proxy them, we take a big performance hit in the common
         // case, and doing more proxying wouldn't exercise any additional code so
         // we wouldn't gain a testability/predictability benefit.
         $drequest->setIsClusterRequest($is_cluster_request);
         $this->setDiffusionRequest($drequest);
         // TODO: Allow web UI queries opt out of this if they don't care about
         // fetching the most up-to-date data? Synchronization can be slow, and a
         // lot of web reads are probably fine if they're a few seconds out of
         // date.
         id(new DiffusionRepositoryClusterEngine())->setViewer($viewer)->setRepository($repository)->synchronizeWorkingCopyBeforeRead();
         return $this->getResult($request);
     }
 }
 private function buildHumanReadableResponse($method, ConduitAPIRequest $request = null, $result = null)
 {
     $param_rows = array();
     $param_rows[] = array('Method', $this->renderAPIValue($method));
     if ($request) {
         foreach ($request->getAllParameters() as $key => $value) {
             $param_rows[] = array($key, $this->renderAPIValue($value));
         }
     }
     $param_table = new AphrontTableView($param_rows);
     $param_table->setDeviceReadyTable(true);
     $param_table->setColumnClasses(array('header', 'wide'));
     $result_rows = array();
     foreach ($result as $key => $value) {
         $result_rows[] = array($key, $this->renderAPIValue($value));
     }
     $result_table = new AphrontTableView($result_rows);
     $result_table->setDeviceReadyTable(true);
     $result_table->setColumnClasses(array('header', 'wide'));
     $param_panel = new AphrontPanelView();
     $param_panel->setHeader('Method Parameters');
     $param_panel->appendChild($param_table);
     $result_panel = new AphrontPanelView();
     $result_panel->setHeader('Method Result');
     $result_panel->appendChild($result_table);
     $param_head = id(new PHUIHeaderView())->setHeader(pht('Method Parameters'));
     $result_head = id(new PHUIHeaderView())->setHeader(pht('Method Result'));
     $method_uri = $this->getApplicationURI('method/' . $method . '/');
     $crumbs = $this->buildApplicationCrumbs()->addTextCrumb($method, $method_uri)->addTextCrumb(pht('Call'));
     return $this->buildApplicationPage(array($crumbs, $param_head, $param_table, $result_head, $result_table), array('title' => 'Method Call Result'));
 }