From ec5476a01f5fd7dc559fce0a129c8cf73dd690da Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 15 Feb 2021 10:04:47 -0800 Subject: [PATCH] Add a PHID to Changesets Summary: Ref T13605. Changesets currently have no PHID, which limits their ability to use standard API infrastructure. Give them a PHID, since there's no reason they don't have one other than their age. Test Plan: - Ran migrations, saw PHIDs populated. - Created new changesets, saw PHIDs. Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13605 Differential Revision: https://secure.phabricator.com/D21557 --- .../20210215.changeset.01.phid.sql | 2 + .../20210215.changeset.02.phid-populate.php | 26 ++++++++++++ src/__phutil_library_map__.php | 2 + .../phid/DifferentialChangesetPHIDType.php | 41 +++++++++++++++++++ .../storage/DifferentialChangeset.php | 5 +++ 5 files changed, 76 insertions(+) create mode 100644 resources/sql/autopatches/20210215.changeset.01.phid.sql create mode 100644 resources/sql/autopatches/20210215.changeset.02.phid-populate.php create mode 100644 src/applications/differential/phid/DifferentialChangesetPHIDType.php diff --git a/resources/sql/autopatches/20210215.changeset.01.phid.sql b/resources/sql/autopatches/20210215.changeset.01.phid.sql new file mode 100644 index 0000000000..25cab7805a --- /dev/null +++ b/resources/sql/autopatches/20210215.changeset.01.phid.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_differential.differential_changeset + ADD phid VARBINARY(64) NOT NULL; diff --git a/resources/sql/autopatches/20210215.changeset.02.phid-populate.php b/resources/sql/autopatches/20210215.changeset.02.phid-populate.php new file mode 100644 index 0000000000..da64650006 --- /dev/null +++ b/resources/sql/autopatches/20210215.changeset.02.phid-populate.php @@ -0,0 +1,26 @@ +establishConnection('w'); +$table_name = $changeset_table->getTableName(); + +$iterator = new LiskRawMigrationIterator($conn, $table_name); +foreach ($iterator as $changeset_row) { + $phid = $changeset_row['phid']; + + if (strlen($phid)) { + continue; + } + + $phid = PhabricatorPHID::generateNewPHID($phid_type); + + queryfx( + $conn, + 'UPDATE %T SET phid = %s WHERE id = %d', + $table_name, + $phid, + $changeset_row['id']); +} diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 57e9a22a57..847001dd46 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -472,6 +472,7 @@ phutil_register_library_map(array( 'DifferentialChangesetOneUpMailRenderer' => 'applications/differential/render/DifferentialChangesetOneUpMailRenderer.php', 'DifferentialChangesetOneUpRenderer' => 'applications/differential/render/DifferentialChangesetOneUpRenderer.php', 'DifferentialChangesetOneUpTestRenderer' => 'applications/differential/render/DifferentialChangesetOneUpTestRenderer.php', + 'DifferentialChangesetPHIDType' => 'applications/differential/phid/DifferentialChangesetPHIDType.php', 'DifferentialChangesetParser' => 'applications/differential/parser/DifferentialChangesetParser.php', 'DifferentialChangesetParserTestCase' => 'applications/differential/parser/__tests__/DifferentialChangesetParserTestCase.php', 'DifferentialChangesetQuery' => 'applications/differential/query/DifferentialChangesetQuery.php', @@ -6541,6 +6542,7 @@ phutil_register_library_map(array( 'DifferentialChangesetOneUpMailRenderer' => 'DifferentialChangesetRenderer', 'DifferentialChangesetOneUpRenderer' => 'DifferentialChangesetHTMLRenderer', 'DifferentialChangesetOneUpTestRenderer' => 'DifferentialChangesetTestRenderer', + 'DifferentialChangesetPHIDType' => 'PhabricatorPHIDType', 'DifferentialChangesetParser' => 'Phobject', 'DifferentialChangesetParserTestCase' => 'PhabricatorTestCase', 'DifferentialChangesetQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', diff --git a/src/applications/differential/phid/DifferentialChangesetPHIDType.php b/src/applications/differential/phid/DifferentialChangesetPHIDType.php new file mode 100644 index 0000000000..c558c0a6a2 --- /dev/null +++ b/src/applications/differential/phid/DifferentialChangesetPHIDType.php @@ -0,0 +1,41 @@ +withPHIDs($phids); + } + + public function loadHandles( + PhabricatorHandleQuery $query, + array $handles, + array $objects) { + + foreach ($handles as $phid => $handle) { + $changeset = $objects[$phid]; + + $id = $changeset->getID(); + + $handle->setName(pht('Changeset %d', $id)); + } + } + +} diff --git a/src/applications/differential/storage/DifferentialChangeset.php b/src/applications/differential/storage/DifferentialChangeset.php index d7d66ae97d..add76cd7bf 100644 --- a/src/applications/differential/storage/DifferentialChangeset.php +++ b/src/applications/differential/storage/DifferentialChangeset.php @@ -45,6 +45,7 @@ final class DifferentialChangeset protected function getConfiguration() { return array( + self::CONFIG_AUX_PHID => true, self::CONFIG_SERIALIZATION => array( 'metadata' => self::SERIALIZATION_JSON, 'oldProperties' => self::SERIALIZATION_JSON, @@ -75,6 +76,10 @@ final class DifferentialChangeset ) + parent::getConfiguration(); } + public function getPHIDType() { + return DifferentialChangesetPHIDType::TYPECONST; + } + public function getAffectedLineCount() { return $this->getAddLines() + $this->getDelLines(); }