@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 84 lines 2.3 kB view raw
1<?php 2 3final class ConpherenceThreadIndexEngineExtension 4 extends PhabricatorIndexEngineExtension { 5 6 const EXTENSIONKEY = 'conpherence.thread'; 7 8 public function getExtensionName() { 9 return pht('Conpherence Threads'); 10 } 11 12 public function shouldIndexObject($object) { 13 return ($object instanceof ConpherenceThread); 14 } 15 16 public function indexObject( 17 PhabricatorIndexEngine $engine, 18 $object) { 19 20 $force = $this->shouldForceFullReindex(); 21 22 if (!$force) { 23 $xaction_phids = $this->getParameter('transactionPHIDs'); 24 if (!$xaction_phids) { 25 return; 26 } 27 } 28 29 $query = id(new ConpherenceTransactionQuery()) 30 ->setViewer($this->getViewer()) 31 ->withObjectPHIDs(array($object->getPHID())) 32 ->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT)) 33 ->needComments(true); 34 35 if (!$force) { 36 $query->withPHIDs($xaction_phids); 37 } 38 39 $xactions = $query->execute(); 40 41 if (!$xactions) { 42 return; 43 } 44 45 foreach ($xactions as $xaction) { 46 $this->indexComment($object, $xaction); 47 } 48 } 49 50 private function indexComment( 51 ConpherenceThread $thread, 52 ConpherenceTransaction $xaction) { 53 54 $pager = id(new AphrontCursorPagerView()) 55 ->setPageSize(1) 56 ->setAfterID($xaction->getID()); 57 58 $previous_xactions = id(new ConpherenceTransactionQuery()) 59 ->setViewer($this->getViewer()) 60 ->withObjectPHIDs(array($thread->getPHID())) 61 ->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT)) 62 ->executeWithCursorPager($pager); 63 $previous = head($previous_xactions); 64 65 $index = id(new ConpherenceIndex()) 66 ->setThreadPHID($thread->getPHID()) 67 ->setTransactionPHID($xaction->getPHID()) 68 ->setPreviousTransactionPHID($previous ? $previous->getPHID() : null) 69 ->setCorpus($xaction->getComment()->getContent()); 70 71 queryfx( 72 $index->establishConnection('w'), 73 'INSERT INTO %T 74 (threadPHID, transactionPHID, previousTransactionPHID, corpus) 75 VALUES (%s, %s, %ns, %s) 76 ON DUPLICATE KEY UPDATE corpus = VALUES(corpus)', 77 $index->getTableName(), 78 $index->getThreadPHID(), 79 $index->getTransactionPHID(), 80 $index->getPreviousTransactionPHID(), 81 $index->getCorpus()); 82 } 83 84}