Differential D14841 Diff 35874 src/applications/conpherence/engineextension/ConpherenceThreadIndexEngineExtension.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/conpherence/engineextension/ConpherenceThreadIndexEngineExtension.php
- This file was moved from src/applications/conpherence/search/ConpherenceThreadIndexer.php.
<?php | <?php | ||||
final class ConpherenceThreadIndexer | final class ConpherenceThreadIndexEngineExtension | ||||
extends PhabricatorSearchDocumentIndexer { | extends PhabricatorIndexEngineExtension { | ||||
public function getIndexableObject() { | const EXTENSIONKEY = 'conpherence.thread'; | ||||
return new ConpherenceThread(); | |||||
} | |||||
protected function loadDocumentByPHID($phid) { | public function getExtensionName() { | ||||
$object = id(new ConpherenceThreadQuery()) | return pht('Conpherence Threads'); | ||||
->setViewer($this->getViewer()) | |||||
->withPHIDs(array($phid)) | |||||
->executeOne(); | |||||
if (!$object) { | |||||
throw new Exception(pht('No thread "%s" exists!', $phid)); | |||||
} | } | ||||
return $object; | public function shouldIndexObject($object) { | ||||
return ($object instanceof ConpherenceThread); | |||||
} | } | ||||
protected function buildAbstractDocumentByPHID($phid) { | public function indexObject( | ||||
$thread = $this->loadDocumentByPHID($phid); | PhabricatorIndexEngine $engine, | ||||
$object) { | |||||
// NOTE: We're explicitly not building a document here, only rebuilding | |||||
// the Conpherence search index. | |||||
$context = nonempty($this->getContext(), array()); | $force = $this->shouldForceFullReindex(); | ||||
$comment_phids = idx($context, 'commentPHIDs'); | |||||
if (is_array($comment_phids) && !$comment_phids) { | if (!$force) { | ||||
// If this property is set, but empty, the transaction did not | $xaction_phids = $this->getParameter('transactionPHIDs'); | ||||
// include any chat text. For example, a user might have left the | if (!$xaction_phids) { | ||||
// conversation. | return; | ||||
return null; | } | ||||
} | } | ||||
$query = id(new ConpherenceTransactionQuery()) | $query = id(new ConpherenceTransactionQuery()) | ||||
->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
->withObjectPHIDs(array($thread->getPHID())) | ->withObjectPHIDs(array($object->getPHID())) | ||||
->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT)) | ->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT)) | ||||
->needComments(true); | ->needComments(true); | ||||
if ($comment_phids !== null) { | if (!$force) { | ||||
$query->withPHIDs($comment_phids); | $query->withPHIDs($xaction_phids); | ||||
} | } | ||||
$xactions = $query->execute(); | $xactions = $query->execute(); | ||||
foreach ($xactions as $xaction) { | if (!$xactions) { | ||||
$this->indexComment($thread, $xaction); | return; | ||||
} | } | ||||
return null; | foreach ($xactions as $xaction) { | ||||
$this->indexComment($object, $xaction); | |||||
} | |||||
} | } | ||||
private function indexComment( | private function indexComment( | ||||
ConpherenceThread $thread, | ConpherenceThread $thread, | ||||
ConpherenceTransaction $xaction) { | ConpherenceTransaction $xaction) { | ||||
$previous = id(new ConpherenceTransactionQuery()) | $previous = id(new ConpherenceTransactionQuery()) | ||||
->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
Show All 26 Lines |