コード例 #1
0
 public final function willBeginExecution()
 {
     $request = $this->getRequest();
     $user = new PhabricatorUser();
     $phusr = $request->getCookie('phusr');
     $phsid = $request->getCookie('phsid');
     if ($phusr && $phsid) {
         $info = queryfx_one($user->establishConnection('r'), 'SELECT u.* FROM %T u JOIN %T s ON u.phid = s.userPHID
       AND s.type LIKE %> AND s.sessionKey = %s', $user->getTableName(), 'phabricator_session', 'web-', $phsid);
         if ($info) {
             $user->loadFromArray($info);
         }
     }
     $request->setUser($user);
     if ($user->getIsDisabled() && $this->shouldRequireEnabledUser()) {
         $disabled_user_controller = newv('PhabricatorDisabledUserController', array($request));
         return $this->delegateToController($disabled_user_controller);
     }
     if (PhabricatorEnv::getEnvConfig('darkconsole.enabled')) {
         if ($user->getConsoleEnabled() || PhabricatorEnv::getEnvConfig('darkconsole.always-on')) {
             $console = new DarkConsoleCore();
             $request->getApplicationConfiguration()->setConsole($console);
         }
     }
     if ($this->shouldRequireLogin() && !$user->getPHID()) {
         $login_controller = newv('PhabricatorLoginController', array($request));
         return $this->delegateToController($login_controller);
     }
     if ($this->shouldRequireAdmin() && !$user->getIsAdmin()) {
         return new Aphront403Response();
     }
 }
コード例 #2
0
 public final function buildController()
 {
     $map = $this->getURIMap();
     $mapper = new AphrontURIMapper($map);
     $request = $this->getRequest();
     $path = $request->getPath();
     list($controller_class, $uri_data) = $mapper->mapPath($path);
     if (!$controller_class) {
         if (!preg_match('@/$@', $path)) {
             // If we failed to match anything but don't have a trailing slash, try
             // to add a trailing slash and issue a redirect if that resolves.
             list($controller_class, $uri_data) = $mapper->mapPath($path . '/');
             // NOTE: For POST, just 404 instead of redirecting, since the redirect
             // will be a GET without parameters.
             if ($controller_class && !$request->isHTTPPost()) {
                 $uri = $request->getRequestURI()->setPath($path . '/');
                 return $this->buildRedirectController($uri);
             }
         }
         return $this->build404Controller();
     }
     PhutilSymbolLoader::loadClass($controller_class);
     $controller = newv($controller_class, array($request));
     return array($controller, $uri_data);
 }
コード例 #3
0
 public function run()
 {
     $argv = $this->getArgv();
     if (count($argv) !== 1) {
         throw new Exception("usage: PhabricatorIRCBot <json_config_file>");
     }
     $json_raw = Filesystem::readFile($argv[0]);
     $config = json_decode($json_raw, true);
     if (!is_array($config)) {
         throw new Exception("File '{$argv[0]}' is not valid JSON!");
     }
     $server = idx($config, 'server');
     $port = idx($config, 'port', 6667);
     $handlers = idx($config, 'handlers', array());
     $pass = idx($config, 'pass');
     $nick = idx($config, 'nick', 'phabot');
     $user = idx($config, 'user', $nick);
     $ssl = idx($config, 'ssl', false);
     $nickpass = idx($config, 'nickpass');
     $this->config = $config;
     if (!preg_match('/^[A-Za-z0-9_`[{}^|\\]\\-]+$/', $nick)) {
         throw new Exception("Nickname '{$nick}' is invalid!");
     }
     foreach ($handlers as $handler) {
         $obj = newv($handler, array($this));
         $this->handlers[] = $obj;
     }
     $conduit_uri = idx($config, 'conduit.uri');
     if ($conduit_uri) {
         $conduit_user = idx($config, 'conduit.user');
         $conduit_cert = idx($config, 'conduit.cert');
         $conduit = new ConduitClient($conduit_uri);
         $response = $conduit->callMethodSynchronous('conduit.connect', array('client' => 'PhabricatorIRCBot', 'clientVersion' => '1.0', 'clientDescription' => php_uname('n') . ':' . $nick, 'user' => $conduit_user, 'certificate' => $conduit_cert));
         $this->conduit = $conduit;
     }
     $errno = null;
     $error = null;
     if (!$ssl) {
         $socket = fsockopen($server, $port, $errno, $error);
     } else {
         $socket = fsockopen('ssl://' . $server, $port, $errno, $error);
     }
     if (!$socket) {
         throw new Exception("Failed to connect, #{$errno}: {$error}");
     }
     $ok = stream_set_blocking($socket, false);
     if (!$ok) {
         throw new Exception("Failed to set stream nonblocking.");
     }
     $this->socket = $socket;
     $this->writeCommand('USER', "{$user} 0 * :{$user}");
     if ($pass) {
         $this->writeCommand('PASS', "{$pass}");
     }
     if ($nickpass) {
         $this->writeCommand("NickServ IDENTIFY ", "{$nickpass}");
     }
     $this->writeCommand('NICK', "{$nick}");
     $this->runSelectLoop();
 }
コード例 #4
0
 protected function applyCustomInternalTransaction(PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction)
 {
     $new = $xaction->getNewValue();
     switch ($xaction->getTransactionType()) {
         case ReleephRequestTransaction::TYPE_REQUEST:
             $object->setRequestCommitPHID($new);
             break;
         case ReleephRequestTransaction::TYPE_USER_INTENT:
             $user_phid = $xaction->getAuthorPHID();
             $intents = $object->getUserIntents();
             $intents[$user_phid] = $new;
             $object->setUserIntents($intents);
             break;
         case ReleephRequestTransaction::TYPE_EDIT_FIELD:
             $field = newv($xaction->getMetadataValue('fieldClass'), array());
             $field->setReleephRequest($object)->setValue($new);
             break;
         case ReleephRequestTransaction::TYPE_PICK_STATUS:
             $object->setPickStatus($new);
             break;
         case ReleephRequestTransaction::TYPE_COMMIT:
             $this->setInBranchFromAction($object, $xaction);
             $object->setCommitIdentifier($new);
             break;
         case ReleephRequestTransaction::TYPE_DISCOVERY:
             $this->setInBranchFromAction($object, $xaction);
             $object->setCommitPHID($new);
             break;
         case ReleephRequestTransaction::TYPE_MANUAL_IN_BRANCH:
             $object->setInBranch((int) $new);
             break;
     }
 }
コード例 #5
0
 public static function newAPIFromWorkingCopyIdentity(ArcanistWorkingCopyIdentity $working_copy)
 {
     $root = $working_copy->getProjectRoot();
     if (!$root) {
         throw new ArcanistUsageException("There is no readable '.arcconfig' file in the working directory or " . "any parent directory. Create an '.arcconfig' file to configure arc.");
     }
     // check if we're in an svn working copy
     list($err) = exec_manual('svn info');
     if (!$err) {
         $api = newv('ArcanistSubversionAPI', array($root));
         $api->workingCopyIdentity = $working_copy;
         return $api;
     }
     if (Filesystem::pathExists($root . '/.hg')) {
         $api = newv('ArcanistMercurialAPI', array($root));
         $api->workingCopyIdentity = $working_copy;
         return $api;
     }
     $git_root = self::discoverGitBaseDirectory($root);
     if ($git_root) {
         if (!Filesystem::pathsAreEquivalent($root, $git_root)) {
             throw new ArcanistUsageException("'.arcconfig' file is located at '{$root}', but working copy root " . "is '{$git_root}'. Move '.arcconfig' file to the working copy root.");
         }
         $api = newv('ArcanistGitAPI', array($root));
         $api->workingCopyIdentity = $working_copy;
         return $api;
     }
     throw new ArcanistUsageException("The current working directory is not part of a working copy for a " . "supported version control system (svn, git or mercurial).");
 }
 public function processRequest()
 {
     $classes = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorUIExample')->selectAndLoadSymbols();
     $classes = ipull($classes, 'name', 'name');
     $selected = null;
     foreach ($classes as $class => $ignored) {
         $classes[$class] = newv($class, array());
         if ($this->class == $classes[$class]->getName()) {
             $selected = $class;
         }
     }
     if (!$selected) {
         reset($classes);
         $selected = key($classes);
     }
     $nav = new AphrontSideNavView();
     foreach ($classes as $class => $obj) {
         $name = $obj->getName();
         $nav->addNavItem(phutil_render_tag('a', array('href' => '/uiexample/view/' . $name . '/', 'class' => $selected == $class ? 'aphront-side-nav-selected' : null), phutil_escape_html($obj->getName())));
     }
     require_celerity_resource('phabricator-ui-example-css');
     $example = $classes[$selected];
     $example->setRequest($this->getRequest());
     $nav->appendChild('<div class="phabricator-ui-example-header">' . '<h1 class="phabricator-ui-example-name">' . phutil_escape_html($example->getName()) . ' (' . get_class($example) . ')' . '</h1>' . '<p class="phabricator-ui-example-description">' . $example->getDescription() . '</p>' . '</div>');
     $nav->appendChild($example->renderExample());
     return $this->buildStandardPageResponse($nav, array('title' => 'UI Example'));
 }
 protected final function updateCommitData($author, $message)
 {
     $commit = $this->commit;
     $data = id(new PhabricatorRepositoryCommitData())->loadOneWhere('commitID = %d', $commit->getID());
     if (!$data) {
         $data = new PhabricatorRepositoryCommitData();
     }
     $data->setCommitID($commit->getID());
     $data->setAuthorName($author);
     $data->setCommitMessage($message);
     $repository = $this->repository;
     $detail_parser = $repository->getDetail('detail-parser', 'PhabricatorRepositoryDefaultCommitMessageDetailParser');
     if ($detail_parser) {
         PhutilSymbolLoader::loadClass($detail_parser);
         $parser_obj = newv($detail_parser, array($commit, $data));
         $parser_obj->parseCommitDetails();
     }
     $data->save();
     $revision_id = $data->getCommitDetail('differential.revisionID');
     if ($revision_id) {
         $revision = id(new DifferentialRevision())->load($revision_id);
         if ($revision) {
             queryfx($revision->establishConnection('w'), 'INSERT IGNORE INTO %T (revisionID, commitPHID) VALUES (%d, %s)', DifferentialRevision::TABLE_COMMIT, $revision->getID(), $commit->getPHID());
             if ($revision->getStatus() != DifferentialRevisionStatus::COMMITTED) {
                 $editor = new DifferentialCommentEditor($revision, $revision->getAuthorPHID(), DifferentialAction::ACTION_COMMIT);
                 $editor->save();
             }
         }
     }
 }
コード例 #8
0
 public function processRequest()
 {
     $classes = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorUIExample')->setConcreteOnly(true)->selectAndLoadSymbols();
     $classes = ipull($classes, 'name', 'name');
     foreach ($classes as $class => $ignored) {
         $classes[$class] = newv($class, array());
     }
     $classes = msort($classes, 'getName');
     $nav = new AphrontSideNavFilterView();
     $nav->setBaseURI(new PhutilURI($this->getApplicationURI('view/')));
     foreach ($classes as $class => $obj) {
         $name = $obj->getName();
         $nav->addFilter($class, $name);
     }
     $selected = $nav->selectFilter($this->class, head_key($classes));
     require_celerity_resource('phabricator-ui-example-css');
     $example = $classes[$selected];
     $example->setRequest($this->getRequest());
     $result = $example->renderExample();
     if ($result instanceof AphrontResponse) {
         // This allows examples to generate dialogs, etc., for demonstration.
         return $result;
     }
     $nav->appendChild('<div class="phabricator-ui-example-header">' . '<h1 class="phabricator-ui-example-name">' . phutil_escape_html($example->getName()) . ' (' . get_class($example) . ')' . '</h1>' . '<p class="phabricator-ui-example-description">' . $example->getDescription() . '</p>' . '</div>');
     $nav->appendChild($result);
     return $this->buildApplicationPage($nav, array('title' => 'UI Example', 'device' => true));
 }
コード例 #9
0
 private function buildPanels()
 {
     $panel_specs = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorSettingsPanel')->setConcreteOnly(true)->selectAndLoadSymbols();
     $panels = array();
     foreach ($panel_specs as $spec) {
         $class = newv($spec['name'], array());
         $panels[] = $class->buildPanels();
     }
     $panels = array_mergev($panels);
     $panels = mpull($panels, null, 'getPanelKey');
     $result = array();
     foreach ($panels as $key => $panel) {
         $panel->setUser($this->user);
         if (!$panel->isEnabled()) {
             continue;
         }
         if (!$this->isSelf()) {
             if (!$panel->isEditableByAdministrators()) {
                 continue;
             }
         }
         if (!empty($result[$key])) {
             throw new Exception(pht("Two settings panels share the same panel key ('%s'): %s, %s.", $key, get_class($panel), get_class($result[$key])));
         }
         $result[$key] = $panel;
     }
     $result = msort($result, 'getPanelSortKey');
     if (!$result) {
         throw new Exception(pht('No settings panels are available.'));
     }
     return $result;
 }
コード例 #10
0
 protected function loadPage()
 {
     $table = new PhortuneProduct();
     $conn = $table->establishConnection('r');
     $rows = queryfx_all($conn, 'SELECT * FROM %T %Q %Q %Q', $table->getTableName(), $this->buildWhereClause($conn), $this->buildOrderClause($conn), $this->buildLimitClause($conn));
     $page = $table->loadAllFromArray($rows);
     // NOTE: We're loading product implementations here, but also creating any
     // products which do not yet exist.
     $class_map = mgroup($page, 'getProductClass');
     if ($this->refMap) {
         $class_map += array_fill_keys(array_keys($this->refMap), array());
     }
     foreach ($class_map as $class => $products) {
         $refs = mpull($products, null, 'getProductRef');
         if (isset($this->refMap[$class])) {
             $refs += array_fill_keys($this->refMap[$class], null);
         }
         $implementations = newv($class, array())->loadImplementationsForRefs($this->getViewer(), array_keys($refs));
         $implementations = mpull($implementations, null, 'getRef');
         foreach ($implementations as $ref => $implementation) {
             $product = idx($refs, $ref);
             if ($product === null) {
                 // If this product does not exist yet, create it and add it to the
                 // result page.
                 $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
                 $product = PhortuneProduct::initializeNewProduct()->setProductClass($class)->setProductRef($ref)->save();
                 unset($unguarded);
                 $page[] = $product;
             }
             $product->attachImplementation($implementation);
         }
     }
     return $page;
 }
コード例 #11
0
 protected function willFilterPage(array $comments)
 {
     if ($this->needReplyToComments) {
         $reply_phids = array();
         foreach ($comments as $comment) {
             $reply_phid = $comment->getReplyToCommentPHID();
             if ($reply_phid) {
                 $reply_phids[] = $reply_phid;
             }
         }
         if ($reply_phids) {
             $reply_comments = newv(get_class($this), array())->setViewer($this->getViewer())->setParentQuery($this)->withPHIDs($reply_phids)->execute();
             $reply_comments = mpull($reply_comments, null, 'getPHID');
         } else {
             $reply_comments = array();
         }
         foreach ($comments as $key => $comment) {
             $reply_phid = $comment->getReplyToCommentPHID();
             if (!$reply_phid) {
                 $comment->attachReplyToComment(null);
                 continue;
             }
             $reply = idx($reply_comments, $reply_phid);
             if (!$reply) {
                 $this->didRejectResult($comment);
                 unset($comments[$key]);
                 continue;
             }
             $comment->attachReplyToComment($reply);
         }
     }
     return $comments;
 }
コード例 #12
0
 public function establishLiveConnection($mode)
 {
     $conf_provider = PhabricatorEnv::getEnvConfig('mysql.configuration_provider', 'DatabaseConfigurationProvider');
     PhutilSymbolLoader::loadClass($conf_provider);
     $conf = newv($conf_provider, array($this, $mode));
     return new AphrontMySQLDatabaseConnection(array('user' => $conf->getUser(), 'pass' => $conf->getPassword(), 'host' => $conf->getHost(), 'database' => $conf->getDatabase()));
 }
コード例 #13
0
 public function getBlueprint()
 {
     if (empty($this->blueprint)) {
         $this->blueprint = newv($this->blueprintClass, array());
     }
     return $this->blueprint;
 }
コード例 #14
0
 protected function buildLocalFuture(array $argv)
 {
     $argv[0] = 'git ' . $argv[0];
     $future = newv('ExecFuture', $argv);
     $future->setCWD($this->getPath());
     return $future;
 }
コード例 #15
0
 public function loadOneRandom($classname)
 {
     try {
         return newv($classname, array())->loadOneWhere('1 = 1 ORDER BY RAND() LIMIT 1');
     } catch (PhutilMissingSymbolException $ex) {
         throw new PhutilMissingSymbolException(pht('Unable to load symbol %s: this class does not exit.', $classname));
     }
 }
コード例 #16
0
 /**
  * Returns an instance of the linter being tested.
  *
  * @return ArcanistLinter
  */
 protected final function getLinter()
 {
     $matches = null;
     if (!preg_match('/^(\\w+Linter)TestCase$/', get_class($this), $matches) || !is_subclass_of($matches[1], 'ArcanistLinter')) {
         throw new Exception(pht('Unable to infer linter class name.'));
     }
     return newv($matches[1], array());
 }
 public function __construct()
 {
     $root = phutil_get_library_root('phabricator');
     $root = dirname($root);
     require_once $root . '/externals/phpmailer/class.phpmailer-lite.php';
     $this->mailer = newv('PHPMailerLite', array($use_exceptions = true));
     $this->mailer->CharSet = 'utf-8';
 }
コード例 #18
0
 private function renderTestThings($class, $max, $incr)
 {
     $bars = array();
     for ($ii = 0; $ii <= $max; $ii++) {
         $bars[] = newv($class, array())->setValue($ii * $incr)->setMax($max * $incr)->setCaption("{$ii} outta {$max} ain't bad!");
     }
     return $this->wrap("Test {$class}", $bars);
 }
コード例 #19
0
 public static function getConfiguration()
 {
     // Get DB info. Note that we are using a dummy PhabricatorUser object in
     // creating the DatabaseConfigurationProvider, which is not used at all.
     $conf_provider = PhabricatorEnv::getEnvConfig('mysql.configuration_provider', 'DatabaseConfigurationProvider');
     PhutilSymbolLoader::loadClass($conf_provider);
     $conf = newv($conf_provider, array(new PhabricatorUser(), 'r'));
     return $conf;
 }
コード例 #20
0
 public static final function loadAllEngines()
 {
     $classes = id(new PhutilSymbolLoader())->setAncestorClass(__CLASS__)->setConcreteOnly(true)->selectAndLoadSymbols();
     $objects = array();
     foreach ($classes as $class) {
         $objects[] = newv($class['name'], array());
     }
     return $objects;
 }
コード例 #21
0
 public function getTitle()
 {
     $author_phid = $this->getAuthorPHID();
     $object_phid = $this->getObjectPHID();
     $old = $this->getOldValue();
     $new = $this->getNewValue();
     switch ($this->getTransactionType()) {
         case self::TYPE_REQUEST:
             return pht('%s requested %s', $this->renderHandleLink($author_phid), $this->renderHandleLink($new));
             break;
         case self::TYPE_USER_INTENT:
             return $this->getIntentTitle();
             break;
         case self::TYPE_EDIT_FIELD:
             $field = newv($this->getMetadataValue('fieldClass'), array());
             $name = $field->getName();
             $markup = $name;
             if ($this->getRenderingTarget() === parent::TARGET_HTML) {
                 $markup = hsprintf('<em>%s</em>', $name);
             }
             return pht('%s changed the %s to "%s"', $this->renderHandleLink($author_phid), $markup, $field->normalizeForTransactionView($this, $new));
             break;
         case self::TYPE_PICK_STATUS:
             switch ($new) {
                 case ReleephRequest::PICK_OK:
                     return pht('%s found this request picks without error', $this->renderHandleLink($author_phid));
                 case ReleephRequest::REVERT_OK:
                     return pht('%s found this request reverts without error', $this->renderHandleLink($author_phid));
                 case ReleephRequest::PICK_FAILED:
                     return pht("%s couldn't pick this request", $this->renderHandleLink($author_phid));
                 case ReleephRequest::REVERT_FAILED:
                     return pht("%s couldn't revert this request", $this->renderHandleLink($author_phid));
             }
             break;
         case self::TYPE_COMMIT:
             $action_type = $this->getMetadataValue('action');
             switch ($action_type) {
                 case 'pick':
                     return pht('%s picked this request and committed the result upstream', $this->renderHandleLink($author_phid));
                     break;
                 case 'revert':
                     return pht('%s reverted this request and committed the result upstream', $this->renderHandleLink($author_phid));
                     break;
             }
             break;
         case self::TYPE_MANUAL_IN_BRANCH:
             $action = $new ? pht('picked') : pht('reverted');
             return pht('%s marked this request as manually %s', $this->renderHandleLink($author_phid), $action);
             break;
         case self::TYPE_DISCOVERY:
             return pht('%s discovered this commit as %s', $this->renderHandleLink($author_phid), $this->renderHandleLink($new));
             break;
         default:
             return parent::getTitle();
             break;
     }
 }
コード例 #22
0
 public static function establishConnection($phid_type, $conn_type)
 {
     static $class_map = array(PhabricatorPHIDConstants::PHID_TYPE_TASK => 'ManiphestTask', PhabricatorPHIDConstants::PHID_TYPE_CMIT => 'PhabricatorRepository', PhabricatorPHIDConstants::PHID_TYPE_DREV => 'DifferentialRevision', PhabricatorPHIDConstants::PHID_TYPE_FILE => 'PhabricatorFile', PhabricatorPHIDConstants::PHID_TYPE_USER => 'PhabricatorUser', PhabricatorPHIDConstants::PHID_TYPE_PROJ => 'PhabricatorProject', PhabricatorPHIDConstants::PHID_TYPE_MLST => 'PhabricatorMetaMTAMailingList', PhabricatorPHIDConstants::PHID_TYPE_TOBJ => 'HarbormasterObject', PhabricatorPHIDConstants::PHID_TYPE_BLOG => 'PhameBlog', PhabricatorPHIDConstants::PHID_TYPE_POST => 'PhamePost');
     $class = idx($class_map, $phid_type);
     if (!$class) {
         throw new Exception("Edges are not available for objects of type '{$phid_type}'!");
     }
     return newv($class, array())->establishConnection($conn_type);
 }
コード例 #23
0
 public function generateContent($language = null)
 {
     if ($language == null || !in_array($language, array_keys($this->supportedLanguages))) {
         return id(new PhutilLipsumContextFreeGrammar())->generateSeveral(rand(30, 40));
     } else {
         $cfg_class = 'Phutil' . $language . 'CodeSnippetContextFreeGrammar';
         return newv($cfg_class, array())->generate();
     }
 }
コード例 #24
0
 /**
  * Returns an instance of the linter rule being tested.
  *
  * @return ArcanistXHPASTLinterRule
  */
 protected function getLinterRule()
 {
     $class = get_class($this);
     $matches = null;
     if (!preg_match('/^(\\w+XHPASTLinterRule)TestCase$/', $class, $matches) || !is_subclass_of($matches[1], 'ArcanistXHPASTLinterRule')) {
         throw new Exception(pht('Unable to infer linter rule class name.'));
     }
     return newv($matches[1], array());
 }
コード例 #25
0
 protected function doWork()
 {
     $viewer = PhabricatorUser::getOmnipotentUser();
     $task_data = $this->getTaskData();
     $sms = id(new PhabricatorSMS())->loadOneWhere('id = %d', $task_data['smsID']);
     if (!$sms) {
         throw new PhabricatorWorkerPermanentFailureException(pht('SMS object was not found.'));
     }
     // this has the potential to be updated asynchronously
     if ($sms->getSendStatus() == PhabricatorSMS::STATUS_SENT) {
         return;
     }
     $adapter = PhabricatorEnv::getEnvConfig('sms.default-adapter');
     $adapter = newv($adapter, array());
     if ($sms->hasBeenSentAtLeastOnce()) {
         $up_to_date_status = $adapter->pollSMSSentStatus($sms);
         if ($up_to_date_status) {
             $sms->setSendStatus($up_to_date_status);
             if ($up_to_date_status == PhabricatorSMS::STATUS_SENT) {
                 $sms->save();
                 return;
             }
         }
         // TODO - re-jigger this so we can try if appropos (e.g. rate limiting)
         return;
     }
     $from_number = PhabricatorEnv::getEnvConfig('sms.default-sender');
     // always set the from number if we get this far in case of configuration
     // changes.
     $sms->setFromNumber($from_number);
     $adapter->setTo($sms->getToNumber());
     $adapter->setFrom($sms->getFromNumber());
     $adapter->setBody($sms->getBody());
     // give the provider name the same treatment as phone number
     $sms->setProviderShortName($adapter->getProviderShortName());
     if (PhabricatorEnv::getEnvConfig('phabricator.silent')) {
         $sms->setSendStatus(PhabricatorSMS::STATUS_FAILED_PERMANENTLY);
         $sms->save();
         throw new PhabricatorWorkerPermanentFailureException(pht('Phabricator is running in silent mode. See `%s` ' . 'in the configuration to change this setting.', 'phabricator.silent'));
     }
     try {
         $result = $adapter->send();
         list($sms_id, $sent_status) = $adapter->getSMSDataFromResult($result);
     } catch (PhabricatorWorkerPermanentFailureException $e) {
         $sms->setSendStatus(PhabricatorSMS::STATUS_FAILED_PERMANENTLY);
         $sms->save();
         throw $e;
     } catch (Exception $e) {
         $sms->setSendStatus(PhabricatorSMS::STATUS_FAILED_PERMANENTLY);
         $sms->save();
         throw new PhabricatorWorkerPermanentFailureException($e->getMessage());
     }
     $sms->setProviderSMSID($sms_id);
     $sms->setSendStatus($sent_status);
     $sms->save();
 }
 protected final function updateCommitData($author, $message)
 {
     $commit = $this->commit;
     $data = id(new PhabricatorRepositoryCommitData())->loadOneWhere('commitID = %d', $commit->getID());
     if (!$data) {
         $data = new PhabricatorRepositoryCommitData();
     }
     $data->setCommitID($commit->getID());
     $data->setAuthorName($author);
     $data->setCommitMessage($message);
     $repository = $this->repository;
     $detail_parser = $repository->getDetail('detail-parser', 'PhabricatorRepositoryDefaultCommitMessageDetailParser');
     if ($detail_parser) {
         PhutilSymbolLoader::loadClass($detail_parser);
         $parser_obj = newv($detail_parser, array($commit, $data));
         $parser_obj->parseCommitDetails();
     }
     $data->save();
     $conn_w = id(new DifferentialRevision())->establishConnection('w');
     // NOTE: The `differential_commit` table has a unique ID on `commitPHID`,
     // preventing more than one revision from being associated with a commit.
     // Generally this is good and desirable, but with the advent of hash
     // tracking we may end up in a situation where we match several different
     // revisions. We just kind of ignore this and pick one, we might want to
     // revisit this and do something differently. (If we match several revisions
     // someone probably did something very silly, though.)
     $revision_id = $data->getCommitDetail('differential.revisionID');
     if (!$revision_id) {
         $hashes = $this->getCommitHashes($this->repository, $this->commit);
         if ($hashes) {
             $query = new DifferentialRevisionQuery();
             $query->withCommitHashes($hashes);
             $revisions = $query->execute();
             if (!empty($revisions)) {
                 $revision = $this->identifyBestRevision($revisions);
                 $revision_id = $revision->getID();
             }
         }
     }
     if ($revision_id) {
         $revision = id(new DifferentialRevision())->load($revision_id);
         if ($revision) {
             queryfx($conn_w, 'INSERT IGNORE INTO %T (revisionID, commitPHID) VALUES (%d, %s)', DifferentialRevision::TABLE_COMMIT, $revision->getID(), $commit->getPHID());
             if ($revision->getStatus() != DifferentialRevisionStatus::COMMITTED) {
                 $message = null;
                 $committer = $data->getCommitDetail('authorPHID');
                 if (!$committer) {
                     $committer = $revision->getAuthorPHID();
                     $message = 'Change committed by ' . $data->getAuthorName() . '.';
                 }
                 $editor = new DifferentialCommentEditor($revision, $committer, DifferentialAction::ACTION_COMMIT);
                 $editor->setMessage($message)->save();
             }
         }
     }
 }
コード例 #27
0
 public function getDatasource()
 {
     $parameters = $this->getFieldConfigValue('datasource.parameters', array());
     $class = $this->getFieldConfigValue('datasource.class');
     $parent = 'PhabricatorTypeaheadDatasource';
     if (!is_subclass_of($class, $parent)) {
         throw new Exception(pht('Configured datasource class "%s" must be a valid subclass of ' . '"%s".', $class, $parent));
     }
     return newv($class, array())->setParameters($parameters);
 }
コード例 #28
0
 public static final function loadAllFormats()
 {
     $classes = id(new PhutilSymbolLoader())->setAncestorClass(__CLASS__)->setConcreteOnly(true)->selectAndLoadSymbols();
     $objects = array();
     foreach ($classes as $class) {
         $objects[$class['name']] = newv($class['name'], array());
     }
     $objects = msort($objects, 'getOrder');
     return $objects;
 }
コード例 #29
0
 public function getTypeIcon()
 {
     // Default to the application icon if the type doesn't specify one.
     $application_class = $this->getPHIDTypeApplicationClass();
     if ($application_class) {
         $application = newv($application_class, array());
         return $application->getFontIcon();
     }
     return null;
 }
 public function executeSend($body)
 {
     $key = PhabricatorEnv::getEnvConfig('amazon-ses.access-key');
     $secret = PhabricatorEnv::getEnvConfig('amazon-ses.secret-key');
     $root = phutil_get_library_root('phabricator');
     $root = dirname($root);
     require_once $root . '/externals/amazon-ses/ses.php';
     $service = newv('SimpleEmailService', array($key, $secret));
     return $service->sendRawEmail($body);
 }