@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Conpherence - implement PhabricatorDestructibleInterface so threads can be deleted

Summary: Fixes T7694. I had to complicate the `ConpherenceThreadQuery` code slightly so that if we specify id(s) or phid(s) then we don't bother with all that join stuff we need to make sure we have a reasonable query in production.

Test Plan: `bin/remove destroy ZXX` worked! tried to visit `ZXX` and got a nice 404. Clicked around and couldn't find anything broken because of the deletion

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T7756, T7694

Differential Revision: https://secure.phabricator.com/D12304

+64 -4
+1
src/__phutil_library_map__.php
··· 3446 3446 'ConpherenceDAO', 3447 3447 'PhabricatorPolicyInterface', 3448 3448 'PhabricatorApplicationTransactionInterface', 3449 + 'PhabricatorDestructibleInterface', 3449 3450 ), 3450 3451 'ConpherenceThreadIndexer' => 'PhabricatorSearchDocumentIndexer', 3451 3452 'ConpherenceThreadListView' => 'AphrontView',
+30
src/applications/conpherence/phid/PhabricatorConpherenceThreadPHIDType.php
··· 35 35 } 36 36 } 37 37 38 + public function canLoadNamedObject($name) { 39 + return preg_match('/^Z\d*[1-9]\d*$/i', $name); 40 + } 41 + 42 + public function loadNamedObjects( 43 + PhabricatorObjectQuery $query, 44 + array $names) { 45 + 46 + $id_map = array(); 47 + foreach ($names as $name) { 48 + $id = (int)substr($name, 1); 49 + $id_map[$id][] = $name; 50 + } 51 + 52 + $objects = id(new ConpherenceThreadQuery()) 53 + ->setViewer($query->getViewer()) 54 + ->withIDs(array_keys($id_map)) 55 + ->execute(); 56 + $objects = mpull($objects, null, 'getID'); 57 + 58 + $results = array(); 59 + foreach ($objects as $id => $object) { 60 + foreach (idx($id_map, $id, array()) as $name) { 61 + $results[$name] = $object; 62 + } 63 + } 64 + 65 + return $results; 66 + } 67 + 38 68 }
+12 -3
src/applications/conpherence/query/ConpherenceThreadQuery.php
··· 133 133 } 134 134 135 135 $viewer = $this->getViewer(); 136 - if ($viewer->isLoggedIn()) { 136 + if ($this->shouldJoinForViewer($viewer)) { 137 137 $joins[] = qsprintf( 138 138 $conn_r, 139 139 'LEFT JOIN %T v ON v.conpherencePHID = conpherence_thread.phid '. ··· 145 145 146 146 $joins[] = $this->buildApplicationSearchJoinClause($conn_r); 147 147 return implode(' ', $joins); 148 + } 149 + 150 + private function shouldJoinForViewer(PhabricatorUser $viewer) { 151 + if ($viewer->isLoggedIn() && 152 + $this->ids === null && 153 + $this->phids === null) { 154 + return true; 155 + } 156 + return false; 148 157 } 149 158 150 159 protected function buildWhereClause($conn_r) { ··· 181 190 } 182 191 183 192 $viewer = $this->getViewer(); 184 - if ($viewer->isLoggedIn()) { 193 + if ($this->shouldJoinForViewer($viewer)) { 185 194 $where[] = qsprintf( 186 195 $conn_r, 187 196 'conpherence_thread.isRoom = 1 OR v.participantPHID IS NOT NULL'); 188 - } else { 197 + } else if ($this->phids === null && $this->ids === null) { 189 198 $where[] = qsprintf( 190 199 $conn_r, 191 200 'conpherence_thread.isRoom = 1');
+21 -1
src/applications/conpherence/storage/ConpherenceThread.php
··· 3 3 final class ConpherenceThread extends ConpherenceDAO 4 4 implements 5 5 PhabricatorPolicyInterface, 6 - PhabricatorApplicationTransactionInterface { 6 + PhabricatorApplicationTransactionInterface, 7 + PhabricatorDestructibleInterface { 7 8 8 9 protected $title; 9 10 protected $isRoom = 0; ··· 339 340 return $timeline; 340 341 } 341 342 343 + 344 + /* -( PhabricatorDestructibleInterface )----------------------------------- */ 345 + 346 + 347 + public function destroyObjectPermanently( 348 + PhabricatorDestructionEngine $engine) { 349 + 350 + $this->openTransaction(); 351 + $this->delete(); 352 + 353 + $participants = id(new ConpherenceParticipant()) 354 + ->loadAllWhere('conpherencePHID = %s', $this->getPHID()); 355 + foreach ($participants as $participant) { 356 + $participant->delete(); 357 + } 358 + 359 + $this->saveTransaction(); 360 + 361 + } 342 362 }