Path: blob/master/src/applications/conpherence/engineextension/ConpherenceThreadIndexEngineExtension.php
12256 views
<?php12final class ConpherenceThreadIndexEngineExtension3extends PhabricatorIndexEngineExtension {45const EXTENSIONKEY = 'conpherence.thread';67public function getExtensionName() {8return pht('Conpherence Threads');9}1011public function shouldIndexObject($object) {12return ($object instanceof ConpherenceThread);13}1415public function indexObject(16PhabricatorIndexEngine $engine,17$object) {1819$force = $this->shouldForceFullReindex();2021if (!$force) {22$xaction_phids = $this->getParameter('transactionPHIDs');23if (!$xaction_phids) {24return;25}26}2728$query = id(new ConpherenceTransactionQuery())29->setViewer($this->getViewer())30->withObjectPHIDs(array($object->getPHID()))31->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT))32->needComments(true);3334if (!$force) {35$query->withPHIDs($xaction_phids);36}3738$xactions = $query->execute();3940if (!$xactions) {41return;42}4344foreach ($xactions as $xaction) {45$this->indexComment($object, $xaction);46}47}4849private function indexComment(50ConpherenceThread $thread,51ConpherenceTransaction $xaction) {5253$pager = id(new AphrontCursorPagerView())54->setPageSize(1)55->setAfterID($xaction->getID());5657$previous_xactions = id(new ConpherenceTransactionQuery())58->setViewer($this->getViewer())59->withObjectPHIDs(array($thread->getPHID()))60->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT))61->executeWithCursorPager($pager);62$previous = head($previous_xactions);6364$index = id(new ConpherenceIndex())65->setThreadPHID($thread->getPHID())66->setTransactionPHID($xaction->getPHID())67->setPreviousTransactionPHID($previous ? $previous->getPHID() : null)68->setCorpus($xaction->getComment()->getContent());6970queryfx(71$index->establishConnection('w'),72'INSERT INTO %T73(threadPHID, transactionPHID, previousTransactionPHID, corpus)74VALUES (%s, %s, %ns, %s)75ON DUPLICATE KEY UPDATE corpus = VALUES(corpus)',76$index->getTableName(),77$index->getThreadPHID(),78$index->getTransactionPHID(),79$index->getPreviousTransactionPHID(),80$index->getCorpus());81}8283}848586