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

Make Images in Pholio refer to mocks by PHID instead of ID

Summary:
Ref T11351. In Pholio, we currently use a `mockID`, but a `mockPHID` is generally preferable / more modern / more flexible. In particular, we need PHIDs to load handles and prefer PHIDs when exposing information to the API, and using PHIDs internally makes a bunch of things easier/better/faster and ~nothing harder/worse/slower.

I'll add some inlines about a few things.

Test Plan: Ran migrations, spot-checked database for sanity. Loaded Pholio, saw data unchanged. Created and edited images.

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T11351

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

+88 -49
+2
resources/sql/autopatches/20181219.pholio.01.imagephid.sql
··· 1 + ALTER TABLE {$NAMESPACE}_pholio.pholio_image 2 + ADD mockPHID VARBINARY(64);
+35
resources/sql/autopatches/20181219.pholio.02.imagemigrate.php
··· 1 + <?php 2 + 3 + // Old images used a "mockID" instead of a "mockPHID" to reference mocks. 4 + // Set the "mockPHID" column to the value that corresponds to the "mockID". 5 + 6 + $image = new PholioImage(); 7 + $mock = new PholioMock(); 8 + 9 + $conn = $image->establishConnection('w'); 10 + $iterator = new LiskRawMigrationIterator($conn, $image->getTableName()); 11 + 12 + foreach ($iterator as $image_row) { 13 + if ($image_row['mockPHID']) { 14 + continue; 15 + } 16 + 17 + $mock_id = $image_row['mockID']; 18 + 19 + $mock_row = queryfx_one( 20 + $conn, 21 + 'SELECT phid FROM %R WHERE id = %d', 22 + $mock, 23 + $mock_id); 24 + 25 + if (!$mock_row) { 26 + continue; 27 + } 28 + 29 + queryfx( 30 + $conn, 31 + 'UPDATE %R SET mockPHID = %s WHERE id = %d', 32 + $image, 33 + $mock_row['phid'], 34 + $image_row['id']); 35 + }
+2
resources/sql/autopatches/20181219.pholio.03.imageid.sql
··· 1 + ALTER TABLE {$NAMESPACE}_pholio.pholio_image 2 + DROP mockID;
+1 -1
src/applications/pholio/editor/PholioMockEditor.php
··· 91 91 92 92 $images = $this->getNewImages(); 93 93 foreach ($images as $image) { 94 - $image->setMockID($object->getID()); 94 + $image->setMockPHID($object->getPHID()); 95 95 $image->save(); 96 96 } 97 97
+1 -1
src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php
··· 65 65 ->setActor($author) 66 66 ->applyTransactions($mock, $transactions); 67 67 foreach ($images as $image) { 68 - $image->setMockID($mock->getID()); 68 + $image->setMockPHID($mock->getPHID()); 69 69 $image->save(); 70 70 } 71 71
+3 -7
src/applications/pholio/phid/PholioImagePHIDType.php
··· 32 32 foreach ($handles as $phid => $handle) { 33 33 $image = $objects[$phid]; 34 34 35 - $id = $image->getID(); 36 - $mock_id = $image->getMockID(); 37 - $name = $image->getName(); 38 - 39 - $handle->setURI("/M{$mock_id}/{$id}/"); 40 - $handle->setName($name); 41 - $handle->setFullName($name); 35 + $handle 36 + ->setName($image->getName()) 37 + ->setURI($image->getURI()); 42 38 } 43 39 } 44 40
+12 -23
src/applications/pholio/query/PholioImageQuery.php
··· 5 5 6 6 private $ids; 7 7 private $phids; 8 - private $mockIDs; 9 - private $obsolete; 8 + private $mockPHIDs; 10 9 11 10 private $needInlineComments; 12 11 private $mockCache = array(); ··· 21 20 return $this; 22 21 } 23 22 24 - public function withMockIDs(array $mock_ids) { 25 - $this->mockIDs = $mock_ids; 26 - return $this; 27 - } 28 - 29 - public function withObsolete($obsolete) { 30 - $this->obsolete = $obsolete; 23 + public function withMockPHIDs(array $mock_phids) { 24 + $this->mockPHIDs = $mock_phids; 31 25 return $this; 32 26 } 33 27 ··· 69 63 $this->phids); 70 64 } 71 65 72 - if ($this->mockIDs !== null) { 66 + if ($this->mockPHIDs !== null) { 73 67 $where[] = qsprintf( 74 68 $conn, 75 - 'mockID IN (%Ld)', 76 - $this->mockIDs); 77 - } 78 - 79 - if ($this->obsolete !== null) { 80 - $where[] = qsprintf( 81 - $conn, 82 - 'isObsolete = %d', 83 - $this->obsolete); 69 + 'mockPHID IN (%Ls)', 70 + $this->mockPHIDs); 84 71 } 85 72 86 73 return $where; ··· 92 79 if ($this->getMockCache()) { 93 80 $mocks = $this->getMockCache(); 94 81 } else { 95 - $mock_ids = mpull($images, 'getMockID'); 82 + $mock_phids = mpull($images, 'getMockPHID'); 83 + 96 84 // DO NOT set needImages to true; recursion results! 97 85 $mocks = id(new PholioMockQuery()) 98 86 ->setViewer($this->getViewer()) 99 - ->withIDs($mock_ids) 87 + ->withPHIDs($mock_phids) 100 88 ->execute(); 101 - $mocks = mpull($mocks, null, 'getID'); 89 + $mocks = mpull($mocks, null, 'getPHID'); 102 90 } 91 + 103 92 foreach ($images as $index => $image) { 104 - $mock = idx($mocks, $image->getMockID()); 93 + $mock = idx($mocks, $image->getMockPHID()); 105 94 if ($mock) { 106 95 $image->attachMock($mock); 107 96 } else {
+4 -4
src/applications/pholio/query/PholioMockQuery.php
··· 115 115 $need_inline_comments) { 116 116 assert_instances_of($mocks, 'PholioMock'); 117 117 118 - $mock_map = mpull($mocks, null, 'getID'); 118 + $mock_map = mpull($mocks, null, 'getPHID'); 119 119 $all_images = id(new PholioImageQuery()) 120 120 ->setViewer($viewer) 121 121 ->setMockCache($mock_map) 122 - ->withMockIDs(array_keys($mock_map)) 122 + ->withMockPHIDs(array_keys($mock_map)) 123 123 ->needInlineComments($need_inline_comments) 124 124 ->execute(); 125 125 126 - $image_groups = mgroup($all_images, 'getMockID'); 126 + $image_groups = mgroup($all_images, 'getMockPHID'); 127 127 128 128 foreach ($mocks as $mock) { 129 - $mock_images = idx($image_groups, $mock->getID(), array()); 129 + $mock_images = idx($image_groups, $mock->getPHID(), array()); 130 130 $mock->attachAllImages($mock_images); 131 131 $active_images = mfilter($mock_images, 'getIsObsolete', true); 132 132 $mock->attachImages(msort($active_images, 'getSequence'));
+27 -12
src/applications/pholio/storage/PholioImage.php
··· 6 6 PhabricatorExtendedPolicyInterface { 7 7 8 8 protected $authorPHID; 9 - protected $mockID; 9 + protected $mockPHID; 10 10 protected $filePHID; 11 11 protected $name; 12 12 protected $description; ··· 29 29 return array( 30 30 self::CONFIG_AUX_PHID => true, 31 31 self::CONFIG_COLUMN_SCHEMA => array( 32 - 'mockID' => 'id?', 32 + 'mockPHID' => 'phid?', 33 33 'name' => 'text128', 34 34 'description' => 'text', 35 35 'sequence' => 'uint32', ··· 37 37 'replacesImagePHID' => 'phid?', 38 38 ), 39 39 self::CONFIG_KEY_SCHEMA => array( 40 - 'key_phid' => null, 41 - 'keyPHID' => array( 42 - 'columns' => array('phid'), 43 - 'unique' => true, 44 - ), 45 - 'mockID' => array( 46 - 'columns' => array('mockID', 'isObsolete', 'sequence'), 47 - ), 40 + // TODO: There should be a key starting with "mockPHID" here at a 41 + // minimum, but it's not entirely clear what other columns we should 42 + // have as part of the key. 48 43 ), 49 44 ) + parent::getConfiguration(); 50 45 } ··· 71 66 return $this->assertAttached($this->mock); 72 67 } 73 68 69 + public function hasMock() { 70 + return (bool)$this->getMockPHID(); 71 + } 72 + 74 73 public function attachInlineComments(array $inline_comments) { 75 74 assert_instances_of($inline_comments, 'PholioTransactionComment'); 76 75 $this->inlineComments = $inline_comments; ··· 82 81 return $this->inlineComments; 83 82 } 84 83 84 + public function getURI() { 85 + if ($this->hasMock()) { 86 + $mock = $this->getMock(); 87 + 88 + $mock_uri = $mock->getURI(); 89 + $image_id = $this->getID(); 90 + 91 + return "{$mock_uri}/{$image_id}/"; 92 + } 93 + 94 + // For now, standalone images have no URI. We could provide one at some 95 + // point, although it's not clear that there's any motivation to do so. 96 + 97 + return null; 98 + } 99 + 85 100 86 101 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 87 102 ··· 96 111 public function getPolicy($capability) { 97 112 // If the image is attached to a mock, we use an extended policy to match 98 113 // the mock's permissions. 99 - if ($this->getMockID()) { 114 + if ($this->hasMock()) { 100 115 return PhabricatorPolicies::getMostOpenPolicy(); 101 116 } 102 117 ··· 113 128 114 129 115 130 public function getExtendedPolicy($capability, PhabricatorUser $viewer) { 116 - if ($this->getMockID()) { 131 + if ($this->hasMock()) { 117 132 return array( 118 133 array( 119 134 $this->getMock(),
+1 -1
src/applications/pholio/storage/PholioMock.php
··· 259 259 $this->openTransaction(); 260 260 $images = id(new PholioImageQuery()) 261 261 ->setViewer($engine->getViewer()) 262 - ->withMockIDs(array($this->getID())) 262 + ->withMockIDs(array($this->getPHID())) 263 263 ->execute(); 264 264 foreach ($images as $image) { 265 265 $image->delete();