Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/index/PhabricatorSearchDocumentIndexer.php
<?php | <?php | ||||
abstract class PhabricatorSearchDocumentIndexer { | abstract class PhabricatorSearchDocumentIndexer extends Phobject { | ||||
private $context; | |||||
protected function setContext($context) { | |||||
$this->context = $context; | |||||
return $this; | |||||
} | |||||
protected function getContext() { | |||||
return $this->context; | |||||
} | |||||
abstract public function getIndexableObject(); | abstract public function getIndexableObject(); | ||||
abstract protected function buildAbstractDocumentByPHID($phid); | abstract protected function buildAbstractDocumentByPHID($phid); | ||||
protected function getViewer() { | protected function getViewer() { | ||||
return PhabricatorUser::getOmnipotentUser(); | return PhabricatorUser::getOmnipotentUser(); | ||||
} | } | ||||
Show All 13 Lines | $object = id(new PhabricatorObjectQuery()) | ||||
->withPHIDs(array($phid)) | ->withPHIDs(array($phid)) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$object) { | if (!$object) { | ||||
throw new Exception("Unable to load object by phid '{$phid}'!"); | throw new Exception("Unable to load object by phid '{$phid}'!"); | ||||
} | } | ||||
return $object; | return $object; | ||||
} | } | ||||
public function indexDocumentByPHID($phid) { | public function indexDocumentByPHID($phid, $context) { | ||||
try { | try { | ||||
$this->setContext($context); | |||||
$document = $this->buildAbstractDocumentByPHID($phid); | $document = $this->buildAbstractDocumentByPHID($phid); | ||||
if ($document === null) { | |||||
// This indexer doesn't build a document index, so we're done. | |||||
return $this; | |||||
} | |||||
$object = $this->loadDocumentByPHID($phid); | $object = $this->loadDocumentByPHID($phid); | ||||
// Automatically rebuild CustomField indexes if the object uses custom | // Automatically rebuild CustomField indexes if the object uses custom | ||||
// fields. | // fields. | ||||
if ($object instanceof PhabricatorCustomFieldInterface) { | if ($object instanceof PhabricatorCustomFieldInterface) { | ||||
$this->indexCustomFields($document, $object); | $this->indexCustomFields($document, $object); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 135 Lines • Show Last 20 Lines |