@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 69 lines 1.8 kB view raw
1<?php 2 3final class PhabricatorProjectTriggerUsageIndexEngineExtension 4 extends PhabricatorIndexEngineExtension { 5 6 const EXTENSIONKEY = 'trigger.usage'; 7 8 public function getExtensionName() { 9 return pht('Trigger Usage'); 10 } 11 12 public function shouldIndexObject($object) { 13 if (!($object instanceof PhabricatorProjectTrigger)) { 14 return false; 15 } 16 17 return true; 18 } 19 20 public function indexObject( 21 PhabricatorIndexEngine $engine, 22 $object) { 23 24 $usage_table = new PhabricatorProjectTriggerUsage(); 25 $column_table = new PhabricatorProjectColumn(); 26 27 $conn_w = $object->establishConnection('w'); 28 29 $active_statuses = array( 30 PhabricatorProjectColumn::STATUS_ACTIVE, 31 ); 32 33 // Select summary information to populate the usage index. When picking 34 // an "examplePHID", we try to pick an active column. 35 $row = queryfx_one( 36 $conn_w, 37 'SELECT phid, COUNT(*) N, SUM(IF(status IN (%Ls), 1, 0)) M FROM %R 38 WHERE triggerPHID = %s 39 ORDER BY IF(status IN (%Ls), 1, 0) DESC, id ASC', 40 $active_statuses, 41 $column_table, 42 $object->getPHID(), 43 $active_statuses); 44 if ($row) { 45 $example_phid = $row['phid']; 46 $column_count = $row['N']; 47 $active_count = $row['M']; 48 } else { 49 $example_phid = null; 50 $column_count = 0; 51 $active_count = 0; 52 } 53 54 queryfx( 55 $conn_w, 56 'INSERT INTO %R (triggerPHID, examplePHID, columnCount, activeColumnCount) 57 VALUES (%s, %ns, %d, %d) 58 ON DUPLICATE KEY UPDATE 59 examplePHID = VALUES(examplePHID), 60 columnCount = VALUES(columnCount), 61 activeColumnCount = VALUES(activeColumnCount)', 62 $usage_table, 63 $object->getPHID(), 64 $example_phid, 65 $column_count, 66 $active_count); 67 } 68 69}