repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/console/plugin/DarkConsoleRealtimePlugin.php
src/applications/console/plugin/DarkConsoleRealtimePlugin.php
<?php final class DarkConsoleRealtimePlugin extends DarkConsolePlugin { public function getName() { return pht('Realtime'); } public function getColor() { return null; } public function getDescription() { return pht('Debugging console for real-time notifications.'); } public function renderPanel() { $frame = phutil_tag( 'div', array( 'id' => 'dark-console-realtime-log', 'class' => 'dark-console-log-frame', )); $reconnect_label = pht('Reconnect'); $replay_label = pht('Replay'); $repaint_label = pht('Repaint'); $buttons = phutil_tag( 'div', array( 'class' => 'dark-console-realtime-actions', ), array( id(new PHUIButtonView()) ->setIcon('fa-refresh') ->setColor(PHUIButtonView::GREY) ->setText($reconnect_label) ->addSigil('dark-console-realtime-action') ->setMetadata( array( 'action' => 'reconnect', 'label' => $reconnect_label, )), id(new PHUIButtonView()) ->setIcon('fa-backward') ->setColor(PHUIButtonView::GREY) ->setText($replay_label) ->addSigil('dark-console-realtime-action') ->setMetadata( array( 'action' => 'replay', 'label' => $replay_label, )), id(new PHUIButtonView()) ->setIcon('fa-paint-brush') ->setColor(PHUIButtonView::GREY) ->setText($repaint_label) ->addSigil('dark-console-realtime-action') ->setMetadata( array( 'action' => 'repaint', 'label' => $repaint_label, )), )); return phutil_tag( 'div', array( 'class' => 'dark-console-realtime', ), array( $buttons, $frame, )); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/console/plugin/DarkConsoleErrorLogPlugin.php
src/applications/console/plugin/DarkConsoleErrorLogPlugin.php
<?php final class DarkConsoleErrorLogPlugin extends DarkConsolePlugin { public function getName() { $count = count($this->getData()); if ($count) { return pht('Error Log (%d)', $count); } return pht('Error Log'); } public function getOrder() { return 0; } public function getColor() { if (count($this->getData())) { return '#ff0000'; } return null; } public function getDescription() { return pht('Shows errors and warnings.'); } public function generateData() { return DarkConsoleErrorLogPluginAPI::getErrors(); } public function renderPanel() { $data = $this->getData(); $rows = array(); $details = array(); foreach ($data as $index => $row) { $file = $row['file']; $line = $row['line']; $tag = javelin_tag( 'a', array( 'sigil' => 'darkconsole-expand', 'meta' => array( 'expandID' => 'row-details-'.$index, ), ), $row['str'].' at ['.basename($file).':'.$line.']'); $rows[] = array($tag); $details[] = hsprintf( '<div class="dark-console-panel-error-details" id="row-details-%s">'. "%s\nStack trace:\n", $index, $row['details']); foreach ($row['trace'] as $key => $entry) { $line = ''; if (isset($entry['class'])) { $line .= $entry['class'].'::'; } $line .= idx($entry, 'function', ''); $href = null; if (isset($entry['file'])) { $line .= ' called at ['.$entry['file'].':'.$entry['line'].']'; } $details[] = $line; $details[] = "\n"; } $details[] = hsprintf('</div>'); } $table = new AphrontTableView($rows); $table->setClassName('error-log'); $table->setHeaders(array(pht('Error'))); $table->setNoDataString(pht('No errors.')); return phutil_tag( 'div', array(), array( phutil_tag('div', array(), $table->render()), phutil_tag('pre', array('class' => 'PhabricatorMonospaced'), $details), )); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/console/plugin/xhprof/DarkConsoleXHProfPluginAPI.php
src/applications/console/plugin/xhprof/DarkConsoleXHProfPluginAPI.php
<?php /** * @phutil-external-symbol function xhprof_enable * @phutil-external-symbol function xhprof_disable */ final class DarkConsoleXHProfPluginAPI extends Phobject { private static $profilerStarted; private static $profilerRunning; private static $profileFilePHID; public static function isProfilerAvailable() { return extension_loaded('xhprof'); } public static function getProfilerHeader() { return 'X-Phabricator-Profiler'; } public static function isProfilerRequested() { if (!empty($_REQUEST['__profile__'])) { return $_REQUEST['__profile__']; } $header = AphrontRequest::getHTTPHeader(self::getProfilerHeader()); if ($header) { return $header; } return false; } private static function shouldStartProfiler() { if (self::isProfilerRequested()) { return true; } static $sample_request = null; if ($sample_request === null) { if (PhabricatorEnv::getEnvConfig('debug.profile-rate')) { $rate = PhabricatorEnv::getEnvConfig('debug.profile-rate'); if (mt_rand(1, $rate) == 1) { $sample_request = true; } else { $sample_request = false; } } } return $sample_request; } public static function isProfilerStarted() { return self::$profilerStarted; } private static function isProfilerRunning() { return self::$profilerRunning; } public static function includeXHProfLib() { // TODO: this is incredibly stupid, but we may not have Phutil metamodule // stuff loaded yet so we can't just phutil_get_library_root() our way // to victory. $root = __FILE__; for ($ii = 0; $ii < 6; $ii++) { $root = dirname($root); } require_once $root.'/externals/xhprof/xhprof_lib.php'; } public static function saveProfilerSample(PhutilDeferredLog $access_log) { $file_phid = self::getProfileFilePHID(); if (!$file_phid) { return; } if (self::isProfilerRequested()) { $sample_rate = 0; } else { $sample_rate = PhabricatorEnv::getEnvConfig('debug.profile-rate'); } $profile_sample = id(new PhabricatorXHProfSample()) ->setFilePHID($file_phid) ->setSampleRate($sample_rate) ->setUsTotal($access_log->getData('T')) ->setHostname($access_log->getData('h')) ->setRequestPath($access_log->getData('U')) ->setController($access_log->getData('C')) ->setUserPHID($access_log->getData('P')); AphrontWriteGuard::allowDangerousUnguardedWrites(true); $caught = null; try { $profile_sample->save(); } catch (Exception $ex) { $caught = $ex; } AphrontWriteGuard::allowDangerousUnguardedWrites(false); if ($caught) { throw $caught; } } public static function hookProfiler() { if (!self::shouldStartProfiler()) { return; } if (!self::isProfilerAvailable()) { return; } if (self::$profilerStarted) { return; } self::startProfiler(); } /** * @phutil-external-symbol class PhabricatorStartup */ private static function startProfiler() { PhabricatorStartup::beginStartupPhase('profiler.init'); self::includeXHProfLib(); xhprof_enable(); self::$profilerStarted = true; self::$profilerRunning = true; } /** * @phutil-external-symbol class PhabricatorStartup */ public static function getProfileFilePHID() { if (!self::isProfilerRunning()) { return; } PhabricatorStartup::beginStartupPhase('profiler.stop'); self::stopProfiler(); PhabricatorStartup::beginStartupPhase('profiler.done'); return self::$profileFilePHID; } private static function stopProfiler() { $data = xhprof_disable(); $data = @json_encode($data); self::$profilerRunning = false; // Since these happen on GET we can't do guarded writes. These also // sometimes happen after we've disposed of the write guard; in this // case we need to disable the whole mechanism. $use_scope = AphrontWriteGuard::isGuardActive(); if ($use_scope) { $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); } else { AphrontWriteGuard::allowDangerousUnguardedWrites(true); } $caught = null; try { $file = call_user_func( array('PhabricatorFile', 'newFromFileData'), $data, array( 'mime-type' => 'application/xhprof', 'name' => 'profile.xhprof', )); } catch (Exception $ex) { $caught = $ex; } if ($use_scope) { unset($unguarded); } else { AphrontWriteGuard::allowDangerousUnguardedWrites(false); } if ($caught) { throw $caught; } self::$profileFilePHID = $file->getPHID(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/console/plugin/errorlog/DarkConsoleErrorLogPluginAPI.php
src/applications/console/plugin/errorlog/DarkConsoleErrorLogPluginAPI.php
<?php final class DarkConsoleErrorLogPluginAPI extends Phobject { private static $errors = array(); private static $discardMode = false; public static function registerErrorHandler() { // NOTE: This forces PhutilReadableSerializer to load, so that we are // able to handle errors which fire from inside autoloaders (PHP will not // reenter autoloaders). PhutilReadableSerializer::printableValue(null); PhutilErrorHandler::setErrorListener( array(__CLASS__, 'handleErrors')); } public static function enableDiscardMode() { self::$discardMode = true; } public static function disableDiscardMode() { self::$discardMode = false; } public static function getErrors() { return self::$errors; } public static function handleErrors($event, $value, $metadata) { if (self::$discardMode) { return; } switch ($event) { case PhutilErrorHandler::EXCEPTION: // $value is of type Exception self::$errors[] = array( 'details' => $value->getMessage(), 'event' => $event, 'file' => $value->getFile(), 'line' => $value->getLine(), 'str' => $value->getMessage(), 'trace' => $metadata['trace'], ); break; case PhutilErrorHandler::ERROR: // $value is a simple string self::$errors[] = array( 'details' => $value, 'event' => $event, 'file' => $metadata['file'], 'line' => $metadata['line'], 'str' => $value, 'trace' => $metadata['trace'], ); break; case PhutilErrorHandler::PHLOG: // $value can be anything self::$errors[] = array( 'details' => PhutilReadableSerializer::printShallow($value, 3), 'event' => $event, 'file' => $metadata['file'], 'line' => $metadata['line'], 'str' => PhutilReadableSerializer::printShort($value), 'trace' => $metadata['trace'], ); break; default: error_log(pht('Unknown event: %s', $event)); break; } } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/console/plugin/event/DarkConsoleEventPluginAPI.php
src/applications/console/plugin/event/DarkConsoleEventPluginAPI.php
<?php final class DarkConsoleEventPluginAPI extends PhabricatorEventListener { private static $events = array(); private static $discardMode = false; public static function enableDiscardMode() { self::$discardMode = true; } public static function getEvents() { return self::$events; } public function register() { $this->listen(PhabricatorEventType::TYPE_ALL); } public function handleEvent(PhutilEvent $event) { if (self::$discardMode) { return; } self::$events[] = $event; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/console/application/PhabricatorConsoleApplication.php
src/applications/console/application/PhabricatorConsoleApplication.php
<?php final class PhabricatorConsoleApplication extends PhabricatorApplication { public function getName() { return pht('Console'); } public function canUninstall() { return false; } public function isUnlisted() { return true; } public function getRoutes() { return array( '/~/' => array( '' => 'DarkConsoleController', 'data/(?P<key>[^/]+)/' => 'DarkConsoleDataController', ), ); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/console/core/DarkConsoleCore.php
src/applications/console/core/DarkConsoleCore.php
<?php final class DarkConsoleCore extends Phobject { private $plugins = array(); const STORAGE_VERSION = 1; public function __construct() { $this->plugins = id(new PhutilClassMapQuery()) ->setAncestorClass('DarkConsolePlugin') ->execute(); foreach ($this->plugins as $plugin) { $plugin->setConsoleCore($this); $plugin->didStartup(); } } public function getPlugins() { return $this->plugins; } public function getKey(AphrontRequest $request) { $plugins = $this->getPlugins(); foreach ($plugins as $plugin) { $plugin->setRequest($request); $plugin->willShutdown(); } foreach ($plugins as $plugin) { $plugin->didShutdown(); } foreach ($plugins as $plugin) { $plugin->setData($plugin->generateData()); } $plugins = msort($plugins, 'getOrderKey'); $key = Filesystem::readRandomCharacters(24); $tabs = array(); $data = array(); foreach ($plugins as $plugin) { $class = get_class($plugin); $tabs[] = array( 'class' => $class, 'name' => $plugin->getName(), 'color' => $plugin->getColor(), ); $data[$class] = $this->sanitizeForJSON($plugin->getData()); } $storage = array( 'vers' => self::STORAGE_VERSION, 'tabs' => $tabs, 'data' => $data, 'user' => $request->getUser() ? $request->getUser()->getPHID() : null, ); $cache = new PhabricatorKeyValueDatabaseCache(); $cache = new PhutilKeyValueCacheProfiler($cache); $cache->setProfiler(PhutilServiceProfiler::getInstance()); // This encoding may fail if there are, e.g., database queries which // include binary data. It would be a little cleaner to try to strip these, // but just do something non-broken here if we end up with unrepresentable // data. $json = @json_encode($storage); if (!$json) { $json = '{}'; } $cache->setKeys( array( 'darkconsole:'.$key => $json, ), $ttl = (60 * 60 * 6)); return $key; } public function getColor() { foreach ($this->getPlugins() as $plugin) { if ($plugin->getColor()) { return $plugin->getColor(); } } } public function render(AphrontRequest $request) { $user = $request->getUser(); $visible = $user->getUserSetting( PhabricatorDarkConsoleVisibleSetting::SETTINGKEY); return javelin_tag( 'div', array( 'id' => 'darkconsole', 'class' => 'dark-console', 'style' => $visible ? '' : 'display: none;', 'data-console-key' => $this->getKey($request), 'data-console-color' => $this->getColor(), ), ''); } /** * Sometimes, tab data includes binary information (like INSERT queries which * write file data into the database). To successfully JSON encode it, we * need to convert it to UTF-8. */ private function sanitizeForJSON($data) { if ($data === null) { return '<null>'; } if (is_object($data)) { return '<object:'.get_class($data).'>'; } else if (is_array($data)) { foreach ($data as $key => $value) { $data[$key] = $this->sanitizeForJSON($value); } return $data; } else if (is_resource($data)) { return '<resource>'; } else { // Truncate huge strings. Since the data doesn't really matter much, // just truncate bytes to avoid PhutilUTF8StringTruncator overhead. $length = strlen($data); $max = 4096; if ($length > $max) { $data = substr($data, 0, $max).'...<'.$length.' bytes>...'; } return phutil_utf8ize($data); } } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/controller/PonderQuestionStatusController.php
src/applications/ponder/controller/PonderQuestionStatusController.php
<?php final class PonderQuestionStatusController extends PonderController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $question = id(new PonderQuestionQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$question) { return new Aphront404Response(); } $view_uri = '/Q'.$question->getID(); $v_status = $question->getStatus(); if ($request->isFormPost()) { $v_status = $request->getStr('status'); $xactions = array(); $xactions[] = id(new PonderQuestionTransaction()) ->setTransactionType(PonderQuestionStatusTransaction::TRANSACTIONTYPE) ->setNewValue($v_status); $editor = id(new PonderQuestionEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request); $editor->applyTransactions($question, $xactions); return id(new AphrontRedirectResponse())->setURI($view_uri); } $radio = id(new AphrontFormRadioButtonControl()) ->setLabel(pht('Status')) ->setName('status') ->setValue($v_status); foreach (PonderQuestionStatus::getQuestionStatusMap() as $value => $name) { $description = PonderQuestionStatus::getQuestionStatusDescription($value); $radio->addButton($value, $name, $description); } $form = id(new AphrontFormView()) ->setUser($viewer) ->appendChild($radio); return $this->newDialog() ->setTitle(pht('Change Question Status')) ->appendChild($form->buildLayoutView()) ->addSubmitButton(pht('Submit')) ->addCancelButton($view_uri); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/controller/PonderAnswerEditController.php
src/applications/ponder/controller/PonderAnswerEditController.php
<?php final class PonderAnswerEditController extends PonderController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $answer = id(new PonderAnswerQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$answer) { return new Aphront404Response(); } $v_content = $answer->getContent(); $v_status = $answer->getStatus(); $e_content = true; $question = $answer->getQuestion(); $qid = $question->getID(); $answer_uri = $answer->getURI(); $errors = array(); if ($request->isFormPost()) { $v_content = $request->getStr('content'); $v_status = $request->getStr('status'); if (!strlen($v_content)) { $errors[] = pht('You must provide some substance in your answer.'); $e_content = pht('Required'); } if (!$errors) { $xactions = array(); $xactions[] = id(new PonderAnswerTransaction()) ->setTransactionType(PonderAnswerContentTransaction::TRANSACTIONTYPE) ->setNewValue($v_content); $xactions[] = id(new PonderAnswerTransaction()) ->setTransactionType(PonderAnswerStatusTransaction::TRANSACTIONTYPE) ->setNewValue($v_status); $editor = id(new PonderAnswerEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true); $editor->applyTransactions($answer, $xactions); return id(new AphrontRedirectResponse()) ->setURI($answer_uri); } } $answer_content_id = celerity_generate_unique_node_id(); $form = id(new AphrontFormView()) ->setUser($viewer) ->appendChild( id(new AphrontFormStaticControl()) ->setLabel(pht('Question')) ->setValue($question->getTitle())) ->appendChild( id(new AphrontFormSelectControl()) ->setLabel(pht('Status')) ->setName('status') ->setValue($v_status) ->setOptions(PonderAnswerStatus::getAnswerStatusMap())) ->appendChild( id(new PhabricatorRemarkupControl()) ->setUser($viewer) ->setLabel(pht('Answer')) ->setName('content') ->setID($answer_content_id) ->setValue($v_content) ->setError($e_content)) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue(pht('Submit')) ->addCancelButton($answer_uri)); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb("Q{$qid}", $answer_uri); $crumbs->addTextCrumb(pht('Edit Answer')); $crumbs->setBorder(true); $header = id(new PHUIHeaderView()) ->setHeader(pht('Edit Answer')) ->setHeaderIcon('fa-pencil'); $box = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Answer')) ->setFormErrors($errors) ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) ->setForm($form); $preview = id(new PHUIRemarkupPreviewPanel()) ->setHeader(pht('Answer Preview')) ->setControlID($answer_content_id) ->setPreviewURI($this->getApplicationURI('preview/')); $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setFooter(array( $box, $preview, )); return $this->newPage() ->setTitle(pht('Edit Answer')) ->setCrumbs($crumbs) ->appendChild($view); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/controller/PonderQuestionListController.php
src/applications/ponder/controller/PonderQuestionListController.php
<?php final class PonderQuestionListController extends PonderController { public function shouldAllowPublic() { return true; } public function handleRequest(AphrontRequest $request) { $query_key = $request->getURIData('queryKey'); $controller = id(new PhabricatorApplicationSearchController()) ->setQueryKey($query_key) ->setSearchEngine(new PonderQuestionSearchEngine()) ->setNavigation($this->buildSideNavView()); return $this->delegateToController($controller); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/controller/PonderQuestionViewController.php
src/applications/ponder/controller/PonderQuestionViewController.php
<?php final class PonderQuestionViewController extends PonderController { public function shouldAllowPublic() { return true; } public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $question = id(new PonderQuestionQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->needAnswers(true) ->needProjectPHIDs(true) ->executeOne(); if (!$question) { return new Aphront404Response(); } $answers = $this->buildAnswers($question); $answer_add_panel = id(new PonderAddAnswerView()) ->setQuestion($question) ->setUser($viewer) ->setActionURI('/ponder/answer/add/'); $header = new PHUIHeaderView(); $header->setHeader($question->getTitle()); $header->setUser($viewer); $header->setPolicyObject($question); $header->setHeaderIcon('fa-university'); if ($question->getStatus() == PonderQuestionStatus::STATUS_OPEN) { $header->setStatus('fa-square-o', 'bluegrey', pht('Open')); } else { $text = PonderQuestionStatus::getQuestionStatusFullName( $question->getStatus()); $icon = PonderQuestionStatus::getQuestionStatusIcon( $question->getStatus()); $header->setStatus($icon, 'dark', $text); } $curtain = $this->buildCurtain($question); $details = $this->buildPropertySectionView($question); $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $question, PhabricatorPolicyCapability::CAN_EDIT); $content_id = celerity_generate_unique_node_id(); $timeline = $this->buildTransactionTimeline( $question, id(new PonderQuestionTransactionQuery()) ->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT))); $xactions = $timeline->getTransactions(); $add_comment = id(new PhabricatorApplicationTransactionCommentView()) ->setUser($viewer) ->setObjectPHID($question->getPHID()) ->setShowPreview(false) ->setAction($this->getApplicationURI("/question/comment/{$id}/")) ->setSubmitButtonName(pht('Comment')); $add_comment = phutil_tag_div( 'ponder-question-add-comment-view', $add_comment); $comment_view = phutil_tag( 'div', array( 'id' => $content_id, 'style' => 'display: none;', ), array( $timeline, $add_comment, )); $footer = id(new PonderFooterView()) ->setContentID($content_id) ->setCount(count($xactions)); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb('Q'.$id, '/Q'.$id); $crumbs->setBorder(true); $subheader = $this->buildSubheaderView($question); $answer_wiki = null; if ($question->getAnswerWiki()) { $wiki = new PHUIRemarkupView($viewer, $question->getAnswerWiki()); $answer_wiki = id(new PHUIObjectBoxView()) ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) ->setHeaderText(pht('Answer Summary')) ->appendChild($wiki) ->addClass('ponder-answer-wiki'); } require_celerity_resource('ponder-view-css'); $ponder_content = phutil_tag( 'div', array( 'class' => 'ponder-question-content', ), array( $answer_wiki, $footer, $comment_view, $answers, $answer_add_panel, )); $ponder_view = id(new PHUITwoColumnView()) ->setHeader($header) ->setSubheader($subheader) ->setCurtain($curtain) ->setMainColumn($ponder_content) ->addPropertySection(pht('Details'), $details) ->addClass('ponder-question-view'); $page_objects = array_merge( array($question->getPHID()), mpull($question->getAnswers(), 'getPHID')); return $this->newPage() ->setTitle('Q'.$question->getID().' '.$question->getTitle()) ->setCrumbs($crumbs) ->setPageObjectPHIDs($page_objects) ->appendChild($ponder_view); } private function buildCurtain(PonderQuestion $question) { $viewer = $this->getViewer(); $id = $question->getID(); $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $question, PhabricatorPolicyCapability::CAN_EDIT); $curtain = $this->newCurtainView($question); if ($question->getStatus() == PonderQuestionStatus::STATUS_OPEN) { $name = pht('Close Question'); $icon = 'fa-check-square-o'; } else { $name = pht('Reopen Question'); $icon = 'fa-square-o'; } $curtain->addAction( id(new PhabricatorActionView()) ->setIcon('fa-pencil') ->setName(pht('Edit Question')) ->setHref($this->getApplicationURI("/question/edit/{$id}/")) ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); $curtain->addAction( id(new PhabricatorActionView()) ->setName($name) ->setIcon($icon) ->setWorkflow(true) ->setDisabled(!$can_edit) ->setHref($this->getApplicationURI("/question/status/{$id}/"))); $curtain->addAction( id(new PhabricatorActionView()) ->setIcon('fa-list') ->setName(pht('View History')) ->setHref($this->getApplicationURI("/question/history/{$id}/"))); return $curtain; } private function buildSubheaderView( PonderQuestion $question) { $viewer = $this->getViewer(); $asker = $viewer->renderHandle($question->getAuthorPHID())->render(); $date = phabricator_datetime($question->getDateCreated(), $viewer); $asker = phutil_tag('strong', array(), $asker); $author = id(new PhabricatorPeopleQuery()) ->setViewer($viewer) ->withPHIDs(array($question->getAuthorPHID())) ->needProfileImage(true) ->executeOne(); $image_uri = $author->getProfileImageURI(); $image_href = '/p/'.$author->getUsername(); $content = pht('Asked by %s on %s.', $asker, $date); return id(new PHUIHeadThingView()) ->setImage($image_uri) ->setImageHref($image_href) ->setContent($content); } private function buildPropertySectionView( PonderQuestion $question) { $viewer = $this->getViewer(); $question_details = PhabricatorMarkupEngine::renderOneObject( $question, $question->getMarkupField(), $viewer); if (!$question_details) { $question_details = phutil_tag( 'em', array(), pht('No further details for this question.')); } $question_details = phutil_tag_div( 'phabricator-remarkup ml', $question_details); return $question_details; } /** * This is fairly non-standard; building N timelines at once (N = number of * answers) is tricky business. * * TODO - re-factor this to ajax in one answer panel at a time in a more * standard fashion. This is necessary to scale this application. */ private function buildAnswers(PonderQuestion $question) { $viewer = $this->getViewer(); $answers = $question->getAnswers(); if ($answers) { $author_phids = mpull($answers, 'getAuthorPHID'); $handles = $this->loadViewerHandles($author_phids); $view = array(); foreach ($answers as $answer) { $id = $answer->getID(); $handle = $handles[$answer->getAuthorPHID()]; $timeline = $this->buildTransactionTimeline( $answer, id(new PonderAnswerTransactionQuery()) ->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT))); $xactions = $timeline->getTransactions(); $view[] = id(new PonderAnswerView()) ->setUser($viewer) ->setAnswer($answer) ->setTransactions($xactions) ->setTimeline($timeline) ->setHandle($handle); } $header = id(new PHUIHeaderView()) ->setHeader('Answers'); return id(new PHUIBoxView()) ->addClass('ponder-answer-section') ->appendChild($header) ->appendChild($view); } return null; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/controller/PonderAnswerCommentController.php
src/applications/ponder/controller/PonderAnswerCommentController.php
<?php final class PonderAnswerCommentController extends PonderController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); if (!$request->isFormPost()) { return new Aphront400Response(); } $answer = id(new PonderAnswerQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); if (!$answer) { return new Aphront404Response(); } $is_preview = $request->isPreviewRequest(); $qid = $answer->getQuestion()->getID(); $aid = $answer->getID(); // TODO, this behaves badly when redirecting to the answer $view_uri = "/Q{$qid}"; $xactions = array(); $xactions[] = id(new PonderAnswerTransaction()) ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) ->attachComment( id(new PonderAnswerTransactionComment()) ->setContent($request->getStr('comment'))); $editor = id(new PonderAnswerEditor()) ->setActor($viewer) ->setContinueOnNoEffect($request->isContinueRequest()) ->setContentSourceFromRequest($request) ->setIsPreview($is_preview); try { $xactions = $editor->applyTransactions($answer, $xactions); } catch (PhabricatorApplicationTransactionNoEffectException $ex) { return id(new PhabricatorApplicationTransactionNoEffectResponse()) ->setCancelURI($view_uri) ->setException($ex); } if ($request->isAjax() && $is_preview) { return id(new PhabricatorApplicationTransactionResponse()) ->setObject($answer) ->setViewer($viewer) ->setTransactions($xactions) ->setIsPreview($is_preview); } else { return id(new AphrontRedirectResponse()) ->setURI($view_uri); } } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/controller/PonderQuestionCommentController.php
src/applications/ponder/controller/PonderQuestionCommentController.php
<?php final class PonderQuestionCommentController extends PonderController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); if (!$request->isFormPost()) { return new Aphront400Response(); } $question = id(new PonderQuestionQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); if (!$question) { return new Aphront404Response(); } $is_preview = $request->isPreviewRequest(); $qid = $question->getID(); $view_uri = "/Q{$qid}"; $xactions = array(); $xactions[] = id(new PonderQuestionTransaction()) ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) ->attachComment( id(new PonderQuestionTransactionComment()) ->setContent($request->getStr('comment'))); $editor = id(new PonderQuestionEditor()) ->setActor($viewer) ->setContinueOnNoEffect($request->isContinueRequest()) ->setContentSourceFromRequest($request) ->setIsPreview($is_preview); try { $xactions = $editor->applyTransactions($question, $xactions); } catch (PhabricatorApplicationTransactionNoEffectException $ex) { return id(new PhabricatorApplicationTransactionNoEffectResponse()) ->setCancelURI($view_uri) ->setException($ex); } if ($request->isAjax() && $is_preview) { return id(new PhabricatorApplicationTransactionResponse()) ->setObject($question) ->setViewer($viewer) ->setTransactions($xactions) ->setIsPreview($is_preview); } else { return id(new AphrontRedirectResponse()) ->setURI($view_uri); } } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/controller/PonderAnswerSaveController.php
src/applications/ponder/controller/PonderAnswerSaveController.php
<?php final class PonderAnswerSaveController extends PonderController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); if (!$request->isFormPost()) { return new Aphront400Response(); } $question_id = $request->getInt('question_id'); $question = id(new PonderQuestionQuery()) ->setViewer($viewer) ->withIDs(array($question_id)) ->needAnswers(true) ->executeOne(); if (!$question) { return new Aphront404Response(); } $content = $request->getStr('answer'); if (!strlen(trim($content))) { $dialog = id(new AphrontDialogView()) ->setUser($viewer) ->setTitle(pht('Empty Answer')) ->appendChild( phutil_tag('p', array(), pht('Your answer must not be empty.'))) ->addCancelButton('/Q'.$question_id); return id(new AphrontDialogResponse())->setDialog($dialog); } $answer = PonderAnswer::initializeNewAnswer($viewer, $question); // Question Editor $xactions = array(); $xactions[] = id(new PonderQuestionTransaction()) ->setTransactionType(PonderQuestionAnswerTransaction::TRANSACTIONTYPE) ->setNewValue( array( '+' => array( array('answer' => $answer), ), )); $editor = id(new PonderQuestionEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request); $editor->applyTransactions($question, $xactions); // Answer Editor $template = id(new PonderAnswerTransaction()); $xactions = array(); $xactions[] = id(clone $template) ->setTransactionType(PonderAnswerQuestionIDTransaction::TRANSACTIONTYPE) ->setNewValue($question->getID()); $xactions[] = id(clone $template) ->setTransactionType(PonderAnswerContentTransaction::TRANSACTIONTYPE) ->setNewValue($content); $editor = id(new PonderAnswerEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true); $editor->applyTransactions($answer, $xactions); return id(new AphrontRedirectResponse())->setURI( id(new PhutilURI('/Q'.$question->getID()))); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/controller/PonderController.php
src/applications/ponder/controller/PonderController.php
<?php abstract class PonderController extends PhabricatorController { protected function buildSideNavView($for_app = false) { $user = $this->getRequest()->getUser(); $nav = new AphrontSideNavFilterView(); $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); if ($for_app) { $nav->addFilter('question/create/', pht('Ask Question')); } id(new PonderQuestionSearchEngine()) ->setViewer($user) ->addNavigationItems($nav->getMenu()); $nav->selectFilter(null); return $nav; } public function buildApplicationMenu() { return $this->buildSideNavView($for_app = true)->getMenu(); } protected function buildApplicationCrumbs() { $crumbs = parent::buildApplicationCrumbs(); id(new PonderQuestionEditEngine()) ->setViewer($this->getViewer()) ->addActionToCrumbs($crumbs); return $crumbs; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/controller/PonderAnswerHistoryController.php
src/applications/ponder/controller/PonderAnswerHistoryController.php
<?php final class PonderAnswerHistoryController extends PonderController { public function shouldAllowPublic() { return true; } public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $answer = id(new PonderAnswerQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); if (!$answer) { return new Aphront404Response(); } $timeline = $this->buildTransactionTimeline( $answer, new PonderAnswerTransactionQuery()); $timeline->setShouldTerminate(true); $qid = $answer->getQuestion()->getID(); $aid = $answer->getID(); $crumbs = $this->buildApplicationCrumbs(); $crumbs->setBorder(true); $crumbs->addTextCrumb("Q{$qid}", "/Q{$qid}"); $crumbs->addTextCrumb("A{$aid}", "/Q{$qid}#{$aid}"); $crumbs->addTextCrumb(pht('History')); $crumbs->setBorder(true); $header = id(new PHUIHeaderView()) ->setHeader(pht('Answer History')) ->setHeaderIcon('fa-history'); $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setFooter($timeline); return $this->newPage() ->setTitle(pht('Answer History')) ->setCrumbs($crumbs) ->appendChild($view); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/controller/PonderQuestionEditController.php
src/applications/ponder/controller/PonderQuestionEditController.php
<?php final class PonderQuestionEditController extends PonderController { public function handleRequest(AphrontRequest $request) { return id(new PonderQuestionEditEngine()) ->setController($this) ->buildResponse(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/controller/PonderQuestionHistoryController.php
src/applications/ponder/controller/PonderQuestionHistoryController.php
<?php final class PonderQuestionHistoryController extends PonderController { public function shouldAllowPublic() { return true; } public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $question = id(new PonderQuestionQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); if (!$question) { return new Aphront404Response(); } $timeline = $this->buildTransactionTimeline( $question, new PonderQuestionTransactionQuery()); $timeline->setShouldTerminate(true); $qid = $question->getID(); $crumbs = $this->buildApplicationCrumbs(); $crumbs->setBorder(true); $crumbs->addTextCrumb("Q{$qid}", "/Q{$qid}"); $crumbs->addTextCrumb(pht('History')); $crumbs->setBorder(true); $header = id(new PHUIHeaderView()) ->setHeader($question->getTitle()) ->setHeaderIcon('fa-history'); $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setFooter($timeline); return $this->newPage() ->setTitle(pht('Question History')) ->setCrumbs($crumbs) ->appendChild($view); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/storage/PonderQuestionTransactionComment.php
src/applications/ponder/storage/PonderQuestionTransactionComment.php
<?php final class PonderQuestionTransactionComment extends PhabricatorApplicationTransactionComment { public function getApplicationTransactionObject() { return new PonderQuestionTransaction(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/storage/PonderQuestionTransaction.php
src/applications/ponder/storage/PonderQuestionTransaction.php
<?php final class PonderQuestionTransaction extends PhabricatorModularTransaction { const MAILTAG_DETAILS = 'question:details'; const MAILTAG_COMMENT = 'question:comment'; const MAILTAG_ANSWERS = 'question:answer'; const MAILTAG_OTHER = 'question:other'; public function getApplicationName() { return 'ponder'; } public function getTableName() { return 'ponder_questiontransaction'; } public function getApplicationTransactionType() { return PonderQuestionPHIDType::TYPECONST; } public function getApplicationTransactionCommentObject() { return new PonderQuestionTransactionComment(); } public function getBaseTransactionClass() { return 'PonderQuestionTransactionType'; } public function getMailTags() { $tags = parent::getMailTags(); switch ($this->getTransactionType()) { case PhabricatorTransactions::TYPE_COMMENT: $tags[] = self::MAILTAG_COMMENT; break; case PonderQuestionTitleTransaction::TRANSACTIONTYPE: case PonderQuestionContentTransaction::TRANSACTIONTYPE: case PonderQuestionStatusTransaction::TRANSACTIONTYPE: case PonderQuestionAnswerWikiTransaction::TRANSACTIONTYPE: $tags[] = self::MAILTAG_DETAILS; break; case PonderQuestionAnswerTransaction::TRANSACTIONTYPE: $tags[] = self::MAILTAG_ANSWERS; break; default: $tags[] = self::MAILTAG_OTHER; break; } return $tags; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/storage/PonderAnswerTransactionComment.php
src/applications/ponder/storage/PonderAnswerTransactionComment.php
<?php final class PonderAnswerTransactionComment extends PhabricatorApplicationTransactionComment { public function getApplicationTransactionObject() { return new PonderAnswerTransaction(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/storage/PonderDAO.php
src/applications/ponder/storage/PonderDAO.php
<?php abstract class PonderDAO extends PhabricatorLiskDAO { public function getApplicationName() { return 'ponder'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/storage/PonderSchemaSpec.php
src/applications/ponder/storage/PonderSchemaSpec.php
<?php final class PonderSchemaSpec extends PhabricatorConfigSchemaSpec { public function buildSchemata() { $this->buildEdgeSchemata(new PonderQuestion()); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/storage/PonderAnswerTransaction.php
src/applications/ponder/storage/PonderAnswerTransaction.php
<?php final class PonderAnswerTransaction extends PhabricatorModularTransaction { public function getApplicationName() { return 'ponder'; } public function getTableName() { return 'ponder_answertransaction'; } public function getApplicationTransactionType() { return PonderAnswerPHIDType::TYPECONST; } public function getApplicationTransactionCommentObject() { return new PonderAnswerTransactionComment(); } public function getBaseTransactionClass() { return 'PonderAnswerTransactionType'; } public function getMailTags() { $tags = parent::getMailTags(); $tags[] = PonderQuestionTransaction::MAILTAG_OTHER; return $tags; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/storage/PonderQuestion.php
src/applications/ponder/storage/PonderQuestion.php
<?php final class PonderQuestion extends PonderDAO implements PhabricatorApplicationTransactionInterface, PhabricatorMarkupInterface, PhabricatorSubscribableInterface, PhabricatorFlaggableInterface, PhabricatorPolicyInterface, PhabricatorTokenReceiverInterface, PhabricatorProjectInterface, PhabricatorDestructibleInterface, PhabricatorSpacesInterface, PhabricatorFulltextInterface, PhabricatorFerretInterface { const MARKUP_FIELD_CONTENT = 'markup:content'; protected $title; protected $phid; protected $authorPHID; protected $status; protected $content; protected $answerWiki; protected $contentSource; protected $viewPolicy; protected $spacePHID; protected $answerCount; protected $mailKey; private $answers; private $comments; private $projectPHIDs = self::ATTACHABLE; public static function initializeNewQuestion(PhabricatorUser $actor) { $app = id(new PhabricatorApplicationQuery()) ->setViewer($actor) ->withClasses(array('PhabricatorPonderApplication')) ->executeOne(); $view_policy = $app->getPolicy( PonderDefaultViewCapability::CAPABILITY); return id(new PonderQuestion()) ->setAuthorPHID($actor->getPHID()) ->setViewPolicy($view_policy) ->setStatus(PonderQuestionStatus::STATUS_OPEN) ->setAnswerCount(0) ->setAnswerWiki('') ->setSpacePHID($actor->getDefaultSpacePHID()); } protected function getConfiguration() { return array( self::CONFIG_AUX_PHID => true, self::CONFIG_COLUMN_SCHEMA => array( 'title' => 'text255', 'status' => 'text32', 'content' => 'text', 'answerWiki' => 'text', 'answerCount' => 'uint32', 'mailKey' => 'bytes20', // T6203/NULLABILITY // This should always exist. 'contentSource' => 'text?', ), self::CONFIG_KEY_SCHEMA => array( 'key_phid' => null, 'phid' => array( 'columns' => array('phid'), 'unique' => true, ), 'authorPHID' => array( 'columns' => array('authorPHID'), ), 'status' => array( 'columns' => array('status'), ), ), ) + parent::getConfiguration(); } public function generatePHID() { return PhabricatorPHID::generateNewPHID(PonderQuestionPHIDType::TYPECONST); } public function setContentSource(PhabricatorContentSource $content_source) { $this->contentSource = $content_source->serialize(); return $this; } public function getContentSource() { return PhabricatorContentSource::newFromSerialized($this->contentSource); } public function setComments($comments) { $this->comments = $comments; return $this; } public function getComments() { return $this->comments; } public function getMonogram() { return 'Q'.$this->getID(); } public function getViewURI() { return '/'.$this->getMonogram(); } public function attachAnswers(array $answers) { assert_instances_of($answers, 'PonderAnswer'); $this->answers = $answers; return $this; } public function getAnswers() { return $this->answers; } public function getProjectPHIDs() { return $this->assertAttached($this->projectPHIDs); } public function attachProjectPHIDs(array $phids) { $this->projectPHIDs = $phids; return $this; } public function getMarkupField() { return self::MARKUP_FIELD_CONTENT; } /* -( PhabricatorApplicationTransactionInterface )------------------------- */ public function getApplicationTransactionEditor() { return new PonderQuestionEditor(); } public function getApplicationTransactionTemplate() { return new PonderQuestionTransaction(); } // Markup interface public function getMarkupFieldKey($field) { $content = $this->getMarkupText($field); return PhabricatorMarkupEngine::digestRemarkupContent($this, $content); } public function getMarkupText($field) { return $this->getContent(); } public function newMarkupEngine($field) { return PhabricatorMarkupEngine::getEngine(); } public function didMarkupText( $field, $output, PhutilMarkupEngine $engine) { return $output; } public function shouldUseMarkupCache($field) { return (bool)$this->getID(); } public function save() { if (!$this->getMailKey()) { $this->setMailKey(Filesystem::readRandomCharacters(20)); } return parent::save(); } public function getFullTitle() { $id = $this->getID(); $title = $this->getTitle(); return "Q{$id}: {$title}"; } /* -( PhabricatorPolicyInterface )----------------------------------------- */ public function getCapabilities() { return array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, ); } public function getPolicy($capability) { switch ($capability) { case PhabricatorPolicyCapability::CAN_VIEW: return $this->getViewPolicy(); case PhabricatorPolicyCapability::CAN_EDIT: $app = PhabricatorApplication::getByClass( 'PhabricatorPonderApplication'); return $app->getPolicy(PonderModerateCapability::CAPABILITY); } } public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { if ($capability == PhabricatorPolicyCapability::CAN_VIEW) { if (PhabricatorPolicyFilter::hasCapability( $viewer, $this, PhabricatorPolicyCapability::CAN_EDIT)) { return true; } } return ($viewer->getPHID() == $this->getAuthorPHID()); } public function describeAutomaticCapability($capability) { $out = array(); $out[] = pht('The user who asked a question can always view and edit it.'); switch ($capability) { case PhabricatorPolicyCapability::CAN_VIEW: $out[] = pht( 'A moderator can always view the question.'); break; } return $out; } /* -( PhabricatorSubscribableInterface )----------------------------------- */ public function isAutomaticallySubscribed($phid) { return ($phid == $this->getAuthorPHID()); } /* -( PhabricatorTokenReceiverInterface )---------------------------------- */ public function getUsersToNotifyOfTokenGiven() { return array( $this->getAuthorPHID(), ); } /* -( PhabricatorDestructibleInterface )----------------------------------- */ public function destroyObjectPermanently( PhabricatorDestructionEngine $engine) { $this->openTransaction(); $answers = id(new PonderAnswer())->loadAllWhere( 'questionID = %d', $this->getID()); foreach ($answers as $answer) { $engine->destroyObject($answer); } $this->delete(); $this->saveTransaction(); } /* -( PhabricatorSpacesInterface )----------------------------------------- */ public function getSpacePHID() { return $this->spacePHID; } /* -( PhabricatorFulltextInterface )--------------------------------------- */ public function newFulltextEngine() { return new PonderQuestionFulltextEngine(); } /* -( PhabricatorFerretInterface )----------------------------------------- */ public function newFerretEngine() { return new PonderQuestionFerretEngine(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/storage/PonderAnswer.php
src/applications/ponder/storage/PonderAnswer.php
<?php final class PonderAnswer extends PonderDAO implements PhabricatorApplicationTransactionInterface, PhabricatorMarkupInterface, PhabricatorPolicyInterface, PhabricatorFlaggableInterface, PhabricatorSubscribableInterface, PhabricatorDestructibleInterface { const MARKUP_FIELD_CONTENT = 'markup:content'; protected $authorPHID; protected $questionID; protected $content; protected $mailKey; protected $status; protected $voteCount; private $question = self::ATTACHABLE; private $comments; public static function initializeNewAnswer( PhabricatorUser $actor, PonderQuestion $question) { $app = id(new PhabricatorApplicationQuery()) ->setViewer($actor) ->withClasses(array('PhabricatorPonderApplication')) ->executeOne(); return id(new PonderAnswer()) ->setQuestionID($question->getID()) ->setContent('') ->attachQuestion($question) ->setAuthorPHID($actor->getPHID()) ->setVoteCount(0) ->setStatus(PonderAnswerStatus::ANSWER_STATUS_VISIBLE); } public function attachQuestion(PonderQuestion $question = null) { $this->question = $question; return $this; } public function getQuestion() { return $this->assertAttached($this->question); } public function getURI() { return '/Q'.$this->getQuestionID().'#A'.$this->getID(); } public function setComments($comments) { $this->comments = $comments; return $this; } public function getComments() { return $this->comments; } protected function getConfiguration() { return array( self::CONFIG_AUX_PHID => true, self::CONFIG_COLUMN_SCHEMA => array( 'voteCount' => 'sint32', 'content' => 'text', 'status' => 'text32', 'mailKey' => 'bytes20', ), self::CONFIG_KEY_SCHEMA => array( 'key_phid' => null, 'phid' => array( 'columns' => array('phid'), 'unique' => true, ), 'key_oneanswerperquestion' => array( 'columns' => array('questionID', 'authorPHID'), 'unique' => true, ), 'questionID' => array( 'columns' => array('questionID'), ), 'authorPHID' => array( 'columns' => array('authorPHID'), ), 'status' => array( 'columns' => array('status'), ), ), ) + parent::getConfiguration(); } public function generatePHID() { return PhabricatorPHID::generateNewPHID(PonderAnswerPHIDType::TYPECONST); } public function getMarkupField() { return self::MARKUP_FIELD_CONTENT; } public function save() { if (!$this->getMailKey()) { $this->setMailKey(Filesystem::readRandomCharacters(20)); } return parent::save(); } /* -( PhabricatorApplicationTransactionInterface )------------------------- */ public function getApplicationTransactionEditor() { return new PonderAnswerEditor(); } public function getApplicationTransactionTemplate() { return new PonderAnswerTransaction(); } // Markup interface public function getMarkupFieldKey($field) { $content = $this->getMarkupText($field); return PhabricatorMarkupEngine::digestRemarkupContent($this, $content); } public function getMarkupText($field) { return $this->getContent(); } public function newMarkupEngine($field) { return PhabricatorMarkupEngine::getEngine(); } public function didMarkupText( $field, $output, PhutilMarkupEngine $engine) { return $output; } public function shouldUseMarkupCache($field) { return (bool)$this->getID(); } /* -( PhabricatorPolicyInterface )----------------------------------------- */ public function getCapabilities() { return array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, ); } public function getPolicy($capability) { switch ($capability) { case PhabricatorPolicyCapability::CAN_VIEW: return $this->getQuestion()->getPolicy($capability); case PhabricatorPolicyCapability::CAN_EDIT: $app = PhabricatorApplication::getByClass( 'PhabricatorPonderApplication'); return $app->getPolicy(PonderModerateCapability::CAPABILITY); } } public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { switch ($capability) { case PhabricatorPolicyCapability::CAN_VIEW: if ($this->getAuthorPHID() == $viewer->getPHID()) { return true; } return $this->getQuestion()->hasAutomaticCapability( $capability, $viewer); case PhabricatorPolicyCapability::CAN_EDIT: return ($this->getAuthorPHID() == $viewer->getPHID()); } } public function describeAutomaticCapability($capability) { $out = array(); $out[] = pht('The author of an answer can always view and edit it.'); switch ($capability) { case PhabricatorPolicyCapability::CAN_VIEW: $out[] = pht( 'The user who asks a question can always view the answers.'); $out[] = pht( 'A moderator can always view the answers.'); break; } return $out; } /* -( PhabricatorSubscribableInterface )----------------------------------- */ public function isAutomaticallySubscribed($phid) { return ($phid == $this->getAuthorPHID()); } /* -( PhabricatorDestructibleInterface )----------------------------------- */ public function destroyObjectPermanently( PhabricatorDestructionEngine $engine) { $this->openTransaction(); $this->delete(); $this->saveTransaction(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/query/PonderQuestionTransactionQuery.php
src/applications/ponder/query/PonderQuestionTransactionQuery.php
<?php final class PonderQuestionTransactionQuery extends PhabricatorApplicationTransactionQuery { public function getTemplateApplicationTransaction() { return new PonderQuestionTransaction(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/query/PonderAnswerQuery.php
src/applications/ponder/query/PonderAnswerQuery.php
<?php final class PonderAnswerQuery extends PhabricatorCursorPagedPolicyAwareQuery { private $ids; private $phids; private $authorPHIDs; private $questionIDs; public function withIDs(array $ids) { $this->ids = $ids; return $this; } public function withPHIDs(array $phids) { $this->phids = $phids; return $this; } public function withAuthorPHIDs(array $phids) { $this->authorPHIDs = $phids; return $this; } public function withQuestionIDs(array $ids) { $this->questionIDs = $ids; return $this; } protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { $where = parent::buildWhereClauseParts($conn); if ($this->ids !== null) { $where[] = qsprintf( $conn, 'id IN (%Ld)', $this->ids); } if ($this->phids !== null) { $where[] = qsprintf( $conn, 'phid IN (%Ls)', $this->phids); } if ($this->authorPHIDs !== null) { $where[] = qsprintf( $conn, 'authorPHID IN (%Ls)', $this->authorPHIDs); } return $where; } public function newResultObject() { return new PonderAnswer(); } protected function willFilterPage(array $answers) { $questions = id(new PonderQuestionQuery()) ->setViewer($this->getViewer()) ->withIDs(mpull($answers, 'getQuestionID')) ->execute(); foreach ($answers as $key => $answer) { $question = idx($questions, $answer->getQuestionID()); if (!$question) { unset($answers[$key]); continue; } $answer->attachQuestion($question); } return $answers; } public function getQueryApplicationClass() { return 'PhabricatorPonderApplication'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/query/PonderQuestionQuery.php
src/applications/ponder/query/PonderQuestionQuery.php
<?php final class PonderQuestionQuery extends PhabricatorCursorPagedPolicyAwareQuery { private $ids; private $phids; private $status; private $authorPHIDs; private $answererPHIDs; private $needProjectPHIDs; private $needAnswers; public function withIDs(array $ids) { $this->ids = $ids; return $this; } public function withPHIDs(array $phids) { $this->phids = $phids; return $this; } public function withAuthorPHIDs(array $phids) { $this->authorPHIDs = $phids; return $this; } public function withStatuses($status) { $this->status = $status; return $this; } public function withAnswererPHIDs(array $phids) { $this->answererPHIDs = $phids; return $this; } public function needAnswers($need_answers) { $this->needAnswers = $need_answers; return $this; } public function needProjectPHIDs($need_projects) { $this->needProjectPHIDs = $need_projects; return $this; } protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { $where = parent::buildWhereClauseParts($conn); if ($this->ids !== null) { $where[] = qsprintf( $conn, 'q.id IN (%Ld)', $this->ids); } if ($this->phids !== null) { $where[] = qsprintf( $conn, 'q.phid IN (%Ls)', $this->phids); } if ($this->authorPHIDs !== null) { $where[] = qsprintf( $conn, 'q.authorPHID IN (%Ls)', $this->authorPHIDs); } if ($this->status !== null) { $where[] = qsprintf( $conn, 'q.status IN (%Ls)', $this->status); } return $where; } public function newResultObject() { return new PonderQuestion(); } protected function willFilterPage(array $questions) { $phids = mpull($questions, 'getPHID'); if ($this->needAnswers) { $aquery = id(new PonderAnswerQuery()) ->setViewer($this->getViewer()) ->setOrderVector(array('-id')) ->withQuestionIDs(mpull($questions, 'getID')); $answers = $aquery->execute(); $answers = mgroup($answers, 'getQuestionID'); foreach ($questions as $question) { $question_answers = idx($answers, $question->getID(), array()); $question->attachAnswers(mpull($question_answers, null, 'getPHID')); } } if ($this->needProjectPHIDs) { $edge_query = id(new PhabricatorEdgeQuery()) ->withSourcePHIDs($phids) ->withEdgeTypes( array( PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, )); $edge_query->execute(); foreach ($questions as $question) { $project_phids = $edge_query->getDestinationPHIDs( array($question->getPHID())); $question->attachProjectPHIDs($project_phids); } } return $questions; } protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { $joins = parent::buildJoinClauseParts($conn); if ($this->answererPHIDs) { $answer_table = new PonderAnswer(); $joins[] = qsprintf( $conn, 'JOIN %T a ON a.questionID = q.id AND a.authorPHID IN (%Ls)', $answer_table->getTableName(), $this->answererPHIDs); } return $joins; } protected function getPrimaryTableAlias() { return 'q'; } public function getQueryApplicationClass() { return 'PhabricatorPonderApplication'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/query/PonderAnswerTransactionQuery.php
src/applications/ponder/query/PonderAnswerTransactionQuery.php
<?php final class PonderAnswerTransactionQuery extends PhabricatorApplicationTransactionQuery { public function getTemplateApplicationTransaction() { return new PonderAnswerTransaction(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/query/PonderQuestionSearchEngine.php
src/applications/ponder/query/PonderQuestionSearchEngine.php
<?php final class PonderQuestionSearchEngine extends PhabricatorApplicationSearchEngine { public function getResultTypeDescription() { return pht('Ponder Questions'); } public function getApplicationClassName() { return 'PhabricatorPonderApplication'; } public function newQuery() { return id(new PonderQuestionQuery()) ->needProjectPHIDs(true); } protected function buildQueryFromParameters(array $map) { $query = $this->newQuery(); if ($map['authorPHIDs']) { $query->withAuthorPHIDs($map['authorPHIDs']); } if ($map['answerers']) { $query->withAnswererPHIDs($map['answerers']); } if ($map['statuses']) { $query->withStatuses($map['statuses']); } return $query; } protected function buildCustomSearchFields() { return array( id(new PhabricatorUsersSearchField()) ->setKey('authorPHIDs') ->setAliases(array('authors')) ->setLabel(pht('Authors')), id(new PhabricatorUsersSearchField()) ->setKey('answerers') ->setAliases(array('answerers')) ->setLabel(pht('Answered By')), id(new PhabricatorSearchCheckboxesField()) ->setLabel(pht('Status')) ->setKey('statuses') ->setOptions(PonderQuestionStatus::getQuestionStatusMap()), ); } protected function getURI($path) { return '/ponder/'.$path; } protected function getBuiltinQueryNames() { $names = array( 'recent' => pht('Recent Questions'), 'open' => pht('Open Questions'), 'resolved' => pht('Resolved Questions'), 'all' => pht('All Questions'), ); if ($this->requireViewer()->isLoggedIn()) { $names['authored'] = pht('Authored'); $names['answered'] = pht('Answered'); } return $names; } public function buildSavedQueryFromBuiltin($query_key) { $query = $this->newSavedQuery(); $query->setQueryKey($query_key); switch ($query_key) { case 'all': return $query; case 'open': return $query->setParameter( 'statuses', array(PonderQuestionStatus::STATUS_OPEN)); case 'recent': return $query->setParameter( 'statuses', array( PonderQuestionStatus::STATUS_OPEN, PonderQuestionStatus::STATUS_CLOSED_RESOLVED, )); case 'resolved': return $query->setParameter( 'statuses', array(PonderQuestionStatus::STATUS_CLOSED_RESOLVED)); case 'authored': return $query->setParameter( 'authorPHIDs', array($this->requireViewer()->getPHID())); case 'answered': return $query->setParameter( 'answerers', array($this->requireViewer()->getPHID())); } return parent::buildSavedQueryFromBuiltin($query_key); } protected function getRequiredHandlePHIDsForResultList( array $questions, PhabricatorSavedQuery $query) { return mpull($questions, 'getAuthorPHID'); } protected function renderResultList( array $questions, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($questions, 'PonderQuestion'); $viewer = $this->requireViewer(); $proj_phids = array(); foreach ($questions as $question) { foreach ($question->getProjectPHIDs() as $project_phid) { $proj_phids[] = $project_phid; } } $proj_handles = id(new PhabricatorHandleQuery()) ->setViewer($viewer) ->withPHIDs($proj_phids) ->execute(); $view = id(new PHUIObjectItemListView()) ->setUser($viewer); foreach ($questions as $question) { $color = PonderQuestionStatus::getQuestionStatusTagColor( $question->getStatus()); $icon = PonderQuestionStatus::getQuestionStatusIcon( $question->getStatus()); $full_status = PonderQuestionStatus::getQuestionStatusFullName( $question->getStatus()); $item = new PHUIObjectItemView(); $item->setObjectName('Q'.$question->getID()); $item->setHeader($question->getTitle()); $item->setHref('/Q'.$question->getID()); $item->setObject($question); $item->setStatusIcon($icon.' '.$color, $full_status); $project_handles = array_select_keys( $proj_handles, $question->getProjectPHIDs()); $created_date = phabricator_date($question->getDateCreated(), $viewer); $item->addIcon('none', $created_date); $item->addByline( pht( 'Asked by %s', $handles[$question->getAuthorPHID()]->renderLink())); $item->addAttribute( pht( '%s Answer(s)', new PhutilNumber($question->getAnswerCount()))); if ($project_handles) { $item->addAttribute( id(new PHUIHandleTagListView()) ->setLimit(4) ->setSlim(true) ->setHandles($project_handles)); } $view->addItem($item); } $result = new PhabricatorApplicationSearchResultView(); $result->setObjectList($view); $result->setNoDataString(pht('No questions found.')); return $result; } protected function getNewUserBody() { $create_button = id(new PHUIButtonView()) ->setTag('a') ->setText(pht('Ask a Question')) ->setHref('/ponder/question/create/') ->setColor(PHUIButtonView::GREEN); $icon = $this->getApplication()->getIcon(); $app_name = $this->getApplication()->getName(); $view = id(new PHUIBigInfoView()) ->setIcon($icon) ->setTitle(pht('Welcome to %s', $app_name)) ->setDescription( pht('A simple questions and answers application for your teams.')) ->addAction($create_button); return $view; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/mail/PonderAnswerReplyHandler.php
src/applications/ponder/mail/PonderAnswerReplyHandler.php
<?php final class PonderAnswerReplyHandler extends PhabricatorApplicationTransactionReplyHandler { public function validateMailReceiver($mail_receiver) { if (!($mail_receiver instanceof PonderAnswer)) { throw new Exception(pht('Mail receiver is not a %s!', 'PonderAnswer')); } } public function getObjectPrefix() { return 'ANSR'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/mail/PonderAnswerMailReceiver.php
src/applications/ponder/mail/PonderAnswerMailReceiver.php
<?php final class PonderAnswerMailReceiver extends PhabricatorObjectMailReceiver { public function isEnabled() { $app_class = 'PhabricatorPonderApplication'; return PhabricatorApplication::isClassInstalled($app_class); } protected function getObjectPattern() { return 'ANSR[1-9]\d*'; } protected function loadObject($pattern, PhabricatorUser $viewer) { $id = (int)substr($pattern, 4); return id(new PonderAnswerQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); } protected function getTransactionReplyHandler() { return new PonderAnswerReplyHandler(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/mail/PonderQuestionMailReceiver.php
src/applications/ponder/mail/PonderQuestionMailReceiver.php
<?php final class PonderQuestionMailReceiver extends PhabricatorObjectMailReceiver { public function isEnabled() { $app_class = 'PhabricatorPonderApplication'; return PhabricatorApplication::isClassInstalled($app_class); } protected function getObjectPattern() { return 'Q[1-9]\d*'; } protected function loadObject($pattern, PhabricatorUser $viewer) { $id = (int)substr($pattern, 1); return id(new PonderQuestionQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); } protected function getTransactionReplyHandler() { return new PonderQuestionReplyHandler(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/mail/PonderQuestionReplyHandler.php
src/applications/ponder/mail/PonderQuestionReplyHandler.php
<?php final class PonderQuestionReplyHandler extends PhabricatorApplicationTransactionReplyHandler { public function validateMailReceiver($mail_receiver) { if (!($mail_receiver instanceof PonderQuestion)) { throw new Exception(pht('Mail receiver is not a %s!', 'PonderQuestion')); } } public function getObjectPrefix() { return 'Q'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/mail/PonderQuestionCreateMailReceiver.php
src/applications/ponder/mail/PonderQuestionCreateMailReceiver.php
<?php final class PonderQuestionCreateMailReceiver extends PhabricatorApplicationMailReceiver { protected function newApplication() { return new PhabricatorPonderApplication(); } protected function processReceivedMail( PhabricatorMetaMTAReceivedMail $mail, PhutilEmailAddress $target) { $author = $this->getAuthor(); $title = $mail->getSubject(); if (!strlen($title)) { $title = pht('New Question'); } $xactions = array(); $xactions[] = id(new PonderQuestionTransaction()) ->setTransactionType(PonderQuestionTransaction::TYPE_TITLE) ->setNewValue($title); $xactions[] = id(new PonderQuestionTransaction()) ->setTransactionType(PonderQuestionTransaction::TYPE_CONTENT) ->setNewValue($mail->getCleanTextBody()); $question = PonderQuestion::initializeNewQuestion($author); $content_source = $mail->newContentSource(); $editor = id(new PonderQuestionEditor()) ->setActor($author) ->setContentSource($content_source) ->setContinueOnNoEffect(true); $xactions = $editor->applyTransactions($question, $xactions); $mail->setRelatedPHID($question->getPHID()); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/editor/PonderQuestionEditor.php
src/applications/ponder/editor/PonderQuestionEditor.php
<?php final class PonderQuestionEditor extends PonderEditor { private $answer; public function getEditorObjectsDescription() { return pht('Ponder Questions'); } public function getCreateObjectTitle($author, $object) { return pht('%s asked this question.', $author); } public function getCreateObjectTitleForFeed($author, $object) { return pht('%s asked %s.', $author, $object); } /** * This is used internally on @{method:applyInitialEffects} if a transaction * of type PonderQuestionTransaction::TYPE_ANSWERS is in the mix. The value * is set to the //last// answer in the transactions. Practically, one * answer is given at a time in the application, though theoretically * this is buggy. * * The answer is used in emails to generate proper links. */ private function setAnswer(PonderAnswer $answer) { $this->answer = $answer; return $this; } private function getAnswer() { return $this->answer; } protected function shouldApplyInitialEffects( PhabricatorLiskDAO $object, array $xactions) { foreach ($xactions as $xaction) { switch ($xaction->getTransactionType()) { case PonderQuestionAnswerTransaction::TRANSACTIONTYPE: return true; } } return false; } protected function applyInitialEffects( PhabricatorLiskDAO $object, array $xactions) { foreach ($xactions as $xaction) { switch ($xaction->getTransactionType()) { case PonderQuestionAnswerTransaction::TRANSACTIONTYPE: $new_value = $xaction->getNewValue(); $new = idx($new_value, '+', array()); foreach ($new as $new_answer) { $answer = idx($new_answer, 'answer'); if (!$answer) { continue; } $answer->save(); $this->setAnswer($answer); } break; } } } public function getTransactionTypes() { $types = parent::getTransactionTypes(); $types[] = PhabricatorTransactions::TYPE_COMMENT; $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; return $types; } protected function supportsSearch() { return true; } protected function shouldImplyCC( PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction) { switch ($xaction->getTransactionType()) { case PonderQuestionAnswerTransaction::TRANSACTIONTYPE: return false; } return parent::shouldImplyCC($object, $xaction); } protected function shouldSendMail( PhabricatorLiskDAO $object, array $xactions) { foreach ($xactions as $xaction) { switch ($xaction->getTransactionType()) { case PonderQuestionAnswerTransaction::TRANSACTIONTYPE: return false; } } return true; } protected function getMailTo(PhabricatorLiskDAO $object) { return array( $object->getAuthorPHID(), $this->requireActor()->getPHID(), ); } protected function shouldPublishFeedStory( PhabricatorLiskDAO $object, array $xactions) { foreach ($xactions as $xaction) { switch ($xaction->getTransactionType()) { case PonderQuestionAnswerTransaction::TRANSACTIONTYPE: return false; } } return true; } public function getMailTagsMap() { return array( PonderQuestionTransaction::MAILTAG_DETAILS => pht('Someone changes the questions details.'), PonderQuestionTransaction::MAILTAG_ANSWERS => pht('Someone adds a new answer.'), PonderQuestionTransaction::MAILTAG_COMMENT => pht('Someone comments on the question.'), PonderQuestionTransaction::MAILTAG_OTHER => pht('Other question activity not listed above occurs.'), ); } protected function buildReplyHandler(PhabricatorLiskDAO $object) { return id(new PonderQuestionReplyHandler()) ->setMailReceiver($object); } protected function buildMailTemplate(PhabricatorLiskDAO $object) { $id = $object->getID(); $title = $object->getTitle(); return id(new PhabricatorMetaMTAMail()) ->setSubject("Q{$id}: {$title}"); } protected function buildMailBody( PhabricatorLiskDAO $object, array $xactions) { $body = parent::buildMailBody($object, $xactions); $header = pht('QUESTION DETAIL'); $uri = '/Q'.$object->getID(); foreach ($xactions as $xaction) { $type = $xaction->getTransactionType(); $old = $xaction->getOldValue(); $new = $xaction->getNewValue(); // If the user just asked the question, add the question text. if ($type == PonderQuestionContentTransaction::TRANSACTIONTYPE) { if ($old === null) { $body->addRawSection($new); } } } $body->addLinkSection( $header, PhabricatorEnv::getProductionURI($uri)); return $body; } protected function shouldApplyHeraldRules( PhabricatorLiskDAO $object, array $xactions) { return true; } protected function buildHeraldAdapter( PhabricatorLiskDAO $object, array $xactions) { return id(new HeraldPonderQuestionAdapter()) ->setQuestion($object); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/editor/PonderEditor.php
src/applications/ponder/editor/PonderEditor.php
<?php abstract class PonderEditor extends PhabricatorApplicationTransactionEditor { public function getEditorApplicationClass() { return 'PhabricatorPonderApplication'; } protected function getMailSubjectPrefix() { return '[Ponder]'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/editor/PonderQuestionEditEngine.php
src/applications/ponder/editor/PonderQuestionEditEngine.php
<?php final class PonderQuestionEditEngine extends PhabricatorEditEngine { const ENGINECONST = 'ponder.question'; public function getEngineName() { return pht('Ponder Question'); } public function getEngineApplicationClass() { return 'PhabricatorPonderApplication'; } public function getSummaryHeader() { return pht('Configure Ponder Question Forms'); } public function getSummaryText() { return pht('Configure creation and editing forms in Ponder Questions.'); } public function isEngineConfigurable() { return false; } protected function newEditableObject() { return PonderQuestion::initializeNewQuestion($this->getViewer()); } protected function newObjectQuery() { return new PonderQuestionQuery(); } protected function getObjectCreateTitleText($object) { return pht('Create New Question'); } protected function getObjectEditTitleText($object) { return pht('Edit Question: %s', $object->getTitle()); } protected function getObjectEditShortText($object) { return $object->getTitle(); } protected function getObjectCreateShortText() { return pht('New Question'); } protected function getObjectName() { return pht('Question'); } protected function getObjectCreateCancelURI($object) { return $this->getApplication()->getApplicationURI('/'); } protected function getEditorURI() { return $this->getApplication()->getApplicationURI('question/edit/'); } protected function getObjectViewURI($object) { return $object->getViewURI(); } protected function buildCustomEditFields($object) { return array( id(new PhabricatorTextEditField()) ->setKey('title') ->setLabel(pht('Question')) ->setDescription(pht('Question title.')) ->setConduitTypeDescription(pht('New question title.')) ->setTransactionType( PonderQuestionTitleTransaction::TRANSACTIONTYPE) ->setValue($object->getTitle()) ->setIsRequired(true), id(new PhabricatorRemarkupEditField()) ->setKey('content') ->setLabel(pht('Details')) ->setDescription(pht('Long details of the question.')) ->setConduitTypeDescription(pht('New question details.')) ->setValue($object->getContent()) ->setTransactionType( PonderQuestionContentTransaction::TRANSACTIONTYPE), id(new PhabricatorRemarkupEditField()) ->setKey('answerWiki') ->setLabel(pht('Answer Summary')) ->setDescription(pht('Answer summary of the question.')) ->setConduitTypeDescription(pht('New question answer summary.')) ->setValue($object->getAnswerWiki()) ->setTransactionType( PonderQuestionAnswerWikiTransaction::TRANSACTIONTYPE), id(new PhabricatorSelectEditField()) ->setKey('status') ->setLabel(pht('Status')) ->setDescription(pht('Status of the question.')) ->setConduitTypeDescription(pht('New question status.')) ->setValue($object->getStatus()) ->setTransactionType( PonderQuestionStatusTransaction::TRANSACTIONTYPE) ->setOptions(PonderQuestionStatus::getQuestionStatusMap()), ); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/editor/PonderAnswerEditor.php
src/applications/ponder/editor/PonderAnswerEditor.php
<?php final class PonderAnswerEditor extends PonderEditor { public function getEditorObjectsDescription() { return pht('Ponder Answers'); } public function getCreateObjectTitle($author, $object) { return pht('%s added this answer.', $author); } public function getCreateObjectTitleForFeed($author, $object) { return pht('%s added %s.', $author, $object); } public function getTransactionTypes() { $types = parent::getTransactionTypes(); $types[] = PhabricatorTransactions::TYPE_COMMENT; return $types; } protected function shouldSendMail( PhabricatorLiskDAO $object, array $xactions) { return true; } protected function getMailTo(PhabricatorLiskDAO $object) { $phids = array(); $phids[] = $object->getAuthorPHID(); $phids[] = $this->requireActor()->getPHID(); $question = id(new PonderQuestionQuery()) ->setViewer($this->requireActor()) ->withIDs(array($object->getQuestionID())) ->executeOne(); $phids[] = $question->getAuthorPHID(); return $phids; } protected function shouldPublishFeedStory( PhabricatorLiskDAO $object, array $xactions) { return true; } protected function buildReplyHandler(PhabricatorLiskDAO $object) { return id(new PonderAnswerReplyHandler()) ->setMailReceiver($object); } protected function buildMailTemplate(PhabricatorLiskDAO $object) { $id = $object->getID(); return id(new PhabricatorMetaMTAMail()) ->setSubject("ANSR{$id}"); } protected function buildMailBody( PhabricatorLiskDAO $object, array $xactions) { $body = parent::buildMailBody($object, $xactions); // If the user just gave the answer, add the answer text. foreach ($xactions as $xaction) { $type = $xaction->getTransactionType(); $new = $xaction->getNewValue(); if ($type == PonderAnswerContentTransaction::TRANSACTIONTYPE) { $body->addRawSection($new); } } $body->addLinkSection( pht('ANSWER DETAIL'), PhabricatorEnv::getProductionURI($object->getURI())); return $body; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/xaction/PonderAnswerContentTransaction.php
src/applications/ponder/xaction/PonderAnswerContentTransaction.php
<?php final class PonderAnswerContentTransaction extends PonderAnswerTransactionType { const TRANSACTIONTYPE = 'ponder.answer:content'; public function generateOldValue($object) { return $object->getContent(); } public function applyInternalEffects($object, $value) { $object->setContent($value); } public function getTitle() { $old = $this->getOldValue(); if (!strlen($old)) { return pht( '%s added an answer.', $this->renderAuthor()); } return pht( '%s updated the answer details.', $this->renderAuthor()); } public function getTitleForFeed() { $old = $this->getOldValue(); if (!strlen($old)) { return pht( '%s added %s.', $this->renderAuthor(), $this->renderObject()); } return pht( '%s updated the answer details for %s.', $this->renderAuthor(), $this->renderObject()); } public function hasChangeDetailView() { return true; } public function getMailDiffSectionHeader() { return pht('CHANGES TO ANSWER DETAILS'); } public function newChangeDetailView() { $viewer = $this->getViewer(); return id(new PhabricatorApplicationTransactionTextDiffDetailView()) ->setViewer($viewer) ->setOldText($this->getOldValue()) ->setNewText($this->getNewValue()); } public function newRemarkupChanges() { $changes = array(); $changes[] = $this->newRemarkupChange() ->setOldValue($this->getOldValue()) ->setNewValue($this->getNewValue()); return $changes; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/xaction/PonderQuestionTitleTransaction.php
src/applications/ponder/xaction/PonderQuestionTitleTransaction.php
<?php final class PonderQuestionTitleTransaction extends PonderQuestionTransactionType { const TRANSACTIONTYPE = 'ponder.question:question'; public function generateOldValue($object) { return $object->getTitle(); } public function applyInternalEffects($object, $value) { $object->setTitle($value); } public function getTitle() { return pht( '%s updated the question from %s to %s.', $this->renderAuthor(), $this->renderOldValue(), $this->renderNewValue()); } public function getTitleForFeed() { return pht( '%s updated %s from %s to %s.', $this->renderAuthor(), $this->renderObject(), $this->renderOldValue(), $this->renderNewValue()); } public function validateTransactions($object, array $xactions) { $errors = array(); if ($this->isEmptyTextTransaction($object->getTitle(), $xactions)) { $errors[] = $this->newRequiredError( pht('Questions must have a title.')); } $max_length = $object->getColumnMaximumByteLength('title'); foreach ($xactions as $xaction) { $new_value = $xaction->getNewValue(); $new_length = strlen($new_value); if ($new_length > $max_length) { $errors[] = $this->newInvalidError( pht('The title can be no longer than %s characters.', new PhutilNumber($max_length))); } } return $errors; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/xaction/PonderAnswerStatusTransaction.php
src/applications/ponder/xaction/PonderAnswerStatusTransaction.php
<?php final class PonderAnswerStatusTransaction extends PonderAnswerTransactionType { const TRANSACTIONTYPE = 'ponder.answer:status'; public function generateOldValue($object) { return $object->getStatus(); } public function applyInternalEffects($object, $value) { $object->setStatus($value); } public function getTitle() { $new = $this->getNewValue(); if ($new == PonderAnswerStatus::ANSWER_STATUS_VISIBLE) { return pht( '%s marked this answer as visible.', $this->renderAuthor()); } else if ($new == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) { return pht( '%s marked this answer as hidden.', $this->renderAuthor()); } } public function getTitleForFeed() { $new = $this->getNewValue(); if ($new == PonderAnswerStatus::ANSWER_STATUS_VISIBLE) { return pht( '%s marked %s as visible.', $this->renderAuthor(), $this->renderObject()); } else if ($new == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) { return pht( '%s marked %s as hidden.', $this->renderAuthor(), $this->renderObject()); } } public function getIcon() { $new = $this->getNewValue(); if ($new == PonderAnswerStatus::ANSWER_STATUS_VISIBLE) { return 'fa-ban'; } else if ($new == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) { return 'fa-check'; } } public function getColor() { $new = $this->getNewValue(); if ($new == PonderAnswerStatus::ANSWER_STATUS_VISIBLE) { return 'green'; } else if ($new == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) { return 'indigo'; } } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/xaction/PonderAnswerQuestionIDTransaction.php
src/applications/ponder/xaction/PonderAnswerQuestionIDTransaction.php
<?php final class PonderAnswerQuestionIDTransaction extends PonderAnswerTransactionType { const TRANSACTIONTYPE = 'ponder.answer:question-id'; public function generateOldValue($object) { return $object->getQuestionID(); } public function applyInternalEffects($object, $value) { $object->setQuestionID($value); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/xaction/PonderQuestionAnswerWikiTransaction.php
src/applications/ponder/xaction/PonderQuestionAnswerWikiTransaction.php
<?php final class PonderQuestionAnswerWikiTransaction extends PonderQuestionTransactionType { const TRANSACTIONTYPE = 'ponder.question:wiki'; public function generateOldValue($object) { return $object->getAnswerWiki(); } public function applyInternalEffects($object, $value) { $object->setAnswerWiki($value); } public function getTitle() { return pht( '%s updated the answer wiki.', $this->renderAuthor()); } public function getTitleForFeed() { return pht( '%s updated the answer wiki for %s.', $this->renderAuthor(), $this->renderObject()); } public function hasChangeDetailView() { return true; } public function getMailDiffSectionHeader() { return pht('CHANGES TO ANSWER WIKI'); } public function newChangeDetailView() { $viewer = $this->getViewer(); return id(new PhabricatorApplicationTransactionTextDiffDetailView()) ->setViewer($viewer) ->setOldText($this->getOldValue()) ->setNewText($this->getNewValue()); } public function newRemarkupChanges() { $changes = array(); $changes[] = $this->newRemarkupChange() ->setOldValue($this->getOldValue()) ->setNewValue($this->getNewValue()); return $changes; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/xaction/PonderQuestionAnswerTransaction.php
src/applications/ponder/xaction/PonderQuestionAnswerTransaction.php
<?php final class PonderQuestionAnswerTransaction extends PonderQuestionTransactionType { const TRANSACTIONTYPE = 'ponder.question:answer'; public function generateOldValue($object) { return $object->getAnswers(); } public function applyInternalEffects($object, $value) { $count = $object->getAnswerCount(); $count++; $object->setAnswerCount($count); } public function getTitle() { return pht( '%s added an answer.', $this->renderAuthor()); } public function getTitleForFeed() { return pht( '%s added an answer to %s.', $this->renderAuthor(), $this->renderObject()); } public function getIcon() { return 'fa-plus'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/xaction/PonderQuestionTransactionType.php
src/applications/ponder/xaction/PonderQuestionTransactionType.php
<?php abstract class PonderQuestionTransactionType extends PhabricatorModularTransactionType {}
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/xaction/PonderAnswerTransactionType.php
src/applications/ponder/xaction/PonderAnswerTransactionType.php
<?php abstract class PonderAnswerTransactionType extends PhabricatorModularTransactionType {}
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/xaction/PonderQuestionContentTransaction.php
src/applications/ponder/xaction/PonderQuestionContentTransaction.php
<?php final class PonderQuestionContentTransaction extends PonderQuestionTransactionType { const TRANSACTIONTYPE = 'ponder.question:content'; public function generateOldValue($object) { return $object->getContent(); } public function applyInternalEffects($object, $value) { $object->setContent($value); } public function getTitle() { return pht( '%s updated the question details.', $this->renderAuthor()); } public function getTitleForFeed() { return pht( '%s updated the question details for %s.', $this->renderAuthor(), $this->renderObject()); } public function hasChangeDetailView() { return true; } public function getMailDiffSectionHeader() { return pht('CHANGES TO QUESTION DETAILS'); } public function newChangeDetailView() { $viewer = $this->getViewer(); return id(new PhabricatorApplicationTransactionTextDiffDetailView()) ->setViewer($viewer) ->setOldText($this->getOldValue()) ->setNewText($this->getNewValue()); } public function newRemarkupChanges() { $changes = array(); $changes[] = $this->newRemarkupChange() ->setOldValue($this->getOldValue()) ->setNewValue($this->getNewValue()); return $changes; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/xaction/PonderQuestionStatusTransaction.php
src/applications/ponder/xaction/PonderQuestionStatusTransaction.php
<?php final class PonderQuestionStatusTransaction extends PonderQuestionTransactionType { const TRANSACTIONTYPE = 'ponder.question:status'; public function generateOldValue($object) { return $object->getStatus(); } public function applyInternalEffects($object, $value) { $object->setStatus($value); } public function getTitle() { $new = $this->getNewValue(); switch ($new) { case PonderQuestionStatus::STATUS_OPEN: return pht( '%s reopened this question.', $this->renderAuthor()); case PonderQuestionStatus::STATUS_CLOSED_RESOLVED: return pht( '%s closed this question as resolved.', $this->renderAuthor()); case PonderQuestionStatus::STATUS_CLOSED_OBSOLETE: return pht( '%s closed this question as obsolete.', $this->renderAuthor()); case PonderQuestionStatus::STATUS_CLOSED_INVALID: return pht( '%s closed this question as invalid.', $this->renderAuthor()); } } public function getTitleForFeed() { $new = $this->getNewValue(); switch ($new) { case PonderQuestionStatus::STATUS_OPEN: return pht( '%s reopened %s.', $this->renderAuthor(), $this->renderObject()); case PonderQuestionStatus::STATUS_CLOSED_RESOLVED: return pht( '%s closed %s as resolved.', $this->renderAuthor(), $this->renderObject()); case PonderQuestionStatus::STATUS_CLOSED_INVALID: return pht( '%s closed %s as invalid.', $this->renderAuthor(), $this->renderObject()); case PonderQuestionStatus::STATUS_CLOSED_OBSOLETE: return pht( '%s closed %s as obsolete.', $this->renderAuthor(), $this->renderObject()); } } public function getIcon() { $new = $this->getNewValue(); return PonderQuestionStatus::getQuestionStatusIcon($new); } public function getColor() { $new = $this->getNewValue(); return PonderQuestionStatus::getQuestionStatusTagColor($new); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/application/PhabricatorPonderApplication.php
src/applications/ponder/application/PhabricatorPonderApplication.php
<?php final class PhabricatorPonderApplication extends PhabricatorApplication { public function getBaseURI() { return '/ponder/'; } public function getName() { return pht('Ponder'); } public function getShortDescription() { return pht('Questions and Answers'); } public function getIcon() { return 'fa-university'; } public function getTitleGlyph() { return "\xE2\x97\xB3"; } public function getRemarkupRules() { return array( new PonderRemarkupRule(), ); } public function getApplicationGroup() { return self::GROUP_UTILITIES; } public function supportsEmailIntegration() { return true; } public function getAppEmailBlurb() { return pht( 'Send email to these addresses to create questions. %s', phutil_tag( 'a', array( 'href' => $this->getInboundEmailSupportLink(), ), pht('Learn More'))); } public function getRoutes() { return array( '/Q(?P<id>[1-9]\d*)' => 'PonderQuestionViewController', '/ponder/' => array( '(?:query/(?P<queryKey>[^/]+)/)?' => 'PonderQuestionListController', 'answer/' => array( 'add/' => 'PonderAnswerSaveController', 'edit/(?P<id>\d+)/' => 'PonderAnswerEditController', 'comment/(?P<id>\d+)/' => 'PonderAnswerCommentController', 'history/(?P<id>\d+)/' => 'PonderAnswerHistoryController', ), 'question/' => array( $this->getEditRoutePattern('edit/') => 'PonderQuestionEditController', 'create/' => 'PonderQuestionEditController', 'comment/(?P<id>\d+)/' => 'PonderQuestionCommentController', 'history/(?P<id>\d+)/' => 'PonderQuestionHistoryController', ), 'preview/' => 'PhabricatorMarkupPreviewController', 'question/status/(?P<id>[1-9]\d*)/' => 'PonderQuestionStatusController', ), ); } public function getMailCommandObjects() { return array( 'question' => array( 'name' => pht('Email Commands: Questions'), 'header' => pht('Interacting with Ponder Questions'), 'object' => new PonderQuestion(), 'summary' => pht( 'This page documents the commands you can use to interact with '. 'questions in Ponder.'), ), ); } protected function getCustomCapabilities() { return array( PonderDefaultViewCapability::CAPABILITY => array( 'template' => PonderQuestionPHIDType::TYPECONST, 'capability' => PhabricatorPolicyCapability::CAN_VIEW, ), PonderModerateCapability::CAPABILITY => array( 'default' => PhabricatorPolicies::POLICY_ADMIN, 'template' => PonderQuestionPHIDType::TYPECONST, 'capability' => PhabricatorPolicyCapability::CAN_EDIT, ), ); } public function getApplicationSearchDocumentTypes() { return array( PonderQuestionPHIDType::TYPECONST, ); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/view/PonderFooterView.php
src/applications/ponder/view/PonderFooterView.php
<?php final class PonderFooterView extends AphrontTagView { private $contentID; private $count; private $actions = array(); public function setContentID($content_id) { $this->contentID = $content_id; return $this; } public function setCount($count) { $this->count = $count; return $this; } public function addAction($action) { $this->actions[] = $action; return $this; } protected function getTagAttributes() { return array( 'class' => 'ponder-footer-view', ); } protected function getTagContent() { require_celerity_resource('ponder-view-css'); Javelin::initBehavior('phabricator-reveal-content'); $hide_action_id = celerity_generate_unique_node_id(); $show_action_id = celerity_generate_unique_node_id(); $content_id = $this->contentID; if ($this->count == 0) { $text = pht('Add a Comment'); } else { $text = pht('Show %d Comment(s)', new PhutilNumber($this->count)); } $actions = array(); $hide_action = javelin_tag( 'a', array( 'sigil' => 'reveal-content', 'class' => 'ponder-footer-action', 'id' => $hide_action_id, 'href' => '#', 'meta' => array( 'showIDs' => array($content_id, $show_action_id), 'hideIDs' => array($hide_action_id), ), ), array($text)); $show_action = javelin_tag( 'a', array( 'sigil' => 'reveal-content', 'style' => 'display: none;', 'class' => 'ponder-footer-action', 'id' => $show_action_id, 'href' => '#', 'meta' => array( 'showIDs' => array($hide_action_id), 'hideIDs' => array($content_id, $show_action_id), ), ), array(pht('Hide Comments'))); $actions[] = $hide_action; $actions[] = $show_action; return array($actions, $this->actions); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/view/PonderAddAnswerView.php
src/applications/ponder/view/PonderAddAnswerView.php
<?php final class PonderAddAnswerView extends AphrontView { private $question; private $actionURI; private $draft; public function setQuestion($question) { $this->question = $question; return $this; } public function setActionURI($uri) { $this->actionURI = $uri; return $this; } public function render() { $question = $this->question; $viewer = $this->getViewer(); $authors = mpull($question->getAnswers(), null, 'getAuthorPHID'); if (isset($authors[$viewer->getPHID()])) { $view = id(new PHUIInfoView()) ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) ->setTitle(pht('Already Answered')) ->appendChild( pht( 'You have already answered this question. You can not answer '. 'twice, but you can edit your existing answer.')); return phutil_tag_div('ponder-add-answer-view', $view); } $info_panel = null; if ($question->getStatus() != PonderQuestionStatus::STATUS_OPEN) { $info_panel = id(new PHUIInfoView()) ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) ->appendChild( pht( 'This question has been marked as closed, but you can still leave a new answer.')); } $box_style = null; $header = id(new PHUIHeaderView()) ->setHeader(pht('New Answer')) ->addClass('ponder-add-answer-header'); $form = new AphrontFormView(); $form ->setViewer($viewer) ->setAction($this->actionURI) ->setWorkflow(true) ->addHiddenInput('question_id', $question->getID()) ->appendChild( id(new PhabricatorRemarkupControl()) ->setName('answer') ->setLabel(pht('Answer')) ->setError(true) ->setID('answer-content') ->setViewer($viewer)) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue(pht('Add Answer'))); if (!$viewer->isLoggedIn()) { $login_href = id(new PhutilURI('/auth/start/')) ->replaceQueryParam('next', '/Q'.$question->getID()); $form = id(new PHUIFormLayoutView()) ->addClass('login-to-participate') ->appendChild( id(new PHUIButtonView()) ->setTag('a') ->setText(pht('Log In to Answer')) ->setHref((string)$login_href)); } $box = id(new PHUIObjectBoxView()) ->appendChild($form) ->setHeaderText(pht('Answer')) ->addClass('ponder-add-answer-view'); if ($info_panel) { $box->setInfoView($info_panel); } return array($header, $box); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/view/PonderAnswerView.php
src/applications/ponder/view/PonderAnswerView.php
<?php final class PonderAnswerView extends AphrontTagView { private $answer; private $transactions; private $timeline; private $handle; public function setAnswer($answer) { $this->answer = $answer; return $this; } public function setTransactions($transactions) { $this->transactions = $transactions; return $this; } public function setTimeline($timeline) { $this->timeline = $timeline; return $this; } public function setHandle($handle) { $this->handle = $handle; return $this; } protected function getTagAttributes() { return array( 'class' => 'ponder-answer-view', ); } protected function getTagContent() { require_celerity_resource('ponder-view-css'); $answer = $this->answer; $viewer = $this->getUser(); $status = $answer->getStatus(); $author_phid = $answer->getAuthorPHID(); $actions = $this->buildAnswerActions(); $handle = $this->handle; $id = $answer->getID(); if ($status == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) { $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $answer, PhabricatorPolicyCapability::CAN_EDIT); $message = array(); $message[] = phutil_tag( 'em', array(), pht('This answer has been hidden.')); if ($can_edit) { $message[] = phutil_tag( 'a', array( 'href' => "/ponder/answer/edit/{$id}/", ), pht('Edit Answer')); } $message = phutil_implode_html(' ', $message); return id(new PHUIInfoView()) ->setSeverity(PHUIInfoView::SEVERITY_NODATA) ->appendChild($message); } $action_button = id(new PHUIButtonView()) ->setTag('a') ->setText(pht('Actions')) ->setHref('#') ->setIcon('fa-bars') ->setDropdownMenu($actions); $header_name = phutil_tag( 'a', array( 'href' => $handle->getURI(), ), $handle->getName()); $header = id(new PHUIHeaderView()) ->setUser($viewer) ->setEpoch($answer->getDateModified()) ->setHeader($header_name) ->addActionLink($action_button) ->setImage($handle->getImageURI()) ->setImageURL($handle->getURI()); $content = phutil_tag( 'div', array( 'class' => 'phabricator-remarkup', ), PhabricatorMarkupEngine::renderOneObject( $answer, $answer->getMarkupField(), $viewer)); $anchor = id(new PhabricatorAnchorView()) ->setAnchorName("A$id"); $content_id = celerity_generate_unique_node_id(); $footer = id(new PonderFooterView()) ->setContentID($content_id) ->setCount(count($this->transactions)); $content = phutil_tag_div( 'ponder-answer-content', array($anchor, $content, $footer)); $answer_view = id(new PHUIObjectBoxView()) ->setHeader($header) ->setBackground(PHUIObjectBoxView::GREY) ->addClass('ponder-answer') ->appendChild($content); $comment_view = id(new PhabricatorApplicationTransactionCommentView()) ->setUser($viewer) ->setObjectPHID($answer->getPHID()) ->setShowPreview(false) ->setHeaderText(pht('Answer Comment')) ->setAction("/ponder/answer/comment/{$id}/") ->setSubmitButtonName(pht('Comment')); $hidden_view = phutil_tag( 'div', array( 'id' => $content_id, 'style' => 'display: none;', ), array( $this->timeline, $comment_view, )); return array( $answer_view, $hidden_view, ); } private function buildAnswerActions() { $viewer = $this->getUser(); $answer = $this->answer; $id = $answer->getID(); $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $answer, PhabricatorPolicyCapability::CAN_EDIT); $view = id(new PhabricatorActionListView()) ->setUser($viewer) ->setObject($answer); $view->addAction( id(new PhabricatorActionView()) ->setIcon('fa-pencil') ->setName(pht('Edit Answer')) ->setHref("/ponder/answer/edit/{$id}/") ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); $view->addAction( id(new PhabricatorActionView()) ->setIcon('fa-list') ->setName(pht('View History')) ->setHref("/ponder/answer/history/{$id}/")); return $view; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/phid/PonderQuestionPHIDType.php
src/applications/ponder/phid/PonderQuestionPHIDType.php
<?php final class PonderQuestionPHIDType extends PhabricatorPHIDType { const TYPECONST = 'QUES'; public function getTypeName() { return pht('Ponder Question'); } public function newObject() { return new PonderQuestion(); } public function getPHIDTypeApplicationClass() { return 'PhabricatorPonderApplication'; } protected function buildQueryForObjects( PhabricatorObjectQuery $query, array $phids) { return id(new PonderQuestionQuery()) ->withPHIDs($phids); } public function loadHandles( PhabricatorHandleQuery $query, array $handles, array $objects) { foreach ($handles as $phid => $handle) { $question = $objects[$phid]; $id = $question->getID(); $handle->setName("Q{$id}"); $handle->setURI("/Q{$id}"); $handle->setFullName($question->getFullTitle()); } } public function canLoadNamedObject($name) { return preg_match('/^Q\d*[1-9]\d*$/i', $name); } public function loadNamedObjects( PhabricatorObjectQuery $query, array $names) { $id_map = array(); foreach ($names as $name) { $id = (int)substr($name, 1); $id_map[$id][] = $name; } $objects = id(new PonderQuestionQuery()) ->setViewer($query->getViewer()) ->withIDs(array_keys($id_map)) ->execute(); $results = array(); foreach ($objects as $id => $object) { foreach (idx($id_map, $id, array()) as $name) { $results[$name] = $object; } } return $results; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/phid/PonderAnswerPHIDType.php
src/applications/ponder/phid/PonderAnswerPHIDType.php
<?php final class PonderAnswerPHIDType extends PhabricatorPHIDType { const TYPECONST = 'ANSW'; public function getTypeName() { return pht('Ponder Answer'); } public function getPHIDTypeApplicationClass() { return 'PhabricatorPonderApplication'; } public function newObject() { return new PonderAnswer(); } protected function buildQueryForObjects( PhabricatorObjectQuery $query, array $phids) { return id(new PonderAnswerQuery()) ->withPHIDs($phids); } public function loadHandles( PhabricatorHandleQuery $query, array $handles, array $objects) { foreach ($handles as $phid => $handle) { $answer = $objects[$phid]; $id = $answer->getID(); $question = $answer->getQuestion(); $question_title = $question->getFullTitle(); $handle->setName(pht('%s (Answer %s)', $question_title, $id)); $handle->setURI($answer->getURI()); } } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/herald/HeraldPonderQuestionAdapter.php
src/applications/ponder/herald/HeraldPonderQuestionAdapter.php
<?php final class HeraldPonderQuestionAdapter extends HeraldAdapter { private $question; protected function newObject() { return new PonderQuestion(); } public function getAdapterApplicationClass() { return 'PhabricatorPonderApplication'; } public function getAdapterContentDescription() { return pht('React to questions being created or updated.'); } protected function initializeNewAdapter() { $this->question = $this->newObject(); } public function isTestAdapterForObject($object) { return ($object instanceof PonderQuestion); } public function getAdapterTestDescription() { return pht( 'Test rules which run when a question is created or updated.'); } public function setObject($object) { $this->question = $object; return $this; } public function supportsApplicationEmail() { return true; } public function supportsRuleType($rule_type) { switch ($rule_type) { case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL: return true; case HeraldRuleTypeConfig::RULE_TYPE_OBJECT: default: return false; } } public function setQuestion(PonderQuestion $question) { $this->question = $question; return $this; } public function getObject() { return $this->question; } public function getAdapterContentName() { return pht('Ponder Questions'); } public function getHeraldName() { return 'Q'.$this->getObject()->getID(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/search/PonderQuestionFulltextEngine.php
src/applications/ponder/search/PonderQuestionFulltextEngine.php
<?php final class PonderQuestionFulltextEngine extends PhabricatorFulltextEngine { protected function buildAbstractDocument( PhabricatorSearchAbstractDocument $document, $object) { $question = $object; $document->setDocumentTitle($question->getTitle()); $document->addField( PhabricatorSearchDocumentFieldType::FIELD_BODY, $question->getContent()); $document->addRelationship( PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $question->getAuthorPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $question->getDateCreated()); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/search/PonderQuestionFerretEngine.php
src/applications/ponder/search/PonderQuestionFerretEngine.php
<?php final class PonderQuestionFerretEngine extends PhabricatorFerretEngine { public function getApplicationName() { return 'ponder'; } public function getScopeName() { return 'question'; } public function newSearchEngine() { return new PonderQuestionSearchEngine(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/capability/PonderDefaultViewCapability.php
src/applications/ponder/capability/PonderDefaultViewCapability.php
<?php final class PonderDefaultViewCapability extends PhabricatorPolicyCapability { const CAPABILITY = 'ponder.default.view'; public function getCapabilityName() { return pht('Default View Policy'); } public function shouldAllowPublicPolicySetting() { return true; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/capability/PonderModerateCapability.php
src/applications/ponder/capability/PonderModerateCapability.php
<?php final class PonderModerateCapability extends PhabricatorPolicyCapability { const CAPABILITY = 'ponder.moderate'; public function getCapabilityName() { return pht('Moderate Policy'); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/remarkup/PonderRemarkupRule.php
src/applications/ponder/remarkup/PonderRemarkupRule.php
<?php final class PonderRemarkupRule extends PhabricatorObjectRemarkupRule { protected function getObjectNamePrefix() { return 'Q'; } protected function loadObjects(array $ids) { $viewer = $this->getEngine()->getConfig('viewer'); return id(new PonderQuestionQuery()) ->setViewer($viewer) ->withIDs($ids) ->execute(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/constants/PonderAnswerStatus.php
src/applications/ponder/constants/PonderAnswerStatus.php
<?php final class PonderAnswerStatus extends PonderConstants { const ANSWER_STATUS_VISIBLE = 'visible'; const ANSWER_STATUS_HIDDEN = 'hidden'; public static function getAnswerStatusMap() { return array( self::ANSWER_STATUS_VISIBLE => pht('Visible'), self::ANSWER_STATUS_HIDDEN => pht('Hidden'), ); } public static function getAnswerStatusName($status) { $map = array( self::ANSWER_STATUS_VISIBLE => pht('Visible'), self::ANSWER_STATUS_HIDDEN => pht('Hidden'), ); return idx($map, $status, pht('Unknown')); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/constants/PonderConstants.php
src/applications/ponder/constants/PonderConstants.php
<?php abstract class PonderConstants extends Phobject {}
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/ponder/constants/PonderQuestionStatus.php
src/applications/ponder/constants/PonderQuestionStatus.php
<?php final class PonderQuestionStatus extends PonderConstants { const STATUS_OPEN = 'open'; const STATUS_CLOSED_RESOLVED = 'resolved'; const STATUS_CLOSED_OBSOLETE = 'obsolete'; const STATUS_CLOSED_INVALID = 'invalid'; public static function getQuestionStatusMap() { return array( self::STATUS_OPEN => pht('Open'), self::STATUS_CLOSED_RESOLVED => pht('Closed, Resolved'), self::STATUS_CLOSED_OBSOLETE => pht('Closed, Obsolete'), self::STATUS_CLOSED_INVALID => pht('Closed, Invalid'), ); } public static function getQuestionStatusFullName($status) { $map = array( self::STATUS_OPEN => pht('Open'), self::STATUS_CLOSED_RESOLVED => pht('Closed, Resolved'), self::STATUS_CLOSED_OBSOLETE => pht('Closed, Obsolete'), self::STATUS_CLOSED_INVALID => pht('Closed, Invalid'), ); return idx($map, $status, pht('Unknown')); } public static function getQuestionStatusName($status) { $map = array( self::STATUS_OPEN => pht('Open'), self::STATUS_CLOSED_RESOLVED => pht('Resolved'), self::STATUS_CLOSED_OBSOLETE => pht('Obsolete'), self::STATUS_CLOSED_INVALID => pht('Invalid'), ); return idx($map, $status, pht('Unknown')); } public static function getQuestionStatusDescription($status) { $map = array( self::STATUS_OPEN => pht('This question is open for answers.'), self::STATUS_CLOSED_RESOLVED => pht('This question has been answered or resolved.'), self::STATUS_CLOSED_OBSOLETE => pht('This question is out of date.'), self::STATUS_CLOSED_INVALID => pht('This question is invalid.'), ); return idx($map, $status, pht('Unknown')); } public static function getQuestionStatusTagColor($status) { $map = array( self::STATUS_OPEN => PHUITagView::COLOR_BLUE, self::STATUS_CLOSED_RESOLVED => PHUITagView::COLOR_BLACK, self::STATUS_CLOSED_OBSOLETE => PHUITagView::COLOR_BLACK, self::STATUS_CLOSED_INVALID => PHUITagView::COLOR_BLACK, ); return idx($map, $status); } public static function getQuestionStatusIcon($status) { $map = array( self::STATUS_OPEN => 'fa-question-circle', self::STATUS_CLOSED_RESOLVED => 'fa-check', self::STATUS_CLOSED_OBSOLETE => 'fa-ban', self::STATUS_CLOSED_INVALID => 'fa-ban', ); return idx($map, $status); } public static function getQuestionStatusOpenMap() { return array( self::STATUS_OPEN, ); } public static function getQuestionStatusClosedMap() { return array( self::STATUS_CLOSED_RESOLVED, self::STATUS_CLOSED_OBSOLETE, self::STATUS_CLOSED_INVALID, ); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockBlueprintDisableController.php
src/applications/drydock/controller/DrydockBlueprintDisableController.php
<?php final class DrydockBlueprintDisableController extends DrydockBlueprintController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $blueprint = id(new DrydockBlueprintQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$blueprint) { return new Aphront404Response(); } $is_disable = ($request->getURIData('action') == 'disable'); $id = $blueprint->getID(); $cancel_uri = $this->getApplicationURI("blueprint/{$id}/"); if ($request->isFormPost()) { $xactions = array(); $xactions[] = id(new DrydockBlueprintTransaction()) ->setTransactionType( DrydockBlueprintDisableTransaction::TRANSACTIONTYPE) ->setNewValue($is_disable ? 1 : 0); $editor = id(new DrydockBlueprintEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true) ->setContinueOnMissingFields(true) ->applyTransactions($blueprint, $xactions); return id(new AphrontRedirectResponse())->setURI($cancel_uri); } if ($is_disable) { $title = pht('Disable Blueprint'); $body = pht( 'If you disable this blueprint, Drydock will no longer use it to '. 'allocate new resources. Existing resources will not be affected.'); $button = pht('Disable Blueprint'); } else { $title = pht('Enable Blueprint'); $body = pht( 'If you enable this blueprint, Drydock will start using it to '. 'allocate new resources.'); $button = pht('Enable Blueprint'); } return $this->newDialog() ->setTitle($title) ->appendParagraph($body) ->addCancelButton($cancel_uri) ->addSubmitButton($button); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockAuthorizationViewController.php
src/applications/drydock/controller/DrydockAuthorizationViewController.php
<?php final class DrydockAuthorizationViewController extends DrydockController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $authorization = id(new DrydockAuthorizationQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); if (!$authorization) { return new Aphront404Response(); } $id = $authorization->getID(); $title = pht('Authorization %d', $id); $blueprint = $authorization->getBlueprint(); $blueprint_id = $blueprint->getID(); $header = id(new PHUIHeaderView()) ->setHeader($title) ->setUser($viewer) ->setPolicyObject($authorization); $state = $authorization->getBlueprintAuthorizationState(); $icon = DrydockAuthorization::getBlueprintStateIcon($state); $name = DrydockAuthorization::getBlueprintStateName($state); $header->setStatus($icon, null, $name); $curtain = $this->buildCurtain($authorization); $properties = $this->buildPropertyListView($authorization); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb( pht('Blueprints'), $this->getApplicationURI('blueprint/')); $crumbs->addTextCrumb( $blueprint->getBlueprintName(), $this->getApplicationURI("blueprint/{$blueprint_id}/")); $crumbs->addTextCrumb($title); $crumbs->setBorder(true); $object_box = id(new PHUIObjectBoxView()) ->setHeader($header) ->addPropertyList($properties); $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setCurtain($curtain) ->addPropertySection(pht('Properties'), $properties); return $this->newPage() ->setTitle($title) ->setCrumbs($crumbs) ->appendChild( array( $view, )); } private function buildCurtain(DrydockAuthorization $authorization) { $viewer = $this->getViewer(); $id = $authorization->getID(); $curtain = $this->newCurtainView($authorization); $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $authorization, PhabricatorPolicyCapability::CAN_EDIT); $authorize_uri = $this->getApplicationURI("authorization/{$id}/authorize/"); $decline_uri = $this->getApplicationURI("authorization/{$id}/decline/"); $state_authorized = DrydockAuthorization::BLUEPRINTAUTH_AUTHORIZED; $state_declined = DrydockAuthorization::BLUEPRINTAUTH_DECLINED; $state = $authorization->getBlueprintAuthorizationState(); $can_authorize = $can_edit && ($state != $state_authorized); $can_decline = $can_edit && ($state != $state_declined); $curtain->addAction( id(new PhabricatorActionView()) ->setHref($authorize_uri) ->setName(pht('Approve Authorization')) ->setIcon('fa-check') ->setWorkflow(true) ->setDisabled(!$can_authorize)); $curtain->addAction( id(new PhabricatorActionView()) ->setHref($decline_uri) ->setName(pht('Decline Authorization')) ->setIcon('fa-times') ->setWorkflow(true) ->setDisabled(!$can_decline)); return $curtain; } private function buildPropertyListView(DrydockAuthorization $authorization) { $viewer = $this->getViewer(); $object_phid = $authorization->getObjectPHID(); $handles = $viewer->loadHandles(array($object_phid)); $handle = $handles[$object_phid]; $view = new PHUIPropertyListView(); $view->addProperty( pht('Authorized Object'), $handle->renderLink($handle->getFullName())); $view->addProperty(pht('Object Type'), $handle->getTypeName()); $object_state = $authorization->getObjectAuthorizationState(); $view->addProperty( pht('Authorization State'), DrydockAuthorization::getObjectStateName($object_state)); return $view; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockRepositoryOperationStatusController.php
src/applications/drydock/controller/DrydockRepositoryOperationStatusController.php
<?php final class DrydockRepositoryOperationStatusController extends DrydockRepositoryOperationController { public function shouldAllowPublic() { return true; } public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $operation = id(new DrydockRepositoryOperationQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); if (!$operation) { return new Aphront404Response(); } $id = $operation->getID(); $status_view = id(new DrydockRepositoryOperationStatusView()) ->setUser($viewer) ->setOperation($operation); if ($request->isAjax()) { $payload = array( 'markup' => $status_view->renderUnderwayState(), 'isUnderway' => $operation->isUnderway(), ); return id(new AphrontAjaxResponse()) ->setContent($payload); } $title = pht('Repository Operation %d', $id); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb( pht('Operations'), $this->getApplicationURI('operation/')); $crumbs->addTextCrumb($title); return $this->newPage() ->setTitle(pht('Status')) ->setCrumbs($crumbs) ->appendChild($status_view); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockLeaseListController.php
src/applications/drydock/controller/DrydockLeaseListController.php
<?php final class DrydockLeaseListController extends DrydockLeaseController { public function shouldAllowPublic() { return true; } public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $query_key = $request->getURIData('queryKey'); $engine = new DrydockLeaseSearchEngine(); $id = $request->getURIData('id'); if ($id) { $resource = id(new DrydockResourceQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); if (!$resource) { return new Aphront404Response(); } $this->setResource($resource); $engine->setResource($resource); } $controller = id(new PhabricatorApplicationSearchController()) ->setQueryKey($query_key) ->setSearchEngine($engine) ->setNavigation($this->buildSideNavView()); return $this->delegateToController($controller); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockBlueprintEditController.php
src/applications/drydock/controller/DrydockBlueprintEditController.php
<?php final class DrydockBlueprintEditController extends DrydockBlueprintController { public function handleRequest(AphrontRequest $request) { $engine = id(new DrydockBlueprintEditEngine()) ->setController($this); $id = $request->getURIData('id'); if (!$id) { $this->requireApplicationCapability( DrydockCreateBlueprintsCapability::CAPABILITY); $type = $request->getStr('blueprintType'); $impl = DrydockBlueprintImplementation::getNamedImplementation($type); if (!$impl || !$impl->isEnabled()) { return $this->buildTypeSelectionResponse(); } $engine ->addContextParameter('blueprintType', $type) ->setBlueprintImplementation($impl); } return $engine->buildResponse(); } private function buildTypeSelectionResponse() { $request = $this->getRequest(); $viewer = $this->getViewer(); $implementations = DrydockBlueprintImplementation::getAllBlueprintImplementations(); $errors = array(); $e_blueprint = null; if ($request->isFormPost()) { $class = $request->getStr('blueprintType'); if (!isset($implementations[$class])) { $e_blueprint = pht('Required'); $errors[] = pht('You must choose a blueprint type.'); } } $control = id(new AphrontFormRadioButtonControl()) ->setName('blueprintType') ->setLabel(pht('Blueprint Type')) ->setError($e_blueprint); foreach ($implementations as $implementation_name => $implementation) { $disabled = !$implementation->isEnabled(); $impl_icon = $implementation->getBlueprintIcon(); $impl_name = $implementation->getBlueprintName(); $impl_icon = id(new PHUIIconView()) ->setIcon($impl_icon, 'lightgreytext'); $control->addButton( $implementation_name, array($impl_icon, ' ', $impl_name), array( pht('Provides: %s', $implementation->getType()), phutil_tag('br'), phutil_tag('br'), $implementation->getDescription(), ), $disabled ? 'disabled' : null, $disabled); } $title = pht('Create New Blueprint'); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('New Blueprint')); $crumbs->setBorder(true); $form = id(new AphrontFormView()) ->setUser($viewer) ->appendChild($control) ->appendChild( id(new AphrontFormSubmitControl()) ->addCancelButton($this->getApplicationURI('blueprint/')) ->setValue(pht('Continue'))); $box = id(new PHUIObjectBoxView()) ->setFormErrors($errors) ->setHeaderText($title) ->setBackground(PHUIObjectBoxView::WHITE_CONFIG) ->setForm($form); $view = id(new PHUITwoColumnView()) ->setFooter($box); return $this->newPage() ->setTitle($title) ->setCrumbs($crumbs) ->appendChild($view); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockBlueprintViewController.php
src/applications/drydock/controller/DrydockBlueprintViewController.php
<?php final class DrydockBlueprintViewController extends DrydockBlueprintController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $blueprint = id(new DrydockBlueprintQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); if (!$blueprint) { return new Aphront404Response(); } $title = $blueprint->getBlueprintName(); $header = id(new PHUIHeaderView()) ->setHeader($title) ->setUser($viewer) ->setPolicyObject($blueprint) ->setHeaderIcon('fa-map-o'); if ($blueprint->getIsDisabled()) { $header->setStatus('fa-ban', 'red', pht('Disabled')); } else { $header->setStatus('fa-check', 'bluegrey', pht('Active')); } $curtain = $this->buildCurtain($blueprint); $properties = $this->buildPropertyListView($blueprint); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Blueprint %d', $blueprint->getID())); $crumbs->setBorder(true); $field_list = PhabricatorCustomField::getObjectFields( $blueprint, PhabricatorCustomField::ROLE_VIEW); $field_list ->setViewer($viewer) ->readFieldsFromStorage($blueprint); $field_list->appendFieldsToPropertyList( $blueprint, $viewer, $properties); $resources = $this->buildResourceBox($blueprint); $authorizations = $this->buildAuthorizationsBox($blueprint); $timeline = $this->buildTransactionTimeline( $blueprint, new DrydockBlueprintTransactionQuery()); $timeline->setShouldTerminate(true); $log_query = id(new DrydockLogQuery()) ->withBlueprintPHIDs(array($blueprint->getPHID())); $log_table = $this->buildLogTable($log_query) ->setHideBlueprints(true); $logs = $this->buildLogBox( $log_table, $this->getApplicationURI("blueprint/{$id}/logs/query/all/")); $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setCurtain($curtain) ->addPropertySection(pht('Properties'), $properties) ->setMainColumn(array( $resources, $authorizations, $logs, $timeline, )); return $this->newPage() ->setTitle($title) ->setCrumbs($crumbs) ->appendChild( array( $view, )); } private function buildCurtain(DrydockBlueprint $blueprint) { $viewer = $this->getViewer(); $id = $blueprint->getID(); $curtain = $this->newCurtainView($blueprint); $edit_uri = $this->getApplicationURI("blueprint/edit/{$id}/"); $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $blueprint, PhabricatorPolicyCapability::CAN_EDIT); $curtain->addAction( id(new PhabricatorActionView()) ->setHref($edit_uri) ->setName(pht('Edit Blueprint')) ->setIcon('fa-pencil') ->setWorkflow(!$can_edit) ->setDisabled(!$can_edit)); if (!$blueprint->getIsDisabled()) { $disable_name = pht('Disable Blueprint'); $disable_icon = 'fa-ban'; $disable_uri = $this->getApplicationURI("blueprint/{$id}/disable/"); } else { $disable_name = pht('Enable Blueprint'); $disable_icon = 'fa-check'; $disable_uri = $this->getApplicationURI("blueprint/{$id}/enable/"); } $curtain->addAction( id(new PhabricatorActionView()) ->setHref($disable_uri) ->setName($disable_name) ->setIcon($disable_icon) ->setWorkflow(true) ->setDisabled(!$can_edit)); return $curtain; } private function buildPropertyListView( DrydockBlueprint $blueprint) { $viewer = $this->getViewer(); $view = id(new PHUIPropertyListView()) ->setUser($viewer); $view->addProperty( pht('Type'), $blueprint->getImplementation()->getBlueprintName()); return $view; } private function buildResourceBox(DrydockBlueprint $blueprint) { $viewer = $this->getViewer(); $resources = id(new DrydockResourceQuery()) ->setViewer($viewer) ->withBlueprintPHIDs(array($blueprint->getPHID())) ->withStatuses( array( DrydockResourceStatus::STATUS_PENDING, DrydockResourceStatus::STATUS_ACTIVE, )) ->setLimit(100) ->execute(); $resource_list = id(new DrydockResourceListView()) ->setUser($viewer) ->setResources($resources) ->render() ->setNoDataString(pht('This blueprint has no active resources.')); $id = $blueprint->getID(); $resources_uri = "blueprint/{$id}/resources/query/all/"; $resources_uri = $this->getApplicationURI($resources_uri); $resource_header = id(new PHUIHeaderView()) ->setHeader(pht('Active Resources')) ->addActionLink( id(new PHUIButtonView()) ->setTag('a') ->setHref($resources_uri) ->setIcon('fa-search') ->setText(pht('View All'))); return id(new PHUIObjectBoxView()) ->setHeader($resource_header) ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) ->setObjectList($resource_list); } private function buildAuthorizationsBox(DrydockBlueprint $blueprint) { $viewer = $this->getViewer(); $limit = 25; // If there are pending authorizations against this blueprint, make sure // we show them first. $pending_authorizations = id(new DrydockAuthorizationQuery()) ->setViewer($viewer) ->withBlueprintPHIDs(array($blueprint->getPHID())) ->withObjectStates( array( DrydockAuthorization::OBJECTAUTH_ACTIVE, )) ->withBlueprintStates( array( DrydockAuthorization::BLUEPRINTAUTH_REQUESTED, )) ->setLimit($limit) ->execute(); $all_authorizations = id(new DrydockAuthorizationQuery()) ->setViewer($viewer) ->withBlueprintPHIDs(array($blueprint->getPHID())) ->withObjectStates( array( DrydockAuthorization::OBJECTAUTH_ACTIVE, )) ->withBlueprintStates( array( DrydockAuthorization::BLUEPRINTAUTH_REQUESTED, DrydockAuthorization::BLUEPRINTAUTH_AUTHORIZED, )) ->setLimit($limit) ->execute(); $authorizations = mpull($pending_authorizations, null, 'getPHID') + mpull($all_authorizations, null, 'getPHID'); $authorization_list = id(new DrydockAuthorizationListView()) ->setUser($viewer) ->setAuthorizations($authorizations) ->setNoDataString( pht('No objects have active authorizations to use this blueprint.')); $id = $blueprint->getID(); $authorizations_uri = "blueprint/{$id}/authorizations/query/all/"; $authorizations_uri = $this->getApplicationURI($authorizations_uri); $authorizations_header = id(new PHUIHeaderView()) ->setHeader(pht('Active Authorizations')) ->addActionLink( id(new PHUIButtonView()) ->setTag('a') ->setHref($authorizations_uri) ->setIcon('fa-search') ->setText(pht('View All'))); return id(new PHUIObjectBoxView()) ->setHeader($authorizations_header) ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) ->setObjectList($authorization_list); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockResourceViewController.php
src/applications/drydock/controller/DrydockResourceViewController.php
<?php final class DrydockResourceViewController extends DrydockResourceController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $resource = id(new DrydockResourceQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->needUnconsumedCommands(true) ->executeOne(); if (!$resource) { return new Aphront404Response(); } $title = pht( 'Resource %s %s', $resource->getID(), $resource->getResourceName()); $header = id(new PHUIHeaderView()) ->setUser($viewer) ->setPolicyObject($resource) ->setHeader($title) ->setHeaderIcon('fa-map') ->setStatus( $resource->getStatusIcon(), $resource->getStatusColor(), $resource->getStatusDisplayName()); if ($resource->isReleasing()) { $header->addTag( id(new PHUITagView()) ->setType(PHUITagView::TYPE_SHADE) ->setIcon('fa-exclamation-triangle') ->setColor('red') ->setName('Releasing')); } $curtain = $this->buildCurtain($resource); $properties = $this->buildPropertyListView($resource); $id = $resource->getID(); $resource_uri = $this->getApplicationURI("resource/{$id}/"); $log_query = id(new DrydockLogQuery()) ->withResourcePHIDs(array($resource->getPHID())); $log_table = $this->buildLogTable($log_query) ->setHideResources(true); $logs = $this->buildLogBox( $log_table, $this->getApplicationURI("resource/{$id}/logs/query/all/")); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Resource %d', $resource->getID())); $crumbs->setBorder(true); $locks = $this->buildLocksTab($resource->getPHID()); $commands = $this->buildCommandsTab($resource->getPHID()); $tab_group = id(new PHUITabGroupView()) ->addTab( id(new PHUITabView()) ->setName(pht('Properties')) ->setKey('properties') ->appendChild($properties)) ->addTab( id(new PHUITabView()) ->setName(pht('Slot Locks')) ->setKey('locks') ->appendChild($locks)) ->addTab( id(new PHUITabView()) ->setName(pht('Commands')) ->setKey('commands') ->appendChild($commands)); $object_box = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Properties')) ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) ->addTabGroup($tab_group); $lease_box = $this->buildLeaseBox($resource); $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setCurtain($curtain) ->setMainColumn( array( $object_box, $lease_box, $logs, )); return $this->newPage() ->setTitle($title) ->setCrumbs($crumbs) ->appendChild( array( $view, )); } private function buildCurtain(DrydockResource $resource) { $viewer = $this->getViewer(); $curtain = $this->newCurtainView($resource); $can_release = $resource->canRelease(); if ($resource->isReleasing()) { $can_release = false; } $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $resource, PhabricatorPolicyCapability::CAN_EDIT); $uri = '/resource/'.$resource->getID().'/release/'; $uri = $this->getApplicationURI($uri); $curtain->addAction( id(new PhabricatorActionView()) ->setHref($uri) ->setName(pht('Release Resource')) ->setIcon('fa-times') ->setWorkflow(true) ->setDisabled(!$can_release || !$can_edit)); return $curtain; } private function buildPropertyListView( DrydockResource $resource) { $viewer = $this->getViewer(); $view = new PHUIPropertyListView(); $until = $resource->getUntil(); if ($until) { $until_display = phabricator_datetime($until, $viewer); } else { $until_display = phutil_tag('em', array(), pht('Never')); } $view->addProperty(pht('Expires'), $until_display); $view->addProperty( pht('Resource Type'), $resource->getType()); $view->addProperty( pht('Blueprint'), $viewer->renderHandle($resource->getBlueprintPHID())); $attributes = $resource->getAttributes(); if ($attributes) { $view->addSectionHeader( pht('Attributes'), 'fa-list-ul'); foreach ($attributes as $key => $value) { $view->addProperty($key, $value); } } return $view; } private function buildLeaseBox(DrydockResource $resource) { $viewer = $this->getViewer(); $leases = id(new DrydockLeaseQuery()) ->setViewer($viewer) ->withResourcePHIDs(array($resource->getPHID())) ->withStatuses( array( DrydockLeaseStatus::STATUS_PENDING, DrydockLeaseStatus::STATUS_ACQUIRED, DrydockLeaseStatus::STATUS_ACTIVE, )) ->setLimit(100) ->execute(); $id = $resource->getID(); $leases_uri = "resource/{$id}/leases/query/all/"; $leases_uri = $this->getApplicationURI($leases_uri); $lease_header = id(new PHUIHeaderView()) ->setHeader(pht('Active Leases')) ->addActionLink( id(new PHUIButtonView()) ->setTag('a') ->setHref($leases_uri) ->setIcon('fa-search') ->setText(pht('View All'))); $lease_list = id(new DrydockLeaseListView()) ->setUser($viewer) ->setLeases($leases) ->render() ->setNoDataString(pht('This resource has no active leases.')); return id(new PHUIObjectBoxView()) ->setHeader($lease_header) ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) ->setObjectList($lease_list); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockLeaseViewController.php
src/applications/drydock/controller/DrydockLeaseViewController.php
<?php final class DrydockLeaseViewController extends DrydockLeaseController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $lease = id(new DrydockLeaseQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->needUnconsumedCommands(true) ->executeOne(); if (!$lease) { return new Aphront404Response(); } $id = $lease->getID(); $lease_uri = $this->getApplicationURI("lease/{$id}/"); $title = pht('Lease %d', $lease->getID()); $header = id(new PHUIHeaderView()) ->setHeader($title) ->setHeaderIcon('fa-link') ->setStatus( $lease->getStatusIcon(), $lease->getStatusColor(), $lease->getStatusDisplayName()); if ($lease->isReleasing()) { $header->addTag( id(new PHUITagView()) ->setType(PHUITagView::TYPE_SHADE) ->setIcon('fa-exclamation-triangle') ->setColor('red') ->setName('Releasing')); } $curtain = $this->buildCurtain($lease); $properties = $this->buildPropertyListView($lease); $log_query = id(new DrydockLogQuery()) ->withLeasePHIDs(array($lease->getPHID())); $log_table = $this->buildLogTable($log_query) ->setHideLeases(true); $logs = $this->buildLogBox( $log_table, $this->getApplicationURI("lease/{$id}/logs/query/all/")); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($title, $lease_uri); $crumbs->setBorder(true); $locks = $this->buildLocksTab($lease->getPHID()); $commands = $this->buildCommandsTab($lease->getPHID()); $tab_group = id(new PHUITabGroupView()) ->addTab( id(new PHUITabView()) ->setName(pht('Properties')) ->setKey('properties') ->appendChild($properties)) ->addTab( id(new PHUITabView()) ->setName(pht('Slot Locks')) ->setKey('locks') ->appendChild($locks)) ->addTab( id(new PHUITabView()) ->setName(pht('Commands')) ->setKey('commands') ->appendChild($commands)); $object_box = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Properties')) ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) ->addTabGroup($tab_group); $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setCurtain($curtain) ->setMainColumn(array( $object_box, $logs, )); return $this->newPage() ->setTitle($title) ->setCrumbs($crumbs) ->appendChild( array( $view, )); } private function buildCurtain(DrydockLease $lease) { $viewer = $this->getViewer(); $curtain = $this->newCurtainView($lease); $id = $lease->getID(); $can_release = $lease->canRelease(); if ($lease->isReleasing()) { $can_release = false; } $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $lease, PhabricatorPolicyCapability::CAN_EDIT); $curtain->addAction( id(new PhabricatorActionView()) ->setName(pht('Release Lease')) ->setIcon('fa-times') ->setHref($this->getApplicationURI("/lease/{$id}/release/")) ->setWorkflow(true) ->setDisabled(!$can_release || !$can_edit)); return $curtain; } private function buildPropertyListView( DrydockLease $lease) { $viewer = $this->getViewer(); $view = new PHUIPropertyListView(); $view->addProperty( pht('Resource Type'), $lease->getResourceType()); $owner_phid = $lease->getOwnerPHID(); if ($owner_phid) { $owner_display = $viewer->renderHandle($owner_phid); } else { $owner_display = phutil_tag('em', array(), pht('No Owner')); } $view->addProperty(pht('Owner'), $owner_display); $authorizing_phid = $lease->getAuthorizingPHID(); if ($authorizing_phid) { $authorizing_display = $viewer->renderHandle($authorizing_phid); } else { $authorizing_display = phutil_tag('em', array(), pht('None')); } $view->addProperty(pht('Authorized By'), $authorizing_display); $resource_phid = $lease->getResourcePHID(); if ($resource_phid) { $resource_display = $viewer->renderHandle($resource_phid); } else { $resource_display = phutil_tag('em', array(), pht('No Resource')); } $view->addProperty(pht('Resource'), $resource_display); $until = $lease->getUntil(); if ($until) { $until_display = phabricator_datetime($until, $viewer); } else { $until_display = phutil_tag('em', array(), pht('Never')); } $view->addProperty(pht('Expires'), $until_display); $acquired_epoch = $lease->getAcquiredEpoch(); $activated_epoch = $lease->getActivatedEpoch(); if ($acquired_epoch) { $acquired_display = phabricator_datetime($acquired_epoch, $viewer); } else { if ($activated_epoch) { $acquired_display = phutil_tag( 'em', array(), pht('Activated on Acquisition')); } else { $acquired_display = phutil_tag('em', array(), pht('Not Acquired')); } } $view->addProperty(pht('Acquired'), $acquired_display); if ($activated_epoch) { $activated_display = phabricator_datetime($activated_epoch, $viewer); } else { $activated_display = phutil_tag('em', array(), pht('Not Activated')); } $view->addProperty(pht('Activated'), $activated_display); $attributes = $lease->getAttributes(); if ($attributes) { $view->addSectionHeader( pht('Attributes'), 'fa-list-ul'); foreach ($attributes as $key => $value) { $view->addProperty($key, $value); } } return $view; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockLeaseController.php
src/applications/drydock/controller/DrydockLeaseController.php
<?php abstract class DrydockLeaseController extends DrydockController { private $resource; public function setResource($resource) { $this->resource = $resource; return $this; } public function getResource() { return $this->resource; } public function buildSideNavView() { $nav = new AphrontSideNavFilterView(); $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); $engine = id(new DrydockLeaseSearchEngine()) ->setViewer($this->getRequest()->getUser()); if ($this->getResource()) { $engine->setResource($this->getResource()); } $engine->addNavigationItems($nav->getMenu()); $nav->selectFilter(null); return $nav; } protected function buildApplicationCrumbs() { $crumbs = parent::buildApplicationCrumbs(); $resource = $this->getResource(); if ($resource) { $id = $resource->getID(); $crumbs->addTextCrumb( pht('Resources'), $this->getApplicationURI('resource/')); $crumbs->addTextCrumb( $resource->getResourceName(), $this->getApplicationURI("resource/{$id}/")); $crumbs->addTextCrumb( pht('Leases'), $this->getApplicationURI("resource/{$id}/leases/")); } else { $crumbs->addTextCrumb( pht('Leases'), $this->getApplicationURI('lease/')); } return $crumbs; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockLogController.php
src/applications/drydock/controller/DrydockLogController.php
<?php abstract class DrydockLogController extends DrydockController { private $blueprint; private $resource; private $lease; private $operation; public function setBlueprint(DrydockBlueprint $blueprint) { $this->blueprint = $blueprint; return $this; } public function getBlueprint() { return $this->blueprint; } public function setResource(DrydockResource $resource) { $this->resource = $resource; return $this; } public function getResource() { return $this->resource; } public function setLease(DrydockLease $lease) { $this->lease = $lease; return $this; } public function getLease() { return $this->lease; } public function setOperation(DrydockRepositoryOperation $operation) { $this->operation = $operation; return $this; } public function getOperation() { return $this->operation; } public function buildSideNavView() { $nav = new AphrontSideNavFilterView(); $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); $engine = id(new DrydockLogSearchEngine()) ->setViewer($this->getRequest()->getUser()); $blueprint = $this->getBlueprint(); if ($blueprint) { $engine->setBlueprint($blueprint); } $resource = $this->getResource(); if ($resource) { $engine->setResource($resource); } $lease = $this->getLease(); if ($lease) { $engine->setLease($lease); } $operation = $this->getOperation(); if ($operation) { $engine->setOperation($operation); } $engine->addNavigationItems($nav->getMenu()); $nav->selectFilter(null); return $nav; } protected function buildApplicationCrumbs() { $crumbs = parent::buildApplicationCrumbs(); $viewer = $this->getViewer(); $blueprint = $this->getBlueprint(); $resource = $this->getResource(); $lease = $this->getLease(); $operation = $this->getOperation(); if ($blueprint) { $id = $blueprint->getID(); $crumbs->addTextCrumb( pht('Blueprints'), $this->getApplicationURI('blueprint/')); $crumbs->addTextCrumb( $blueprint->getBlueprintName(), $this->getApplicationURI("blueprint/{$id}/")); $crumbs->addTextCrumb( pht('Logs'), $this->getApplicationURI("blueprint/{$id}/logs/")); } else if ($resource) { $id = $resource->getID(); $crumbs->addTextCrumb( pht('Resources'), $this->getApplicationURI('resource/')); $crumbs->addTextCrumb( $resource->getResourceName(), $this->getApplicationURI("resource/{$id}/")); $crumbs->addTextCrumb( pht('Logs'), $this->getApplicationURI("resource/{$id}/logs/")); } else if ($lease) { $id = $lease->getID(); $crumbs->addTextCrumb( pht('Leases'), $this->getApplicationURI('lease/')); $crumbs->addTextCrumb( $lease->getLeaseName(), $this->getApplicationURI("lease/{$id}/")); $crumbs->addTextCrumb( pht('Logs'), $this->getApplicationURI("lease/{$id}/logs/")); } else if ($operation) { $id = $operation->getID(); $crumbs->addTextCrumb( pht('Operations'), $this->getApplicationURI('operation/')); $crumbs->addTextCrumb( pht('Repository Operation %d', $id), $this->getApplicationURI("operation/{$id}/")); $crumbs->addTextCrumb( pht('Logs'), $this->getApplicationURI("operation/{$id}/logs/")); } return $crumbs; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockAuthorizationAuthorizeController.php
src/applications/drydock/controller/DrydockAuthorizationAuthorizeController.php
<?php final class DrydockAuthorizationAuthorizeController extends DrydockController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $authorization = id(new DrydockAuthorizationQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$authorization) { return new Aphront404Response(); } $authorization_uri = $this->getApplicationURI("authorization/{$id}/"); $is_authorize = ($request->getURIData('action') == 'authorize'); $state_authorized = DrydockAuthorization::BLUEPRINTAUTH_AUTHORIZED; $state_declined = DrydockAuthorization::BLUEPRINTAUTH_DECLINED; $state = $authorization->getBlueprintAuthorizationState(); $can_authorize = ($state != $state_authorized); $can_decline = ($state != $state_declined); if ($is_authorize && !$can_authorize) { return $this->newDialog() ->setTitle(pht('Already Authorized')) ->appendParagraph( pht( 'This authorization has already been approved.')) ->addCancelButton($authorization_uri); } if (!$is_authorize && !$can_decline) { return $this->newDialog() ->setTitle(pht('Already Declined')) ->appendParagraph( pht('This authorization has already been declined.')) ->addCancelButton($authorization_uri); } if ($request->isFormPost()) { if ($is_authorize) { $new_state = $state_authorized; } else { $new_state = $state_declined; } $authorization ->setBlueprintAuthorizationState($new_state) ->save(); return id(new AphrontRedirectResponse())->setURI($authorization_uri); } if ($is_authorize) { $title = pht('Approve Authorization'); $body = pht( 'Approve this authorization? The object will be able to lease and '. 'allocate resources created by this blueprint.'); $button = pht('Approve Authorization'); } else { $title = pht('Decline Authorization'); $body = pht( 'Decline this authorization? The object will not be able to lease '. 'or allocate resources created by this blueprint.'); $button = pht('Decline Authorization'); } return $this->newDialog() ->setTitle($title) ->appendParagraph($body) ->addSubmitButton($button) ->addCancelButton($authorization_uri); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockRepositoryOperationController.php
src/applications/drydock/controller/DrydockRepositoryOperationController.php
<?php abstract class DrydockRepositoryOperationController extends DrydockController { public function buildApplicationMenu() { return $this->newApplicationMenu() ->setSearchEngine(new DrydockRepositoryOperationSearchEngine()); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockRepositoryOperationListController.php
src/applications/drydock/controller/DrydockRepositoryOperationListController.php
<?php final class DrydockRepositoryOperationListController extends DrydockRepositoryOperationController { public function shouldAllowPublic() { return true; } public function handleRequest(AphrontRequest $request) { return id(new DrydockRepositoryOperationSearchEngine()) ->setController($this) ->buildResponse(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockLeaseReleaseController.php
src/applications/drydock/controller/DrydockLeaseReleaseController.php
<?php final class DrydockLeaseReleaseController extends DrydockLeaseController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $lease = id(new DrydockLeaseQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$lease) { return new Aphront404Response(); } $lease_uri = '/lease/'.$lease->getID().'/'; $lease_uri = $this->getApplicationURI($lease_uri); if (!$lease->canRelease()) { return $this->newDialog() ->setTitle(pht('Lease Not Releasable')) ->appendParagraph( pht( 'Leases can not be released after they are destroyed.')) ->addCancelButton($lease_uri); } if ($request->isFormPost()) { $command = DrydockCommand::initializeNewCommand($viewer) ->setTargetPHID($lease->getPHID()) ->setCommand(DrydockCommand::COMMAND_RELEASE) ->save(); $lease->scheduleUpdate(); return id(new AphrontRedirectResponse())->setURI($lease_uri); } return $this->newDialog() ->setTitle(pht('Release Lease?')) ->appendParagraph( pht( 'Forcefully releasing a lease may interfere with the operation '. 'of the lease holder and trigger destruction of the underlying '. 'resource. It can not be undone.')) ->addSubmitButton(pht('Release Lease')) ->addCancelButton($lease_uri); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockResourceController.php
src/applications/drydock/controller/DrydockResourceController.php
<?php abstract class DrydockResourceController extends DrydockController { private $blueprint; public function setBlueprint($blueprint) { $this->blueprint = $blueprint; return $this; } public function getBlueprint() { return $this->blueprint; } public function buildSideNavView() { $nav = new AphrontSideNavFilterView(); $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); $engine = id(new DrydockResourceSearchEngine()) ->setViewer($this->getViewer()); if ($this->getBlueprint()) { $engine->setBlueprint($this->getBlueprint()); } $engine->addNavigationItems($nav->getMenu()); $nav->selectFilter(null); return $nav; } protected function buildApplicationCrumbs() { $crumbs = parent::buildApplicationCrumbs(); $blueprint = $this->getBlueprint(); if ($blueprint) { $id = $blueprint->getID(); $crumbs->addTextCrumb( pht('Blueprints'), $this->getApplicationURI('blueprint/')); $crumbs->addTextCrumb( $blueprint->getBlueprintName(), $this->getApplicationURI("blueprint/{$id}/")); $crumbs->addTextCrumb( pht('Resources'), $this->getApplicationURI("blueprint/{$id}/resources/")); } else { $crumbs->addTextCrumb( pht('Resources'), $this->getApplicationURI('resource/')); } return $crumbs; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockRepositoryOperationViewController.php
src/applications/drydock/controller/DrydockRepositoryOperationViewController.php
<?php final class DrydockRepositoryOperationViewController extends DrydockRepositoryOperationController { public function shouldAllowPublic() { return true; } public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $operation = id(new DrydockRepositoryOperationQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); if (!$operation) { return new Aphront404Response(); } $id = $operation->getID(); $title = pht('Repository Operation %d', $id); $header = id(new PHUIHeaderView()) ->setHeader($title) ->setUser($viewer) ->setPolicyObject($operation) ->setHeaderIcon('fa-fighter-jet'); $state = $operation->getOperationState(); $icon = DrydockRepositoryOperation::getOperationStateIcon($state); $name = DrydockRepositoryOperation::getOperationStateName($state); $header->setStatus($icon, null, $name); $curtain = $this->buildCurtain($operation); $properties = $this->buildPropertyListView($operation); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb( pht('Operations'), $this->getApplicationURI('operation/')); $crumbs->addTextCrumb($title); $crumbs->setBorder(true); $status_view = id(new DrydockRepositoryOperationStatusView()) ->setUser($viewer) ->setOperation($operation); $log_query = id(new DrydockLogQuery()) ->withOperationPHIDs(array($operation->getPHID())); $log_table = $this->buildLogTable($log_query) ->setHideOperations(true); $logs = $this->buildLogBox( $log_table, $this->getApplicationURI("operation/{$id}/logs/query/all/")); $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setCurtain($curtain) ->addPropertySection(pht('Properties'), $properties) ->setMainColumn( array( $status_view, $logs, )); return $this->newPage() ->setTitle($title) ->setCrumbs($crumbs) ->appendChild( array( $view, )); } private function buildCurtain(DrydockRepositoryOperation $operation) { $viewer = $this->getViewer(); $id = $operation->getID(); $curtain = $this->newCurtainView($operation); return $curtain; } private function buildPropertyListView( DrydockRepositoryOperation $operation) { $viewer = $this->getViewer(); $view = new PHUIPropertyListView(); $view->addProperty( pht('Repository'), $viewer->renderHandle($operation->getRepositoryPHID())); $view->addProperty( pht('Object'), $viewer->renderHandle($operation->getObjectPHID())); $lease_phid = $operation->getWorkingCopyLeasePHID(); if ($lease_phid) { $lease_display = $viewer->renderHandle($lease_phid); } else { $lease_display = phutil_tag('em', array(), pht('None')); } $view->addProperty(pht('Working Copy'), $lease_display); return $view; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockResourceReleaseController.php
src/applications/drydock/controller/DrydockResourceReleaseController.php
<?php final class DrydockResourceReleaseController extends DrydockResourceController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $resource = id(new DrydockResourceQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$resource) { return new Aphront404Response(); } $resource_uri = '/resource/'.$resource->getID().'/'; $resource_uri = $this->getApplicationURI($resource_uri); if (!$resource->canRelease()) { return $this->newDialog() ->setTitle(pht('Resource Not Releasable')) ->appendParagraph( pht( 'Resources can not be released after they are destroyed.')) ->addCancelButton($resource_uri); } if ($request->isFormPost()) { $command = DrydockCommand::initializeNewCommand($viewer) ->setTargetPHID($resource->getPHID()) ->setCommand(DrydockCommand::COMMAND_RELEASE) ->save(); $resource->scheduleUpdate(); return id(new AphrontRedirectResponse())->setURI($resource_uri); } return $this->newDialog() ->setTitle(pht('Really release resource?')) ->appendChild( pht( 'Releasing a resource releases all leases and destroys the '. 'resource. It can not be undone.')) ->addSubmitButton(pht('Release Resource')) ->addCancelButton($resource_uri); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockResourceListController.php
src/applications/drydock/controller/DrydockResourceListController.php
<?php final class DrydockResourceListController extends DrydockResourceController { public function shouldAllowPublic() { return true; } public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $engine = new DrydockResourceSearchEngine(); $id = $request->getURIData('id'); if ($id) { $blueprint = id(new DrydockBlueprintQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); if (!$blueprint) { return new Aphront404Response(); } $this->setBlueprint($blueprint); $engine->setBlueprint($blueprint); } $querykey = $request->getURIData('queryKey'); $controller = id(new PhabricatorApplicationSearchController()) ->setQueryKey($querykey) ->setSearchEngine($engine) ->setNavigation($this->buildSideNavView()); return $this->delegateToController($controller); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockBlueprintController.php
src/applications/drydock/controller/DrydockBlueprintController.php
<?php abstract class DrydockBlueprintController extends DrydockController { public function buildApplicationMenu() { return $this->newApplicationMenu() ->setSearchEngine(new DrydockBlueprintSearchEngine()); } protected function buildApplicationCrumbs() { $crumbs = parent::buildApplicationCrumbs(); $crumbs->addTextCrumb( pht('Blueprints'), $this->getApplicationURI('blueprint/')); return $crumbs; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockAuthorizationListController.php
src/applications/drydock/controller/DrydockAuthorizationListController.php
<?php final class DrydockAuthorizationListController extends DrydockController { private $blueprint; public function setBlueprint(DrydockBlueprint $blueprint) { $this->blueprint = $blueprint; return $this; } public function getBlueprint() { return $this->blueprint; } public function shouldAllowPublic() { return true; } public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $engine = new DrydockAuthorizationSearchEngine(); $id = $request->getURIData('id'); $blueprint = id(new DrydockBlueprintQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); if (!$blueprint) { return new Aphront404Response(); } $this->setBlueprint($blueprint); $engine->setBlueprint($blueprint); $querykey = $request->getURIData('queryKey'); $controller = id(new PhabricatorApplicationSearchController()) ->setQueryKey($querykey) ->setSearchEngine($engine) ->setNavigation($this->buildSideNavView()); return $this->delegateToController($controller); } public function buildSideNavView() { $nav = new AphrontSideNavFilterView(); $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); $engine = id(new DrydockAuthorizationSearchEngine()) ->setViewer($this->getViewer()); $engine->setBlueprint($this->getBlueprint()); $engine->addNavigationItems($nav->getMenu()); $nav->selectFilter(null); return $nav; } protected function buildApplicationCrumbs() { $crumbs = parent::buildApplicationCrumbs(); $blueprint = $this->getBlueprint(); if ($blueprint) { $id = $blueprint->getID(); $crumbs->addTextCrumb( pht('Blueprints'), $this->getApplicationURI('blueprint/')); $crumbs->addTextCrumb( $blueprint->getBlueprintName(), $this->getApplicationURI("blueprint/{$id}/")); $crumbs->addTextCrumb( pht('Authorizations'), $this->getApplicationURI("blueprint/{$id}/authorizations/")); } return $crumbs; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockBlueprintListController.php
src/applications/drydock/controller/DrydockBlueprintListController.php
<?php final class DrydockBlueprintListController extends DrydockBlueprintController { public function shouldAllowPublic() { return true; } public function handleRequest(AphrontRequest $request) { return id(new DrydockBlueprintSearchEngine()) ->setController($this) ->buildResponse(); } protected function buildApplicationCrumbs() { $crumbs = parent::buildApplicationCrumbs(); id(new DrydockBlueprintEditEngine()) ->setViewer($this->getViewer()) ->addActionToCrumbs($crumbs); return $crumbs; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockLogListController.php
src/applications/drydock/controller/DrydockLogListController.php
<?php final class DrydockLogListController extends DrydockLogController { public function shouldAllowPublic() { return true; } public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $engine = new DrydockLogSearchEngine(); $id = $request->getURIData('id'); $type = $request->getURIData('type'); switch ($type) { case 'blueprint': $blueprint = id(new DrydockBlueprintQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); if (!$blueprint) { return new Aphront404Response(); } $engine->setBlueprint($blueprint); $this->setBlueprint($blueprint); break; case 'resource': $resource = id(new DrydockResourceQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); if (!$resource) { return new Aphront404Response(); } $engine->setResource($resource); $this->setResource($resource); break; case 'lease': $lease = id(new DrydockLeaseQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); if (!$lease) { return new Aphront404Response(); } $engine->setLease($lease); $this->setLease($lease); break; case 'operation': $operation = id(new DrydockRepositoryOperationQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); if (!$operation) { return new Aphront404Response(); } $engine->setOperation($operation); $this->setOperation($operation); break; default: return new Aphront404Response(); } $query_key = $request->getURIData('queryKey'); $controller = id(new PhabricatorApplicationSearchController()) ->setQueryKey($query_key) ->setSearchEngine($engine) ->setNavigation($this->buildSideNavView()); return $this->delegateToController($controller); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockConsoleController.php
src/applications/drydock/controller/DrydockConsoleController.php
<?php final class DrydockConsoleController extends DrydockController { public function shouldAllowPublic() { return true; } public function buildSideNavView() { $nav = new AphrontSideNavFilterView(); $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); // These are only used on mobile. $nav->addFilter('blueprint', pht('Blueprints')); $nav->addFilter('resource', pht('Resources')); $nav->addFilter('lease', pht('Leases')); $nav->addFilter('operation', pht('Repository Operations')); $nav->selectFilter(null); return $nav; } public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $menu = id(new PHUIObjectItemListView()) ->setUser($viewer) ->setBig(true); $menu->addItem( id(new PHUIObjectItemView()) ->setHeader(pht('Blueprints')) ->setImageIcon('fa-map-o') ->setHref($this->getApplicationURI('blueprint/')) ->setClickable(true) ->addAttribute( pht( 'Configure blueprints so Drydock can build resources, like '. 'hosts and working copies.'))); $menu->addItem( id(new PHUIObjectItemView()) ->setHeader(pht('Resources')) ->setImageIcon('fa-map') ->setHref($this->getApplicationURI('resource/')) ->setClickable(true) ->addAttribute( pht('View and manage resources Drydock has built, like hosts.'))); $menu->addItem( id(new PHUIObjectItemView()) ->setHeader(pht('Leases')) ->setImageIcon('fa-link') ->setHref($this->getApplicationURI('lease/')) ->setClickable(true) ->addAttribute(pht('Manage leases on resources.'))); $menu->addItem( id(new PHUIObjectItemView()) ->setHeader(pht('Repository Operations')) ->setImageIcon('fa-fighter-jet') ->setHref($this->getApplicationURI('operation/')) ->setClickable(true) ->addAttribute(pht('Review the repository operation queue.'))); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Console')); $crumbs->setBorder(true); $title = pht('Drydock Console'); $box = id(new PHUIObjectBoxView()) ->setHeaderText($title) ->setBackground(PHUIObjectBoxView::WHITE_CONFIG) ->setObjectList($menu); $launcher_view = id(new PHUILauncherView()) ->appendChild($box); $view = id(new PHUITwoColumnView()) ->setFooter($launcher_view); return $this->newPage() ->setTitle($title) ->setCrumbs($crumbs) ->appendChild($view); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockRepositoryOperationDismissController.php
src/applications/drydock/controller/DrydockRepositoryOperationDismissController.php
<?php final class DrydockRepositoryOperationDismissController extends DrydockRepositoryOperationController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $operation = id(new DrydockRepositoryOperationQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, )) ->executeOne(); if (!$operation) { return new Aphront404Response(); } $object_phid = $operation->getObjectPHID(); $handles = $viewer->loadHandles(array($object_phid)); $done_uri = $handles[$object_phid]->getURI(); if ($operation->getIsDismissed()) { return $this->newDialog() ->setTitle(pht('Already Dismissed')) ->appendParagraph( pht( 'This operation has already been dismissed, and can not be '. 'dismissed any further.')) ->addCancelButton($done_uri); } if ($request->isFormPost()) { $operation ->setIsDismissed(1) ->save(); return id(new AphrontRedirectResponse())->setURI($done_uri); } return $this->newDialog() ->setTitle(pht('Dismiss Operation')) ->appendParagraph( pht( 'Dismiss this operation? It will no longer be shown, but logs '. 'can be found in Drydock.')) ->addSubmitButton(pht('Dismiss')) ->addCancelButton($done_uri); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/controller/DrydockController.php
src/applications/drydock/controller/DrydockController.php
<?php abstract class DrydockController extends PhabricatorController { protected function buildLocksTab($owner_phid) { $locks = DrydockSlotLock::loadLocks($owner_phid); $rows = array(); foreach ($locks as $lock) { $rows[] = array( $lock->getID(), $lock->getLockKey(), ); } $table = id(new AphrontTableView($rows)) ->setNoDataString(pht('No slot locks held.')) ->setHeaders( array( pht('ID'), pht('Lock Key'), )) ->setColumnClasses( array( null, 'wide', )); return id(new PHUIPropertyListView()) ->addRawContent($table); } protected function buildCommandsTab($target_phid) { $viewer = $this->getViewer(); $commands = id(new DrydockCommandQuery()) ->setViewer($viewer) ->withTargetPHIDs(array($target_phid)) ->execute(); $consumed_yes = id(new PHUIIconView()) ->setIcon('fa-check green'); $consumed_no = id(new PHUIIconView()) ->setIcon('fa-clock-o grey'); $rows = array(); foreach ($commands as $command) { $rows[] = array( $command->getID(), $viewer->renderHandle($command->getAuthorPHID()), $command->getCommand(), ($command->getIsConsumed() ? $consumed_yes : $consumed_no), phabricator_datetime($command->getDateCreated(), $viewer), ); } $table = id(new AphrontTableView($rows)) ->setNoDataString(pht('No commands issued.')) ->setHeaders( array( pht('ID'), pht('From'), pht('Command'), null, pht('Date'), )) ->setColumnClasses( array( null, null, 'wide', null, null, )); return id(new PHUIPropertyListView()) ->addRawContent($table); } protected function buildLogTable(DrydockLogQuery $query) { $viewer = $this->getViewer(); $logs = $query ->setViewer($viewer) ->setLimit(100) ->execute(); $log_table = id(new DrydockLogListView()) ->setUser($viewer) ->setLogs($logs); return $log_table; } protected function buildLogBox(DrydockLogListView $log_table, $all_uri) { $log_header = id(new PHUIHeaderView()) ->setHeader(pht('Logs')) ->addActionLink( id(new PHUIButtonView()) ->setTag('a') ->setHref($all_uri) ->setIcon('fa-search') ->setText(pht('View All'))); return id(new PHUIObjectBoxView()) ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) ->setHeader($log_header) ->setTable($log_table); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/storage/DrydockBlueprintTransaction.php
src/applications/drydock/storage/DrydockBlueprintTransaction.php
<?php final class DrydockBlueprintTransaction extends PhabricatorModularTransaction { const TYPE_NAME = 'drydock:blueprint:name'; const TYPE_DISABLED = 'drydock:blueprint:disabled'; public function getApplicationName() { return 'drydock'; } public function getApplicationTransactionType() { return DrydockBlueprintPHIDType::TYPECONST; } public function getBaseTransactionClass() { return 'DrydockBlueprintTransactionType'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/storage/DrydockLog.php
src/applications/drydock/storage/DrydockLog.php
<?php final class DrydockLog extends DrydockDAO implements PhabricatorPolicyInterface { protected $blueprintPHID; protected $resourcePHID; protected $leasePHID; protected $operationPHID; protected $epoch; protected $type; protected $data = array(); private $blueprint = self::ATTACHABLE; private $resource = self::ATTACHABLE; private $lease = self::ATTACHABLE; private $operation = self::ATTACHABLE; protected function getConfiguration() { return array( self::CONFIG_TIMESTAMPS => false, self::CONFIG_SERIALIZATION => array( 'data' => self::SERIALIZATION_JSON, ), self::CONFIG_COLUMN_SCHEMA => array( 'blueprintPHID' => 'phid?', 'resourcePHID' => 'phid?', 'leasePHID' => 'phid?', 'operationPHID' => 'phid?', 'type' => 'text64', ), self::CONFIG_KEY_SCHEMA => array( 'key_blueprint' => array( 'columns' => array('blueprintPHID', 'type'), ), 'key_resource' => array( 'columns' => array('resourcePHID', 'type'), ), 'key_lease' => array( 'columns' => array('leasePHID', 'type'), ), 'key_operation' => array( 'columns' => array('operationPHID', 'type'), ), 'epoch' => array( 'columns' => array('epoch'), ), ), ) + parent::getConfiguration(); } public function attachBlueprint(DrydockBlueprint $blueprint = null) { $this->blueprint = $blueprint; return $this; } public function getBlueprint() { return $this->assertAttached($this->blueprint); } public function attachResource(DrydockResource $resource = null) { $this->resource = $resource; return $this; } public function getResource() { return $this->assertAttached($this->resource); } public function attachLease(DrydockLease $lease = null) { $this->lease = $lease; return $this; } public function getLease() { return $this->assertAttached($this->lease); } public function attachOperation( DrydockRepositoryOperation $operation = null) { $this->operation = $operation; return $this; } public function getOperation() { return $this->assertAttached($this->operation); } public function isComplete() { if ($this->getBlueprintPHID() && !$this->getBlueprint()) { return false; } if ($this->getResourcePHID() && !$this->getResource()) { return false; } if ($this->getLeasePHID() && !$this->getLease()) { return false; } if ($this->getOperationPHID() && !$this->getOperation()) { return false; } return true; } /* -( PhabricatorPolicyInterface )----------------------------------------- */ public function getCapabilities() { return array( PhabricatorPolicyCapability::CAN_VIEW, ); } public function getPolicy($capability) { // NOTE: We let you see that logs exist no matter what, but don't actually // show you log content unless you can see all of the associated objects. return PhabricatorPolicies::getMostOpenPolicy(); } public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { return false; } public function describeAutomaticCapability($capability) { return pht( 'To view log details, you must be able to view all associated '. 'blueprints, resources, leases, and repository operations.'); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/storage/DrydockResource.php
src/applications/drydock/storage/DrydockResource.php
<?php final class DrydockResource extends DrydockDAO implements PhabricatorPolicyInterface, PhabricatorConduitResultInterface { protected $id; protected $phid; protected $blueprintPHID; protected $status; protected $until; protected $type; protected $attributes = array(); protected $capabilities = array(); protected $ownerPHID; private $blueprint = self::ATTACHABLE; private $unconsumedCommands = self::ATTACHABLE; private $isAllocated = false; private $isActivated = false; private $activateWhenAllocated = false; private $slotLocks = array(); protected function getConfiguration() { return array( self::CONFIG_AUX_PHID => true, self::CONFIG_SERIALIZATION => array( 'attributes' => self::SERIALIZATION_JSON, 'capabilities' => self::SERIALIZATION_JSON, ), self::CONFIG_COLUMN_SCHEMA => array( 'ownerPHID' => 'phid?', 'status' => 'text32', 'type' => 'text64', 'until' => 'epoch?', ), self::CONFIG_KEY_SCHEMA => array( 'key_type' => array( 'columns' => array('type', 'status'), ), 'key_blueprint' => array( 'columns' => array('blueprintPHID', 'status'), ), ), ) + parent::getConfiguration(); } public function generatePHID() { return PhabricatorPHID::generateNewPHID(DrydockResourcePHIDType::TYPECONST); } public function getResourceName() { return $this->getBlueprint()->getResourceName($this); } public function getAttribute($key, $default = null) { return idx($this->attributes, $key, $default); } public function getAttributesForTypeSpec(array $attribute_names) { return array_select_keys($this->attributes, $attribute_names); } public function setAttribute($key, $value) { $this->attributes[$key] = $value; return $this; } public function getCapability($key, $default = null) { return idx($this->capbilities, $key, $default); } public function getInterface(DrydockLease $lease, $type) { return $this->getBlueprint()->getInterface($this, $lease, $type); } public function getBlueprint() { return $this->assertAttached($this->blueprint); } public function attachBlueprint(DrydockBlueprint $blueprint) { $this->blueprint = $blueprint; return $this; } public function getUnconsumedCommands() { return $this->assertAttached($this->unconsumedCommands); } public function attachUnconsumedCommands(array $commands) { $this->unconsumedCommands = $commands; return $this; } public function isReleasing() { foreach ($this->getUnconsumedCommands() as $command) { if ($command->getCommand() == DrydockCommand::COMMAND_RELEASE) { return true; } } return false; } public function setActivateWhenAllocated($activate) { $this->activateWhenAllocated = $activate; return $this; } public function needSlotLock($key) { $this->slotLocks[] = $key; return $this; } public function allocateResource() { // We expect resources to have a pregenerated PHID, as they should have // been created by a call to DrydockBlueprint->newResourceTemplate(). if (!$this->getPHID()) { throw new Exception( pht( 'Trying to allocate a resource with no generated PHID. Use "%s" to '. 'create new resource templates.', 'newResourceTemplate()')); } $expect_status = DrydockResourceStatus::STATUS_PENDING; $actual_status = $this->getStatus(); if ($actual_status != $expect_status) { throw new Exception( pht( 'Trying to allocate a resource from the wrong status. Status must '. 'be "%s", actually "%s".', $expect_status, $actual_status)); } if ($this->activateWhenAllocated) { $new_status = DrydockResourceStatus::STATUS_ACTIVE; } else { $new_status = DrydockResourceStatus::STATUS_PENDING; } $this->openTransaction(); try { DrydockSlotLock::acquireLocks($this->getPHID(), $this->slotLocks); $this->slotLocks = array(); } catch (DrydockSlotLockException $ex) { $this->killTransaction(); if ($this->getID()) { $log_target = $this; } else { // If we don't have an ID, we have to log this on the blueprint, as the // resource is not going to be saved so the PHID will vanish. $log_target = $this->getBlueprint(); } $log_target->logEvent( DrydockSlotLockFailureLogType::LOGCONST, array( 'locks' => $ex->getLockMap(), )); throw $ex; } $this ->setStatus($new_status) ->save(); $this->saveTransaction(); $this->isAllocated = true; if ($new_status == DrydockResourceStatus::STATUS_ACTIVE) { $this->didActivate(); } return $this; } public function isAllocatedResource() { return $this->isAllocated; } public function activateResource() { if (!$this->getID()) { throw new Exception( pht( 'Trying to activate a resource which has not yet been persisted.')); } $expect_status = DrydockResourceStatus::STATUS_PENDING; $actual_status = $this->getStatus(); if ($actual_status != $expect_status) { throw new Exception( pht( 'Trying to activate a resource from the wrong status. Status must '. 'be "%s", actually "%s".', $expect_status, $actual_status)); } $this->openTransaction(); try { DrydockSlotLock::acquireLocks($this->getPHID(), $this->slotLocks); $this->slotLocks = array(); } catch (DrydockSlotLockException $ex) { $this->killTransaction(); $this->logEvent( DrydockSlotLockFailureLogType::LOGCONST, array( 'locks' => $ex->getLockMap(), )); throw $ex; } $this ->setStatus(DrydockResourceStatus::STATUS_ACTIVE) ->save(); $this->saveTransaction(); $this->isActivated = true; $this->didActivate(); return $this; } public function isActivatedResource() { return $this->isActivated; } public function scheduleUpdate($epoch = null) { PhabricatorWorker::scheduleTask( 'DrydockResourceUpdateWorker', array( 'resourcePHID' => $this->getPHID(), 'isExpireTask' => ($epoch !== null), ), array( 'objectPHID' => $this->getPHID(), 'delayUntil' => ($epoch ? (int)$epoch : null), )); } private function didActivate() { $viewer = PhabricatorUser::getOmnipotentUser(); $need_update = false; $commands = id(new DrydockCommandQuery()) ->setViewer($viewer) ->withTargetPHIDs(array($this->getPHID())) ->withConsumed(false) ->execute(); if ($commands) { $need_update = true; } if ($need_update) { $this->scheduleUpdate(); } $expires = $this->getUntil(); if ($expires) { $this->scheduleUpdate($expires); } } public function logEvent($type, array $data = array()) { $log = id(new DrydockLog()) ->setEpoch(PhabricatorTime::getNow()) ->setType($type) ->setData($data); $log->setResourcePHID($this->getPHID()); $log->setBlueprintPHID($this->getBlueprintPHID()); return $log->save(); } public function getDisplayName() { return pht('Drydock Resource %d', $this->getID()); } /* -( Status )------------------------------------------------------------- */ public function getStatusObject() { return DrydockResourceStatus::newStatusObject($this->getStatus()); } public function getStatusIcon() { return $this->getStatusObject()->getIcon(); } public function getStatusColor() { return $this->getStatusObject()->getColor(); } public function getStatusDisplayName() { return $this->getStatusObject()->getDisplayName(); } public function canRelease() { return $this->getStatusObject()->canRelease(); } public function canReceiveCommands() { return $this->getStatusObject()->canReceiveCommands(); } public function isActive() { return $this->getStatusObject()->isActive(); } /* -( PhabricatorPolicyInterface )----------------------------------------- */ public function getCapabilities() { return array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, ); } public function getPolicy($capability) { return $this->getBlueprint()->getPolicy($capability); } public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { return $this->getBlueprint()->hasAutomaticCapability( $capability, $viewer); } public function describeAutomaticCapability($capability) { return pht('Resources inherit the policies of their blueprints.'); } /* -( PhabricatorConduitResultInterface )---------------------------------- */ public function getFieldSpecificationsForConduit() { return array( id(new PhabricatorConduitSearchFieldSpecification()) ->setKey('blueprintPHID') ->setType('phid') ->setDescription(pht('The blueprint which generated this resource.')), id(new PhabricatorConduitSearchFieldSpecification()) ->setKey('status') ->setType('map<string, wild>') ->setDescription(pht('Information about resource status.')), ); } public function getFieldValuesForConduit() { $status = $this->getStatus(); return array( 'blueprintPHID' => $this->getBlueprintPHID(), 'status' => array( 'value' => $status, 'name' => DrydockResourceStatus::getNameForStatus($status), ), ); } public function getConduitSearchAttachments() { return array(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/storage/DrydockLease.php
src/applications/drydock/storage/DrydockLease.php
<?php final class DrydockLease extends DrydockDAO implements PhabricatorPolicyInterface, PhabricatorConduitResultInterface { protected $resourcePHID; protected $resourceType; protected $until; protected $ownerPHID; protected $authorizingPHID; protected $attributes = array(); protected $status = DrydockLeaseStatus::STATUS_PENDING; protected $acquiredEpoch; protected $activatedEpoch; private $resource = self::ATTACHABLE; private $unconsumedCommands = self::ATTACHABLE; private $releaseOnDestruction; private $isAcquired = false; private $isActivated = false; private $activateWhenAcquired = false; private $slotLocks = array(); public static function initializeNewLease() { $lease = new DrydockLease(); // Pregenerate a PHID so that the caller can set something up to release // this lease before queueing it for activation. $lease->setPHID($lease->generatePHID()); return $lease; } /** * Flag this lease to be released when its destructor is called. This is * mostly useful if you have a script which acquires, uses, and then releases * a lease, as you don't need to explicitly handle exceptions to properly * release the lease. */ public function setReleaseOnDestruction($release) { $this->releaseOnDestruction = $release; return $this; } public function __destruct() { if (!$this->releaseOnDestruction) { return; } if (!$this->canRelease()) { return; } $actor = PhabricatorUser::getOmnipotentUser(); $drydock_phid = id(new PhabricatorDrydockApplication())->getPHID(); $command = DrydockCommand::initializeNewCommand($actor) ->setTargetPHID($this->getPHID()) ->setAuthorPHID($drydock_phid) ->setCommand(DrydockCommand::COMMAND_RELEASE) ->save(); $this->scheduleUpdate(); } public function setStatus($status) { if ($status == DrydockLeaseStatus::STATUS_ACQUIRED) { if (!$this->getAcquiredEpoch()) { $this->setAcquiredEpoch(PhabricatorTime::getNow()); } } if ($status == DrydockLeaseStatus::STATUS_ACTIVE) { if (!$this->getActivatedEpoch()) { $this->setActivatedEpoch(PhabricatorTime::getNow()); } } return parent::setStatus($status); } public function getLeaseName() { return pht('Lease %d', $this->getID()); } protected function getConfiguration() { return array( self::CONFIG_AUX_PHID => true, self::CONFIG_SERIALIZATION => array( 'attributes' => self::SERIALIZATION_JSON, ), self::CONFIG_COLUMN_SCHEMA => array( 'status' => 'text32', 'until' => 'epoch?', 'resourceType' => 'text128', 'ownerPHID' => 'phid?', 'resourcePHID' => 'phid?', 'acquiredEpoch' => 'epoch?', 'activatedEpoch' => 'epoch?', ), self::CONFIG_KEY_SCHEMA => array( 'key_resource' => array( 'columns' => array('resourcePHID', 'status'), ), 'key_status' => array( 'columns' => array('status'), ), 'key_owner' => array( 'columns' => array('ownerPHID'), ), 'key_recent' => array( 'columns' => array('resourcePHID', 'dateModified'), ), ), ) + parent::getConfiguration(); } public function setAttribute($key, $value) { $this->attributes[$key] = $value; return $this; } public function getAttribute($key, $default = null) { return idx($this->attributes, $key, $default); } public function generatePHID() { return PhabricatorPHID::generateNewPHID(DrydockLeasePHIDType::TYPECONST); } public function getInterface($type) { return $this->getResource()->getInterface($this, $type); } public function getResource() { return $this->assertAttached($this->resource); } public function attachResource(DrydockResource $resource = null) { $this->resource = $resource; return $this; } public function hasAttachedResource() { return ($this->resource !== null); } public function getUnconsumedCommands() { return $this->assertAttached($this->unconsumedCommands); } public function attachUnconsumedCommands(array $commands) { $this->unconsumedCommands = $commands; return $this; } public function isReleasing() { foreach ($this->getUnconsumedCommands() as $command) { if ($command->getCommand() == DrydockCommand::COMMAND_RELEASE) { return true; } } return false; } public function queueForActivation() { if ($this->getID()) { throw new Exception( pht('Only new leases may be queued for activation!')); } if (!$this->getAuthorizingPHID()) { throw new Exception( pht( 'Trying to queue a lease for activation without an authorizing '. 'object. Use "%s" to specify the PHID of the authorizing object. '. 'The authorizing object must be approved to use the allowed '. 'blueprints.', 'setAuthorizingPHID()')); } if (!$this->getAllowedBlueprintPHIDs()) { throw new Exception( pht( 'Trying to queue a lease for activation without any allowed '. 'Blueprints. Use "%s" to specify allowed blueprints. The '. 'authorizing object must be approved to use the allowed blueprints.', 'setAllowedBlueprintPHIDs()')); } $this ->setStatus(DrydockLeaseStatus::STATUS_PENDING) ->save(); $this->scheduleUpdate(); $this->logEvent(DrydockLeaseQueuedLogType::LOGCONST); return $this; } public function setActivateWhenAcquired($activate) { $this->activateWhenAcquired = true; return $this; } public function needSlotLock($key) { $this->slotLocks[] = $key; return $this; } public function acquireOnResource(DrydockResource $resource) { $expect_status = DrydockLeaseStatus::STATUS_PENDING; $actual_status = $this->getStatus(); if ($actual_status != $expect_status) { throw new Exception( pht( 'Trying to acquire a lease on a resource which is in the wrong '. 'state: status must be "%s", actually "%s".', $expect_status, $actual_status)); } if ($this->activateWhenAcquired) { $new_status = DrydockLeaseStatus::STATUS_ACTIVE; } else { $new_status = DrydockLeaseStatus::STATUS_ACQUIRED; } if ($new_status == DrydockLeaseStatus::STATUS_ACTIVE) { if ($resource->getStatus() == DrydockResourceStatus::STATUS_PENDING) { throw new Exception( pht( 'Trying to acquire an active lease on a pending resource. '. 'You can not immediately activate leases on resources which '. 'need time to start up.')); } } // Before we associate the lease with the resource, we lock the resource // and reload it to make sure it is still pending or active. If we don't // do this, the resource may have just been reclaimed. (Once we acquire // the resource that stops it from being released, so we're nearly safe.) $resource_phid = $resource->getPHID(); $hash = PhabricatorHash::digestForIndex($resource_phid); $lock_key = 'drydock.resource:'.$hash; $lock = PhabricatorGlobalLock::newLock($lock_key); try { $lock->lock(15); } catch (Exception $ex) { throw new DrydockResourceLockException( pht( 'Failed to acquire lock for resource ("%s") while trying to '. 'acquire lease ("%s").', $resource->getPHID(), $this->getPHID())); } $resource->reload(); if (($resource->getStatus() !== DrydockResourceStatus::STATUS_ACTIVE) && ($resource->getStatus() !== DrydockResourceStatus::STATUS_PENDING)) { throw new DrydockAcquiredBrokenResourceException( pht( 'Trying to acquire lease ("%s") on a resource ("%s") in the '. 'wrong status ("%s").', $this->getPHID(), $resource->getPHID(), $resource->getStatus())); } $caught = null; try { $this->openTransaction(); try { DrydockSlotLock::acquireLocks($this->getPHID(), $this->slotLocks); $this->slotLocks = array(); } catch (DrydockSlotLockException $ex) { $this->killTransaction(); $this->logEvent( DrydockSlotLockFailureLogType::LOGCONST, array( 'locks' => $ex->getLockMap(), )); throw $ex; } $this ->setResourcePHID($resource->getPHID()) ->attachResource($resource) ->setStatus($new_status) ->save(); $this->saveTransaction(); } catch (Exception $ex) { $caught = $ex; } $lock->unlock(); if ($caught) { throw $caught; } $this->isAcquired = true; $this->logEvent(DrydockLeaseAcquiredLogType::LOGCONST); if ($new_status == DrydockLeaseStatus::STATUS_ACTIVE) { $this->didActivate(); } return $this; } public function isAcquiredLease() { return $this->isAcquired; } public function activateOnResource(DrydockResource $resource) { $expect_status = DrydockLeaseStatus::STATUS_ACQUIRED; $actual_status = $this->getStatus(); if ($actual_status != $expect_status) { throw new Exception( pht( 'Trying to activate a lease which has the wrong status: status '. 'must be "%s", actually "%s".', $expect_status, $actual_status)); } if ($resource->getStatus() == DrydockResourceStatus::STATUS_PENDING) { // TODO: Be stricter about this? throw new Exception( pht( 'Trying to activate a lease on a pending resource.')); } $this->openTransaction(); try { DrydockSlotLock::acquireLocks($this->getPHID(), $this->slotLocks); $this->slotLocks = array(); } catch (DrydockSlotLockException $ex) { $this->killTransaction(); $this->logEvent( DrydockSlotLockFailureLogType::LOGCONST, array( 'locks' => $ex->getLockMap(), )); throw $ex; } $this ->setStatus(DrydockLeaseStatus::STATUS_ACTIVE) ->save(); $this->saveTransaction(); $this->isActivated = true; $this->didActivate(); return $this; } public function isActivatedLease() { return $this->isActivated; } public function scheduleUpdate($epoch = null) { PhabricatorWorker::scheduleTask( 'DrydockLeaseUpdateWorker', array( 'leasePHID' => $this->getPHID(), 'isExpireTask' => ($epoch !== null), ), array( 'objectPHID' => $this->getPHID(), 'delayUntil' => ($epoch ? (int)$epoch : null), )); } public function getAllocatedResourcePHIDs() { return $this->getAttribute('internal.resourcePHIDs.allocated', array()); } public function setAllocatedResourcePHIDs(array $phids) { return $this->setAttribute('internal.resourcePHIDs.allocated', $phids); } public function addAllocatedResourcePHIDs(array $phids) { $allocated_phids = $this->getAllocatedResourcePHIDs(); foreach ($phids as $phid) { $allocated_phids[$phid] = $phid; } return $this->setAllocatedResourcePHIDs($allocated_phids); } public function removeAllocatedResourcePHIDs(array $phids) { $allocated_phids = $this->getAllocatedResourcePHIDs(); foreach ($phids as $phid) { unset($allocated_phids[$phid]); } return $this->setAllocatedResourcePHIDs($allocated_phids); } public function getReclaimedResourcePHIDs() { return $this->getAttribute('internal.resourcePHIDs.reclaimed', array()); } public function setReclaimedResourcePHIDs(array $phids) { return $this->setAttribute('internal.resourcePHIDs.reclaimed', $phids); } public function addReclaimedResourcePHIDs(array $phids) { $reclaimed_phids = $this->getReclaimedResourcePHIDs(); foreach ($phids as $phid) { $reclaimed_phids[$phid] = $phid; } return $this->setReclaimedResourcePHIDs($reclaimed_phids); } public function removeReclaimedResourcePHIDs(array $phids) { $reclaimed_phids = $this->getReclaimedResourcePHIDs(); foreach ($phids as $phid) { unset($reclaimed_phids[$phid]); } return $this->setReclaimedResourcePHIDs($reclaimed_phids); } public function setAwakenTaskIDs(array $ids) { $this->setAttribute('internal.awakenTaskIDs', $ids); return $this; } public function setAllowedBlueprintPHIDs(array $phids) { $this->setAttribute('internal.blueprintPHIDs', $phids); return $this; } public function getAllowedBlueprintPHIDs() { return $this->getAttribute('internal.blueprintPHIDs', array()); } private function didActivate() { $viewer = PhabricatorUser::getOmnipotentUser(); $need_update = false; $this->logEvent(DrydockLeaseActivatedLogType::LOGCONST); $commands = id(new DrydockCommandQuery()) ->setViewer($viewer) ->withTargetPHIDs(array($this->getPHID())) ->withConsumed(false) ->execute(); if ($commands) { $need_update = true; } if ($need_update) { $this->scheduleUpdate(); } $expires = $this->getUntil(); if ($expires) { $this->scheduleUpdate($expires); } $this->awakenTasks(); } public function logEvent($type, array $data = array()) { $log = id(new DrydockLog()) ->setEpoch(PhabricatorTime::getNow()) ->setType($type) ->setData($data); $log->setLeasePHID($this->getPHID()); $resource_phid = $this->getResourcePHID(); if ($resource_phid) { $resource = $this->getResource(); $log->setResourcePHID($resource->getPHID()); $log->setBlueprintPHID($resource->getBlueprintPHID()); } return $log->save(); } /** * Awaken yielded tasks after a state change. * * @return this */ public function awakenTasks() { $awaken_ids = $this->getAttribute('internal.awakenTaskIDs'); if (is_array($awaken_ids) && $awaken_ids) { PhabricatorWorker::awakenTaskIDs($awaken_ids); } return $this; } public function getURI() { $id = $this->getID(); return "/drydock/lease/{$id}/"; } public function getDisplayName() { return pht('Drydock Lease %d', $this->getID()); } /* -( Status )------------------------------------------------------------- */ public function getStatusObject() { return DrydockLeaseStatus::newStatusObject($this->getStatus()); } public function getStatusIcon() { return $this->getStatusObject()->getIcon(); } public function getStatusColor() { return $this->getStatusObject()->getColor(); } public function getStatusDisplayName() { return $this->getStatusObject()->getDisplayName(); } public function isActivating() { return $this->getStatusObject()->isActivating(); } public function isActive() { return $this->getStatusObject()->isActive(); } public function canRelease() { if (!$this->getID()) { return false; } return $this->getStatusObject()->canRelease(); } public function canReceiveCommands() { return $this->getStatusObject()->canReceiveCommands(); } /* -( PhabricatorPolicyInterface )----------------------------------------- */ public function getCapabilities() { return array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, ); } public function getPolicy($capability) { if ($this->getResource()) { return $this->getResource()->getPolicy($capability); } // TODO: Implement reasonable policies. return PhabricatorPolicies::getMostOpenPolicy(); } public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { if ($this->getResource()) { return $this->getResource()->hasAutomaticCapability($capability, $viewer); } return false; } public function describeAutomaticCapability($capability) { return pht('Leases inherit policies from the resources they lease.'); } /* -( PhabricatorConduitResultInterface )---------------------------------- */ public function getFieldSpecificationsForConduit() { return array( id(new PhabricatorConduitSearchFieldSpecification()) ->setKey('resourcePHID') ->setType('phid?') ->setDescription(pht('PHID of the leased resource, if any.')), id(new PhabricatorConduitSearchFieldSpecification()) ->setKey('resourceType') ->setType('string') ->setDescription(pht('Type of resource being leased.')), id(new PhabricatorConduitSearchFieldSpecification()) ->setKey('until') ->setType('int?') ->setDescription(pht('Epoch at which this lease expires, if any.')), id(new PhabricatorConduitSearchFieldSpecification()) ->setKey('ownerPHID') ->setType('phid?') ->setDescription(pht('The PHID of the object that owns this lease.')), id(new PhabricatorConduitSearchFieldSpecification()) ->setKey('authorizingPHID') ->setType('phid') ->setDescription(pht( 'The PHID of the object that authorized this lease.')), id(new PhabricatorConduitSearchFieldSpecification()) ->setKey('status') ->setType('map<string, wild>') ->setDescription(pht( "The string constant and name of this lease's status.")), ); } public function getFieldValuesForConduit() { $status = $this->getStatus(); $until = $this->getUntil(); if ($until) { $until = (int)$until; } else { $until = null; } return array( 'resourcePHID' => $this->getResourcePHID(), 'resourceType' => $this->getResourceType(), 'until' => $until, 'ownerPHID' => $this->getOwnerPHID(), 'authorizingPHID' => $this->getAuthorizingPHID(), 'status' => array( 'value' => $status, 'name' => DrydockLeaseStatus::getNameForStatus($status), ), ); } public function getConduitSearchAttachments() { return array(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/storage/DrydockBlueprintNameNgrams.php
src/applications/drydock/storage/DrydockBlueprintNameNgrams.php
<?php final class DrydockBlueprintNameNgrams extends PhabricatorSearchNgrams { public function getNgramKey() { return 'blueprintname'; } public function getColumnName() { return 'blueprintName'; } public function getApplicationName() { return 'drydock'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/storage/DrydockDAO.php
src/applications/drydock/storage/DrydockDAO.php
<?php abstract class DrydockDAO extends PhabricatorLiskDAO { public function getApplicationName() { return 'drydock'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/storage/DrydockSlotLock.php
src/applications/drydock/storage/DrydockSlotLock.php
<?php /** * Simple optimistic locks for Drydock resources and leases. * * Most blueprints only need very simple locks: for example, a host blueprint * might not want to create multiple resources representing the same physical * machine. These optimistic "slot locks" provide a flexible way to do this * sort of simple locking. * * @task info Getting Lock Information * @task lock Acquiring and Releasing Locks */ final class DrydockSlotLock extends DrydockDAO { protected $ownerPHID; protected $lockIndex; protected $lockKey; protected function getConfiguration() { return array( self::CONFIG_TIMESTAMPS => false, self::CONFIG_COLUMN_SCHEMA => array( 'lockIndex' => 'bytes12', 'lockKey' => 'text', ), self::CONFIG_KEY_SCHEMA => array( 'key_lock' => array( 'columns' => array('lockIndex'), 'unique' => true, ), 'key_owner' => array( 'columns' => array('ownerPHID'), ), ), ) + parent::getConfiguration(); } /* -( Getting Lock Information )------------------------------------------- */ /** * Load all locks held by a particular owner. * * @param phid Owner PHID. * @return list<DrydockSlotLock> All held locks. * @task info */ public static function loadLocks($owner_phid) { return id(new DrydockSlotLock())->loadAllWhere( 'ownerPHID = %s', $owner_phid); } /** * Test if a lock is currently free. * * @param string Lock key to test. * @return bool True if the lock is currently free. * @task info */ public static function isLockFree($lock) { return self::areLocksFree(array($lock)); } /** * Test if a list of locks are all currently free. * * @param list<string> List of lock keys to test. * @return bool True if all locks are currently free. * @task info */ public static function areLocksFree(array $locks) { $lock_map = self::loadHeldLocks($locks); return !$lock_map; } /** * Load named locks. * * @param list<string> List of lock keys to load. * @return list<DrydockSlotLock> List of held locks. * @task info */ public static function loadHeldLocks(array $locks) { if (!$locks) { return array(); } $table = new DrydockSlotLock(); $conn_r = $table->establishConnection('r'); $indexes = array(); foreach ($locks as $lock) { $indexes[] = PhabricatorHash::digestForIndex($lock); } return id(new DrydockSlotLock())->loadAllWhere( 'lockIndex IN (%Ls)', $indexes); } /* -( Acquiring and Releasing Locks )-------------------------------------- */ /** * Acquire a set of slot locks. * * This method either acquires all the locks or throws an exception (usually * because one or more locks are held). * * @param phid Lock owner PHID. * @param list<string> List of locks to acquire. * @return void * @task locks */ public static function acquireLocks($owner_phid, array $locks) { if (!$locks) { return; } $table = new DrydockSlotLock(); $conn_w = $table->establishConnection('w'); $sql = array(); foreach ($locks as $lock) { $sql[] = qsprintf( $conn_w, '(%s, %s, %s)', $owner_phid, PhabricatorHash::digestForIndex($lock), $lock); } try { queryfx( $conn_w, 'INSERT INTO %T (ownerPHID, lockIndex, lockKey) VALUES %LQ', $table->getTableName(), $sql); } catch (AphrontDuplicateKeyQueryException $ex) { // Try to improve the readability of the exception. We might miss on // this query if the lock has already been released, but most of the // time we should be able to figure out which locks are already held. $held = self::loadHeldLocks($locks); $held = mpull($held, 'getOwnerPHID', 'getLockKey'); throw new DrydockSlotLockException($held); } } /** * Release all locks held by an owner. * * @param phid Lock owner PHID. * @return void * @task locks */ public static function releaseLocks($owner_phid) { $table = new DrydockSlotLock(); $conn_w = $table->establishConnection('w'); queryfx( $conn_w, 'DELETE FROM %T WHERE ownerPHID = %s', $table->getTableName(), $owner_phid); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/storage/DrydockSchemaSpec.php
src/applications/drydock/storage/DrydockSchemaSpec.php
<?php final class DrydockSchemaSpec extends PhabricatorConfigSchemaSpec { public function buildSchemata() { $this->buildEdgeSchemata(new DrydockBlueprint()); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/storage/DrydockRepositoryOperation.php
src/applications/drydock/storage/DrydockRepositoryOperation.php
<?php /** * Represents a request to perform a repository operation like a merge or * cherry-pick. */ final class DrydockRepositoryOperation extends DrydockDAO implements PhabricatorPolicyInterface { const STATE_WAIT = 'wait'; const STATE_WORK = 'work'; const STATE_DONE = 'done'; const STATE_FAIL = 'fail'; protected $authorPHID; protected $objectPHID; protected $repositoryPHID; protected $repositoryTarget; protected $operationType; protected $operationState; protected $properties = array(); protected $isDismissed; private $repository = self::ATTACHABLE; private $object = self::ATTACHABLE; private $implementation = self::ATTACHABLE; private $workingCopyLease = self::ATTACHABLE; public static function initializeNewOperation( DrydockRepositoryOperationType $op) { return id(new DrydockRepositoryOperation()) ->setOperationState(self::STATE_WAIT) ->setOperationType($op->getOperationConstant()) ->setIsDismissed(0); } protected function getConfiguration() { return array( self::CONFIG_AUX_PHID => true, self::CONFIG_SERIALIZATION => array( 'properties' => self::SERIALIZATION_JSON, ), self::CONFIG_COLUMN_SCHEMA => array( 'repositoryTarget' => 'bytes', 'operationType' => 'text32', 'operationState' => 'text32', 'isDismissed' => 'bool', ), self::CONFIG_KEY_SCHEMA => array( 'key_object' => array( 'columns' => array('objectPHID'), ), 'key_repository' => array( 'columns' => array('repositoryPHID', 'operationState'), ), 'key_state' => array( 'columns' => array('operationState'), ), 'key_author' => array( 'columns' => array('authorPHID', 'operationState'), ), ), ) + parent::getConfiguration(); } public function generatePHID() { return PhabricatorPHID::generateNewPHID( DrydockRepositoryOperationPHIDType::TYPECONST); } public function attachRepository(PhabricatorRepository $repository) { $this->repository = $repository; return $this; } public function getRepository() { return $this->assertAttached($this->repository); } public function attachObject($object) { $this->object = $object; return $this; } public function getObject() { return $this->assertAttached($this->object); } public function attachImplementation(DrydockRepositoryOperationType $impl) { $this->implementation = $impl; return $this; } public function getImplementation() { return $this->implementation; } public function getWorkingCopyLease() { return $this->assertAttached($this->workingCopyLease); } public function attachWorkingCopyLease(DrydockLease $lease) { $this->workingCopyLease = $lease; return $this; } public function hasWorkingCopyLease() { return ($this->workingCopyLease !== self::ATTACHABLE); } public function getProperty($key, $default = null) { return idx($this->properties, $key, $default); } public function setProperty($key, $value) { $this->properties[$key] = $value; return $this; } public static function getOperationStateNameMap() { return array( self::STATE_WAIT => pht('Waiting'), self::STATE_WORK => pht('Working'), self::STATE_DONE => pht('Done'), self::STATE_FAIL => pht('Failed'), ); } public static function getOperationStateIcon($state) { $map = array( self::STATE_WAIT => 'fa-clock-o', self::STATE_WORK => 'fa-plane ph-spin blue', self::STATE_DONE => 'fa-check green', self::STATE_FAIL => 'fa-times red', ); return idx($map, $state, null); } public static function getOperationStateName($state) { $map = self::getOperationStateNameMap(); return idx($map, $state, pht('<Unknown: %s>', $state)); } public function scheduleUpdate() { PhabricatorWorker::scheduleTask( 'DrydockRepositoryOperationUpdateWorker', array( 'operationPHID' => $this->getPHID(), ), array( 'objectPHID' => $this->getPHID(), 'priority' => PhabricatorWorker::PRIORITY_ALERTS, )); } public function applyOperation(DrydockInterface $interface) { $impl = $this->getImplementation(); $impl->setInterface($interface); return $impl->applyOperation($this, $interface); } public function getOperationDescription(PhabricatorUser $viewer) { return $this->getImplementation()->getOperationDescription( $this, $viewer); } public function getOperationCurrentStatus(PhabricatorUser $viewer) { return $this->getImplementation()->getOperationCurrentStatus( $this, $viewer); } public function isUnderway() { switch ($this->getOperationState()) { case self::STATE_WAIT: case self::STATE_WORK: return true; } return false; } public function isDone() { return ($this->getOperationState() === self::STATE_DONE); } public function getWorkingCopyMerges() { return $this->getImplementation()->getWorkingCopyMerges( $this); } public function setWorkingCopyLeasePHID($lease_phid) { return $this->setProperty('exec.leasePHID', $lease_phid); } public function getWorkingCopyLeasePHID() { return $this->getProperty('exec.leasePHID'); } public function setCommandError(array $error) { return $this->setProperty('exec.workingcopy.error', $error); } public function getCommandError() { return $this->getProperty('exec.workingcopy.error'); } public function logText($text) { return $this->logEvent( DrydockTextLogType::LOGCONST, array( 'text' => $text, )); } public function logEvent($type, array $data = array()) { $log = id(new DrydockLog()) ->setEpoch(PhabricatorTime::getNow()) ->setType($type) ->setData($data); $log->setOperationPHID($this->getPHID()); if ($this->hasWorkingCopyLease()) { $lease = $this->getWorkingCopyLease(); $log->setLeasePHID($lease->getPHID()); $resource_phid = $lease->getResourcePHID(); if ($resource_phid) { $resource = $lease->getResource(); $log->setResourcePHID($resource->getPHID()); $log->setBlueprintPHID($resource->getBlueprintPHID()); } } return $log->save(); } /* -( PhabricatorPolicyInterface )----------------------------------------- */ public function getCapabilities() { return array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, ); } public function getPolicy($capability) { $need_capability = $this->getRequiredRepositoryCapability($capability); return $this->getRepository() ->getPolicy($need_capability); } public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { $need_capability = $this->getRequiredRepositoryCapability($capability); return $this->getRepository() ->hasAutomaticCapability($need_capability, $viewer); } public function describeAutomaticCapability($capability) { return pht( 'A repository operation inherits the policies of the repository it '. 'affects.'); } private function getRequiredRepositoryCapability($capability) { // To edit a RepositoryOperation, require that the user be able to push // to the repository. $map = array( PhabricatorPolicyCapability::CAN_EDIT => DiffusionPushCapability::CAPABILITY, ); return idx($map, $capability, $capability); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/storage/DrydockCommand.php
src/applications/drydock/storage/DrydockCommand.php
<?php final class DrydockCommand extends DrydockDAO implements PhabricatorPolicyInterface { const COMMAND_RELEASE = 'release'; const COMMAND_RECLAIM = 'reclaim'; protected $authorPHID; protected $targetPHID; protected $command; protected $isConsumed; protected $properties = array(); private $commandTarget = self::ATTACHABLE; public static function initializeNewCommand(PhabricatorUser $author) { return id(new DrydockCommand()) ->setAuthorPHID($author->getPHID()) ->setIsConsumed(0); } protected function getConfiguration() { return array( self::CONFIG_SERIALIZATION => array( 'properties' => self::SERIALIZATION_JSON, ), self::CONFIG_COLUMN_SCHEMA => array( 'command' => 'text32', 'isConsumed' => 'bool', ), self::CONFIG_KEY_SCHEMA => array( 'key_target' => array( 'columns' => array('targetPHID', 'isConsumed'), ), ), ) + parent::getConfiguration(); } public function attachCommandTarget($target) { $this->commandTarget = $target; return $this; } public function getCommandTarget() { return $this->assertAttached($this->commandTarget); } public function setProperty($key, $value) { $this->properties[$key] = $value; return $this; } public function getProperty($key, $default = null) { return idx($this->properties, $key, $default); } /* -( PhabricatorPolicyInterface )----------------------------------------- */ public function getCapabilities() { return array( PhabricatorPolicyCapability::CAN_VIEW, ); } public function getPolicy($capability) { return $this->getCommandTarget()->getPolicy($capability); } public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { return $this->getCommandTarget()->hasAutomaticCapability( $capability, $viewer); } public function describeAutomaticCapability($capability) { return pht('Drydock commands have the same policies as their targets.'); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false