Differential D14842 Diff 35894 src/applications/search/management/PhabricatorSearchManagementIndexWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/management/PhabricatorSearchManagementIndexWorkflow.php
<?php | <?php | ||||
final class PhabricatorSearchManagementIndexWorkflow | final class PhabricatorSearchManagementIndexWorkflow | ||||
extends PhabricatorSearchManagementWorkflow { | extends PhabricatorSearchManagementWorkflow { | ||||
protected function didConstruct() { | protected function didConstruct() { | ||||
$this | $this | ||||
->setName('index') | ->setName('index') | ||||
->setSynopsis(pht('Build or rebuild search indexes.')) | ->setSynopsis(pht('Build or rebuild search indexes.')) | ||||
->setExamples( | ->setExamples( | ||||
"**index** D123\n". | "**index** D123\n". | ||||
"**index** --type DREV\n". | "**index** --type task\n". | ||||
"**index** --all") | "**index** --all") | ||||
->setArguments( | ->setArguments( | ||||
array( | array( | ||||
array( | array( | ||||
'name' => 'all', | 'name' => 'all', | ||||
'help' => pht('Reindex all documents.'), | 'help' => pht('Reindex all documents.'), | ||||
), | ), | ||||
array( | array( | ||||
'name' => 'type', | 'name' => 'type', | ||||
'param' => 'TYPE', | 'param' => 'type', | ||||
'help' => pht('PHID type to reindex, like "TASK" or "DREV".'), | 'help' => pht( | ||||
'Object types to reindex, like "task", "commit" or "revision".'), | |||||
), | ), | ||||
array( | array( | ||||
'name' => 'background', | 'name' => 'background', | ||||
'help' => pht( | 'help' => pht( | ||||
'Instead of indexing in this process, queue tasks for '. | 'Instead of indexing in this process, queue tasks for '. | ||||
'the daemons. This can improve performance, but makes '. | 'the daemons. This can improve performance, but makes '. | ||||
'it more difficult to debug search indexing.'), | 'it more difficult to debug search indexing.'), | ||||
), | ), | ||||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | foreach ($names as $name) { | ||||
$name)); | $name)); | ||||
} | } | ||||
} | } | ||||
return mpull($objects, 'getPHID'); | return mpull($objects, 'getPHID'); | ||||
} | } | ||||
private function loadPHIDsByTypes($type) { | private function loadPHIDsByTypes($type) { | ||||
$indexers = id(new PhutilClassMapQuery()) | $objects = id(new PhutilClassMapQuery()) | ||||
->setAncestorClass('PhabricatorSearchDocumentIndexer') | ->setAncestorClass('PhabricatorFulltextInterface') | ||||
->execute(); | ->execute(); | ||||
$phids = array(); | $normalized_type = phutil_utf8_strtolower($type); | ||||
foreach ($indexers as $indexer) { | |||||
$indexer_phid = $indexer->getIndexableObject()->generatePHID(); | $matches = array(); | ||||
$indexer_type = phid_get_type($indexer_phid); | foreach ($objects as $object) { | ||||
$object_class = get_class($object); | |||||
$normalized_class = phutil_utf8_strtolower($object_class); | |||||
if (!strlen($type) || | |||||
strpos($normalized_class, $normalized_type) !== false) { | |||||
$matches[$object_class] = $object; | |||||
} | |||||
} | |||||
if (!$matches) { | |||||
$all_types = array(); | |||||
foreach ($objects as $object) { | |||||
$all_types[] = get_class($object); | |||||
} | |||||
sort($all_types); | |||||
if ($type && strcasecmp($indexer_type, $type)) { | throw new PhutilArgumentUsageException( | ||||
continue; | pht( | ||||
'Type "%s" matches no indexable objects. Supported types are: %s.', | |||||
$type, | |||||
implode(', ', $all_types))); | |||||
} | |||||
if ((count($matches) > 1) && strlen($type)) { | |||||
throw new PhutilArgumentUsageException( | |||||
pht( | |||||
'Type "%s" matches multiple indexable objects. Use a more '. | |||||
'specific string. Matching object types are: %s.', | |||||
$type, | |||||
implode(', ', array_keys($matches)))); | |||||
} | } | ||||
$iterator = $indexer->getIndexIterator(); | $phids = array(); | ||||
foreach ($matches as $match) { | |||||
$iterator = new LiskMigrationIterator($match); | |||||
foreach ($iterator as $object) { | foreach ($iterator as $object) { | ||||
$phids[] = $object->getPHID(); | $phids[] = $object->getPHID(); | ||||
} | } | ||||
} | } | ||||
return $phids; | return $phids; | ||||
} | } | ||||
} | } |