@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.

Implement PolicyInterface, ExtendedPolicyInterface, and DestructibleInterface on PhrictionContent

Summary:
Depends on D19093. Ref T13077. Although content objects normally don't have any edges today, they may in the future.

Also implement Policy stuff properly.

Test Plan: Used `bin/remove destroy` to destroy a document, verified it also loaded and destroyed the correspoding Content correctly by looking at `--trace` and the database rows.

Maniphest Tasks: T13077

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

+130 -11
+5 -1
src/__phutil_library_map__.php
··· 10755 10755 'PhrictionChangeType' => 'PhrictionConstants', 10756 10756 'PhrictionConduitAPIMethod' => 'ConduitAPIMethod', 10757 10757 'PhrictionConstants' => 'Phobject', 10758 - 'PhrictionContent' => 'PhrictionDAO', 10758 + 'PhrictionContent' => array( 10759 + 'PhrictionDAO', 10760 + 'PhabricatorPolicyInterface', 10761 + 'PhabricatorDestructibleInterface', 10762 + ), 10759 10763 'PhrictionContentPHIDType' => 'PhabricatorPHIDType', 10760 10764 'PhrictionContentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 10761 10765 'PhrictionController' => 'PhabricatorController',
+66 -2
src/applications/phriction/query/PhrictionContentQuery.php
··· 5 5 6 6 private $ids; 7 7 private $phids; 8 + private $documentPHIDs; 8 9 9 10 public function withIDs(array $ids) { 10 11 $this->ids = $ids; ··· 16 17 return $this; 17 18 } 18 19 20 + public function withDocumentPHIDs(array $phids) { 21 + $this->documentPHIDs = $phids; 22 + return $this; 23 + } 24 + 19 25 public function newResultObject() { 20 26 return new PhrictionContent(); 21 27 } ··· 30 36 if ($this->ids !== null) { 31 37 $where[] = qsprintf( 32 38 $conn, 33 - 'id IN (%Ld)', 39 + 'c.id IN (%Ld)', 34 40 $this->ids); 35 41 } 36 42 37 43 if ($this->phids !== null) { 38 44 $where[] = qsprintf( 39 45 $conn, 40 - 'phid IN (%Ls)', 46 + 'c.phid IN (%Ls)', 41 47 $this->phids); 48 + } 49 + 50 + if ($this->documentPHIDs !== null) { 51 + $where[] = qsprintf( 52 + $conn, 53 + 'd.phid IN (%Ls)', 54 + $this->documentPHIDs); 42 55 } 43 56 44 57 return $where; 58 + } 59 + 60 + protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { 61 + $joins = parent::buildJoinClauseParts($conn); 62 + 63 + if ($this->shouldJoinDocumentTable()) { 64 + $joins[] = qsprintf( 65 + $conn, 66 + 'JOIN %T d ON d.id = c.documentID', 67 + id(new PhrictionDocument())->getTableName()); 68 + } 69 + 70 + return $joins; 71 + } 72 + 73 + protected function willFilterPage(array $contents) { 74 + $document_ids = mpull($contents, 'getDocumentID'); 75 + 76 + $documents = id(new PhrictionDocumentQuery()) 77 + ->setViewer($this->getViewer()) 78 + ->setParentQuery($this) 79 + ->withIDs($document_ids) 80 + ->execute(); 81 + $documents = mpull($documents, null, 'getID'); 82 + 83 + foreach ($contents as $key => $content) { 84 + $document_id = $content->getDocumentID(); 85 + 86 + $document = idx($documents, $document_id); 87 + if (!$document) { 88 + unset($contents[$key]); 89 + $this->didRejectResult($content); 90 + continue; 91 + } 92 + 93 + $content->attachDocument($document); 94 + } 95 + 96 + return $contents; 97 + } 98 + 99 + private function shouldJoinDocumentTable() { 100 + if ($this->documentPHIDs !== null) { 101 + return true; 102 + } 103 + 104 + return false; 105 + } 106 + 107 + protected function getPrimaryTableAlias() { 108 + return 'c'; 45 109 } 46 110 47 111 public function getQueryApplicationClass() {
+52 -2
src/applications/phriction/storage/PhrictionContent.php
··· 1 1 <?php 2 2 3 3 final class PhrictionContent 4 - extends PhrictionDAO { 4 + extends PhrictionDAO 5 + implements 6 + PhabricatorPolicyInterface, 7 + PhabricatorDestructibleInterface { 5 8 6 - protected $id; 7 9 protected $documentID; 8 10 protected $version; 9 11 protected $authorPHID; ··· 15 17 16 18 protected $changeType; 17 19 protected $changeRef; 20 + 21 + private $document = self::ATTACHABLE; 18 22 19 23 protected function getConfiguration() { 20 24 return array( ··· 54 58 return id(new PHUIRemarkupView($viewer, $this->getContent())) 55 59 ->setRemarkupOption(PHUIRemarkupView::OPTION_GENERATE_TOC, true) 56 60 ->setGenerateTableOfContents(true); 61 + } 62 + 63 + public function attachDocument(PhrictionDocument $document) { 64 + $this->document = $document; 65 + return $this; 66 + } 67 + 68 + public function getDocument() { 69 + return $this->assertAttached($this->document); 70 + } 71 + 72 + 73 + /* -( PhabricatorPolicyInterface )----------------------------------------- */ 74 + 75 + 76 + public function getCapabilities() { 77 + return array( 78 + PhabricatorPolicyCapability::CAN_VIEW, 79 + ); 80 + } 81 + 82 + public function getPolicy($capability) { 83 + return PhabricatorPolicies::getMostOpenPolicy(); 84 + } 85 + 86 + public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 87 + return false; 88 + } 89 + 90 + 91 + /* -( PhabricatorExtendedPolicyInterface )--------------------------------- */ 92 + 93 + 94 + public function getExtendedPolicy($capability, PhabricatorUser $viewer) { 95 + return array( 96 + array($this->getDocument(), PhabricatorPolicyCapability::CAN_VIEW), 97 + ); 98 + } 99 + 100 + 101 + /* -( PhabricatorDestructibleInterface )----------------------------------- */ 102 + 103 + 104 + public function destroyObjectPermanently( 105 + PhabricatorDestructionEngine $engine) { 106 + $this->delete(); 57 107 } 58 108 59 109 }
+7 -6
src/applications/phriction/storage/PhrictionDocument.php
··· 236 236 237 237 $this->openTransaction(); 238 238 239 - $this->delete(); 240 - 241 - $contents = id(new PhrictionContent())->loadAllWhere( 242 - 'documentID = %d', 243 - $this->getID()); 239 + $contents = id(new PhrictionContentQuery()) 240 + ->setViewer($engine->getViewer()) 241 + ->withDocumentPHIDs(array($this->getPHID())) 242 + ->execute(); 244 243 foreach ($contents as $content) { 245 - $content->delete(); 244 + $engine->destroyObject($content); 246 245 } 246 + 247 + $this->delete(); 247 248 248 249 $this->saveTransaction(); 249 250 }