1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 06:42:42 +01:00

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
This commit is contained in:
epriestley 2021-02-15 10:04:47 -08:00
parent 42c26821ef
commit ec5476a01f
5 changed files with 76 additions and 0 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_differential.differential_changeset
ADD phid VARBINARY(64) NOT NULL;

View file

@ -0,0 +1,26 @@
<?php
$phid_type = DifferentialChangesetPHIDType::TYPECONST;
$changeset_table = new DifferentialChangeset();
$conn = $changeset_table->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']);
}

View file

@ -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',

View file

@ -0,0 +1,41 @@
<?php
final class DifferentialChangesetPHIDType extends PhabricatorPHIDType {
const TYPECONST = 'DCNG';
public function getTypeName() {
return pht('Differential Changeset');
}
public function newObject() {
return new DifferentialChangeset();
}
public function getPHIDTypeApplicationClass() {
return 'PhabricatorDifferentialApplication';
}
protected function buildQueryForObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new DifferentialChangesetQuery())
->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));
}
}
}

View file

@ -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();
}