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

Assign PHIDs to all diffs

Summary:
Ref T1049. Ref T2222. `DifferentialDiff` does not currently have a PHID, but we need it for Harbormaster and ApplicationTransactions. See some discussion in D7501.

(I split the SQL into two sections so we can't fail in the middle. At some point, I'd like to do a pass on the migration stuff and get this happening automatically, and also simplify the PatchList.)

Test Plan:
- Ran `bin/storage upgrade`.
- Checked for valid PHIDs in the database.
- Used `phid.query` to look up a diff by PHID.
- Created a new diff and verified it got a PHID.

Reviewers: btrahan, hach-que

Reviewed By: btrahan

CC: aran, vrana

Maniphest Tasks: T2222, T1049

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

+134
+2
resources/sql/patches/20131106.diffphid.1.col.sql
··· 1 + ALTER TABLE {$NAMESPACE}_differential.differential_diff 2 + ADD phid VARCHAR(64) NOT NULL COLLATE utf8_bin AFTER id;
+47
resources/sql/patches/20131106.diffphid.2.mig.php
··· 1 + <?php 2 + 3 + $diff_table = new DifferentialDiff(); 4 + $conn_w = $diff_table->establishConnection('w'); 5 + 6 + $size = 1000; 7 + 8 + $row_iter = id(new LiskMigrationIterator($diff_table))->setPageSize($size); 9 + $chunk_iter = new PhutilChunkedIterator($row_iter, $size); 10 + 11 + foreach ($chunk_iter as $chunk) { 12 + $sql = array(); 13 + 14 + foreach ($chunk as $diff) { 15 + $id = $diff->getID(); 16 + echo "Migrating diff ID {$id}...\n"; 17 + 18 + $phid = $diff->getPHID(); 19 + if (strlen($phid)) { 20 + continue; 21 + } 22 + 23 + $type_diff = DifferentialPHIDTypeDiff::TYPECONST; 24 + $new_phid = PhabricatorPHID::generateNewPHID($type_diff); 25 + 26 + $sql[] = qsprintf( 27 + $conn_w, 28 + '(%d, %s)', 29 + $id, 30 + $new_phid); 31 + } 32 + 33 + if (!$sql) { 34 + continue; 35 + } 36 + 37 + foreach (PhabricatorLiskDAO::chunkSQL($sql, ', ') as $sql_chunk) { 38 + queryfx( 39 + $conn_w, 40 + 'INSERT IGNORE INTO %T (id, phid) VALUES %Q 41 + ON DUPLICATE KEY UPDATE phid = VALUES(phid)', 42 + $diff_table->getTableName(), 43 + $sql_chunk); 44 + } 45 + } 46 + 47 + echo "Done.\n";
+2
resources/sql/patches/20131106.diffphid.3.key.sql
··· 1 + ALTER TABLE {$NAMESPACE}_differential.differential_diff 2 + ADD UNIQUE KEY `key_phid` (phid);
+2
src/__phutil_library_map__.php
··· 396 396 'DifferentialMailPhase' => 'applications/differential/constants/DifferentialMailPhase.php', 397 397 'DifferentialManiphestTasksFieldSpecification' => 'applications/differential/field/specification/DifferentialManiphestTasksFieldSpecification.php', 398 398 'DifferentialNewDiffMail' => 'applications/differential/mail/DifferentialNewDiffMail.php', 399 + 'DifferentialPHIDTypeDiff' => 'applications/differential/phid/DifferentialPHIDTypeDiff.php', 399 400 'DifferentialPHIDTypeRevision' => 'applications/differential/phid/DifferentialPHIDTypeRevision.php', 400 401 'DifferentialParseRenderTestCase' => 'applications/differential/__tests__/DifferentialParseRenderTestCase.php', 401 402 'DifferentialPathFieldSpecification' => 'applications/differential/field/specification/DifferentialPathFieldSpecification.php', ··· 2606 2607 'DifferentialMail' => 'PhabricatorMail', 2607 2608 'DifferentialManiphestTasksFieldSpecification' => 'DifferentialFieldSpecification', 2608 2609 'DifferentialNewDiffMail' => 'DifferentialReviewRequestMail', 2610 + 'DifferentialPHIDTypeDiff' => 'PhabricatorPHIDType', 2609 2611 'DifferentialPHIDTypeRevision' => 'PhabricatorPHIDType', 2610 2612 'DifferentialParseRenderTestCase' => 'PhabricatorTestCase', 2611 2613 'DifferentialPathFieldSpecification' => 'DifferentialFieldSpecification',
+45
src/applications/differential/phid/DifferentialPHIDTypeDiff.php
··· 1 + <?php 2 + 3 + final class DifferentialPHIDTypeDiff extends PhabricatorPHIDType { 4 + 5 + const TYPECONST = 'DIFF'; 6 + 7 + public function getTypeConstant() { 8 + return self::TYPECONST; 9 + } 10 + 11 + public function getTypeName() { 12 + return pht('Differential Diff'); 13 + } 14 + 15 + public function newObject() { 16 + return new DifferentialDiff(); 17 + } 18 + 19 + protected function buildQueryForObjects( 20 + PhabricatorObjectQuery $query, 21 + array $phids) { 22 + 23 + return id(new DifferentialDiffQuery()) 24 + ->withPHIDs($phids); 25 + } 26 + 27 + public function loadHandles( 28 + PhabricatorHandleQuery $query, 29 + array $handles, 30 + array $objects) { 31 + 32 + foreach ($handles as $phid => $handle) { 33 + $diff = $objects[$phid]; 34 + 35 + $id = $diff->getID(); 36 + 37 + $handle->setName(pht('Diff %d', $id)); 38 + } 39 + } 40 + 41 + public function canLoadNamedObject($name) { 42 + return false; 43 + } 44 + 45 + }
+13
src/applications/differential/query/DifferentialDiffQuery.php
··· 4 4 extends PhabricatorCursorPagedPolicyAwareQuery { 5 5 6 6 private $ids; 7 + private $phids; 7 8 private $revisionIDs; 8 9 private $needChangesets = false; 9 10 private $needArcanistProjects = false; 10 11 11 12 public function withIDs(array $ids) { 12 13 $this->ids = $ids; 14 + return $this; 15 + } 16 + 17 + public function withPHIDs(array $phids) { 18 + $this->phids = $phids; 13 19 return $this; 14 20 } 15 21 ··· 124 130 $conn_r, 125 131 'id IN (%Ld)', 126 132 $this->ids); 133 + } 134 + 135 + if ($this->phids) { 136 + $where[] = qsprintf( 137 + $conn_r, 138 + 'phid IN (%Ls)', 139 + $this->phids); 127 140 } 128 141 129 142 if ($this->revisionIDs) {
+11
src/applications/differential/storage/DifferentialDiff.php
··· 34 34 private $arcanistProject = self::ATTACHABLE; 35 35 private $revision = self::ATTACHABLE; 36 36 37 + public function getConfiguration() { 38 + return array( 39 + self::CONFIG_AUX_PHID => true, 40 + ) + parent::getConfiguration(); 41 + } 42 + 43 + public function generatePHID() { 44 + return PhabricatorPHID::generateNewPHID( 45 + DifferentialPHIDTypeDiff::TYPECONST); 46 + } 47 + 37 48 public function addUnsavedChangeset(DifferentialChangeset $changeset) { 38 49 if ($this->changesets === null) { 39 50 $this->changesets = array();
+12
src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
··· 1724 1724 'type' => 'sql', 1725 1725 'name' => $this->getPatchPath('20131105.buildstep.sql'), 1726 1726 ), 1727 + '20131106.diffphid.1.col.sql' => array( 1728 + 'type' => 'sql', 1729 + 'name' => $this->getPatchPath('20131106.diffphid.1.col.sql'), 1730 + ), 1731 + '20131106.diffphid.2.mig.php' => array( 1732 + 'type' => 'php', 1733 + 'name' => $this->getPatchPath('20131106.diffphid.2.mig.php'), 1734 + ), 1735 + '20131106.diffphid.3.key.sql' => array( 1736 + 'type' => 'sql', 1737 + 'name' => $this->getPatchPath('20131106.diffphid.3.key.sql'), 1738 + ), 1727 1739 ); 1728 1740 } 1729 1741 }