protected function execute(ConduitAPIRequest $request)
 {
     $query = new PhameBlogQuery();
     $query->setViewer($request->getUser());
     $ids = $request->getValue('ids', array());
     if ($ids) {
         $query->withIDs($ids);
     }
     $phids = $request->getValue('phids', array());
     if ($phids) {
         $query->withPHIDs($phids);
     }
     $after = $request->getValue('after', null);
     if ($after !== null) {
         $query->setAfterID($after);
     }
     $before = $request->getValue('before', null);
     if ($before !== null) {
         $query->setBeforeID($before);
     }
     $limit = $request->getValue('limit', null);
     if ($limit !== null) {
         $query->setLimit($limit);
     }
     $blogs = $query->execute();
     $results = array();
     foreach ($blogs as $blog) {
         $results[] = array('id' => $blog->getID(), 'phid' => $blog->getPHID(), 'name' => $blog->getName(), 'description' => $blog->getDescription(), 'domain' => $blog->getDomain(), 'creatorPHID' => $blog->getCreatorPHID());
     }
     return $results;
 }
 protected function getGitResult(ConduitAPIRequest $request)
 {
     $drequest = $this->getDiffusionRequest();
     $repository = $drequest->getRepository();
     $commit = $drequest->getSymbolicCommit();
     $commit_filter = null;
     if ($commit) {
         $commit_filter = $this->loadTagNamesForCommit($commit);
     }
     $name_filter = $request->getValue('names', null);
     $all_tags = $this->loadGitTagList();
     $all_tags = mpull($all_tags, null, 'getName');
     if ($name_filter !== null) {
         $all_tags = array_intersect_key($all_tags, array_fuse($name_filter));
     }
     if ($commit_filter !== null) {
         $all_tags = array_intersect_key($all_tags, $commit_filter);
     }
     $tags = array_values($all_tags);
     $offset = $request->getValue('offset');
     $limit = $request->getValue('limit');
     if ($offset) {
         $tags = array_slice($tags, $offset);
     }
     if ($limit) {
         $tags = array_slice($tags, 0, $limit);
     }
     if ($request->getValue('needMessages')) {
         $this->loadMessagesForTags($all_tags);
     }
     return mpull($tags, 'toDictionary');
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $is_owner_query = $request->getValue('userOwner') || $request->getValue('projectOwner') ? 1 : 0;
     $is_affiliated_query = $request->getValue('userAffiliated') ? 1 : 0;
     $repo = $request->getValue('repositoryCallsign');
     $path = $request->getValue('path');
     $is_path_query = $repo ? 1 : 0;
     if ($is_owner_query + $is_path_query + $is_affiliated_query === 0) {
         // if no search terms are provided, return everything
         $packages = self::queryAll();
     } else {
         if ($is_owner_query + $is_path_query + $is_affiliated_query > 1) {
             // otherwise, exactly one of these should be provided
             throw new ConduitException('ERR-INVALID-USAGE');
         }
     }
     if ($is_affiliated_query) {
         $query = id(new PhabricatorOwnersPackageQuery())->setViewer($request->getUser());
         $query->withOwnerPHIDs(array($request->getValue('userAffiliated')));
         $packages = $query->execute();
     } else {
         if ($is_owner_query) {
             $owner = nonempty($request->getValue('userOwner'), $request->getValue('projectOwner'));
             $packages = self::queryByOwner($owner);
         } else {
             if ($is_path_query) {
                 $packages = self::queryByPath($request->getUser(), $repo, $path);
             }
         }
     }
     return self::buildPackageInformationDictionaries($packages);
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $query = new PhabricatorFlagQuery();
     $query->setViewer($request->getUser());
     $owner_phids = $request->getValue('ownerPHIDs', array());
     if ($owner_phids) {
         $query->withOwnerPHIDs($owner_phids);
     }
     $object_phids = $request->getValue('objectPHIDs', array());
     if ($object_phids) {
         $query->withObjectPHIDs($object_phids);
     }
     $types = $request->getValue('types', array());
     if ($types) {
         $query->withTypes($types);
     }
     $query->needHandles(true);
     $query->setOffset($request->getValue('offset', 0));
     $query->setLimit($request->getValue('limit', 100));
     $flags = $query->execute();
     $results = array();
     foreach ($flags as $flag) {
         $results[] = $this->buildFlagInfoDictionary($flag);
     }
     return $results;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $diff = id(new DifferentialDiff())->load($request->getValue('diffid'));
     if (!$diff) {
         throw new ConduitException('ERR_BAD_DIFF');
     }
     $revision = id(new DifferentialRevision())->load($request->getValue('id'));
     if (!$revision) {
         throw new ConduitException('ERR_BAD_REVISION');
     }
     if ($request->getUser()->getPHID() !== $revision->getAuthorPHID()) {
         throw new ConduitException('ERR_WRONG_USER');
     }
     if ($revision->getStatus() == ArcanistDifferentialRevisionStatus::CLOSED) {
         throw new ConduitException('ERR_CLOSED');
     }
     $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_CONDUIT, array());
     $editor = new DifferentialRevisionEditor($revision, $revision->getAuthorPHID());
     $editor->setContentSource($content_source);
     $fields = $request->getValue('fields');
     $editor->copyFieldsFromConduit($fields);
     $editor->addDiff($diff, $request->getValue('message'));
     $editor->save();
     return array('revisionid' => $revision->getID(), 'uri' => PhabricatorEnv::getURI('/D' . $revision->getID()));
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $source_phid = $request->getValue('sourcePHID');
     $owner_phid = $request->getValue('ownerPHID');
     $requestor_phid = $request->getValue('requestorPHID');
     $user = $request->getUser();
     $item = NuanceItem::initializeNewItem();
     $xactions = array();
     if ($source_phid) {
         $xactions[] = id(new NuanceItemTransaction())->setTransactionType(NuanceItemTransaction::TYPE_SOURCE)->setNewValue($source_phid);
     } else {
         throw new ConduitException('ERR-NO-SOURCE-PHID');
     }
     if ($owner_phid) {
         $xactions[] = id(new NuanceItemTransaction())->setTransactionType(NuanceItemTransaction::TYPE_OWNER)->setNewValue($owner_phid);
     }
     if ($requestor_phid) {
         $xactions[] = id(new NuanceItemTransaction())->setTransactionType(NuanceItemTransaction::TYPE_REQUESTOR)->setNewValue($requestor_phid);
     } else {
         throw new ConduitException('ERR-NO-REQUESTOR-PHID');
     }
     $source = PhabricatorContentSource::newFromConduitRequest($request);
     $editor = id(new NuanceItemEditor())->setActor($user)->setContentSource($source)->applyTransactions($item, $xactions);
     return $item->toDictionary();
 }
 public final function respondToConduitRequest(ConduitAPIRequest $request)
 {
     $drequest = $this->getRequest();
     $timeout = $request->getValue('timeout');
     if ($timeout) {
         $this->setTimeout($timeout);
     }
     $byte_limit = $request->getValue('byteLimit');
     if ($byte_limit) {
         $this->setByteLimit($byte_limit);
     }
     $file = $this->execute();
     $too_slow = (bool) $this->getExceededTimeLimit();
     $too_huge = (bool) $this->getExceededByteLimit();
     $file_phid = null;
     if (!$too_slow && !$too_huge) {
         $repository = $drequest->getRepository();
         $repository_phid = $repository->getPHID();
         $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
         $file->attachToObject($repository_phid);
         unset($unguarded);
         $file_phid = $file->getPHID();
     }
     return array('tooSlow' => $too_slow, 'tooHuge' => $too_huge, 'filePHID' => $file_phid);
 }
 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)
 {
     $commit_phid = $request->getValue('phid');
     $commit = id(new DiffusionCommitQuery())->setViewer($request->getUser())->withPHIDs(array($commit_phid))->needAuditRequests(true)->executeOne();
     if (!$commit) {
         throw new ConduitException('ERR_BAD_COMMIT');
     }
     $message = trim($request->getValue('message'));
     if (!$message) {
         throw new ConduitException('ERR_MISSING_MESSAGE');
     }
     $action = $request->getValue('action');
     if (!$action) {
         $action = PhabricatorAuditActionConstants::COMMENT;
     }
     // Disallow ADD_CCS, ADD_AUDITORS forever.
     if (!in_array($action, array(PhabricatorAuditActionConstants::CONCERN, PhabricatorAuditActionConstants::ACCEPT, PhabricatorAuditActionConstants::COMMENT, PhabricatorAuditActionConstants::RESIGN, PhabricatorAuditActionConstants::CLOSE))) {
         throw new ConduitException('ERR_BAD_ACTION');
     }
     $xactions = array();
     if ($action != PhabricatorAuditActionConstants::COMMENT) {
         $xactions[] = id(new PhabricatorAuditTransaction())->setTransactionType(PhabricatorAuditActionConstants::ACTION)->setNewValue($action);
     }
     if (strlen($message)) {
         $xactions[] = id(new PhabricatorAuditTransaction())->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)->attachComment(id(new PhabricatorAuditTransactionComment())->setCommitPHID($commit->getPHID())->setContent($message));
     }
     id(new PhabricatorAuditEditor())->setActor($request->getUser())->setContentSourceFromConduitRequest($request)->setDisableEmail($request->getValue('silent'))->setContinueOnMissingFields(true)->applyTransactions($commit, $xactions);
     return true;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $id = $request->getValue('id');
     $object = $request->getValue('objectPHID');
     if ($id) {
         $flag = id(new PhabricatorFlag())->load($id);
         if (!$flag) {
             throw new ConduitException('ERR_NOT_FOUND');
         }
         if ($flag->getOwnerPHID() != $request->getUser()->getPHID()) {
             throw new ConduitException('ERR_WRONG_USER');
         }
     } else {
         if ($object) {
             $flag = id(new PhabricatorFlag())->loadOneWhere('objectPHID = %s AND ownerPHID = %s', $object, $request->getUser()->getPHID());
             if (!$flag) {
                 return null;
             }
         } else {
             throw new ConduitException('ERR_NEED_PARAM');
         }
     }
     $this->attachHandleToFlag($flag, $request->getUser());
     $ret = $this->buildFlagInfoDictionary($flag);
     $flag->delete();
     return $ret;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $diff_id = $request->getValue('diff_id');
     $name = $request->getValue('name');
     $data = json_decode($request->getValue('data'), true);
     self::updateDiffProperty($diff_id, $name, $data);
 }
 protected function getResult(ConduitAPIRequest $request)
 {
     $drequest = $this->getDiffusionRequest();
     $repository = $drequest->getRepository();
     if (!$repository->isGit()) {
         throw new Exception(pht('This API method can only be called on Git repositories.'));
     }
     // Check if the commit has parents. We're testing to see whether it is the
     // first commit in history (in which case we must use "git log") or some
     // other commit (in which case we can use "git diff"). We'd rather use
     // "git diff" because it has the right behavior for merge commits, but
     // it requires the commit to have a parent that we can diff against. The
     // first commit doesn't, so "commit^" is not a valid ref.
     list($parents) = $repository->execxLocalCommand('log -n1 --format=%s %s', '%P', $request->getValue('commit'));
     $use_log = !strlen(trim($parents));
     if ($use_log) {
         // This is the first commit so we need to use "log". We know it's not a
         // merge commit because it couldn't be merging anything, so this is safe.
         // NOTE: "--pretty=format: " is to disable diff output, we only want the
         // part we get from "--raw".
         list($raw) = $repository->execxLocalCommand('log -n1 -M -C -B --find-copies-harder --raw -t ' . '--pretty=format: --abbrev=40 %s', $request->getValue('commit'));
     } else {
         // Otherwise, we can use "diff", which will give us output for merges.
         // We diff against the first parent, as this is generally the expectation
         // and results in sensible behavior.
         list($raw) = $repository->execxLocalCommand('diff -n1 -M -C -B --find-copies-harder --raw -t ' . '--abbrev=40 %s^1 %s', $request->getValue('commit'), $request->getValue('commit'));
     }
     return $raw;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $name = $request->getValue('name');
     $name_prefix = $request->getValue('namePrefix');
     $language = $request->getValue('language');
     $type = $request->getValue('type');
     $query = new DiffusionSymbolQuery();
     if ($name !== null) {
         $query->setName($name);
     }
     if ($name_prefix !== null) {
         $query->setNamePrefix($name_prefix);
     }
     if ($language !== null) {
         $query->setLanguage($language);
     }
     if ($type !== null) {
         $query->setType($type);
     }
     $query->needPaths(true);
     $query->needArcanistProjects(true);
     $query->needRepositories(true);
     $results = $query->execute();
     $response = array();
     foreach ($results as $result) {
         $response[] = array('name' => $result->getSymbolName(), 'type' => $result->getSymbolType(), 'language' => $result->getSymbolLanguage(), 'path' => $result->getPath(), 'line' => $result->getLineNumber(), 'uri' => PhabricatorEnv::getProductionURI($result->getURI()));
     }
     return $response;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $viewer = $request->getUser();
     $query = id(new ReleephProductQuery())->setViewer($viewer);
     $ids = $request->getValue('ids');
     if ($ids !== null) {
         $query->withIDs($ids);
     }
     $phids = $request->getValue('phids');
     if ($phids !== null) {
         $query->withPHIDs($phids);
     }
     $repository_phids = $request->getValue('repositoryPHIDs');
     if ($repository_phids !== null) {
         $query->withRepositoryPHIDs($repository_phids);
     }
     $is_active = $request->getValue('isActive');
     if ($is_active !== null) {
         $query->withActive($is_active);
     }
     $pager = $this->newPager($request);
     $products = $query->executeWithCursorPager($pager);
     $data = array();
     foreach ($products as $product) {
         $id = $product->getID();
         $uri = '/releeph/product/' . $id . '/';
         $uri = PhabricatorEnv::getProductionURI($uri);
         $data[] = array('id' => $id, 'phid' => $product->getPHID(), 'uri' => $uri, 'name' => $product->getName(), 'isActive' => (bool) $product->getIsActive(), 'repositoryPHID' => $product->getRepositoryPHID());
     }
     return $this->addPagerResults(array('data' => $data), $pager);
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $user = $request->getUser();
     $ids = $request->getValue('ids', array());
     $phids = $request->getValue('phids', array());
     $limit = $request->getValue('limit');
     $offset = $request->getValue('offset');
     $query = id(new ConpherenceThreadQuery())->setViewer($user)->needParticipantCache(true)->needFilePHIDs(true);
     if ($ids) {
         $conpherences = $query->withIDs($ids)->setLimit($limit)->setOffset($offset)->execute();
     } else {
         if ($phids) {
             $conpherences = $query->withPHIDs($phids)->setLimit($limit)->setOffset($offset)->execute();
         } else {
             $participation = id(new ConpherenceParticipantQuery())->withParticipantPHIDs(array($user->getPHID()))->setLimit($limit)->setOffset($offset)->execute();
             $conpherence_phids = array_keys($participation);
             $query->withPHIDs($conpherence_phids);
             $conpherences = $query->execute();
             $conpherences = array_select_keys($conpherences, $conpherence_phids);
         }
     }
     $data = array();
     foreach ($conpherences as $conpherence) {
         $id = $conpherence->getID();
         $data[$id] = array('conpherenceID' => $id, 'conpherencePHID' => $conpherence->getPHID(), 'conpherenceTitle' => $conpherence->getTitle(), 'messageCount' => $conpherence->getMessageCount(), 'recentParticipantPHIDs' => $conpherence->getRecentParticipantPHIDs(), 'filePHIDs' => $conpherence->getFilePHIDs(), 'conpherenceURI' => $this->getConpherenceURI($conpherence));
     }
     return $data;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $viewer = $request->getUser();
     $phid = $request->getValue('objectPHID');
     // NOTE: We use withNames() to let monograms like "D123" work, which makes
     // this a little easier to test. Real PHIDs will still work as expected.
     $object = id(new PhabricatorObjectQuery())->setViewer($viewer)->withNames(array($phid))->executeOne();
     if (!$object) {
         throw new Exception(pht('No such object "%s" exists.', $phid));
     }
     if (!$object instanceof HarbormasterBuildableInterface) {
         throw new Exception(pht('Object "%s" does not implement interface "%s". Autotargets may ' . 'only be queried for buildable objects.', $phid, 'HarbormasterBuildableInterface'));
     }
     $autotargets = $request->getValue('targetKeys', array());
     if ($autotargets) {
         $targets = id(new HarbormasterTargetEngine())->setViewer($viewer)->setObject($object)->setAutoTargetKeys($autotargets)->buildTargets();
     } else {
         $targets = array();
     }
     // Reorder the results according to the request order so we can make test
     // assertions that subsequent calls return the same results.
     $map = mpull($targets, 'getPHID');
     $map = array_select_keys($map, $autotargets);
     return array('targetMap' => $map);
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $results = array();
     $revision_ids = $request->getValue('ids');
     if (!$revision_ids) {
         return $results;
     }
     $comments = id(new DifferentialComment())->loadAllWhere('revisionID IN (%Ld)', $revision_ids);
     $with_inlines = $request->getValue('inlines');
     if ($with_inlines) {
         $inlines = id(new DifferentialInlineComment())->loadAllWhere('revisionID IN (%Ld)', $revision_ids);
         $changesets = array();
         if ($inlines) {
             $changesets = id(new DifferentialChangeset())->loadAllWhere('id IN (%Ld)', array_unique(mpull($inlines, 'getChangesetID')));
             $inlines = mgroup($inlines, 'getCommentID');
         }
     }
     foreach ($comments as $comment) {
         $revision_id = $comment->getRevisionID();
         $result = array('revisionID' => $revision_id, 'action' => $comment->getAction(), 'authorPHID' => $comment->getAuthorPHID(), 'dateCreated' => $comment->getDateCreated(), 'content' => $comment->getContent());
         if ($with_inlines) {
             $result['inlines'] = array();
             foreach (idx($inlines, $comment->getID(), array()) as $inline) {
                 $changeset = idx($changesets, $inline->getChangesetID());
                 $result['inlines'][] = $this->buildInlineInfoDictionary($inline, $changeset);
             }
             // TODO: Put synthetic inlines without an attached comment somewhere.
         }
         $results[$revision_id][] = $result;
     }
     return $results;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $query = id(new PhabricatorMacroQuery())->setViewer($request->getUser())->needFiles(true);
     $author_phids = $request->getValue('authorPHIDs');
     $phids = $request->getValue('phids');
     $ids = $request->getValue('ids');
     $name_like = $request->getValue('nameLike');
     $names = $request->getValue('names');
     if ($author_phids) {
         $query->withAuthorPHIDs($author_phids);
     }
     if ($phids) {
         $query->withPHIDs($phids);
     }
     if ($ids) {
         $query->withIDs($ids);
     }
     if ($name_like) {
         $query->withNameLike($name_like);
     }
     if ($names) {
         $query->withNames($names);
     }
     $macros = $query->execute();
     if (!$macros) {
         return array();
     }
     $results = array();
     foreach ($macros as $macro) {
         $file = $macro->getFile();
         $results[$macro->getName()] = array('uri' => $file->getBestURI(), 'phid' => $macro->getPHID(), 'authorPHID' => $file->getAuthorPHID(), 'dateCreated' => $file->getDateCreated(), 'filePHID' => $file->getPHID());
     }
     return $results;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $viewer = $request->getUser();
     $raw_diff = $request->getValue('diff');
     $repository_phid = $request->getValue('repositoryPHID');
     if ($repository_phid) {
         $repository = id(new PhabricatorRepositoryQuery())->setViewer($viewer)->withPHIDs(array($repository_phid))->executeOne();
         if (!$repository) {
             throw new Exception(pht('No such repository "%s"!', $repository_phid));
         }
     }
     $parser = new ArcanistDiffParser();
     $changes = $parser->parseDiff($raw_diff);
     $diff = DifferentialDiff::newFromRawChanges($viewer, $changes);
     // We're bounded by doing INSERTs for all the hunks and changesets, so
     // estimate the number of inserts we'll require.
     $size = 0;
     foreach ($diff->getChangesets() as $changeset) {
         $hunks = $changeset->getHunks();
         $size += 1 + count($hunks);
     }
     $raw_limit = 10000;
     if ($size > $raw_limit) {
         throw new Exception(pht('The raw diff you have submitted is too large to parse (it affects ' . 'more than %s paths and hunks). Differential should only be used ' . 'for changes which are small enough to receive detailed human ' . 'review. See "Differential User Guide: Large Changes" in the ' . 'documentation for more information.', new PhutilNumber($raw_limit)));
     }
     $diff_data_dict = array('creationMethod' => 'web', 'authorPHID' => $viewer->getPHID(), 'repositoryPHID' => $repository_phid, 'lintStatus' => DifferentialLintStatus::LINT_SKIP, 'unitStatus' => DifferentialUnitStatus::UNIT_SKIP);
     $xactions = array(id(new DifferentialDiffTransaction())->setTransactionType(DifferentialDiffTransaction::TYPE_DIFF_CREATE)->setNewValue($diff_data_dict));
     if ($request->getValue('viewPolicy')) {
         $xactions[] = id(new DifferentialDiffTransaction())->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)->setNewValue($request->getValue('viewPolicy'));
     }
     id(new DifferentialDiffEditor())->setActor($viewer)->setContentSource($request->newContentSource())->setContinueOnNoEffect(true)->setLookupRepository(false)->applyTransactions($diff, $xactions);
     return $this->buildDiffInfoDictionary($diff);
 }
 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)
 {
     $diff = null;
     $revision_id = $request->getValue('revision_id');
     if ($revision_id) {
         $revision = id(new DifferentialRevision())->load($revision_id);
         if (!$revision) {
             throw new ConduitException('ERR_BAD_REVISION');
         }
         $diff = id(new DifferentialDiff())->loadOneWhere('revisionID = %d ORDER BY id DESC LIMIT 1', $revision->getID());
     } else {
         $diff_id = $request->getValue('diff_id');
         if ($diff_id) {
             $diff = id(new DifferentialDiff())->load($diff_id);
         }
     }
     if (!$diff) {
         throw new ConduitException('ERR_BAD_DIFF');
     }
     $diff->attachChangesets($diff->loadChangesets());
     // TODO: We could batch this to improve performance.
     foreach ($diff->getChangesets() as $changeset) {
         $changeset->attachHunks($changeset->loadHunks());
     }
     return $this->createDiffDict($diff);
 }
 protected function execute(ConduitAPIRequest $conduit_request)
 {
     $revision_phids = $conduit_request->getValue('revisionPHIDs');
     $requested_commit_phids = $conduit_request->getValue('requestedCommitPHIDs');
     $result = array();
     if (!$revision_phids && !$requested_commit_phids) {
         return $result;
     }
     $query = new ReleephRequestQuery();
     $query->setViewer($conduit_request->getUser());
     if ($revision_phids) {
         $query->withRequestedObjectPHIDs($revision_phids);
     } else {
         if ($requested_commit_phids) {
             $query->withRequestedCommitPHIDs($requested_commit_phids);
         }
     }
     $releeph_requests = $query->execute();
     foreach ($releeph_requests as $releeph_request) {
         $branch = $releeph_request->getBranch();
         $request_commit_phid = $releeph_request->getRequestCommitPHID();
         $object = $releeph_request->getRequestedObject();
         if ($object instanceof DifferentialRevision) {
             $object_phid = $object->getPHID();
         } else {
             $object_phid = null;
         }
         $status = $releeph_request->getStatus();
         $status_name = ReleephRequestStatus::getStatusDescriptionFor($status);
         $url = PhabricatorEnv::getProductionURI('/RQ' . $releeph_request->getID());
         $result[] = array('branchBasename' => $branch->getBasename(), 'branchSymbolic' => $branch->getSymbolicName(), 'requestID' => $releeph_request->getID(), 'revisionPHID' => $object_phid, 'status' => $status, 'status_name' => $status_name, 'url' => $url);
     }
     return $result;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $query = id(new DiffusionCommitQuery())->setViewer($request->getUser())->needAuditRequests(true);
     $auditor_phids = $request->getValue('auditorPHIDs', array());
     if ($auditor_phids) {
         $query->withAuditorPHIDs($auditor_phids);
     }
     $commit_phids = $request->getValue('commitPHIDs', array());
     if ($commit_phids) {
         $query->withPHIDs($commit_phids);
     }
     $status = $request->getValue('status', DiffusionCommitQuery::AUDIT_STATUS_ANY);
     $query->withAuditStatus($status);
     // NOTE: These affect the number of commits identified, which is sort of
     // reasonable but means the method may return an arbitrary number of
     // actual audit requests.
     $query->setOffset($request->getValue('offset', 0));
     $query->setLimit($request->getValue('limit', 100));
     $commits = $query->execute();
     $auditor_map = array_fuse($auditor_phids);
     $results = array();
     foreach ($commits as $commit) {
         $requests = $commit->getAudits();
         foreach ($requests as $request) {
             // If this audit isn't triggered for one of the requested PHIDs,
             // skip it.
             if ($auditor_map && empty($auditor_map[$request->getAuditorPHID()])) {
                 continue;
             }
             $results[] = array('id' => $request->getID(), 'commitPHID' => $request->getCommitPHID(), 'auditorPHID' => $request->getAuditorPHID(), 'reasons' => $request->getAuditReasons(), 'status' => $request->getAuditStatus());
         }
     }
     return $results;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $viewer = $request->getUser();
     $query = id(new PhabricatorAuthSSHKeyQuery())->setViewer($viewer);
     $ids = $request->getValue('ids');
     if ($ids !== null) {
         $query->withIDs($ids);
     }
     $phids = $request->getValue('phids');
     if ($phids !== null) {
         $query->withPHIDs($phids);
     }
     $object_phids = $request->getValue('objectPHIDs');
     if ($object_phids !== null) {
         $query->withObjectPHIDs($object_phids);
     }
     $keys = $request->getValue('keys');
     if ($keys !== null) {
         $key_objects = array();
         foreach ($keys as $key) {
             $key_objects[] = PhabricatorAuthSSHPublicKey::newFromRawKey($key);
         }
         $query->withKeys($key_objects);
     }
     $pager = $this->newPager($request);
     $public_keys = $query->executeWithCursorPager($pager);
     $data = array();
     foreach ($public_keys as $public_key) {
         $data[] = array('id' => $public_key->getID(), 'name' => $public_key->getName(), 'phid' => $public_key->getPHID(), 'objectPHID' => $public_key->getObjectPHID(), 'isTrusted' => (bool) $public_key->getIsTrusted(), 'key' => $public_key->getEntireKey());
     }
     $results = array('data' => $data);
     return $this->addPagerResults($results, $pager);
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $viewer = $request->getUser();
     $query = id(new ReleephBranchQuery())->setViewer($viewer);
     $ids = $request->getValue('ids');
     if ($ids !== null) {
         $query->withIDs($ids);
     }
     $phids = $request->getValue('phids');
     if ($phids !== null) {
         $query->withPHIDs($phids);
     }
     $product_phids = $request->getValue('productPHIDs');
     if ($product_phids !== null) {
         $query->withProductPHIDs($product_phids);
     }
     $pager = $this->newPager($request);
     $branches = $query->executeWithCursorPager($pager);
     $data = array();
     foreach ($branches as $branch) {
         $id = $branch->getID();
         $uri = '/releeph/branch/' . $id . '/';
         $uri = PhabricatorEnv::getProductionURI($uri);
         $data[] = array('id' => $id, 'phid' => $branch->getPHID(), 'uri' => $uri, 'name' => $branch->getName(), 'productPHID' => $branch->getProduct()->getPHID());
     }
     return $this->addPagerResults(array('data' => $data), $pager);
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $diff = null;
     $revision_id = $request->getValue('revision_id');
     if ($revision_id) {
         $revision = id(new DifferentialRevision())->load($revision_id);
         if (!$revision) {
             throw new ConduitException('ERR_BAD_REVISION');
         }
         $diff = id(new DifferentialDiff())->loadOneWhere('revisionID = %d ORDER BY id DESC LIMIT 1', $revision->getID());
     } else {
         $diff_id = $request->getValue('diff_id');
         if ($diff_id) {
             $diff = id(new DifferentialDiff())->load($diff_id);
         }
     }
     if (!$diff) {
         throw new ConduitException('ERR_BAD_DIFF');
     }
     $diff->attachChangesets($diff->loadRelatives(new DifferentialChangeset(), 'diffID'));
     foreach ($diff->getChangesets() as $changeset) {
         $changeset->attachHunks($changeset->loadRelatives(new DifferentialHunk(), 'changesetID'));
     }
     $basic_dict = $diff->getDiffDict();
     // for conduit calls, the basic dict is not enough
     // we also need to include the arcanist project
     $project = $diff->loadArcanistProject();
     if ($project) {
         $project_name = $project->getName();
     } else {
         $project_name = null;
     }
     $basic_dict['projectName'] = $project_name;
     return $basic_dict;
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $viewer = $request->getUser();
     $revision = id(new DifferentialRevisionQuery())->setViewer($viewer)->withIDs(array($request->getValue('revision_id')))->needReviewerStatus(true)->needReviewerAuthority(true)->executeOne();
     if (!$revision) {
         throw new ConduitException('ERR_BAD_REVISION');
     }
     $xactions = array();
     $action = $request->getValue('action');
     if ($action && $action != 'comment' && $action != 'none') {
         $xactions[] = id(new DifferentialTransaction())->setTransactionType(DifferentialTransaction::TYPE_ACTION)->setNewValue($action);
     }
     $content = $request->getValue('message');
     if (strlen($content)) {
         $xactions[] = id(new DifferentialTransaction())->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)->attachComment(id(new DifferentialTransactionComment())->setContent($content));
     }
     if ($request->getValue('attach_inlines')) {
         $type_inline = DifferentialTransaction::TYPE_INLINE;
         $inlines = DifferentialTransactionQuery::loadUnsubmittedInlineComments($viewer, $revision);
         foreach ($inlines as $inline) {
             $xactions[] = id(new DifferentialTransaction())->setTransactionType($type_inline)->attachComment($inline);
         }
     }
     $editor = id(new DifferentialTransactionEditor())->setActor($viewer)->setDisableEmail($request->getValue('silent'))->setContentSource($request->newContentSource())->setContinueOnNoEffect(true)->setContinueOnMissingFields(true);
     $editor->applyTransactions($revision, $xactions);
     return array('revisionid' => $revision->getID(), 'uri' => PhabricatorEnv::getURI('/D' . $revision->getID()));
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $user_phid = $request->getUser()->getPHID();
     $from = $request->getValue('fromEpoch');
     $to = $request->getValue('toEpoch');
     if ($to <= $from) {
         throw new ConduitException('ERR-BAD-EPOCH');
     }
     $table = new PhabricatorCalendarEvent();
     $table->openTransaction();
     $table->beginReadLocking();
     $overlap = $table->loadAllWhere('userPHID = %s AND dateFrom < %d AND dateTo > %d', $user_phid, $to, $from);
     foreach ($overlap as $status) {
         if ($status->getDateFrom() < $from) {
             if ($status->getDateTo() > $to) {
                 // Split the interval.
                 id(new PhabricatorCalendarEvent())->setUserPHID($user_phid)->setDateFrom($to)->setDateTo($status->getDateTo())->setStatus($status->getStatus())->setDescription($status->getDescription())->save();
             }
             $status->setDateTo($from);
             $status->save();
         } else {
             if ($status->getDateTo() > $to) {
                 $status->setDateFrom($to);
                 $status->save();
             } else {
                 $status->delete();
             }
         }
     }
     $table->endReadLocking();
     $table->saveTransaction();
     return count($overlap);
 }
 private function processBranchRefs(ConduitAPIRequest $request, array $refs)
 {
     $drequest = $this->getDiffusionRequest();
     $repository = $drequest->getRepository();
     $offset = $request->getValue('offset');
     $limit = $request->getValue('limit');
     foreach ($refs as $key => $ref) {
         if (!$repository->shouldTrackBranch($ref->getShortName())) {
             unset($refs[$key]);
         }
     }
     $with_closed = $request->getValue('closed');
     if ($with_closed !== null) {
         foreach ($refs as $key => $ref) {
             $fields = $ref->getRawFields();
             if (idx($fields, 'closed') != $with_closed) {
                 unset($refs[$key]);
             }
         }
     }
     // NOTE: We can't apply the offset or limit until here, because we may have
     // filtered untrackable branches out of the result set.
     if ($offset) {
         $refs = array_slice($refs, $offset);
     }
     if ($limit) {
         $refs = array_slice($refs, 0, $limit);
     }
     return mpull($refs, 'toDictionary');
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $query = new PhabricatorFlagQuery();
     $owner_phids = $request->getValue('ownerPHIDs', array());
     if ($owner_phids) {
         $query->withOwnerPHIDs($owner_phids);
     }
     $object_phids = $request->getValue('objectPHIDs', array());
     if ($object_phids) {
         $query->withObjectPHIDs($object_phids);
     }
     $types = $request->getValue('types', array());
     if ($types) {
         $query->withTypes($types);
     }
     $query->needHandles(true);
     $query->setOffset($request->getValue('offset', 0));
     $query->setLimit($request->getValue('limit', 100));
     $flags = $query->execute();
     $results = array();
     foreach ($flags as $flag) {
         $color = $flag->getColor();
         $uri = PhabricatorEnv::getProductionURI($flag->getHandle()->getURI());
         $results[] = array('id' => $flag->getID(), 'ownerPHID' => $flag->getOwnerPHID(), 'type' => $flag->getType(), 'objectPHID' => $flag->getObjectPHID(), 'reasonPHID' => $flag->getReasonPHID(), 'color' => $color, 'colorName' => PhabricatorFlagColor::getColorName($color), 'note' => $flag->getNote(), 'handle' => array('uri' => $uri, 'name' => $flag->getHandle()->getName()), 'dateCreated' => $flag->getDateCreated(), 'dateModified' => $flag->getDateModified());
     }
     return $results;
 }