private function renderRevisionAction(PhutilEvent $event)
 {
     if (!$this->canUseApplication($event->getUser())) {
         return null;
     }
     $revision = $event->getValue('object');
     $repository = $revision->getRepository();
     if ($repository === null) {
         return null;
     }
     if ($repository->canPerformAutomation()) {
         $revision_id = $revision->getID();
         $action = id(new PhabricatorActionView())->setWorkflow(true)->setName(pht('Land Revision'))->setIcon('fa-fighter-jet')->setHref("/differential/revision/operation/{$revision_id}/");
         $this->addActionMenuItems($event, $action);
     }
     $strategies = id(new PhutilClassMapQuery())->setAncestorClass('DifferentialLandingStrategy')->execute();
     foreach ($strategies as $strategy) {
         $viewer = $event->getUser();
         $action = $strategy->createMenuItem($viewer, $revision, $repository);
         if ($action == null) {
             continue;
         }
         if ($strategy->isActionDisabled($viewer, $revision, $repository)) {
             $action->setDisabled(true);
         }
         $this->addActionMenuItems($event, $action);
     }
 }
 public static function dispatchEvent(PhutilEvent $event)
 {
     $instance = self::getInstance();
     $listeners = idx($instance->listeners, $event->getType(), array());
     $global_listeners = idx($instance->listeners, PhutilEventType::TYPE_ALL, array());
     // Merge and deduplicate listeners (we want to send the event to each
     // listener only once, even if it satisfies multiple criteria for the
     // event).
     $listeners = array_merge($listeners, $global_listeners);
     $listeners = mpull($listeners, null, 'getListenerID');
     $profiler = PhutilServiceProfiler::getInstance();
     $profiler_id = $profiler->beginServiceCall(array('type' => 'event', 'kind' => $event->getType(), 'count' => count($listeners)));
     $caught = null;
     try {
         foreach ($listeners as $listener) {
             if ($event->isStopped()) {
                 // Do this first so if someone tries to dispatch a stopped event it
                 // doesn't go anywhere. Silly but less surprising.
                 break;
             }
             $listener->handleEvent($event);
         }
     } catch (Exception $ex) {
         $profiler->endServiceCall($profiler_id, array());
         throw $ex;
     }
     $profiler->endServiceCall($profiler_id, array());
 }
 public function handleEvent(PhutilEvent $event)
 {
     $task = $event->getValue('task');
     // discover DDN field from transactions
     $ddn = null;
     foreach ($event->getValue('transactions') as $transaction) {
         if ($transaction->getTransactionType() != PhabricatorTransactions::TYPE_CUSTOMFIELD) {
             continue;
         }
         $key = $transaction->getMetadataValue('aux:key');
         if ($key != 'disqus:ddn') {
             continue;
         }
         $ddn = (bool) $transaction->getNewValue();
     }
     if ($ddn === null) {
         return;
     }
     $title = $task->getTitle();
     $has_ddn = $this->titleHasPrefix($title);
     if ($ddn && !$has_ddn) {
         $title = '[DDN] ' . $title;
     } elseif (!$ddn && $has_ddn) {
         $title = substr($title, 6);
     }
     $task->setTitle($title);
 }
 public function handleEvent(PhutilEvent $event)
 {
     $corpus = $event->getValue('corpus');
     $generated = $event->getValue('is_generated');
     $generated |= strpos($corpus, 'Autogenerated by Thrift Compiler') !== false;
     $event->setValue('is_generated', $generated);
 }
 private function handleExitEvent(PhutilEvent $event)
 {
     $id = $event->getValue('id');
     $daemon = $this->getDaemon($id);
     $daemon->setStatus(PhabricatorDaemonLog::STATUS_EXITED)->save();
     unset($this->daemons[$id]);
 }
 public function handleEvent(PhutilEvent $event)
 {
     if ($event->getValue('unitResult') == ArcanistUnitWorkflow::RESULT_SKIP) {
         return;
     }
     $server = new FacebookBuildServer();
     $server->startProjectBuilds(true, $event->getValue('diffID'));
 }
 public function handleEvent(PhutilEvent $event)
 {
     switch ($event->getType()) {
         case PhabricatorEventType::TYPE_UI_WILLRENDERPROPERTIES:
             $this->handlePropertyEvent($event);
             break;
     }
 }
 public function handleEvent(PhutilEvent $event)
 {
     switch ($event->getType()) {
         case PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS:
             $this->handleActionEvent($event);
             break;
     }
 }
 public function handleEvent(PhutilEvent $event)
 {
     switch ($event->getType()) {
         case PhabricatorEventType::TYPE_UI_DIDRENDERHOVERCARD:
             $this->handleHovercardEvent($event);
             break;
     }
 }
 private function renderUserItems(PhutilEvent $event)
 {
     if (!$this->canUseApplication($event->getUser())) {
         return null;
     }
     $project = $event->getValue('object');
     $view_uri = '/burndown/view/' . $project->getId();
     return id(new PhabricatorActionView())->setIcon('fa-bar-chart-o')->setName(pht('View Burndown'))->setHref($view_uri);
 }
 public function handleEvent(PhutilEvent $event)
 {
     // When an event you have called listen() for in your register() method
     // occurs, this method will be invoked. You should respond to the event.
     // In this case, we just echo a message out so the event test script will
     // do something visible.
     $console = PhutilConsole::getConsole();
     $console->writeOut("PhabricatorExampleEventListener got test event at %d\n", $event->getValue('time'));
 }
 private function renderUserItems(PhutilEvent $event)
 {
     if (!$this->canUseApplication($event->getUser())) {
         return null;
     }
     $user = $event->getValue('object');
     $href = '/conpherence/new/?participant=' . $user->getPHID();
     return id(new PhabricatorActionView())->setIcon('fa-envelope')->setName(pht('Send Message'))->setWorkflow(true)->setHref($href);
 }
 private function renderUserItems(PhutilEvent $event)
 {
     if (!$this->canUseApplication($event->getUser())) {
         return null;
     }
     $user = $event->getValue('object');
     $phid = $user->getPHID();
     $view_uri = sprintf('/maniphest/?statuses=%s&assigned=%s#R', implode(',', ManiphestTaskStatus::getOpenStatusConstants()), $phid);
     return id(new PhabricatorActionView())->setIcon('fa-anchor')->setName(pht('View Tasks'))->setHref($view_uri);
 }
 private function renderUserItems(PhutilEvent $event)
 {
     if (!$this->canUseApplication($event->getUser())) {
         return null;
     }
     $user = $event->getValue('object');
     $username = phutil_escape_uri($user->getUsername());
     $view_uri = '/audit/?authors=' . $username;
     return id(new PhabricatorActionView())->setIcon('fa-check-circle-o')->setName(pht('View Commits'))->setHref($view_uri);
 }
 private function renderTaskItems(PhutilEvent $event)
 {
     if (!$this->canUseApplication($event->getUser())) {
         return;
     }
     $task = $event->getValue('object');
     $phid = $task->getPHID();
     $can_edit = PhabricatorPolicyFilter::hasCapability($event->getUser(), $task, PhabricatorPolicyCapability::CAN_EDIT);
     return id(new PhabricatorActionView())->setName(pht('Edit Pholio Mocks'))->setHref("/search/attach/{$phid}/MOCK/edge/")->setWorkflow(true)->setIcon('fa-camera-retro')->setDisabled(!$can_edit)->setWorkflow(true);
 }
 private function buildProjectActions(PhutilEvent $event)
 {
     if (!$this->canUseApplication($event->getUser())) {
         return null;
     }
     $project = $event->getValue('object');
     $slug = PhabricatorSlug::normalize($project->getPhrictionSlug());
     $href = '/w/projects/' . $slug;
     return id(new PhabricatorActionView())->setIcon('fa-book')->setName(pht('View Wiki'))->setHref($href);
 }
 public function handleEvent(PhutilEvent $event)
 {
     $phid = $event->getValue('phid');
     $type = phid_get_type($phid);
     // For now, we only index projects.
     if ($type != PhabricatorProjectProjectPHIDType::TYPECONST) {
         return;
     }
     $document = $event->getValue('document');
     ManiphestNameIndex::updateIndex($phid, $document->getDocumentTitle());
 }
 public function handleEvent(PhutilEvent $event)
 {
     // When an event you have called listen() for in your register() method
     // occurs, this method will be invoked. You should respond to the event.
     $user = $event->getValue('query');
     if (isset($this->aliases[$user])) {
         // We have a mapping for this user.
         $alias = $this->aliases[$user];
         $matching = id(new PhabricatorUser())->loadOneWhere('username=%s', $alias);
         if (!empty($matching)) {
             $event->setValue('result', $matching->getPHID());
         }
     }
 }
 private function renderOptionItems(PhutilEvent $event)
 {
     if (!$this->canUseApplication($event->getUser())) {
         return null;
     }
     $project = $event->getValue('object');
     $projectid = $project->getId();
     $phragile_uri = 'https://phragile.wmflabs.org/sprints/' . $projectid;
     $view_uri = '/project/sprint/view/' . $projectid;
     $board_uri = '/project/sprint/board/' . $projectid;
     $burndown = id(new PhabricatorActionView())->setIcon('fa-bar-chart-o')->setName(pht('View Burndown'))->setHref($view_uri);
     $board = id(new PhabricatorActionView())->setIcon('fa-columns')->setName(pht('View Sprint Board'))->setHref($board_uri);
     $phragile = id(new PhabricatorActionView())->setIcon('fa-pie-chart')->setName(pht('View in Phragile'))->setHref($phragile_uri);
     return array($burndown, $board, $phragile);
 }
 public function handleEvent(PhutilEvent $event)
 {
     $diff_id = $event->getValue('diffID');
     /* Need to send a get request to jenkins to trigger the job. We pass the
      * diff id to jenkins via its api.
      */
     $workflow = $event->getValue('workflow');
     $jenkins_uri = $workflow->getConfigFromAnySource('jenkins.uri');
     $jenkins_job = $workflow->getConfigFromAnySource('jenkins.job');
     if (!$jenkins_uri || !$jenkins_job) {
         return;
     }
     $url = $jenkins_uri . "/job/" . $jenkins_job . "/buildWithParameters?token=arcanist&DIFF_ID=" . $diff_id;
     file_get_contents($url);
 }
 public function handleEvent(PhutilEvent $event)
 {
     $mail = $event->getValue('mail');
     $subject = $mail->getSubject();
     $match = null;
     preg_match('/([[:alnum:]]+-[[:digit:]]+)\\s+\\[jira\\]/', $subject, $match);
     if (!$match) {
         // Not a JIRA mail, ignore it.
         return;
     }
     $jira_id = $match[1];
     $attachments = $mail->getAttachments();
     foreach ($attachments as $attachment) {
         $attachment->setFileName($jira_id . '.' . $attachment->getFileName());
     }
 }
 protected function addActionMenuItems(PhutilEvent $event, $items)
 {
     if ($event->getType() !== PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS) {
         throw new Exception(pht('Not an action menu event!'));
     }
     if (!$items) {
         return;
     }
     if (!is_array($items)) {
         $items = array($items);
     }
     $event_actions = $event->getValue('actions');
     foreach ($items as $item) {
         $event_actions[] = $item;
     }
     $event->setValue('actions', $event_actions);
 }
 public function handleEvent(PhutilEvent $event)
 {
     $diff_id = $event->getValue('diffID');
     /* Need to send a get request to jenkins to trigger the job. We pass the
      * diff id to jenkins via its api.
      */
     $workflow = $event->getValue('workflow');
     $jenkins_uri = $workflow->getConfigFromAnySource('jenkins.uri');
     $jenkins_job = $workflow->getConfigFromAnySource('jenkins.job');
     if (!$jenkins_uri || !$jenkins_job) {
         return;
     }
     $url = $jenkins_uri . "/job/" . $jenkins_job . "/buildWithParameters?token=" . $jenkins_job . "&DIFF_ID=" . $diff_id;
     $opts = array('http' => array('method' => 'POST'));
     $context = stream_context_create($opts);
     file_get_contents($url, false, $context);
 }
 public static function dispatchEvent(PhutilEvent $event)
 {
     $instance = self::getInstance();
     $listeners = idx($instance->listeners, $event->getType(), array());
     $global_listeners = idx($instance->listeners, PhutilEventType::TYPE_ALL, array());
     // Merge and deduplicate listeners (we want to send the event to each
     // listener only once, even if it satisfies multiple criteria for the
     // event).
     $listeners = array_merge($listeners, $global_listeners);
     $listeners = mpull($listeners, null, 'getListenerID');
     foreach ($listeners as $listener) {
         if ($event->isStopped()) {
             // Do this first so if someone tries to dispatch a stopped event it
             // doesn't go anywhere. Silly but less surprising.
             break;
         }
         $listener->handleEvent($event);
     }
 }
 private function renderRevisionAction(PhutilEvent $event)
 {
     if (!$this->canUseApplication($event->getUser())) {
         return null;
     }
     $revision = $event->getValue('object');
     $repository = $revision->getRepository();
     if ($repository === null) {
         return null;
     }
     $strategies = id(new PhutilSymbolLoader())->setAncestorClass('DifferentialLandingStrategy')->loadObjects();
     foreach ($strategies as $strategy) {
         $viewer = $event->getUser();
         $action = $strategy->createMenuItem($viewer, $revision, $repository);
         if ($action == null) {
             continue;
         }
         if ($strategy->isActionDisabled($viewer, $revision, $repository)) {
             $action->setDisabled(true);
         }
         $this->addActionMenuItems($event, $action);
     }
 }
 private function handleHovercardEvent(PhutilEvent $event)
 {
     $viewer = $event->getUser();
     $hovercard = $event->getValue('hovercard');
     $handle = $event->getValue('handle');
     $phid = $handle->getPHID();
     $task = $event->getValue('object');
     if (!$task instanceof ManiphestTask) {
         return;
     }
     // Fun with "Unbeta Pholio", hua hua
     $e_dep_on = PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK;
     $e_dep_by = PhabricatorEdgeConfig::TYPE_TASK_DEPENDED_ON_BY_TASK;
     $edge_query = id(new PhabricatorEdgeQuery())->withSourcePHIDs(array($phid))->withEdgeTypes(array($e_dep_on, $e_dep_by));
     $edges = idx($edge_query->execute(), $phid);
     $edge_phids = $edge_query->getDestinationPHIDs();
     $owner_phid = $task->getOwnerPHID();
     $project_phids = $task->getProjectPHIDs();
     $phids = array_filter(array_merge(array($owner_phid), $edge_phids, $project_phids));
     $viewer_handles = $this->loadHandles($phids, $viewer);
     $hovercard->setTitle(pht('T%d', $task->getID()))->setDetail($task->getTitle());
     $owner = phutil_tag('em', array(), pht('None'));
     if ($owner_phid) {
         $owner = $viewer_handles[$owner_phid]->renderLink();
     }
     $hovercard->addField(pht('Assigned to'), $owner);
     if ($project_phids) {
         $hovercard->addField(pht('Projects'), implode_selected_handle_links(', ', $viewer_handles, $project_phids));
     }
     if ($edge_phids) {
         $edge_types = array(PhabricatorEdgeConfig::TYPE_TASK_DEPENDED_ON_BY_TASK => pht('Dependent Tasks'), PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK => pht('Depends On'));
         $max_count = 6;
         foreach ($edge_types as $edge_type => $edge_name) {
             if ($edges[$edge_type]) {
                 // TODO: This can be made more sophisticated. We still load all
                 // edges into memory. Only load the ones we need.
                 $edge_overflow = array();
                 if (count($edges[$edge_type]) > $max_count) {
                     $edges[$edge_type] = array_slice($edges[$edge_type], 0, 6, true);
                     $edge_overflow = ', ...';
                 }
                 $hovercard->addField($edge_name, implode_selected_handle_links(', ', $viewer_handles, array_keys($edges[$edge_type]))->appendHTML($edge_overflow));
             }
         }
     }
     $hovercard->addTag(ManiphestView::renderTagForTask($task));
     $event->setValue('hovercard', $hovercard);
 }
 private function handleHovercardEvent(PhutilEvent $event)
 {
     $viewer = $event->getUser();
     $hovercard = $event->getValue('hovercard');
     $handle = $event->getValue('handle');
     $phid = $handle->getPHID();
     $task = $event->getValue('object');
     if (!$task instanceof ManiphestTask) {
         return;
     }
     $e_project = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
     // Fun with "Unbeta Pholio", hua hua
     $e_dep_on = ManiphestTaskDependsOnTaskEdgeType::EDGECONST;
     $e_dep_by = ManiphestTaskDependedOnByTaskEdgeType::EDGECONST;
     $edge_query = id(new PhabricatorEdgeQuery())->withSourcePHIDs(array($phid))->withEdgeTypes(array($e_project, $e_dep_on, $e_dep_by));
     $edges = idx($edge_query->execute(), $phid);
     $edge_phids = $edge_query->getDestinationPHIDs();
     $owner_phid = $task->getOwnerPHID();
     $hovercard->setTitle(pht('T%d', $task->getID()))->setDetail($task->getTitle());
     if ($owner_phid) {
         $owner = $viewer->renderHandle($owner_phid);
     } else {
         $owner = phutil_tag('em', array(), pht('None'));
     }
     $hovercard->addField(pht('Assigned To'), $owner);
     $hovercard->addField(pht('Priority'), ManiphestTaskPriority::getTaskPriorityName($task->getPriority()));
     if ($edge_phids) {
         $edge_types = array($e_project => pht('Projects'), $e_dep_by => pht('Blocks'), $e_dep_on => pht('Blocked By'));
         $max_count = 6;
         foreach ($edge_types as $edge_type => $edge_name) {
             if ($edges[$edge_type]) {
                 // TODO: This can be made more sophisticated. We still load all
                 // edges into memory. Only load the ones we need.
                 $edge_overflow = array();
                 if (count($edges[$edge_type]) > $max_count) {
                     $edges[$edge_type] = array_slice($edges[$edge_type], 0, 6, true);
                     $edge_overflow = ', ...';
                 }
                 $hovercard->addField($edge_name, array($viewer->renderHandleList(array_keys($edges[$edge_type])), $edge_overflow));
             }
         }
     }
     $hovercard->addTag(ManiphestView::renderTagForTask($task));
     $event->setValue('hovercard', $hovercard);
 }
 private function loadAllEdges(PhutilEvent $event)
 {
     $add_edges = $event->getValue('add');
     $rem_edges = $event->getValue('rem');
     $type_task = PhabricatorPHIDConstants::PHID_TYPE_TASK;
     $all_edges = array_merge($add_edges, $rem_edges);
     $all_edges = $this->filterEdgesBySourceType($all_edges, $type_task);
     if (!$all_edges) {
         return;
     }
     $all_tasks = array();
     $all_types = array();
     foreach ($all_edges as $edge) {
         $all_tasks[$edge['src']] = true;
         $all_types[$edge['type']] = true;
     }
     $all_tasks = array_keys($all_tasks);
     $all_types = array_keys($all_types);
     return id(new PhabricatorEdgeQuery())->withSourcePHIDs($all_tasks)->withEdgeTypes($all_types)->needEdgeData(true)->execute();
 }
Beispiel #29
0
 public function __construct($type, array $data = array())
 {
     parent::__construct($type, $data);
 }