From f28d3089d7d84a86f80306b530d14f4949e35390 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 17 Dec 2013 15:23:23 -0800 Subject: [PATCH] Assign PHIDs to PushLogs Summary: Ref T4195. We need these in Herald, since HeraldTranscripts need to refer to a PHID which they acted upon. Test Plan: Ran migration, got PHIDs: mysql> select phid from repository_pushlog limit 3; +--------------------------------+ | phid | +--------------------------------+ | PHID-PSHL-25jnc6cjgzw5rwqgmr7r | | PHID-PSHL-2vrvmtslkrj5yv7nxsv2 | | PHID-PSHL-34x262zkrwoka6mplony | +--------------------------------+ 3 rows in set (0.00 sec) Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T4195 Differential Revision: https://secure.phabricator.com/D7780 --- .../patches/20131217.pushlogphid.1.col.sql | 2 + .../patches/20131217.pushlogphid.2.mig.php | 20 +++++++++ .../patches/20131217.pushlogphid.3.key.sql | 2 + src/__phutil_library_map__.php | 2 + .../PhabricatorRepositoryPHIDTypePushLog.php | 44 +++++++++++++++++++ .../storage/PhabricatorRepositoryPushLog.php | 6 +++ .../patch/PhabricatorBuiltinPatchList.php | 12 +++++ 7 files changed, 88 insertions(+) create mode 100644 resources/sql/patches/20131217.pushlogphid.1.col.sql create mode 100644 resources/sql/patches/20131217.pushlogphid.2.mig.php create mode 100644 resources/sql/patches/20131217.pushlogphid.3.key.sql create mode 100644 src/applications/repository/phid/PhabricatorRepositoryPHIDTypePushLog.php diff --git a/resources/sql/patches/20131217.pushlogphid.1.col.sql b/resources/sql/patches/20131217.pushlogphid.1.col.sql new file mode 100644 index 0000000000..d52daa2b27 --- /dev/null +++ b/resources/sql/patches/20131217.pushlogphid.1.col.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_repository.repository_pushlog + ADD phid VARCHAR(64) NOT NULL COLLATE utf8_bin AFTER id; diff --git a/resources/sql/patches/20131217.pushlogphid.2.mig.php b/resources/sql/patches/20131217.pushlogphid.2.mig.php new file mode 100644 index 0000000000..edda8d346d --- /dev/null +++ b/resources/sql/patches/20131217.pushlogphid.2.mig.php @@ -0,0 +1,20 @@ +establishConnection('w'); + +echo "Assigning PHIDs to push logs...\n"; + +$logs = new LiskMigrationIterator($table); +foreach ($logs as $log) { + $id = $log->getID(); + echo "Updating {$id}...\n"; + queryfx( + $conn_w, + 'UPDATE %T SET phid = %s WHERE id = %d', + $table->getTableName(), + $log->generatePHID(), + $id); +} + +echo "Done.\n"; diff --git a/resources/sql/patches/20131217.pushlogphid.3.key.sql b/resources/sql/patches/20131217.pushlogphid.3.key.sql new file mode 100644 index 0000000000..6e618cb5c6 --- /dev/null +++ b/resources/sql/patches/20131217.pushlogphid.3.key.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_repository.repository_pushlog + ADD UNIQUE KEY `key_phid` (phid); diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 3d9bdd11c2..bfd60ed692 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1798,6 +1798,7 @@ phutil_register_library_map(array( 'PhabricatorRepositoryPHIDTypeArcanistProject' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeArcanistProject.php', 'PhabricatorRepositoryPHIDTypeCommit' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeCommit.php', 'PhabricatorRepositoryPHIDTypeMirror' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeMirror.php', + 'PhabricatorRepositoryPHIDTypePushLog' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypePushLog.php', 'PhabricatorRepositoryPHIDTypeRepository' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeRepository.php', 'PhabricatorRepositoryPullEngine' => 'applications/repository/engine/PhabricatorRepositoryPullEngine.php', 'PhabricatorRepositoryPullLocalDaemon' => 'applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php', @@ -4363,6 +4364,7 @@ phutil_register_library_map(array( 'PhabricatorRepositoryPHIDTypeArcanistProject' => 'PhabricatorPHIDType', 'PhabricatorRepositoryPHIDTypeCommit' => 'PhabricatorPHIDType', 'PhabricatorRepositoryPHIDTypeMirror' => 'PhabricatorPHIDType', + 'PhabricatorRepositoryPHIDTypePushLog' => 'PhabricatorPHIDType', 'PhabricatorRepositoryPHIDTypeRepository' => 'PhabricatorPHIDType', 'PhabricatorRepositoryPullEngine' => 'PhabricatorRepositoryEngine', 'PhabricatorRepositoryPullLocalDaemon' => 'PhabricatorDaemon', diff --git a/src/applications/repository/phid/PhabricatorRepositoryPHIDTypePushLog.php b/src/applications/repository/phid/PhabricatorRepositoryPHIDTypePushLog.php new file mode 100644 index 0000000000..34ff1ebc63 --- /dev/null +++ b/src/applications/repository/phid/PhabricatorRepositoryPHIDTypePushLog.php @@ -0,0 +1,44 @@ +withPHIDs($phids); + } + + public function loadHandles( + PhabricatorHandleQuery $query, + array $handles, + array $objects) { + + foreach ($handles as $phid => $handle) { + $log = $objects[$phid]; + + $handle->setName(pht('Push Log %d', $log->getID())); + } + } + + public function canLoadNamedObject($name) { + return false; + } + +} diff --git a/src/applications/repository/storage/PhabricatorRepositoryPushLog.php b/src/applications/repository/storage/PhabricatorRepositoryPushLog.php index eceed50946..75747a4ef0 100644 --- a/src/applications/repository/storage/PhabricatorRepositoryPushLog.php +++ b/src/applications/repository/storage/PhabricatorRepositoryPushLog.php @@ -57,10 +57,16 @@ final class PhabricatorRepositoryPushLog public function getConfiguration() { return array( + self::CONFIG_AUX_PHID => true, self::CONFIG_TIMESTAMPS => false, ) + parent::getConfiguration(); } + public function generatePHID() { + return PhabricatorPHID::generateNewPHID( + PhabricatorRepositoryPHIDTypePushLog::TYPECONST); + } + public function attachRepository(PhabricatorRepository $repository) { $this->repository = $repository; return $this; diff --git a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php index 9d7e85c4e2..fedec040fb 100644 --- a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php +++ b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php @@ -1832,6 +1832,18 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList { 'type' => 'sql', 'name' => $this->getPatchPath('20131211.phragmentedges.sql'), ), + '20131217.pushlogphid.1.col.sql' => array( + 'type' => 'sql', + 'name' => $this->getPatchPath('20131217.pushlogphid.1.col.sql'), + ), + '20131217.pushlogphid.2.mig.php' => array( + 'type' => 'php', + 'name' => $this->getPatchPath('20131217.pushlogphid.2.mig.php'), + ), + '20131217.pushlogphid.3.key.sql' => array( + 'type' => 'sql', + 'name' => $this->getPatchPath('20131217.pushlogphid.3.key.sql'), + ), ); } }