protected function execute(ConduitAPIRequest $request) { $paths = $request->getValue('paths'); $fragments = id(new PhragmentFragmentQuery())->setViewer($request->getUser())->withPaths($paths)->execute(); $fragments = mpull($fragments, null, 'getPath'); foreach ($paths as $path) { if (!array_key_exists($path, $fragments)) { throw new ConduitException('ERR_BAD_FRAGMENT'); } } $results = array(); foreach ($fragments as $path => $fragment) { $mappings = $fragment->getFragmentMappings($request->getUser(), $fragment->getPath()); $file_phids = mpull(mpull($mappings, 'getLatestVersion'), 'getFilePHID'); $files = id(new PhabricatorFileQuery())->setViewer($request->getUser())->withPHIDs($file_phids)->execute(); $files = mpull($files, null, 'getPHID'); $result = array(); foreach ($mappings as $cpath => $child) { $file_phid = $child->getLatestVersion()->getFilePHID(); if (!isset($files[$file_phid])) { // Skip any files we don't have permission to access. continue; } $file = $files[$file_phid]; $cpath = substr($child->getPath(), strlen($fragment->getPath()) + 1); $result[] = array('phid' => $child->getPHID(), 'phidVersion' => $child->getLatestVersionPHID(), 'path' => $cpath, 'hash' => $file->getContentHash(), 'version' => $child->getLatestVersion()->getSequence(), 'uri' => $file->getViewURI()); } $results[$path] = $result; } return $results; }
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) { $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())->setContentSource($request->newContentSource())->setDisableEmail($request->getValue('silent'))->setContinueOnMissingFields(true)->applyTransactions($commit, $xactions); return true; }
protected function execute(ConduitAPIRequest $request) { $results = array(); $task_ids = $request->getValue('ids'); if (!$task_ids) { return $results; } $tasks = id(new ManiphestTaskQuery())->setViewer($request->getUser())->withIDs($task_ids)->execute(); $tasks = mpull($tasks, null, 'getPHID'); $transactions = array(); if ($tasks) { $transactions = id(new ManiphestTransactionQuery())->setViewer($request->getUser())->withObjectPHIDs(mpull($tasks, 'getPHID'))->needComments(true)->execute(); } foreach ($transactions as $transaction) { $task_phid = $transaction->getObjectPHID(); if (empty($tasks[$task_phid])) { continue; } $task_id = $tasks[$task_phid]->getID(); $comments = null; if ($transaction->hasComment()) { $comments = $transaction->getComment()->getContent(); } $results[$task_id][] = array('taskID' => $task_id, 'transactionPHID' => $transaction->getPHID(), 'transactionType' => $transaction->getTransactionType(), 'oldValue' => $transaction->getOldValue(), 'newValue' => $transaction->getNewValue(), 'comments' => $comments, 'authorPHID' => $transaction->getAuthorPHID(), 'dateCreated' => $transaction->getDateCreated()); } return $results; }
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) { $need_messages = $request->getValue('needMessages'); $bypass_cache = $request->getValue('bypassCache'); $query = id(new DiffusionCommitQuery())->setViewer($request->getUser())->needCommitData(true); $repository_phid = $request->getValue('repositoryPHID'); if ($repository_phid) { $repository = id(new PhabricatorRepositoryQuery())->setViewer($request->getUser())->withPHIDs(array($repository_phid))->executeOne(); if ($repository) { $query->withRepository($repository); } } $names = $request->getValue('names'); if ($names) { $query->withIdentifiers($names); } $ids = $request->getValue('ids'); if ($ids) { $query->withIDs($ids); } $phids = $request->getValue('phids'); if ($phids) { $query->withPHIDs($phids); } $pager = $this->newPager($request); $commits = $query->executeWithCursorPager($pager); $map = $query->getIdentifierMap(); $map = mpull($map, 'getPHID'); $data = array(); foreach ($commits as $commit) { $commit_data = $commit->getCommitData(); $callsign = $commit->getRepository()->getCallsign(); $identifier = $commit->getCommitIdentifier(); $uri = '/r' . $callsign . $identifier; $uri = PhabricatorEnv::getProductionURI($uri); $dict = array('id' => $commit->getID(), 'phid' => $commit->getPHID(), 'repositoryPHID' => $commit->getRepository()->getPHID(), 'identifier' => $identifier, 'epoch' => $commit->getEpoch(), 'uri' => $uri, 'isImporting' => !$commit->isImported(), 'summary' => $commit->getSummary(), 'authorPHID' => $commit->getAuthorPHID(), 'committerPHID' => $commit_data->getCommitDetail('committerPHID'), 'author' => $commit_data->getAuthorName(), 'authorName' => $commit_data->getCommitDetail('authorName'), 'authorEmail' => $commit_data->getCommitDetail('authorEmail'), 'committer' => $commit_data->getCommitDetail('committer'), 'committerName' => $commit_data->getCommitDetail('committerName'), 'committerEmail' => $commit_data->getCommitDetail('committerEmail'), 'hashes' => array()); if ($bypass_cache) { $lowlevel_commitref = id(new DiffusionLowLevelCommitQuery())->setRepository($commit->getRepository())->withIdentifier($commit->getCommitIdentifier())->execute(); $dict['author'] = $lowlevel_commitref->getAuthor(); $dict['authorName'] = $lowlevel_commitref->getAuthorName(); $dict['authorEmail'] = $lowlevel_commitref->getAuthorEmail(); $dict['committer'] = $lowlevel_commitref->getCommitter(); $dict['committerName'] = $lowlevel_commitref->getCommitterName(); $dict['committerEmail'] = $lowlevel_commitref->getCommitterEmail(); if ($need_messages) { $dict['message'] = $lowlevel_commitref->getMessage(); } foreach ($lowlevel_commitref->getHashes() as $hash) { $dict['hashes'][] = array('type' => $hash->getHashType(), 'value' => $hash->getHashValue()); } } if ($need_messages && !$bypass_cache) { $dict['message'] = $commit_data->getCommitMessage(); } $data[$commit->getPHID()] = $dict; } $result = array('data' => $data, 'identifierMap' => nonempty($map, (object) array())); return $this->addPagerResults($result, $pager); }
protected function execute(ConduitAPIRequest $request) { $diff_id = $request->getValue('diffID'); $linter_map = $request->getValue('linters'); $diff = id(new DifferentialDiffQuery())->setViewer($request->getUser())->withIDs(array($diff_id))->executeOne(); if (!$diff) { throw new ConduitException('ERR-BAD-DIFF'); } // Extract the finished linters and messages from the linter map. $finished_linters = array_keys($linter_map); $new_messages = array(); foreach ($linter_map as $linter => $messages) { $new_messages = array_merge($new_messages, $messages); } // Load the postponed linters attached to this diff. $postponed_linters_property = id(new DifferentialDiffProperty())->loadOneWhere('diffID = %d AND name = %s', $diff_id, 'arc:lint-postponed'); if ($postponed_linters_property) { $postponed_linters = $postponed_linters_property->getData(); } else { $postponed_linters = array(); } foreach ($finished_linters as $linter) { if (!in_array($linter, $postponed_linters)) { throw new ConduitException('ERR-BAD-LINTER'); } } foreach ($postponed_linters as $idx => $linter) { if (in_array($linter, $finished_linters)) { unset($postponed_linters[$idx]); } } // Load the lint messages currenty attached to the diff. If this // diff property doesn't exist, create it. $messages_property = id(new DifferentialDiffProperty())->loadOneWhere('diffID = %d AND name = %s', $diff_id, 'arc:lint'); if ($messages_property) { $messages = $messages_property->getData(); } else { $messages = array(); } // Add new lint messages, removing duplicates. foreach ($new_messages as $new_message) { if (!in_array($new_message, $messages)) { $messages[] = $new_message; } } // Use setdiffproperty to update the postponed linters and messages, // as these will also update the lint status correctly. $call = new ConduitCall('differential.setdiffproperty', array('diff_id' => $diff_id, 'name' => 'arc:lint', 'data' => json_encode($messages))); $call->setForceLocal(true); $call->setUser($request->getUser()); $call->execute(); $call = new ConduitCall('differential.setdiffproperty', array('diff_id' => $diff_id, 'name' => 'arc:lint-postponed', 'data' => json_encode($postponed_linters))); $call->setForceLocal(true); $call->setUser($request->getUser()); $call->execute(); }
protected function execute(ConduitAPIRequest $request) { $slug = $request->getValue('slug'); $doc = id(new PhrictionDocumentQuery())->setViewer($request->getUser())->withSlugs(array(PhabricatorSlug::normalize($slug)))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne(); if (!$doc) { throw new Exception(pht('No such document.')); } $editor = id(PhrictionDocumentEditor::newForSlug($slug))->setActor($request->getUser())->setTitle($request->getValue('title'))->setContent($request->getValue('content'))->setDescription($request->getvalue('description'))->save(); return $this->buildDocumentInfoDictionary($editor->getDocument()); }
protected function execute(ConduitAPIRequest $request) { $branch = id(new ReleephBranchQuery())->setViewer($request->getUser())->withPHIDs(array($request->getValue('branchPHID')))->needCutPointCommits(true)->executeOne(); $cut_phid = $branch->getCutPointCommitPHID(); $phids = array($cut_phid); $handles = id(new PhabricatorHandleQuery())->setViewer($request->getUser())->withPHIDs($phids)->execute(); $project = $branch->getProject(); $repo = $project->getRepository(); $commit = $branch->getCutPointCommit(); return array('branchName' => $branch->getName(), 'branchPHID' => $branch->getPHID(), 'vcsType' => $repo->getVersionControlSystem(), 'cutCommitID' => $commit->getCommitIdentifier(), 'cutCommitName' => $handles[$cut_phid]->getName(), 'creatorPHID' => $branch->getCreatedByUserPHID(), 'trunk' => $project->getTrunkBranch()); }
protected function execute(ConduitAPIRequest $request) { $rid = $request->getValue('revisionID'); $did = $request->getValue('diffID'); if ($rid) { // Given both a revision and a diff, check that they match. // Given only a revision, find the active diff. $revision = id(new DifferentialRevisionQuery())->setViewer($request->getUser())->withIDs(array($rid))->executeOne(); if (!$revision) { throw new ConduitException('ERR-BAD-REVISION'); } if (!$did) { // did not! $diff = $revision->loadActiveDiff(); $did = $diff->getID(); } else { // did too! $diff = id(new DifferentialDiff())->load($did); if (!$diff || $diff->getRevisionID() != $rid) { throw new ConduitException('ERR-BAD-DIFF'); } } } else { if ($did) { // Given only a diff, find the parent revision. $diff = id(new DifferentialDiff())->load($did); if (!$diff) { throw new ConduitException('ERR-BAD-DIFF'); } $rid = $diff->getRevisionID(); } else { // Given neither, bail. throw new ConduitException('ERR-NEED-DIFF'); } } $file = $request->getValue('filePath'); if (!$file) { throw new ConduitException('ERR-NEED-FILE'); } $changes = id(new DifferentialChangeset())->loadAllWhere('diffID = %d', $did); $cid = null; foreach ($changes as $id => $change) { if ($file == $change->getFilename()) { $cid = $id; } } if ($cid == null) { throw new ConduitException('ERR-BAD-FILE'); } $inline = id(new DifferentialInlineComment())->setRevisionID($rid)->setChangesetID($cid)->setAuthorPHID($request->getUser()->getPHID())->setContent($request->getValue('content'))->setIsNewFile($request->getValue('isNewFile'))->setLineNumber($request->getValue('lineNumber'))->setLineLength($request->getValue('lineLength', 0))->save(); // Load everything again, just to be safe. $changeset = id(new DifferentialChangeset())->load($inline->getChangesetID()); return $this->buildInlineInfoDictionary($inline, $changeset); }
protected function execute(ConduitAPIRequest $request) { $drequest = DiffusionRequest::newFromDictionary(array('user' => $request->getUser(), 'callsign' => $request->getValue('callsign'), 'path' => $request->getValue('path'), 'branch' => $request->getValue('branch'))); $limit = nonempty($request->getValue('limit'), self::DEFAULT_LIMIT); $history_result = DiffusionQuery::callConduitWithDiffusionRequest($request->getUser(), $drequest, 'diffusion.historyquery', array('commit' => $drequest->getCommit(), 'path' => $drequest->getPath(), 'offset' => 0, 'limit' => $limit, 'needDirectChanges' => true, 'needChildChanges' => true)); $history = DiffusionPathChange::newFromConduit($history_result['pathChanges']); $raw_commit_identifiers = mpull($history, 'getCommitIdentifier'); $result = array(); foreach ($raw_commit_identifiers as $id) { $result[] = 'r' . $request->getValue('callsign') . $id; } return $result; }
protected function execute(ConduitAPIRequest $request) { $names = $request->getValue('names'); $query = id(new PhabricatorObjectQuery())->setViewer($request->getUser())->withNames($names); $query->execute(); $name_map = $query->getNamedResults(); $handles = id(new PhabricatorHandleQuery())->setViewer($request->getUser())->withPHIDs(mpull($name_map, 'getPHID'))->execute(); $result = array(); foreach ($name_map as $name => $object) { $phid = $object->getPHID(); $handle = $handles[$phid]; $result[$name] = $this->buildHandleInformationDictionary($handle); } return $result; }
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) { $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) { $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) { $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) { $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 $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) { $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(); $this->requireApplicationCapability(ProjectCreateProjectsCapability::CAPABILITY, $user); $history = id(new SprintQuery())->setViewer($user)->getTaskHistory($request->getValue('project')); return $history; }
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(); }
protected function execute(ConduitAPIRequest $request) { $logs = $request->getValue('logs'); if (!is_array($logs)) { $logs = array(); } $template = new PhabricatorChatLogEvent(); $template->setLoggedByPHID($request->getUser()->getPHID()); $objs = array(); foreach ($logs as $log) { $channel_name = idx($log, 'channel'); $service_name = idx($log, 'serviceName'); $service_type = idx($log, 'serviceType'); $channel = id(new PhabricatorChatLogChannel())->loadOneWhere('channelName = %s AND serviceName = %s AND serviceType = %s', $channel_name, $service_name, $service_type); if (!$channel) { $channel = id(new PhabricatorChatLogChannel())->setChannelName($channel_name)->setserviceName($service_name)->setServiceType($service_type)->setViewPolicy(PhabricatorPolicies::POLICY_USER)->setEditPolicy(PhabricatorPolicies::POLICY_USER)->save(); } $obj = clone $template; $obj->setChannelID($channel->getID()); $obj->setType(idx($log, 'type')); $obj->setAuthor(idx($log, 'author')); $obj->setEpoch(idx($log, 'epoch')); $obj->setMessage(idx($log, 'message')); $obj->save(); $objs[] = $obj; } return array_values(mpull($objs, 'getID')); }
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) { $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) { $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) { $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); }
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) { $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) { $query = id(new PhabricatorPasteQuery())->setViewer($request->getUser())->needContent(true); if ($request->getValue('ids')) { $query->withIDs($request->getValue('ids')); } if ($request->getValue('phids')) { $query->withPHIDs($request->getValue('phids')); } if ($request->getValue('authorPHIDs')) { $query->withAuthorPHIDs($request->getValue('authorPHIDs')); } if ($request->getValue('after')) { $query->setAfterID($request->getValue('after')); } $limit = $request->getValue('limit', 100); if ($limit) { $query->setLimit($limit); } $pastes = $query->execute(); $results = array(); foreach ($pastes as $paste) { $results[$paste->getPHID()] = $this->buildPasteInfoDictionary($paste); } 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); }