public function getQuickMenuItems()
 {
     $viewer = $this->getViewer();
     $engines = PhabricatorEditEngine::getAllEditEngines();
     foreach ($engines as $key => $engine) {
         if (!$engine->hasQuickCreateActions()) {
             unset($engines[$key]);
         }
     }
     if (!$engines) {
         return array();
     }
     $engine_keys = array_keys($engines);
     $configs = id(new PhabricatorEditEngineConfigurationQuery())->setViewer($viewer)->withEngineKeys($engine_keys)->withIsDefault(true)->withIsDisabled(false)->execute();
     $configs = msort($configs, 'getCreateSortKey');
     $configs = mgroup($configs, 'getEngineKey');
     $items = array();
     foreach ($engines as $key => $engine) {
         $engine_configs = idx($configs, $key, array());
         $engine_items = $engine->newQuickCreateActions($engine_configs);
         foreach ($engine_items as $engine_item) {
             $items[] = $engine_item;
         }
     }
     return $items;
 }
 public function lookupRepository()
 {
     $viewer = $this->viewer;
     $diff = $this->diff;
     // Look for a repository UUID.
     if ($diff->getRepositoryUUID()) {
         $repositories = id(new PhabricatorRepositoryQuery())->setViewer($viewer)->withUUIDs(array($diff->getRepositoryUUID()))->execute();
         if ($repositories) {
             return head($repositories);
         }
     }
     // Look for the base commit in Git and Mercurial.
     $vcs = $diff->getSourceControlSystem();
     $vcs_git = PhabricatorRepositoryType::REPOSITORY_TYPE_GIT;
     $vcs_hg = PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL;
     if ($vcs == $vcs_git || $vcs == $vcs_hg) {
         $base = $diff->getSourceControlBaseRevision();
         if ($base) {
             $commits = id(new DiffusionCommitQuery())->setViewer($viewer)->withIdentifiers(array($base))->execute();
             $commits = mgroup($commits, 'getRepositoryID');
             if (count($commits) == 1) {
                 $repository_id = key($commits);
                 $repositories = id(new PhabricatorRepositoryQuery())->setViewer($viewer)->withIDs(array($repository_id))->execute();
                 if ($repositories) {
                     return head($repositories);
                 }
             }
         }
     }
     // TODO: Compare SVN remote URIs? Compare Git/Hg remote URIs? Add
     // an explicit option to `.arcconfig`?
     return null;
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $applications = PhabricatorApplication::getAllInstalledApplications();
     foreach ($applications as $key => $application) {
         if (!$application->shouldAppearInLaunchView()) {
             unset($applications[$key]);
         }
     }
     $groups = PhabricatorApplication::getApplicationGroups();
     $applications = msort($applications, 'getApplicationOrder');
     $applications = mgroup($applications, 'getApplicationGroup');
     $applications = array_select_keys($applications, array_keys($groups));
     $view = array();
     foreach ($applications as $group => $application_list) {
         $status = array();
         foreach ($application_list as $key => $application) {
             $status[$key] = $application->loadStatus($user);
         }
         $views = array();
         foreach ($application_list as $key => $application) {
             $views[] = id(new PhabricatorApplicationLaunchView())->setApplication($application)->setApplicationStatus(idx($status, $key, array()))->setUser($user);
         }
         $view[] = id(new PhabricatorHeaderView())->setHeader($groups[$group]);
         $view[] = phutil_render_tag('div', array('class' => 'phabricator-application-list'), id(new AphrontNullView())->appendChild($views)->render());
     }
     return $this->buildApplicationPage($view, array('title' => 'Applications', 'device' => true));
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $results = array();
     $revision_ids = $request->getValue('ids');
     if (!$revision_ids) {
         return $results;
     }
     $comments = id(new DifferentialComment())->loadAllWhere('revisionID IN (%Ld)', $revision_ids);
     $with_inlines = $request->getValue('inlines');
     if ($with_inlines) {
         $inlines = id(new DifferentialInlineComment())->loadAllWhere('revisionID IN (%Ld)', $revision_ids);
         $changesets = array();
         if ($inlines) {
             $changesets = id(new DifferentialChangeset())->loadAllWhere('id IN (%Ld)', array_unique(mpull($inlines, 'getChangesetID')));
             $inlines = mgroup($inlines, 'getCommentID');
         }
     }
     foreach ($comments as $comment) {
         $revision_id = $comment->getRevisionID();
         $result = array('revisionID' => $revision_id, 'action' => $comment->getAction(), 'authorPHID' => $comment->getAuthorPHID(), 'dateCreated' => $comment->getDateCreated(), 'content' => $comment->getContent());
         if ($with_inlines) {
             $result['inlines'] = array();
             foreach (idx($inlines, $comment->getID(), array()) as $inline) {
                 $changeset = idx($changesets, $inline->getChangesetID());
                 $result['inlines'][] = $this->buildInlineInfoDictionary($inline, $changeset);
             }
             // TODO: Put synthetic inlines without an attached comment somewhere.
         }
         $results[$revision_id][] = $result;
     }
     return $results;
 }
Example #5
0
 protected function didFilterPage(array $objects)
 {
     $has_properties = head($objects) instanceof AlmanacPropertyInterface;
     if ($has_properties && $this->needProperties) {
         $property_query = id(new AlmanacPropertyQuery())->setViewer($this->getViewer())->setParentQuery($this)->withObjects($objects);
         $properties = $property_query->execute();
         $properties = mgroup($properties, 'getObjectPHID');
         foreach ($objects as $object) {
             $object_properties = idx($properties, $object->getPHID(), array());
             $object_properties = mpull($object_properties, null, 'getFieldName');
             // Create synthetic properties for defaults on the object itself.
             $specs = $object->getAlmanacPropertyFieldSpecifications();
             foreach ($specs as $key => $spec) {
                 if (empty($object_properties[$key])) {
                     $object_properties[$key] = id(new AlmanacProperty())->setObjectPHID($object->getPHID())->setFieldName($key)->setFieldValue($spec->getValueForTransaction());
                 }
             }
             foreach ($object_properties as $property) {
                 $property->attachObject($object);
             }
             $object->attachAlmanacProperties($object_properties);
         }
     }
     return $objects;
 }
 public function processRequest()
 {
     $items = id(new PhabricatorDirectoryItem())->loadAll();
     $items = msort($items, 'getSortKey');
     $categories = id(new PhabricatorDirectoryCategory())->loadAll();
     $categories = msort($categories, 'getSequence');
     $category_map = mpull($categories, 'getName', 'getID');
     $category_map[0] = 'Free Radicals';
     $items = mgroup($items, 'getCategoryID');
     require_celerity_resource('phabricator-directory-css');
     $content = array();
     foreach ($category_map as $id => $category_name) {
         $category_items = idx($items, $id);
         if (!$category_items) {
             continue;
         }
         $item_markup = array();
         foreach ($category_items as $item) {
             $item_markup[] = '<div>' . '<h2>' . phutil_render_tag('a', array('href' => $item->getHref()), phutil_escape_html($item->getName())) . '</h2>' . '<p>' . phutil_escape_html($item->getDescription()) . '</p>' . '</div>';
         }
         $content[] = '<div class="aphront-directory-category">' . '<h1>' . phutil_escape_html($category_name) . '</h1>' . '<div class="aphront-directory-group">' . implode("\n", $item_markup) . '</div>' . '</div>';
     }
     $content = '<div class="aphront-directory-list">' . implode("\n", $content) . '</div>';
     return $this->buildStandardPageResponse($content, array('title' => 'Directory', 'tab' => 'directory'));
 }
 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;
 }
 public static function loadAllForProjectPHIDs($phids)
 {
     if (!$phids) {
         return array();
     }
     $default = array_fill_keys($phids, array());
     $affiliations = id(new PhabricatorProjectAffiliation())->loadAllWhere('projectPHID IN (%Ls) ORDER BY IF(status = "former", 1, 0), dateCreated', $phids);
     return mgroup($affiliations, 'getProjectPHID') + $default;
 }
 public static final function getAllPanelGroupsWithPanels()
 {
     $groups = self::getAllPanelGroups();
     $panels = PhabricatorSettingsPanel::getAllPanels();
     $panels = mgroup($panels, 'getPanelGroupKey');
     foreach ($groups as $key => $group) {
         $group->panels = idx($panels, $key, array());
     }
     return $groups;
 }
 public function save()
 {
     if (!$this->comment) {
         throw new Exception("Must set comment before saving it");
     }
     if (!$this->question) {
         throw new Exception("Must set question before saving comment");
     }
     if (!$this->targetPHID) {
         throw new Exception("Must set target before saving comment");
     }
     if (!$this->viewer) {
         throw new Exception("Must set viewer before saving comment");
     }
     $comment = $this->comment;
     $question = $this->question;
     $target = $this->targetPHID;
     $viewer = $this->viewer;
     $comment->save();
     $question->attachRelated();
     PhabricatorSearchPonderIndexer::indexQuestion($question);
     // subscribe author and @mentions
     $subeditor = id(new PhabricatorSubscriptionsEditor())->setObject($question)->setUser($viewer);
     $subeditor->subscribeExplicit(array($comment->getAuthorPHID()));
     $content = $comment->getContent();
     $at_mention_phids = PhabricatorMarkupEngine::extractPHIDsFromMentions(array($content));
     $subeditor->subscribeImplicit($at_mention_phids);
     $subeditor->save();
     if ($this->shouldEmail) {
         // now load subscribers, including implicitly-added @mention victims
         $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID($question->getPHID());
         // @mention emails (but not for anyone who has explicitly unsubscribed)
         if (array_intersect($at_mention_phids, $subscribers)) {
             id(new PonderMentionMail($question, $comment, $viewer))->setToPHIDs($at_mention_phids)->send();
         }
         if ($target === $question->getPHID()) {
             $target = $question;
         } else {
             $answers_by_phid = mgroup($question->getAnswers(), 'getPHID');
             $target = head($answers_by_phid[$target]);
         }
         // only send emails to others in the same thread
         $thread = mpull($target->getComments(), 'getAuthorPHID');
         $thread[] = $target->getAuthorPHID();
         $thread[] = $question->getAuthorPHID();
         $other_subs = array_diff(array_intersect($thread, $subscribers), $at_mention_phids);
         // 'Comment' emails for subscribers who are in the same comment thread,
         // including the author of the parent question and/or answer, excluding
         // @mentions (and excluding the author, depending on their MetaMTA
         // settings).
         if ($other_subs) {
             id(new PonderCommentMail($question, $comment, $viewer))->setToPHIDs($other_subs)->send();
         }
     }
 }
 /**
  * Publishes stories into JIRA using the JIRA API.
  */
 protected function publishFeedStory()
 {
     $story = $this->getFeedStory();
     $viewer = $this->getViewer();
     $provider = $this->getProvider();
     $object = $this->getStoryObject();
     $publisher = $this->getPublisher();
     $jira_issue_phids = PhabricatorEdgeQuery::loadDestinationPHIDs($object->getPHID(), PhabricatorJiraIssueHasObjectEdgeType::EDGECONST);
     if (!$jira_issue_phids) {
         $this->log("%s\n", pht('Story is about an object with no linked JIRA issues.'));
         return;
     }
     $do_anything = $this->shouldPostComment() || $this->shouldPostLink();
     if (!$do_anything) {
         $this->log("%s\n", pht('JIRA integration is configured not to post anything.'));
         return;
     }
     $xobjs = id(new DoorkeeperExternalObjectQuery())->setViewer($viewer)->withPHIDs($jira_issue_phids)->execute();
     if (!$xobjs) {
         $this->log("%s\n", pht('Story object has no corresponding external JIRA objects.'));
         return;
     }
     $try_users = $this->findUsersToPossess();
     if (!$try_users) {
         $this->log("%s\n", pht('No users to act on linked JIRA objects.'));
         return;
     }
     $xobjs = mgroup($xobjs, 'getApplicationDomain');
     foreach ($xobjs as $domain => $xobj_list) {
         $accounts = id(new PhabricatorExternalAccountQuery())->setViewer($viewer)->withUserPHIDs($try_users)->withAccountTypes(array($provider->getProviderType()))->withAccountDomains(array($domain))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->execute();
         // Reorder accounts in the original order.
         // TODO: This needs to be adjusted if/when we allow you to link multiple
         // accounts.
         $accounts = mpull($accounts, null, 'getUserPHID');
         $accounts = array_select_keys($accounts, $try_users);
         foreach ($xobj_list as $xobj) {
             foreach ($accounts as $account) {
                 try {
                     $jira_key = $xobj->getObjectID();
                     if ($this->shouldPostComment()) {
                         $this->postComment($account, $jira_key);
                     }
                     if ($this->shouldPostLink()) {
                         $this->postLink($account, $jira_key);
                     }
                     break;
                 } catch (HTTPFutureResponseStatus $ex) {
                     phlog($ex);
                     $this->log("%s\n", pht('Failed to update object %s using user %s.', $xobj->getObjectID(), $account->getUserPHID()));
                 }
             }
         }
     }
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $book_name = $request->getURIData('book');
     $book = id(new DivinerBookQuery())->setViewer($viewer)->withNames(array($book_name))->needRepositories(true)->executeOne();
     if (!$book) {
         return new Aphront404Response();
     }
     $actions = $this->buildActionView($viewer, $book);
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->setBorder(true);
     $crumbs->addTextCrumb($book->getShortTitle(), '/book/' . $book->getName() . '/');
     $action_button = id(new PHUIButtonView())->setTag('a')->setText(pht('Actions'))->setHref('#')->setIconFont('fa-bars')->addClass('phui-mobile-menu')->setDropdownMenu($actions);
     $header = id(new PHUIHeaderView())->setHeader($book->getTitle())->setUser($viewer)->setPolicyObject($book)->setEpoch($book->getDateModified())->addActionLink($action_button);
     // TODO: This could probably look better.
     if ($book->getRepositoryPHID()) {
         $header->addTag(id(new PHUITagView())->setType(PHUITagView::TYPE_STATE)->setBackgroundColor(PHUITagView::COLOR_BLUE)->setName($book->getRepository()->getMonogram()));
     }
     $document = new PHUIDocumentView();
     $document->setHeader($header);
     $document->addClass('diviner-view');
     $document->setFontKit(PHUIDocumentView::FONT_SOURCE_SANS);
     $atoms = id(new DivinerAtomQuery())->setViewer($viewer)->withBookPHIDs(array($book->getPHID()))->withGhosts(false)->withIsDocumentable(true)->execute();
     $atoms = msort($atoms, 'getSortKey');
     $group_spec = $book->getConfig('groups');
     if (!is_array($group_spec)) {
         $group_spec = array();
     }
     $groups = mgroup($atoms, 'getGroupName');
     $groups = array_select_keys($groups, array_keys($group_spec)) + $groups;
     if (isset($groups[''])) {
         $no_group = $groups[''];
         unset($groups['']);
         $groups[''] = $no_group;
     }
     $out = array();
     foreach ($groups as $group => $atoms) {
         $group_name = $book->getGroupName($group);
         if (!strlen($group_name)) {
             $group_name = pht('Free Radicals');
         }
         $section = id(new DivinerSectionView())->setHeader($group_name);
         $section->addContent($this->renderAtomList($atoms));
         $out[] = $section;
     }
     $preface = $book->getPreface();
     $preface_view = null;
     if (strlen($preface)) {
         $preface_view = PhabricatorMarkupEngine::renderOneObject(id(new PhabricatorMarkupOneOff())->setContent($preface), 'default', $viewer);
     }
     $document->appendChild($preface_view);
     $document->appendChild($out);
     return $this->buildApplicationPage(array($crumbs, $document), array('title' => $book->getTitle()));
 }
 protected function didFilterPage(array $hunks)
 {
     if ($this->shouldAttachToChangesets) {
         $hunk_groups = mgroup($hunks, 'getChangesetID');
         foreach ($this->changesets as $changeset) {
             $hunks = idx($hunk_groups, $changeset->getID(), array());
             $changeset->attachHunks($hunks);
         }
     }
     return $hunks;
 }
 private function handlePropertyEvent($ui_event)
 {
     $user = $ui_event->getUser();
     $object = $ui_event->getValue('object');
     if (!$object || !$object->getPHID()) {
         // No object, or the object has no PHID yet..
         return;
     }
     if (!$object instanceof PhrequentTrackableInterface) {
         // This object isn't a time trackable object.
         return;
     }
     if (!$this->canUseApplication($ui_event->getUser())) {
         return;
     }
     $events = id(new PhrequentUserTimeQuery())->setViewer($user)->withObjectPHIDs(array($object->getPHID()))->needPreemptingEvents(true)->execute();
     $event_groups = mgroup($events, 'getUserPHID');
     if (!$events) {
         return;
     }
     $handles = id(new PhabricatorHandleQuery())->setViewer($user)->withPHIDs(array_keys($event_groups))->execute();
     $status_view = new PHUIStatusListView();
     foreach ($event_groups as $user_phid => $event_group) {
         $item = new PHUIStatusItemView();
         $item->setTarget($handles[$user_phid]->renderLink());
         $state = 'stopped';
         foreach ($event_group as $event) {
             if ($event->getDateEnded() === null) {
                 if ($event->isPreempted()) {
                     $state = 'suspended';
                 } else {
                     $state = 'active';
                     break;
                 }
             }
         }
         switch ($state) {
             case 'active':
                 $item->setIcon(PHUIStatusItemView::ICON_CLOCK, 'green', pht('Working Now'));
                 break;
             case 'suspended':
                 $item->setIcon(PHUIStatusItemView::ICON_CLOCK, 'yellow', pht('Interrupted'));
                 break;
             case 'stopped':
                 $item->setIcon(PHUIStatusItemView::ICON_CLOCK, 'bluegrey', pht('Not Working Now'));
                 break;
         }
         $block = new PhrequentTimeBlock($event_group);
         $item->setNote(phutil_format_relative_time($block->getTimeSpentOnObject($object->getPHID(), time())));
         $status_view->addItem($item);
     }
     $view = $ui_event->getValue('view');
     $view->addProperty(pht('Time Spent'), $status_view);
 }
Example #15
0
 protected function didFilterPage(array $carts)
 {
     if ($this->needPurchases) {
         $purchases = id(new PhortunePurchaseQuery())->setViewer($this->getViewer())->setParentQuery($this)->withCartPHIDs(mpull($carts, 'getPHID'))->execute();
         $purchases = mgroup($purchases, 'getCartPHID');
         foreach ($carts as $cart) {
             $cart->attachPurchases(idx($purchases, $cart->getPHID(), array()));
         }
     }
     return $carts;
 }
Example #16
0
 protected function didFilterPage(array $leases)
 {
     if ($this->needUnconsumedCommands) {
         $commands = id(new DrydockCommandQuery())->setViewer($this->getViewer())->setParentQuery($this)->withTargetPHIDs(mpull($leases, 'getPHID'))->withConsumed(false)->execute();
         $commands = mgroup($commands, 'getTargetPHID');
         foreach ($leases as $lease) {
             $list = idx($commands, $lease->getPHID(), array());
             $lease->attachUnconsumedCommands($list);
         }
     }
     return $leases;
 }
 public function render()
 {
     require_celerity_resource('conpherence-menu-css');
     $menu = id(new PHUIListView())->addClass('conpherence-menu')->setID('conpherence-menu');
     $policy_objects = ConpherenceThread::loadPolicyObjects($this->getUser(), $this->threads);
     $grouped = mgroup($this->threads, 'getIsRoom');
     $rooms = idx($grouped, 1, array());
     $this->addRoomsToMenu($menu, $rooms, $policy_objects);
     $messages = idx($grouped, 0, array());
     $this->addMessagesToMenu($menu, $messages);
     return $menu;
 }
 public function render()
 {
     require_celerity_resource('harbormaster-css');
     $messages = $this->unitMessages;
     $messages = msort($messages, 'getSortKey');
     $limit = $this->limit;
     if ($this->limit) {
         $display_messages = array_slice($messages, 0, $limit);
     } else {
         $display_messages = $messages;
     }
     $rows = array();
     $any_duration = false;
     foreach ($display_messages as $message) {
         $status = $message->getResult();
         $icon_icon = HarbormasterUnitStatus::getUnitStatusIcon($status);
         $icon_color = HarbormasterUnitStatus::getUnitStatusColor($status);
         $icon_label = HarbormasterUnitStatus::getUnitStatusLabel($status);
         $result_icon = id(new PHUIIconView())->setIcon("{$icon_icon} {$icon_color}")->addSigil('has-tooltip')->setMetadata(array('tip' => $icon_label));
         $duration = $message->getDuration();
         if ($duration !== null) {
             $any_duration = true;
             $duration = pht('%s ms', new PhutilNumber((int) (1000 * $duration)));
         }
         $name = $message->getUnitMessageDisplayName();
         $id = $message->getID();
         if ($id) {
             $name = phutil_tag('a', array('href' => "/harbormaster/unit/view/{$id}/"), $name);
         }
         $details = $message->getUnitMessageDetails();
         if (strlen($details)) {
             $name = array($name, $this->renderUnitTestDetails($details));
         }
         $rows[] = array($result_icon, $duration, $name);
     }
     $full_uri = $this->fullResultsURI;
     if ($full_uri && count($messages) > $limit) {
         $counts = array();
         $groups = mgroup($messages, 'getResult');
         foreach ($groups as $status => $group) {
             $counts[] = HarbormasterUnitStatus::getUnitStatusCountLabel($status, count($group));
         }
         $link_text = pht('View Full Test Results (%s)', implode(" Β· ", $counts));
         $full_link = phutil_tag('a', array('href' => $full_uri), $link_text);
         $link_icon = id(new PHUIIconView())->setIcon('fa-ellipsis-h lightgreytext');
         $rows[] = array($link_icon, null, $full_link);
     }
     $table = id(new AphrontTableView($rows))->setHeaders(array(null, pht('Time'), pht('Test')))->setColumnClasses(array('top center', 'top right', 'top wide'))->setColumnWidths(array('32px', '64px'))->setColumnVisibility(array(true, $any_duration));
     if ($this->notice) {
         $table->setNotice($this->notice);
     }
     return $table;
 }
 protected function didFilterPage(array $badges)
 {
     if ($this->needRecipients) {
         $query = id(new PhabricatorBadgesAwardQuery())->setViewer($this->getViewer())->withBadgePHIDs(mpull($badges, 'getPHID'))->execute();
         $awards = mgroup($query, 'getBadgePHID');
         foreach ($badges as $badge) {
             $badge_awards = idx($awards, $badge->getPHID(), array());
             $badge->attachAwards($badge_awards);
         }
     }
     return $badges;
 }
 protected function loadHarbormasterData(array $diffs)
 {
     $viewer = $this->getViewer();
     $diffs = mpull($diffs, null, 'getPHID');
     $buildables = id(new HarbormasterBuildableQuery())->setViewer($viewer)->withBuildablePHIDs(array_keys($diffs))->withManualBuildables(false)->needBuilds(true)->needTargets(true)->execute();
     $buildables = mpull($buildables, null, 'getBuildablePHID');
     foreach ($diffs as $phid => $diff) {
         $diff->attachBuildable(idx($buildables, $phid));
     }
     $target_map = array();
     foreach ($diffs as $phid => $diff) {
         $target_map[$phid] = $diff->getBuildTargetPHIDs();
     }
     $all_target_phids = array_mergev($target_map);
     if ($all_target_phids) {
         $unit_messages = id(new HarbormasterBuildUnitMessage())->loadAllWhere('buildTargetPHID IN (%Ls)', $all_target_phids);
         $unit_messages = mgroup($unit_messages, 'getBuildTargetPHID');
     } else {
         $unit_messages = array();
     }
     foreach ($diffs as $phid => $diff) {
         $target_phids = idx($target_map, $phid, array());
         $messages = array_select_keys($unit_messages, $target_phids);
         $messages = array_mergev($messages);
         $diff->attachUnitMessages($messages);
     }
     // For diffs with no messages, look for legacy unit messages stored on the
     // diff itself.
     foreach ($diffs as $phid => $diff) {
         if ($diff->getUnitMessages()) {
             continue;
         }
         if (!$diff->hasDiffProperty('arc:unit')) {
             continue;
         }
         $legacy_messages = $diff->getProperty('arc:unit');
         if (!$legacy_messages) {
             continue;
         }
         // Show the top 100 legacy lint messages. Previously, we showed some
         // by default and let the user toggle the rest. With modern messages,
         // we can send the user to the Harbormaster detail page. Just show
         // "a lot" of messages in legacy cases to try to strike a balance
         // between implementation simplicitly and compatibility.
         $legacy_messages = array_slice($legacy_messages, 0, 100);
         $messages = array();
         foreach ($legacy_messages as $message) {
             $messages[] = HarbormasterBuildUnitMessage::newFromDictionary(new HarbormasterBuildTarget(), $this->getModernUnitMessageDictionary($message));
         }
         $diff->attachUnitMessages($messages);
     }
 }
 public function render()
 {
     $inline_comments = mgroup($this->inlineComments, 'getAuditCommentID');
     $num = 1;
     $comments = array();
     foreach ($this->comments as $comment) {
         $inlines = idx($inline_comments, $comment->getID(), array());
         $view = id(new DiffusionCommentView())->setComment($comment)->setInlineComments($inlines)->setCommentNumber($num)->setHandles($this->handles)->setPathMap($this->pathMap)->setUser($this->user);
         $comments[] = $view->render();
         ++$num;
     }
     return '<div class="diffusion-comment-list">' . $this->renderSingleView($comments) . '</div>';
 }
 protected function didFilterPage(array $events)
 {
     $phids = mpull($events, 'getPHID');
     if ($this->needLogs) {
         $logs = id(new PhabricatorRepositoryPushLogQuery())->setParentQuery($this)->setViewer($this->getViewer())->withPushEventPHIDs($phids)->execute();
         $logs = mgroup($logs, 'getPushEventPHID');
         foreach ($events as $key => $event) {
             $event_logs = idx($logs, $event->getPHID(), array());
             $event->attachLogs($event_logs);
         }
     }
     return $events;
 }
 protected function didFilterPage(array $diffs)
 {
     if ($this->needProperties) {
         $properties = id(new DifferentialDiffProperty())->loadAllWhere('diffID IN (%Ld)', mpull($diffs, 'getID'));
         $properties = mgroup($properties, 'getDiffID');
         foreach ($diffs as $diff) {
             $map = idx($properties, $diff->getID(), array());
             $map = mpull($map, 'getData', 'getName');
             $diff->attachDiffProperties($map);
         }
     }
     return $diffs;
 }
 protected function didFilterPage(array $page)
 {
     if ($this->needBuildSteps) {
         $plan_phids = mpull($page, 'getPHID');
         $steps = id(new HarbormasterBuildStepQuery())->setParentQuery($this)->setViewer($this->getViewer())->withBuildPlanPHIDs($plan_phids)->execute();
         $steps = mgroup($steps, 'getBuildPlanPHID');
         foreach ($page as $plan) {
             $plan_steps = idx($steps, $plan->getPHID(), array());
             $plan->attachBuildSteps($plan_steps);
         }
     }
     return $page;
 }
 /**
  * @param string $date
  */
 public function execute($tasks, $recently_closed, $date)
 {
     $result = mgroup($tasks, 'getOwnerPHID');
     $leftover = idx($result, '', array());
     unset($result['']);
     $result_closed = mgroup($recently_closed, 'getOwnerPHID');
     $leftover_closed = idx($result_closed, '', array());
     unset($result_closed['']);
     $base_link = '/maniphest/?assigned=';
     $leftover_name = phutil_tag('em', array(), pht('(Up For Grabs)'));
     $col_header = pht('User');
     $header = pht('Open Tasks by User and Priority (%s)', $date);
     return array($leftover, $leftover_closed, $base_link, $leftover_name, $col_header, $header, $result_closed, $result);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $book = id(new DivinerBookQuery())->setViewer($viewer)->withNames(array($this->bookName))->executeOne();
     if (!$book) {
         return new Aphront404Response();
     }
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb($book->getShortTitle(), '/book/' . $book->getName() . '/');
     $header = id(new PHUIHeaderView())->setHeader($book->getTitle())->setUser($viewer)->setPolicyObject($book);
     $document = new PHUIDocumentView();
     $document->setHeader($header);
     $document->addClass('diviner-view');
     $document->setFontKit(PHUIDocumentView::FONT_SOURCE_SANS);
     $properties = $this->buildPropertyList($book);
     $atoms = id(new DivinerAtomQuery())->setViewer($viewer)->withBookPHIDs(array($book->getPHID()))->execute();
     $atoms = msort($atoms, 'getSortKey');
     $group_spec = $book->getConfig('groups');
     if (!is_array($group_spec)) {
         $group_spec = array();
     }
     $groups = mgroup($atoms, 'getGroupName');
     $groups = array_select_keys($groups, array_keys($group_spec)) + $groups;
     if (isset($groups[''])) {
         $no_group = $groups[''];
         unset($groups['']);
         $groups[''] = $no_group;
     }
     $out = array();
     foreach ($groups as $group => $atoms) {
         $group_name = $book->getGroupName($group);
         if (!strlen($group_name)) {
             $group_name = pht('Free Radicals');
         }
         $section = id(new DivinerSectionView())->setHeader($group_name);
         $section->addContent($this->renderAtomList($atoms));
         $out[] = $section;
     }
     $preface = $book->getPreface();
     $preface_view = null;
     if (strlen($preface)) {
         $preface_view = PhabricatorMarkupEngine::renderOneObject(id(new PhabricatorMarkupOneOff())->setContent($preface), 'default', $viewer);
     }
     $document->appendChild($properties);
     $document->appendChild($preface_view);
     $document->appendChild($out);
     return $this->buildApplicationPage(array($crumbs, $document), array('title' => $book->getTitle()));
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $plan = id(new HarbormasterBuildPlanQuery())->setViewer($viewer)->withIDs(array($request->getURIData('id')))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$plan) {
         return new Aphront404Response();
     }
     $plan_id = $plan->getID();
     $cancel_uri = $this->getApplicationURI("plan/{$plan_id}/");
     $plan_title = pht('Plan %d', $plan_id);
     $all = HarbormasterBuildStepImplementation::getImplementations();
     $all = msort($all, 'getName');
     $all_groups = HarbormasterBuildStepGroup::getAllGroups();
     foreach ($all as $impl) {
         $group_key = $impl->getBuildStepGroupKey();
         if (empty($all_groups[$group_key])) {
             throw new Exception(pht('Build step "%s" has step group key "%s", but no step group ' . 'with that key exists.', get_class($impl), $group_key));
         }
     }
     $groups = mgroup($all, 'getBuildStepGroupKey');
     $boxes = array();
     $enabled_groups = HarbormasterBuildStepGroup::getAllEnabledGroups();
     foreach ($enabled_groups as $group) {
         $list = id(new PHUIObjectItemListView())->setNoDataString(pht('This group has no available build steps.'));
         $steps = idx($groups, $group->getGroupKey(), array());
         foreach ($steps as $key => $impl) {
             if ($impl->shouldRequireAutotargeting()) {
                 unset($steps[$key]);
                 continue;
             }
         }
         if (!$steps && !$group->shouldShowIfEmpty()) {
             continue;
         }
         foreach ($steps as $key => $impl) {
             $class = get_class($impl);
             $new_uri = $this->getApplicationURI("step/new/{$plan_id}/{$class}/");
             $item = id(new PHUIObjectItemView())->setHeader($impl->getName())->setHref($new_uri)->addAttribute($impl->getGenericDescription());
             $list->addItem($item);
         }
         $box = id(new PHUIObjectBoxView())->setHeaderText($group->getGroupName())->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->appendChild($list);
         $boxes[] = $box;
     }
     $crumbs = $this->buildApplicationCrumbs()->addTextCrumb($plan_title, $cancel_uri)->addTextCrumb(pht('Add Build Step'))->setBorder(true);
     $title = array($plan_title, pht('Add Build Step'));
     $header = id(new PHUIHeaderView())->setHeader(pht('Add Build Step'))->setHeaderIcon('fa-plus-square');
     $view = id(new PHUITwoColumnView())->setHeader($header)->setFooter(array($boxes));
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view);
 }
 protected function buildTaskInfoDictionaries(array $tasks)
 {
     if (!$tasks) {
         return array();
     }
     $all_aux = id(new ManiphestTaskAuxiliaryStorage())->loadAllWhere('taskPHID in (%Ls)', mpull($tasks, 'getPHID'));
     $all_aux = mgroup($all_aux, 'getTaskPHID');
     $result = array();
     foreach ($tasks as $task) {
         $auxiliary = idx($all_aux, $task->getPHID(), array());
         $auxiliary = mpull($auxiliary, 'getValue', 'getName');
         $result[$task->getPHID()] = array('id' => $task->getID(), 'phid' => $task->getPHID(), 'authorPHID' => $task->getAuthorPHID(), 'ownerPHID' => $task->getOwnerPHID(), 'ccPHIDs' => $task->getCCPHIDs(), 'status' => $task->getStatus(), 'priority' => ManiphestTaskPriority::getTaskPriorityName($task->getPriority()), 'title' => $task->getTitle(), 'description' => $task->getDescription(), 'projectPHIDs' => $task->getProjectPHIDs(), 'uri' => PhabricatorEnv::getProductionURI('/T' . $task->getID()), 'auxiliary' => $auxiliary, 'objectName' => 'T' . $task->getID(), 'dateCreated' => $task->getDateCreated(), 'dateModified' => $task->getDateModified());
     }
     return $result;
 }
 protected function didFilterPage(array $packages)
 {
     if ($this->needPaths) {
         $package_ids = mpull($packages, 'getID');
         $paths = id(new PhabricatorOwnersPath())->loadAllWhere('packageID IN (%Ld)', $package_ids);
         $paths = mgroup($paths, 'getPackageID');
         foreach ($packages as $package) {
             $package->attachPaths(idx($paths, $package->getID(), array()));
         }
     }
     if ($this->controlMap) {
         $this->controlResults += mpull($packages, null, 'getID');
     }
     return $packages;
 }
 public function renderAtomIndex(array $refs)
 {
     $refs = msort($refs, 'getSortKey');
     $groups = mgroup($refs, 'getGroup');
     $out = array();
     foreach ($groups as $group_key => $refs) {
         $out[] = phutil_tag('h1', array('class' => 'atom-group-name'), $this->getGroupName($group_key));
         $items = array();
         foreach ($refs as $ref) {
             $items[] = phutil_tag('li', array('class' => 'atom-index-item'), array($this->renderAtomRefLink($ref), ' - ', $ref->getSummary()));
         }
         $out[] = phutil_tag('ul', array('class' => 'atom-index-list'), $items);
     }
     return phutil_tag('div', array('class' => 'atom-index'), $out);
 }