public function execute() { $table = new PhabricatorTokenCount(); $conn_r = $table->establishConnection('r'); $rows = queryfx_all($conn_r, 'SELECT objectPHID, tokenCount FROM %T %Q %Q', $table->getTableName(), $this->buildWhereClause($conn_r), $this->buildLimitClause($conn_r)); return ipull($rows, 'tokenCount', 'objectPHID'); }
private function renderListPanel() { if (!$this->packagePHID) { return id(new AphrontErrorView())->setSeverity(AphrontErrorView::SEVERITY_NOTICE)->setTitle('No package seleted. Please select one from above.'); } $package = id(new PhabricatorOwnersPackage())->loadOneWhere("phid = %s", $this->packagePHID); if ($this->view === 'audit' && !$package->getAuditingEnabled()) { return id(new AphrontErrorView())->setSeverity(AphrontErrorView::SEVERITY_NOTICE)->setTitle("Package doesn't have auditing enabled. " . "Please choose another one."); } $conn_r = id(new PhabricatorOwnersPackageCommitRelationship())->establishConnection('r'); $status_arr = $this->getStatusArr(); $offset = $this->request->getInt('offset', 0); $pager = new AphrontPagerView(); $pager->setPageSize(50); $pager->setOffset($offset); $pager->setURI($this->request->getRequestURI(), 'offset'); $data = queryfx_all($conn_r, 'SELECT commitPHID, auditStatus, auditReasons FROM %T WHERE packagePHID = %s AND auditStatus in (%Ls) ORDER BY id DESC LIMIT %d, %d', id(new PhabricatorOwnersPackageCommitRelationship())->getTableName(), $package->getPHID(), $status_arr, $pager->getOffset(), $pager->getPageSize() + 1); $data = $pager->sliceResults($data); $data = ipull($data, null, 'commitPHID'); $list_panel = $this->renderCommitTable($data, $package); $list_panel->appendChild($pager); return $list_panel; }
protected function processDiffusionRequest(AphrontRequest $request) { $limit = 500; $offset = $request->getInt('offset', 0); $drequest = $this->getDiffusionRequest(); $branch = $drequest->loadBranch(); $messages = $this->loadLintMessages($branch, $limit, $offset); $is_dir = substr('/' . $drequest->getPath(), -1) == '/'; $authors = $this->loadViewerHandles(ipull($messages, 'authorPHID')); $rows = array(); foreach ($messages as $message) { $path = phutil_tag('a', array('href' => $drequest->generateURI(array('action' => 'lint', 'path' => $message['path']))), substr($message['path'], strlen($drequest->getPath()) + 1)); $line = phutil_tag('a', array('href' => $drequest->generateURI(array('action' => 'browse', 'path' => $message['path'], 'line' => $message['line'], 'commit' => $branch->getLintCommit()))), $message['line']); $author = $message['authorPHID']; if ($author && $authors[$author]) { $author = $authors[$author]->renderLink(); } $rows[] = array($path, $line, $author, ArcanistLintSeverity::getStringForSeverity($message['severity']), $message['name'], $message['description']); } $table = id(new AphrontTableView($rows))->setHeaders(array(pht('Path'), pht('Line'), pht('Author'), pht('Severity'), pht('Name'), pht('Description')))->setColumnClasses(array('', 'n'))->setColumnVisibility(array($is_dir)); $content = array(); $pager = id(new AphrontPagerView())->setPageSize($limit)->setOffset($offset)->setHasMorePages(count($messages) >= $limit)->setURI($request->getRequestURI(), 'offset'); $content[] = id(new PHUIObjectBoxView())->setHeaderText(pht('Lint Details'))->appendChild($table); $crumbs = $this->buildCrumbs(array('branch' => true, 'path' => true, 'view' => 'lint')); return $this->buildApplicationPage(array($crumbs, $content, $pager), array('title' => array(pht('Lint'), $drequest->getRepository()->getCallsign()))); }
public function execute() { $table = new PhabricatorFlag(); $conn_r = $table->establishConnection('r'); $where = $this->buildWhereClause($conn_r); $limit = $this->buildLimitClause($conn_r); $order = $this->buildOrderClause($conn_r); $data = queryfx_all($conn_r, 'SELECT * FROM %T flag %Q %Q %Q', $table->getTableName(), $where, $order, $limit); $flags = $table->loadAllFromArray($data); if ($this->needHandles || $this->needObjects) { $phids = ipull($data, 'objectPHID'); $query = new PhabricatorObjectHandleData($phids); if ($this->needHandles) { $handles = $query->loadHandles(); foreach ($flags as $flag) { $handle = idx($handles, $flag->getObjectPHID()); if ($handle) { $flag->attachHandle($handle); } } } if ($this->needObjects) { $objects = $query->loadObjects(); foreach ($flags as $flag) { $object = idx($objects, $flag->getObjectPHID()); if ($object) { $flag->attachObject($object); } } } } return $flags; }
private function buildChartForm() { $request = $this->getRequest(); $user = $request->getUser(); $table = new PhabricatorFactRaw(); $conn_r = $table->establishConnection('r'); $table_name = $table->getTableName(); $facts = queryfx_all($conn_r, 'SELECT DISTINCT factType from %T', $table_name); $specs = PhabricatorFactSpec::newSpecsForFactTypes(PhabricatorFactEngine::loadAllEngines(), ipull($facts, 'factType')); $options = array(); foreach ($specs as $spec) { if ($spec->getUnit() == PhabricatorFactSpec::UNIT_COUNT) { $options[$spec->getType()] = $spec->getName(); } } if (!$options) { return id(new AphrontErrorView())->setSeverity(AphrontErrorView::SEVERITY_NOTICE)->setTitle(pht('No Chartable Facts'))->appendChild('<p>' . pht('There are no facts that can be plotted yet.') . '</p>'); } $form = id(new AphrontFormView())->setUser($user)->appendChild(id(new AphrontFormSelectControl())->setLabel('Y-Axis')->setName('y1')->setOptions($options))->appendChild(id(new AphrontFormSubmitControl())->setValue('Plot Chart')); $panel = new AphrontPanelView(); $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); $panel->setHeader('Plot Chart'); return $panel; }
public function getKeys(array $keys) { $results = array(); if ($keys) { $map = $this->digestKeys($keys); $rows = queryfx_all($this->establishConnection('r'), 'SELECT * FROM %T WHERE cacheKeyHash IN (%Ls)', $this->getTableName(), $map); $rows = ipull($rows, null, 'cacheKey'); foreach ($keys as $key) { if (empty($rows[$key])) { continue; } $row = $rows[$key]; if ($row['cacheExpires'] && $row['cacheExpires'] < time()) { continue; } try { $results[$key] = $this->didReadValue($row['cacheFormat'], $row['cacheData']); } catch (Exception $ex) { // Treat this as a cache miss. phlog($ex); } } } return $results; }
public function execute() { $conn_r = id(new PhabricatorRepository())->establishConnection('r'); $where = $this->buildWhereClause($conn_r); $results = queryfx_all($conn_r, 'SELECT * FROM %T %Q', PhabricatorRepository::TABLE_PATH, $where); return ipull($results, null, 'id'); }
public function processRequest() { $classes = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorUIExample')->setConcreteOnly(true)->selectAndLoadSymbols(); $classes = ipull($classes, 'name', 'name'); foreach ($classes as $class => $ignored) { $classes[$class] = newv($class, array()); } $classes = msort($classes, 'getName'); $nav = new AphrontSideNavFilterView(); $nav->setBaseURI(new PhutilURI($this->getApplicationURI('view/'))); foreach ($classes as $class => $obj) { $name = $obj->getName(); $nav->addFilter($class, $name); } $selected = $nav->selectFilter($this->class, head_key($classes)); require_celerity_resource('phabricator-ui-example-css'); $example = $classes[$selected]; $example->setRequest($this->getRequest()); $result = $example->renderExample(); if ($result instanceof AphrontResponse) { // This allows examples to generate dialogs, etc., for demonstration. return $result; } $nav->appendChild('<div class="phabricator-ui-example-header">' . '<h1 class="phabricator-ui-example-name">' . phutil_escape_html($example->getName()) . ' (' . get_class($example) . ')' . '</h1>' . '<p class="phabricator-ui-example-description">' . $example->getDescription() . '</p>' . '</div>'); $nav->appendChild($result); return $this->buildApplicationPage($nav, array('title' => 'UI Example', 'device' => true)); }
public function processRequest() { $classes = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorUIExample')->selectAndLoadSymbols(); $classes = ipull($classes, 'name', 'name'); $selected = null; foreach ($classes as $class => $ignored) { $classes[$class] = newv($class, array()); if ($this->class == $classes[$class]->getName()) { $selected = $class; } } if (!$selected) { reset($classes); $selected = key($classes); } $nav = new AphrontSideNavView(); foreach ($classes as $class => $obj) { $name = $obj->getName(); $nav->addNavItem(phutil_render_tag('a', array('href' => '/uiexample/view/' . $name . '/', 'class' => $selected == $class ? 'aphront-side-nav-selected' : null), phutil_escape_html($obj->getName()))); } require_celerity_resource('phabricator-ui-example-css'); $example = $classes[$selected]; $example->setRequest($this->getRequest()); $nav->appendChild('<div class="phabricator-ui-example-header">' . '<h1 class="phabricator-ui-example-name">' . phutil_escape_html($example->getName()) . ' (' . get_class($example) . ')' . '</h1>' . '<p class="phabricator-ui-example-description">' . $example->getDescription() . '</p>' . '</div>'); $nav->appendChild($example->renderExample()); return $this->buildStandardPageResponse($nav, array('title' => 'UI Example')); }
public function testTimelineSort() { $e1 = $this->newEvent('X1', 1, 1)->setID(1); $in = array(array('event' => $e1, 'at' => 1, 'type' => 'start'), array('event' => $e1, 'at' => 1, 'type' => 'end')); usort($in, array('PhrequentTimeBlock', 'sortTimeline')); $this->assertEqual(array('start', 'end'), ipull($in, 'type')); }
public static function getExpectedSchemaVersion() { $patches = self::getPatchList(); $versions = ipull($patches, 'version'); $max_version = max($versions); return $max_version; }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $query = new PhabricatorSearchQuery(); $query_str = $request->getStr('query'); $matches = array(); $query->setQuery($query_str); $query->setParameter('type', $this->type); switch ($request->getStr('filter')) { case 'assigned': $query->setParameter('owner', array($user->getPHID())); $query->setParameter('open', 1); break; case 'created': $query->setParameter('author', array($user->getPHID())); $query->setParameter('open', 1); break; case 'open': $query->setParameter('open', 1); break; } $engine = PhabricatorSearchEngineSelector::newSelector()->newEngine(); $results = $engine->executeSearch($query); $phids = array_fill_keys(ipull($results, 'phid'), true); $phids += $this->queryObjectNames($query_str); $phids = array_keys($phids); $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); $data = array(); foreach ($handles as $handle) { $view = new PhabricatorHandleObjectSelectorDataView($handle); $data[] = $view->renderData(); } return id(new AphrontAjaxResponse())->setContent($data); }
protected function parseCommit(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit) { // Reload the commit to pull commit data and audit requests. $commit = id(new DiffusionCommitQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withIDs(array($commit->getID()))->needCommitData(true)->needAuditRequests(true)->executeOne(); $data = $commit->getCommitData(); if (!$data) { throw new PhabricatorWorkerPermanentFailureException(pht('Unable to load commit data. The data for this task is invalid ' . 'or no longer exists.')); } $commit->attachRepository($repository); $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_DAEMON, array()); $committer_phid = $data->getCommitDetail('committerPHID'); $author_phid = $data->getCommitDetail('authorPHID'); $acting_as_phid = nonempty($committer_phid, $author_phid, id(new PhabricatorDiffusionApplication())->getPHID()); $editor = id(new PhabricatorAuditEditor())->setActor(PhabricatorUser::getOmnipotentUser())->setActingAsPHID($acting_as_phid)->setContinueOnMissingFields(true)->setContinueOnNoEffect(true)->setContentSource($content_source); $xactions = array(); $xactions[] = id(new PhabricatorAuditTransaction())->setTransactionType(PhabricatorAuditTransaction::TYPE_COMMIT)->setDateCreated($commit->getEpoch())->setNewValue(array('description' => $data->getCommitMessage(), 'summary' => $data->getSummary(), 'authorName' => $data->getAuthorName(), 'authorPHID' => $commit->getAuthorPHID(), 'committerName' => $data->getCommitDetail('committer'), 'committerPHID' => $data->getCommitDetail('committerPHID'))); $reverts_refs = id(new DifferentialCustomFieldRevertsParser())->parseCorpus($data->getCommitMessage()); $reverts = array_mergev(ipull($reverts_refs, 'monograms')); if ($reverts) { $reverted_commits = id(new DiffusionCommitQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withRepository($repository)->withIdentifiers($reverts)->execute(); $reverted_commit_phids = mpull($reverted_commits, 'getPHID', 'getPHID'); // NOTE: Skip any write attempts if a user cleverly implies a commit // reverts itself. unset($reverted_commit_phids[$commit->getPHID()]); $reverts_edge = DiffusionCommitRevertsCommitEdgeType::EDGECONST; $xactions[] = id(new PhabricatorAuditTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', $reverts_edge)->setNewValue(array('+' => array_fuse($reverted_commit_phids))); } try { $raw_patch = $this->loadRawPatchText($repository, $commit); } catch (Exception $ex) { $raw_patch = pht('Unable to generate patch: %s', $ex->getMessage()); } $editor->setRawPatch($raw_patch); return $editor->applyTransactions($commit, $xactions); }
public static function sortAndGroupInlines(array $inlines, array $changesets) { assert_instances_of($inlines, 'DifferentialTransaction'); assert_instances_of($changesets, 'DifferentialChangeset'); $changesets = mpull($changesets, null, 'getID'); $changesets = msort($changesets, 'getFilename'); // Group the changesets by file and reorder them by display order. $inline_groups = array(); foreach ($inlines as $inline) { $changeset_id = $inline->getComment()->getChangesetID(); $inline_groups[$changeset_id][] = $inline; } $inline_groups = array_select_keys($inline_groups, array_keys($changesets)); foreach ($inline_groups as $changeset_id => $group) { // Sort the group of inlines by line number. $items = array(); foreach ($group as $inline) { $comment = $inline->getComment(); $num = $comment->getLineNumber(); $len = $comment->getLineLength(); $id = $comment->getID(); $items[] = array('inline' => $inline, 'sort' => sprintf('~%010d%010d%010d', $num, $len, $id)); } $items = isort($items, 'sort'); $items = ipull($items, 'inline'); $inline_groups[$changeset_id] = $items; } return $inline_groups; }
public static function newFromDictionary(HarbormasterBuildTarget $build_target, array $dict) { $obj = self::initializeNewUnitMessage($build_target); $spec = self::getParameterSpec(); $spec = ipull($spec, 'type'); // We're just going to ignore extra keys for now, to make it easier to // add stuff here later on. $dict = array_select_keys($dict, array_keys($spec)); PhutilTypeSpec::checkMap($dict, $spec); $obj->setEngine(idx($dict, 'engine', '')); $obj->setNamespace(idx($dict, 'namespace', '')); $obj->setName($dict['name']); $obj->setResult($dict['result']); $obj->setDuration((double) idx($dict, 'duration')); $path = idx($dict, 'path'); if (strlen($path)) { $obj->setProperty('path', $path); } $coverage = idx($dict, 'coverage'); if ($coverage) { $obj->setProperty('coverage', $coverage); } $details = idx($dict, 'details'); if ($details) { $obj->setProperty('details', $details); } return $obj; }
protected function buildCustomEditFields($object) { $paths_help = pht(<<<EOTEXT When updating the paths for a package, pass a list of dictionaries like this as the `value` for the transaction: ```lang=json, name="Example Paths Value" [ { "repositoryPHID": "PHID-REPO-1234", "path": "/path/to/directory/", "excluded": false }, { "repositoryPHID": "PHID-REPO-1234", "path": "/another/example/path/", "excluded": false } ] ``` This transaction will set the paths to the list you provide, overwriting any previous paths. Generally, you will call `owners.search` first to get a list of current paths (which are provided in the same format), make changes, then update them by applying a transaction of this type. EOTEXT ); $autoreview_map = PhabricatorOwnersPackage::getAutoreviewOptionsMap(); $autoreview_map = ipull($autoreview_map, 'name'); $dominion_map = PhabricatorOwnersPackage::getDominionOptionsMap(); $dominion_map = ipull($dominion_map, 'name'); return array(id(new PhabricatorTextEditField())->setKey('name')->setLabel(pht('Name'))->setDescription(pht('Name of the package.'))->setTransactionType(PhabricatorOwnersPackageTransaction::TYPE_NAME)->setIsRequired(true)->setValue($object->getName()), id(new PhabricatorDatasourceEditField())->setKey('owners')->setLabel(pht('Owners'))->setDescription(pht('Users and projects which own the package.'))->setTransactionType(PhabricatorOwnersPackageTransaction::TYPE_OWNERS)->setDatasource(new PhabricatorProjectOrUserDatasource())->setIsCopyable(true)->setValue($object->getOwnerPHIDs()), id(new PhabricatorSelectEditField())->setKey('dominion')->setLabel(pht('Dominion'))->setDescription(pht('Change package dominion rules.'))->setTransactionType(PhabricatorOwnersPackageTransaction::TYPE_DOMINION)->setIsCopyable(true)->setValue($object->getDominion())->setOptions($dominion_map), id(new PhabricatorSelectEditField())->setKey('autoReview')->setLabel(pht('Auto Review'))->setDescription(pht('Automatically trigger reviews for commits affecting files in ' . 'this package.'))->setTransactionType(PhabricatorOwnersPackageTransaction::TYPE_AUTOREVIEW)->setIsCopyable(true)->setValue($object->getAutoReview())->setOptions($autoreview_map), id(new PhabricatorSelectEditField())->setKey('auditing')->setLabel(pht('Auditing'))->setDescription(pht('Automatically trigger audits for commits affecting files in ' . 'this package.'))->setTransactionType(PhabricatorOwnersPackageTransaction::TYPE_AUDITING)->setIsCopyable(true)->setValue($object->getAuditingEnabled())->setOptions(array('' => pht('Disabled'), '1' => pht('Enabled'))), id(new PhabricatorRemarkupEditField())->setKey('description')->setLabel(pht('Description'))->setDescription(pht('Human-readable description of the package.'))->setTransactionType(PhabricatorOwnersPackageTransaction::TYPE_DESCRIPTION)->setValue($object->getDescription()), id(new PhabricatorSelectEditField())->setKey('status')->setLabel(pht('Status'))->setDescription(pht('Archive or enable the package.'))->setTransactionType(PhabricatorOwnersPackageTransaction::TYPE_STATUS)->setIsConduitOnly(true)->setValue($object->getStatus())->setOptions($object->getStatusNameMap()), id(new PhabricatorConduitEditField())->setKey('paths.set')->setLabel(pht('Paths'))->setIsConduitOnly(true)->setTransactionType(PhabricatorOwnersPackageTransaction::TYPE_PATHS)->setConduitDescription(pht('Overwrite existing package paths with new paths.'))->setConduitTypeDescription(pht('List of dictionaries, each describing a path.'))->setConduitDocumentation($paths_help)); }
public function execute() { $table = new ConpherenceParticipant(); $conn_r = $table->establishConnection('r'); $rows = queryfx_all($conn_r, 'SELECT COUNT(*) as count, participantPHID ' . 'FROM %T participant %Q %Q %Q', $table->getTableName(), $this->buildWhereClause($conn_r), $this->buildGroupByClause($conn_r), $this->buildLimitClause($conn_r)); return ipull($rows, 'count', 'participantPHID'); }
public function markupNavigation(array $matches) { if (!$this->isFlatText($matches[0])) { return $matches[0]; } $elements = ltrim($matches[1], ", \n"); $elements = explode('>', $elements); $defaults = array('name' => null, 'type' => 'link', 'href' => null, 'icon' => null); $sequence = array(); $parser = new PhutilSimpleOptions(); foreach ($elements as $element) { if (strpos($element, '=') === false) { $sequence[] = array('name' => trim($element)) + $defaults; } else { $sequence[] = $parser->parse($element) + $defaults; } } if ($this->getEngine()->isTextMode()) { return implode(' > ', ipull($sequence, 'name')); } static $icon_names; if (!$icon_names) { $icon_names = array_fuse(PHUIIconView::getIcons()); } $out = array(); foreach ($sequence as $item) { $item_name = $item['name']; $item_color = PHUITagView::COLOR_GREY; if ($item['type'] == 'instructions') { $item_name = phutil_tag('em', array(), $item_name); $item_color = PHUITagView::COLOR_INDIGO; } $tag = id(new PHUITagView())->setType(PHUITagView::TYPE_SHADE)->setShade($item_color)->setName($item_name); if ($item['icon']) { $icon_name = 'fa-' . $item['icon']; if (isset($icon_names[$icon_name])) { $tag->setIcon($icon_name); } } if ($item['href'] !== null) { if (PhabricatorEnv::isValidRemoteURIForLink($item['href'])) { $tag->setHref($item['href']); $tag->setExternal(true); } } $out[] = $tag; } if ($this->getEngine()->isHTMLMailMode()) { $arrow_attr = array('style' => 'color: #92969D;'); $nav_attr = array(); } else { $arrow_attr = array('class' => 'remarkup-nav-sequence-arrow'); $nav_attr = array('class' => 'remarkup-nav-sequence'); } $joiner = phutil_tag('span', $arrow_attr, " → "); $out = phutil_implode_html($joiner, $out); $out = phutil_tag('span', $nav_attr, $out); return $this->getEngine()->storeText($out); }
public function loadTaskStatusCounts() { $table = new PhabricatorWorkerBulkTask(); $conn_r = $table->establishConnection('r'); $rows = queryfx_all($conn_r, 'SELECT status, COUNT(*) N FROM %T WHERE bulkJobPHID = %s GROUP BY status', $table->getTableName(), $this->getPHID()); return ipull($rows, 'N', 'status'); }
protected function loadPage() { $table = new PhabricatorTokenCount(); $conn_r = $table->establishConnection('r'); $rows = queryfx_all($conn_r, 'SELECT objectPHID, tokenCount FROM %T ORDER BY tokenCount DESC', $table->getTableName()); $this->tokenCounts = ipull($rows, 'tokenCount', 'objectPHID'); return ipull($rows, 'objectPHID'); }
public function testDetectCopiedCode() { $root = dirname(__FILE__) . '/diff/'; $parser = new ArcanistDiffParser(); $diff = DifferentialDiff::newFromRawChanges($parser->parseDiff(Filesystem::readFile($root . 'lint_engine.diff'))); $copies = idx(head($diff->getChangesets())->getMetadata(), 'copy:lines'); $this->assertEqual(array_combine(range(237, 252), range(167, 182)), ipull($copies, 1)); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $resource = new DrydockResource(); $json = new PhutilJSON(); $err_attributes = true; $err_capabilities = true; $json_attributes = $json->encodeFormatted($resource->getAttributes()); $json_capabilities = $json->encodeFormatted($resource->getCapabilities()); $errors = array(); if ($request->isFormPost()) { $raw_attributes = $request->getStr('attributes'); $attributes = json_decode($raw_attributes, true); if (!is_array($attributes)) { $err_attributes = 'Invalid'; $errors[] = 'Enter attributes as a valid JSON object.'; $json_attributes = $raw_attributes; } else { $resource->setAttributes($attributes); $json_attributes = $json->encodeFormatted($attributes); $err_attributes = null; } $raw_capabilities = $request->getStr('capabilities'); $capabilities = json_decode($raw_capabilities, true); if (!is_array($capabilities)) { $err_capabilities = 'Invalid'; $errors[] = 'Enter capabilities as a valid JSON object.'; $json_capabilities = $raw_capabilities; } else { $resource->setCapabilities($capabilities); $json_capabilities = $json->encodeFormatted($capabilities); $err_capabilities = null; } $resource->setBlueprintClass($request->getStr('blueprint')); $resource->setType($resource->getBlueprint()->getType()); $resource->setOwnerPHID($user->getPHID()); $resource->setName($request->getStr('name')); if (!$errors) { $resource->save(); return id(new AphrontRedirectResponse())->setURI('/drydock/resource/'); } } $error_view = null; if ($errors) { $error_view = new AphrontErrorView(); $error_view->setTitle('Form Errors'); $error_view->setErrors($errors); } $blueprints = id(new PhutilSymbolLoader())->setType('class')->setAncestorClass('DrydockBlueprint')->selectAndLoadSymbols(); $blueprints = ipull($blueprints, 'name', 'name'); $panel = new AphrontPanelView(); $panel->setWidth(AphrontPanelView::WIDTH_FORM); $panel->setHeader('Allocate Drydock Resource'); $form = id(new AphrontFormView())->setUser($request->getUser())->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($resource->getName()))->appendChild(id(new AphrontFormSelectControl())->setLabel('Blueprint')->setOptions($blueprints)->setName('blueprint')->setValue($resource->getBlueprintClass()))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Attributes')->setName('attributes')->setValue($json_attributes)->setError($err_attributes)->setCaption('Specify attributes in JSON.'))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Capabilities')->setName('capabilities')->setValue($json_capabilities)->setError($err_capabilities)->setCaption('Specify capabilities in JSON.'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Allocate Resource')); $panel->appendChild($form); return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Allocate Resource')); }
public function getAppliedPatches() { try { $applied = queryfx_all($this->getConn('meta_data'), 'SELECT patch FROM patch_status'); return ipull($applied, 'patch'); } catch (AphrontQueryException $ex) { return null; } }
public function getTitle() { $map = PhabricatorOwnersPackage::getAutoreviewOptionsMap(); $map = ipull($map, 'name'); $old = $this->getOldValue(); $new = $this->getNewValue(); $old = idx($map, $old, $old); $new = idx($map, $new, $new); return pht('%s adjusted autoreview from %s to %s.', $this->renderAuthor(), $this->renderValue($old), $this->renderValue($new)); }
public function getTitle() { $map = PhabricatorOwnersPackage::getDominionOptionsMap(); $map = ipull($map, 'short'); $old = $this->getOldValue(); $new = $this->getNewValue(); $old = idx($map, $old, $old); $new = idx($map, $new, $new); return pht('%s adjusted package dominion rules from %s to %s.', $this->renderAuthor(), $this->renderValue($old), $this->renderValue($new)); }
private function processResults(array $data) { $data = ipull($data, 'N', 'path_prefix'); // Strip the leading "/" back off each path. $output = array(); foreach ($data as $path => $count) { $output[substr($path, 1)] = $count; } return $output; }
protected function executeQuery() { $drequest = $this->getRequest(); $repository = $drequest->getRepository(); $path = $drequest->getPath(); $commit = $drequest->getCommit(); $conn_r = $repository->establishConnection('r'); $paths = queryfx_all($conn_r, 'SELECT id, path FROM %T WHERE pathHash IN (%Ls)', PhabricatorRepository::TABLE_PATH, array(md5('/' . trim($path, '/')))); $paths = ipull($paths, 'id', 'path'); $path_id = idx($paths, '/' . trim($path, '/')); if (!$path_id) { return array(); } $filter_query = ''; if ($this->needDirectChanges) { if ($this->needChildChanges) { $type = DifferentialChangeType::TYPE_CHILD; $filter_query = 'AND (isDirect = 1 OR changeType = ' . $type . ')'; } else { $filter_query = 'AND (isDirect = 1)'; } } $history_data = queryfx_all($conn_r, 'SELECT * FROM %T WHERE repositoryID = %d AND pathID = %d AND commitSequence <= %d %Q ORDER BY commitSequence DESC LIMIT %d, %d', PhabricatorRepository::TABLE_PATHCHANGE, $repository->getID(), $path_id, $commit ? $commit : 0x7fffffff, $filter_query, $this->getOffset(), $this->getLimit()); $commits = array(); $commit_data = array(); $commit_ids = ipull($history_data, 'commitID'); if ($commit_ids) { $commits = id(new PhabricatorRepositoryCommit())->loadAllWhere('id IN (%Ld)', $commit_ids); if ($commits) { $commit_data = id(new PhabricatorRepositoryCommitData())->loadAllWhere('commitID in (%Ld)', $commit_ids); $commit_data = mpull($commit_data, null, 'getCommitID'); } } $history = array(); foreach ($history_data as $row) { $item = new DiffusionPathChange(); $commit = idx($commits, $row['commitID']); if ($commit) { $item->setCommit($commit); $item->setCommitIdentifier($commit->getCommitIdentifier()); $data = idx($commit_data, $commit->getID()); if ($data) { $item->setCommitData($data); } } $item->setChangeType($row['changeType']); $item->setFileType($row['fileType']); $history[] = $item; } return $history; }
protected function executeChecks() { $master = PhabricatorDatabaseRef::getMasterDatabaseRef(); if (!$master) { // If we're implicitly in read-only mode during disaster recovery, // don't bother with these setup checks. return; } $conn_raw = $master->newManagementConnection(); try { queryfx($conn_raw, 'SELECT 1'); $database_exception = null; } catch (AphrontInvalidCredentialsQueryException $ex) { $database_exception = $ex; } catch (AphrontConnectionQueryException $ex) { $database_exception = $ex; } if ($database_exception) { $issue = PhabricatorSetupIssue::newDatabaseConnectionIssue($database_exception); $this->addIssue($issue); return; } $engines = queryfx_all($conn_raw, 'SHOW ENGINES'); $engines = ipull($engines, 'Support', 'Engine'); $innodb = idx($engines, 'InnoDB'); if ($innodb != 'YES' && $innodb != 'DEFAULT') { $message = pht("The 'InnoDB' engine is not available in MySQL. Enable InnoDB in " . "your MySQL configuration." . "\n\n" . "(If you aleady created tables, MySQL incorrectly used some other " . "engine to create them. You need to convert them or drop and " . "reinitialize them.)"); $this->newIssue('mysql.innodb')->setName(pht('MySQL InnoDB Engine Not Available'))->setMessage($message)->setIsFatal(true); return; } $namespace = PhabricatorEnv::getEnvConfig('storage.default-namespace'); $databases = queryfx_all($conn_raw, 'SHOW DATABASES'); $databases = ipull($databases, 'Database', 'Database'); if (empty($databases[$namespace . '_meta_data'])) { $message = pht("Run the storage upgrade script to setup Phabricator's database " . "schema."); $this->newIssue('storage.upgrade')->setName(pht('Setup MySQL Schema'))->setMessage($message)->setIsFatal(true)->addCommand(hsprintf('<tt>phabricator/ $</tt> ./bin/storage upgrade')); } else { $conn_meta = $master->newApplicationConnection($namespace . '_meta_data'); $applied = queryfx_all($conn_meta, 'SELECT patch FROM patch_status'); $applied = ipull($applied, 'patch', 'patch'); $all = PhabricatorSQLPatchList::buildAllPatches(); $diff = array_diff_key($all, $applied); if ($diff) { $this->newIssue('storage.patch')->setName(pht('Upgrade MySQL Schema'))->setMessage(pht("Run the storage upgrade script to upgrade Phabricator's " . "database schema. Missing patches:<br />%s<br />", phutil_implode_html(phutil_tag('br'), array_keys($diff))))->addCommand(hsprintf('<tt>phabricator/ $</tt> ./bin/storage upgrade')); } } $host = PhabricatorEnv::getEnvConfig('mysql.host'); $matches = null; if (preg_match('/^([^:]+):(\\d+)$/', $host, $matches)) { $host = $matches[1]; $port = $matches[2]; $this->newIssue('storage.mysql.hostport')->setName(pht('Deprecated mysql.host Format'))->setSummary(pht('Move port information from `%s` to `%s` in your config.', 'mysql.host', 'mysql.port'))->setMessage(pht('Your `%s` configuration contains a port number, but this usage ' . 'is deprecated. Instead, put the port number in `%s`.', 'mysql.host', 'mysql.port'))->addPhabricatorConfig('mysql.host')->addPhabricatorConfig('mysql.port')->addCommand(hsprintf('<tt>phabricator/ $</tt> ./bin/config set mysql.host %s', $host))->addCommand(hsprintf('<tt>phabricator/ $</tt> ./bin/config set mysql.port %s', $port)); } }
public function readRequest(PhabricatorConfigOption $option, AphrontRequest $request) { $e_value = null; $errors = array(); $storage_value = $request->getStr('value'); $in_value = phutil_json_decode($storage_value); // When we submit from JS, we submit a list (since maps are not guaranteed // to retain order). Convert it into a map for storage (since it's far more // convenient for us elsewhere). $storage_value = ipull($in_value, null, 'key'); $display_value = $storage_value; return array($e_value, $errors, $storage_value, $display_value); }
private function buildPropertyView(PhabricatorProject $board) { $viewer = $this->getRequest()->getUser(); $properties = id(new PHUIPropertyListView())->setUser($viewer)->setObject($board); $background = $board->getDisplayWorkboardBackgroundColor(); if ($background !== null) { $map = PhabricatorProjectWorkboardBackgroundColor::getOptions(); $map = ipull($map, 'name'); $name = idx($map, $background, $background); $properties->addProperty(pht('Background Color'), $name); } return $properties; }