2015-01-06 19:24:30 +01:00
|
|
|
<?php
|
|
|
|
|
2015-12-21 15:07:41 +01:00
|
|
|
final class ConpherenceThreadIndexEngineExtension
|
|
|
|
extends PhabricatorIndexEngineExtension {
|
2015-01-06 19:24:30 +01:00
|
|
|
|
2015-12-21 15:07:41 +01:00
|
|
|
const EXTENSIONKEY = 'conpherence.thread';
|
2015-01-06 19:24:30 +01:00
|
|
|
|
2015-12-21 15:07:41 +01:00
|
|
|
public function getExtensionName() {
|
|
|
|
return pht('Conpherence Threads');
|
2015-01-06 19:24:30 +01:00
|
|
|
}
|
|
|
|
|
2015-12-21 15:07:41 +01:00
|
|
|
public function shouldIndexObject($object) {
|
|
|
|
return ($object instanceof ConpherenceThread);
|
|
|
|
}
|
2015-01-06 19:24:30 +01:00
|
|
|
|
2015-12-21 15:07:41 +01:00
|
|
|
public function indexObject(
|
|
|
|
PhabricatorIndexEngine $engine,
|
|
|
|
$object) {
|
2015-01-06 19:24:30 +01:00
|
|
|
|
2015-12-21 15:07:41 +01:00
|
|
|
$force = $this->shouldForceFullReindex();
|
2015-01-06 19:24:30 +01:00
|
|
|
|
2015-12-21 15:07:41 +01:00
|
|
|
if (!$force) {
|
|
|
|
$xaction_phids = $this->getParameter('transactionPHIDs');
|
|
|
|
if (!$xaction_phids) {
|
|
|
|
return;
|
|
|
|
}
|
2015-01-06 19:24:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$query = id(new ConpherenceTransactionQuery())
|
|
|
|
->setViewer($this->getViewer())
|
2015-12-21 15:07:41 +01:00
|
|
|
->withObjectPHIDs(array($object->getPHID()))
|
2015-01-06 19:24:30 +01:00
|
|
|
->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT))
|
|
|
|
->needComments(true);
|
|
|
|
|
2015-12-21 15:07:41 +01:00
|
|
|
if (!$force) {
|
|
|
|
$query->withPHIDs($xaction_phids);
|
2015-01-06 19:24:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$xactions = $query->execute();
|
|
|
|
|
2015-12-21 15:07:41 +01:00
|
|
|
if (!$xactions) {
|
|
|
|
return;
|
2015-01-06 19:24:30 +01:00
|
|
|
}
|
|
|
|
|
2015-12-21 15:07:41 +01:00
|
|
|
foreach ($xactions as $xaction) {
|
|
|
|
$this->indexComment($object, $xaction);
|
|
|
|
}
|
2015-01-06 19:24:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function indexComment(
|
|
|
|
ConpherenceThread $thread,
|
|
|
|
ConpherenceTransaction $xaction) {
|
|
|
|
|
|
|
|
$previous = id(new ConpherenceTransactionQuery())
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withObjectPHIDs(array($thread->getPHID()))
|
|
|
|
->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT))
|
|
|
|
->setAfterID($xaction->getID())
|
|
|
|
->setLimit(1)
|
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
$index = id(new ConpherenceIndex())
|
|
|
|
->setThreadPHID($thread->getPHID())
|
|
|
|
->setTransactionPHID($xaction->getPHID())
|
|
|
|
->setPreviousTransactionPHID($previous ? $previous->getPHID() : null)
|
|
|
|
->setCorpus($xaction->getComment()->getContent());
|
|
|
|
|
|
|
|
queryfx(
|
|
|
|
$index->establishConnection('w'),
|
|
|
|
'INSERT INTO %T
|
|
|
|
(threadPHID, transactionPHID, previousTransactionPHID, corpus)
|
|
|
|
VALUES (%s, %s, %ns, %s)
|
|
|
|
ON DUPLICATE KEY UPDATE corpus = VALUES(corpus)',
|
|
|
|
$index->getTableName(),
|
|
|
|
$index->getThreadPHID(),
|
|
|
|
$index->getTransactionPHID(),
|
|
|
|
$index->getPreviousTransactionPHID(),
|
|
|
|
$index->getCorpus());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|