public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $is_all = $args->getArg('all');
     $is_type = $args->getArg('type');
     $is_force = $args->getArg('force');
     $obj_names = $args->getArg('objects');
     if ($obj_names && ($is_all || $is_type)) {
         throw new PhutilArgumentUsageException(pht("You can not name objects to index alongside the '%s' or '%s' flags.", '--all', '--type'));
     } else {
         if (!$obj_names && !($is_all || $is_type)) {
             throw new PhutilArgumentUsageException(pht("Provide one of '%s', '%s' or a list of object names.", '--all', '--type'));
         }
     }
     if ($obj_names) {
         $phids = $this->loadPHIDsByNames($obj_names);
     } else {
         $phids = $this->loadPHIDsByTypes($is_type);
     }
     if (!$phids) {
         throw new PhutilArgumentUsageException(pht('Nothing to index!'));
     }
     if ($args->getArg('background')) {
         $is_background = true;
     } else {
         PhabricatorWorker::setRunAllTasksInProcess(true);
         $is_background = false;
     }
     if (!$is_background) {
         $console->writeOut("%s\n", pht('Run this workflow with "%s" to queue tasks for the daemon workers.', '--background'));
     }
     $groups = phid_group_by_type($phids);
     foreach ($groups as $group_type => $group) {
         $console->writeOut("%s\n", pht('Indexing %d object(s) of type %s.', count($group), $group_type));
     }
     $bar = id(new PhutilConsoleProgressBar())->setTotal(count($phids));
     $parameters = array('force' => $is_force);
     $any_success = false;
     foreach ($phids as $phid) {
         try {
             PhabricatorSearchWorker::queueDocumentForIndexing($phid, $parameters);
             $any_success = true;
         } catch (Exception $ex) {
             phlog($ex);
         }
         $bar->update(1);
     }
     $bar->done();
     if (!$any_success) {
         throw new Exception(pht('Failed to rebuild search index for any documents.'));
     }
 }
コード例 #2
0
 public static function loadAffiliatedUserPHIDs(array $package_ids)
 {
     if (!$package_ids) {
         return array();
     }
     $owners = id(new PhabricatorOwnersOwner())->loadAllWhere('packageID IN (%Ls)', $package_ids);
     $all_phids = phid_group_by_type(mpull($owners, 'getUserPHID'));
     $user_phids = idx($all_phids, PhabricatorPHIDConstants::PHID_TYPE_USER, array());
     $users_in_project_phids = array();
     if (idx($all_phids, PhabricatorPHIDConstants::PHID_TYPE_PROJ)) {
         $users_in_project_phids = mpull(id(new PhabricatorProjectAffiliation())->loadAllWhere('projectPHID IN (%Ls)', idx($all_phids, PhabricatorPHIDConstants::PHID_TYPE_PROJ, array())), 'getUserPHID');
     }
     return array_unique(array_merge($users_in_project_phids, $user_phids));
 }
コード例 #3
0
 public static function loadAffiliatedUserPHIDs(array $package_ids)
 {
     if (!$package_ids) {
         return array();
     }
     $owners = id(new PhabricatorOwnersOwner())->loadAllWhere('packageID IN (%Ls)', $package_ids);
     $all_phids = phid_group_by_type(mpull($owners, 'getUserPHID'));
     $user_phids = idx($all_phids, PhabricatorPeopleUserPHIDType::TYPECONST, array());
     $users_in_project_phids = array();
     $project_phids = idx($all_phids, PhabricatorProjectProjectPHIDType::TYPECONST);
     if ($project_phids) {
         $query = id(new PhabricatorEdgeQuery())->withSourcePHIDs($project_phids)->withEdgeTypes(array(PhabricatorProjectProjectHasMemberEdgeType::EDGECONST));
         $query->execute();
         $users_in_project_phids = $query->getDestinationPHIDs();
     }
     return array_unique(array_merge($users_in_project_phids, $user_phids));
 }
コード例 #4
0
 public static function loadAffiliatedUserPHIDs(array $package_ids)
 {
     if (!$package_ids) {
         return array();
     }
     $owners = id(new PhabricatorOwnersOwner())->loadAllWhere('packageID IN (%Ls)', $package_ids);
     $all_phids = phid_group_by_type(mpull($owners, 'getUserPHID'));
     $user_phids = idx($all_phids, PhabricatorPeopleUserPHIDType::TYPECONST, array());
     if ($user_phids) {
         $projects = id(new PhabricatorProjectQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withMemberPHIDs($user_phids)->withIsMilestone(false)->execute();
         $project_phids = mpull($projects, 'getPHID');
     } else {
         $project_phids = array();
     }
     $all_phids = array_fuse($user_phids) + array_fuse($project_phids);
     return array_values($all_phids);
 }
コード例 #5
0
 public static function loadAffiliatedUserPHIDs(array $package_ids)
 {
     if (!$package_ids) {
         return array();
     }
     $owners = id(new PhabricatorOwnersOwner())->loadAllWhere('packageID IN (%Ls)', $package_ids);
     $all_phids = phid_group_by_type(mpull($owners, 'getUserPHID'));
     $user_phids = idx($all_phids, PhabricatorPHIDConstants::PHID_TYPE_USER, array());
     $users_in_project_phids = array();
     $project_phids = idx($all_phids, PhabricatorPHIDConstants::PHID_TYPE_PROJ);
     if ($project_phids) {
         $query = id(new PhabricatorEdgeQuery())->withSourcePHIDs($project_phids)->withEdgeTypes(array(PhabricatorEdgeConfig::TYPE_PROJ_MEMBER));
         $query->execute();
         $users_in_project_phids = $query->getDestinationPHIDs();
     }
     return array_unique(array_merge($users_in_project_phids, $user_phids));
 }
コード例 #6
0
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $is_all = $args->getArg('all');
     $is_type = $args->getArg('type');
     $obj_names = $args->getArg('objects');
     if ($obj_names && ($is_all || $is_type)) {
         throw new PhutilArgumentUsageException("You can not name objects to index alongside the '--all' or '--type' " . "flags.");
     } else {
         if (!$obj_names && !($is_all || $is_type)) {
             throw new PhutilArgumentUsageException("Provide one of '--all', '--type' or a list of object names.");
         }
     }
     if ($obj_names) {
         $phids = $this->loadPHIDsByNames($obj_names);
     } else {
         $phids = $this->loadPHIDsByTypes($is_type);
     }
     if (!$phids) {
         throw new PhutilArgumentUsageException('Nothing to index!');
     }
     if ($args->getArg('background')) {
         $is_background = true;
     } else {
         PhabricatorWorker::setRunAllTasksInProcess(true);
         $is_background = false;
     }
     if (!$is_background) {
         $console->writeOut("%s\n", pht('Run this workflow with "--background" to queue tasks for the ' . 'daemon workers.'));
     }
     $groups = phid_group_by_type($phids);
     foreach ($groups as $group_type => $group) {
         $console->writeOut("%s\n", pht('Indexing %d object(s) of type %s.', count($group), $group_type));
     }
     $bar = id(new PhutilConsoleProgressBar())->setTotal(count($phids));
     $indexer = new PhabricatorSearchIndexer();
     foreach ($phids as $phid) {
         $indexer->queueDocumentForIndexing($phid);
         $bar->update(1);
     }
     $bar->done();
 }
コード例 #7
0
 /**
  * Load specified edges.
  *
  * @task exec
  */
 public function execute()
 {
     if (!$this->sourcePHIDs) {
         throw new Exception("You must use withSourcePHIDs() to query edges.");
     }
     $sources = phid_group_by_type($this->sourcePHIDs);
     $result = array();
     // When a query specifies types, make sure we return data for all queried
     // types. This is mostly to make sure PhabricatorLiskDAO->attachEdges()
     // gets some data, so that getEdges() doesn't throw later.
     if ($this->edgeTypes) {
         foreach ($this->sourcePHIDs as $phid) {
             foreach ($this->edgeTypes as $type) {
                 $result[$phid][$type] = array();
             }
         }
     }
     foreach ($sources as $type => $phids) {
         $conn_r = PhabricatorEdgeConfig::establishConnection($type, 'r');
         $where = $this->buildWhereClause($conn_r);
         $order = $this->buildOrderClause($conn_r);
         $edges = queryfx_all($conn_r, 'SELECT edge.* FROM %T edge %Q %Q', PhabricatorEdgeConfig::TABLE_NAME_EDGE, $where, $order);
         if ($this->needEdgeData) {
             $data_ids = array_filter(ipull($edges, 'dataID'));
             $data_map = array();
             if ($data_ids) {
                 $data_rows = queryfx_all($conn_r, 'SELECT edgedata.* FROM %T edgedata WHERE id IN (%Ld)', PhabricatorEdgeConfig::TABLE_NAME_EDGEDATA, $data_ids);
                 foreach ($data_rows as $row) {
                     $data_map[$row['id']] = idx(json_decode($row['data'], true), 'data');
                 }
             }
             foreach ($edges as $key => $edge) {
                 $edges[$key]['data'] = idx($data_map, $edge['dataID']);
             }
         }
         foreach ($edges as $edge) {
             $result[$edge['src']][$edge['type']][$edge['dst']] = $edge;
         }
     }
     return $result;
 }
コード例 #8
0
 /**
  * NOTE: This is a temporary stop gap since its easy to make malformed tasks.
  * Long-term, the values set in @{method:defineParamTypes} will be used to
  * validate data implicitly within the larger Conduit application.
  *
  * TODO: Remove this in favor of generalized Conduit hotness.
  */
 private function validatePHIDList(array $phid_list, $phid_type, $field)
 {
     $phid_groups = phid_group_by_type($phid_list);
     unset($phid_groups[$phid_type]);
     if (!empty($phid_groups)) {
         throw id(new ConduitException('ERR-INVALID-PARAMETER'))->setErrorDescription(pht('One or more PHIDs were invalid for %s.', $field));
     }
     return true;
 }
コード例 #9
0
 public function loadHandles()
 {
     $types = phid_group_by_type($this->phids);
     $handles = array();
     $external_loaders = PhabricatorEnv::getEnvConfig('phid.external-loaders');
     foreach ($types as $type => $phids) {
         switch ($type) {
             case PhabricatorPHIDConstants::PHID_TYPE_MAGIC:
                 // Black magic!
                 foreach ($phids as $phid) {
                     $handle = new PhabricatorObjectHandle();
                     $handle->setPHID($phid);
                     $handle->setType($type);
                     switch ($phid) {
                         case ManiphestTaskOwner::OWNER_UP_FOR_GRABS:
                             $handle->setName('Up For Grabs');
                             $handle->setFullName('upforgrabs (Up For Grabs)');
                             $handle->setComplete(true);
                             break;
                         case ManiphestTaskOwner::PROJECT_NO_PROJECT:
                             $handle->setName('No Project');
                             $handle->setFullName('noproject (No Project)');
                             $handle->setComplete(true);
                             break;
                         default:
                             $handle->setName('Foul Magicks');
                             break;
                     }
                     $handles[$phid] = $handle;
                 }
                 break;
             case PhabricatorPHIDConstants::PHID_TYPE_USER:
                 $object = new PhabricatorUser();
                 $users = $object->loadAllWhere('phid IN (%Ls)', $phids);
                 $users = mpull($users, null, 'getPHID');
                 $image_phids = mpull($users, 'getProfileImagePHID');
                 $image_phids = array_unique(array_filter($image_phids));
                 $images = array();
                 if ($image_phids) {
                     $images = id(new PhabricatorFile())->loadAllWhere('phid IN (%Ls)', $image_phids);
                     $images = mpull($images, 'getBestURI', 'getPHID');
                 }
                 $statuses = id(new PhabricatorUserStatus())->loadCurrentStatuses($phids);
                 foreach ($phids as $phid) {
                     $handle = new PhabricatorObjectHandle();
                     $handle->setPHID($phid);
                     $handle->setType($type);
                     if (empty($users[$phid])) {
                         $handle->setName('Unknown User');
                     } else {
                         $user = $users[$phid];
                         $handle->setName($user->getUsername());
                         $handle->setURI('/p/' . $user->getUsername() . '/');
                         $handle->setFullName($user->getUsername() . ' (' . $user->getRealName() . ')');
                         $handle->setAlternateID($user->getID());
                         $handle->setComplete(true);
                         if (isset($statuses[$phid])) {
                             $handle->setStatus($statuses[$phid]->getTextStatus());
                         }
                         $handle->setDisabled($user->getIsDisabled());
                         $img_uri = idx($images, $user->getProfileImagePHID());
                         if ($img_uri) {
                             $handle->setImageURI($img_uri);
                         } else {
                             $handle->setImageURI(PhabricatorUser::getDefaultProfileImageURI());
                         }
                     }
                     $handles[$phid] = $handle;
                 }
                 break;
             case PhabricatorPHIDConstants::PHID_TYPE_MLST:
                 $object = new PhabricatorMetaMTAMailingList();
                 $lists = $object->loadAllWhere('phid IN (%Ls)', $phids);
                 $lists = mpull($lists, null, 'getPHID');
                 foreach ($phids as $phid) {
                     $handle = new PhabricatorObjectHandle();
                     $handle->setPHID($phid);
                     $handle->setType($type);
                     if (empty($lists[$phid])) {
                         $handle->setName('Unknown Mailing List');
                     } else {
                         $list = $lists[$phid];
                         $handle->setName($list->getName());
                         $handle->setURI($list->getURI());
                         $handle->setFullName($list->getName());
                         $handle->setComplete(true);
                     }
                     $handles[$phid] = $handle;
                 }
                 break;
             case PhabricatorPHIDConstants::PHID_TYPE_DREV:
                 $object = new DifferentialRevision();
                 $revs = $object->loadAllWhere('phid in (%Ls)', $phids);
                 $revs = mpull($revs, null, 'getPHID');
                 foreach ($phids as $phid) {
                     $handle = new PhabricatorObjectHandle();
                     $handle->setPHID($phid);
                     $handle->setType($type);
                     if (empty($revs[$phid])) {
                         $handle->setName('Unknown Revision');
                     } else {
                         $rev = $revs[$phid];
                         $handle->setName($rev->getTitle());
                         $handle->setURI('/D' . $rev->getID());
                         $handle->setFullName('D' . $rev->getID() . ': ' . $rev->getTitle());
                         $handle->setComplete(true);
                         $status = $rev->getStatus();
                         if ($status == ArcanistDifferentialRevisionStatus::CLOSED || $status == ArcanistDifferentialRevisionStatus::ABANDONED) {
                             $closed = PhabricatorObjectHandleStatus::STATUS_CLOSED;
                             $handle->setStatus($closed);
                         }
                     }
                     $handles[$phid] = $handle;
                 }
                 break;
             case PhabricatorPHIDConstants::PHID_TYPE_CMIT:
                 $object = new PhabricatorRepositoryCommit();
                 $commits = $object->loadAllWhere('phid in (%Ls)', $phids);
                 $commits = mpull($commits, null, 'getPHID');
                 $repository_ids = array();
                 $callsigns = array();
                 if ($commits) {
                     $repository_ids = mpull($commits, 'getRepositoryID');
                     $repositories = id(new PhabricatorRepository())->loadAllWhere('id in (%Ld)', array_unique($repository_ids));
                     $callsigns = mpull($repositories, 'getCallsign');
                 }
                 foreach ($phids as $phid) {
                     $handle = new PhabricatorObjectHandle();
                     $handle->setPHID($phid);
                     $handle->setType($type);
                     if (empty($commits[$phid]) || !isset($callsigns[$repository_ids[$phid]])) {
                         $handle->setName('Unknown Commit');
                     } else {
                         $commit = $commits[$phid];
                         $callsign = $callsigns[$repository_ids[$phid]];
                         $repository = $repositories[$repository_ids[$phid]];
                         $commit_identifier = $commit->getCommitIdentifier();
                         // In case where the repository for the commit was deleted,
                         // we don't have have info about the repository anymore.
                         if ($repository) {
                             $name = $repository->formatCommitName($commit_identifier);
                             $handle->setName($name);
                         } else {
                             $handle->setName('Commit ' . 'r' . $callsign . $commit_identifier);
                         }
                         $handle->setURI('/r' . $callsign . $commit_identifier);
                         $handle->setFullName('r' . $callsign . $commit_identifier);
                         $handle->setTimestamp($commit->getEpoch());
                         $handle->setComplete(true);
                     }
                     $handles[$phid] = $handle;
                 }
                 break;
             case PhabricatorPHIDConstants::PHID_TYPE_TASK:
                 $object = new ManiphestTask();
                 $tasks = $object->loadAllWhere('phid in (%Ls)', $phids);
                 $tasks = mpull($tasks, null, 'getPHID');
                 foreach ($phids as $phid) {
                     $handle = new PhabricatorObjectHandle();
                     $handle->setPHID($phid);
                     $handle->setType($type);
                     if (empty($tasks[$phid])) {
                         $handle->setName('Unknown Revision');
                     } else {
                         $task = $tasks[$phid];
                         $handle->setName($task->getTitle());
                         $handle->setURI('/T' . $task->getID());
                         $handle->setFullName('T' . $task->getID() . ': ' . $task->getTitle());
                         $handle->setComplete(true);
                         $handle->setAlternateID($task->getID());
                         if ($task->getStatus() != ManiphestTaskStatus::STATUS_OPEN) {
                             $closed = PhabricatorObjectHandleStatus::STATUS_CLOSED;
                             $handle->setStatus($closed);
                         }
                     }
                     $handles[$phid] = $handle;
                 }
                 break;
             case PhabricatorPHIDConstants::PHID_TYPE_FILE:
                 $object = new PhabricatorFile();
                 $files = $object->loadAllWhere('phid IN (%Ls)', $phids);
                 $files = mpull($files, null, 'getPHID');
                 foreach ($phids as $phid) {
                     $handle = new PhabricatorObjectHandle();
                     $handle->setPHID($phid);
                     $handle->setType($type);
                     if (empty($files[$phid])) {
                         $handle->setName('Unknown File');
                     } else {
                         $file = $files[$phid];
                         $handle->setName($file->getName());
                         $handle->setURI($file->getBestURI());
                         $handle->setComplete(true);
                     }
                     $handles[$phid] = $handle;
                 }
                 break;
             case PhabricatorPHIDConstants::PHID_TYPE_PROJ:
                 $object = new PhabricatorProject();
                 $projects = $object->loadAllWhere('phid IN (%Ls)', $phids);
                 $projects = mpull($projects, null, 'getPHID');
                 foreach ($phids as $phid) {
                     $handle = new PhabricatorObjectHandle();
                     $handle->setPHID($phid);
                     $handle->setType($type);
                     if (empty($projects[$phid])) {
                         $handle->setName('Unknown Project');
                     } else {
                         $project = $projects[$phid];
                         $handle->setName($project->getName());
                         $handle->setURI('/project/view/' . $project->getID() . '/');
                         $handle->setComplete(true);
                     }
                     $handles[$phid] = $handle;
                 }
                 break;
             case PhabricatorPHIDConstants::PHID_TYPE_REPO:
                 $object = new PhabricatorRepository();
                 $repositories = $object->loadAllWhere('phid in (%Ls)', $phids);
                 $repositories = mpull($repositories, null, 'getPHID');
                 foreach ($phids as $phid) {
                     $handle = new PhabricatorObjectHandle();
                     $handle->setPHID($phid);
                     $handle->setType($type);
                     if (empty($repositories[$phid])) {
                         $handle->setName('Unknown Repository');
                     } else {
                         $repository = $repositories[$phid];
                         $handle->setName($repository->getCallsign());
                         $handle->setURI('/diffusion/' . $repository->getCallsign() . '/');
                         $handle->setComplete(true);
                     }
                     $handles[$phid] = $handle;
                 }
                 break;
             case PhabricatorPHIDConstants::PHID_TYPE_OPKG:
                 $object = new PhabricatorOwnersPackage();
                 $packages = $object->loadAllWhere('phid in (%Ls)', $phids);
                 $packages = mpull($packages, null, 'getPHID');
                 foreach ($phids as $phid) {
                     $handle = new PhabricatorObjectHandle();
                     $handle->setPHID($phid);
                     $handle->setType($type);
                     if (empty($packages[$phid])) {
                         $handle->setName('Unknown Package');
                     } else {
                         $package = $packages[$phid];
                         $handle->setName($package->getName());
                         $handle->setURI('/owners/package/' . $package->getID() . '/');
                         $handle->setComplete(true);
                     }
                     $handles[$phid] = $handle;
                 }
                 break;
             case PhabricatorPHIDConstants::PHID_TYPE_APRJ:
                 $project_dao = new PhabricatorRepositoryArcanistProject();
                 $projects = $project_dao->loadAllWhere('phid IN (%Ls)', $phids);
                 $projects = mpull($projects, null, 'getPHID');
                 foreach ($phids as $phid) {
                     $handle = new PhabricatorObjectHandle();
                     $handle->setPHID($phid);
                     $handle->setType($type);
                     if (empty($projects[$phid])) {
                         $handle->setName('Unknown Arcanist Project');
                     } else {
                         $project = $projects[$phid];
                         $handle->setName($project->getName());
                         $handle->setComplete(true);
                     }
                     $handles[$phid] = $handle;
                 }
                 break;
             case PhabricatorPHIDConstants::PHID_TYPE_WIKI:
                 $document_dao = new PhrictionDocument();
                 $content_dao = new PhrictionContent();
                 $conn = $document_dao->establishConnection('r');
                 $documents = queryfx_all($conn, 'SELECT * FROM %T document JOIN %T content
           ON document.contentID = content.id
           WHERE document.phid IN (%Ls)', $document_dao->getTableName(), $content_dao->getTableName(), $phids);
                 $documents = ipull($documents, null, 'phid');
                 foreach ($phids as $phid) {
                     $handle = new PhabricatorObjectHandle();
                     $handle->setPHID($phid);
                     $handle->setType($type);
                     if (empty($documents[$phid])) {
                         $handle->setName('Unknown Document');
                     } else {
                         $info = $documents[$phid];
                         $handle->setName($info['title']);
                         $handle->setURI(PhrictionDocument::getSlugURI($info['slug']));
                         $handle->setComplete(true);
                     }
                     $handles[$phid] = $handle;
                 }
                 break;
             default:
                 $loader = null;
                 if (isset($external_loaders[$type])) {
                     $loader = $external_loaders[$type];
                 } else {
                     if (isset($external_loaders['*'])) {
                         $loader = $external_loaders['*'];
                     }
                 }
                 if ($loader) {
                     $object = newv($loader, array());
                     $handles += $object->loadHandles($phids);
                     break;
                 }
                 foreach ($phids as $phid) {
                     $handle = new PhabricatorObjectHandle();
                     $handle->setType($type);
                     $handle->setPHID($phid);
                     $handle->setName('Unknown Object');
                     $handle->setFullName('An Unknown Object');
                     $handles[$phid] = $handle;
                 }
                 break;
         }
     }
     return $handles;
 }