Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15368725
D7513.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D7513.diff
View Options
Index: resources/sql/patches/20131106.diffphid.1.col.sql
===================================================================
--- /dev/null
+++ resources/sql/patches/20131106.diffphid.1.col.sql
@@ -0,0 +1,2 @@
+ALTER TABLE {$NAMESPACE}_differential.differential_diff
+ ADD phid VARCHAR(64) NOT NULL COLLATE utf8_bin AFTER id;
Index: resources/sql/patches/20131106.diffphid.2.mig.php
===================================================================
--- /dev/null
+++ resources/sql/patches/20131106.diffphid.2.mig.php
@@ -0,0 +1,47 @@
+<?php
+
+$diff_table = new DifferentialDiff();
+$conn_w = $diff_table->establishConnection('w');
+
+$size = 1000;
+
+$row_iter = id(new LiskMigrationIterator($diff_table))->setPageSize($size);
+$chunk_iter = new PhutilChunkedIterator($row_iter, $size);
+
+foreach ($chunk_iter as $chunk) {
+ $sql = array();
+
+ foreach ($chunk as $diff) {
+ $id = $diff->getID();
+ echo "Migrating diff ID {$id}...\n";
+
+ $phid = $diff->getPHID();
+ if (strlen($phid)) {
+ continue;
+ }
+
+ $type_diff = DifferentialPHIDTypeDiff::TYPECONST;
+ $new_phid = PhabricatorPHID::generateNewPHID($type_diff);
+
+ $sql[] = qsprintf(
+ $conn_w,
+ '(%d, %s)',
+ $id,
+ $new_phid);
+ }
+
+ if (!$sql) {
+ continue;
+ }
+
+ foreach (PhabricatorLiskDAO::chunkSQL($sql, ', ') as $sql_chunk) {
+ queryfx(
+ $conn_w,
+ 'INSERT IGNORE INTO %T (id, phid) VALUES %Q
+ ON DUPLICATE KEY UPDATE phid = VALUES(phid)',
+ $diff_table->getTableName(),
+ $sql_chunk);
+ }
+}
+
+echo "Done.\n";
Index: resources/sql/patches/20131106.diffphid.3.key.sql
===================================================================
--- /dev/null
+++ resources/sql/patches/20131106.diffphid.3.key.sql
@@ -0,0 +1,2 @@
+ALTER TABLE {$NAMESPACE}_differential.differential_diff
+ ADD UNIQUE KEY `key_phid` (phid);
Index: src/__phutil_library_map__.php
===================================================================
--- src/__phutil_library_map__.php
+++ src/__phutil_library_map__.php
@@ -396,6 +396,7 @@
'DifferentialMailPhase' => 'applications/differential/constants/DifferentialMailPhase.php',
'DifferentialManiphestTasksFieldSpecification' => 'applications/differential/field/specification/DifferentialManiphestTasksFieldSpecification.php',
'DifferentialNewDiffMail' => 'applications/differential/mail/DifferentialNewDiffMail.php',
+ 'DifferentialPHIDTypeDiff' => 'applications/differential/phid/DifferentialPHIDTypeDiff.php',
'DifferentialPHIDTypeRevision' => 'applications/differential/phid/DifferentialPHIDTypeRevision.php',
'DifferentialParseRenderTestCase' => 'applications/differential/__tests__/DifferentialParseRenderTestCase.php',
'DifferentialPathFieldSpecification' => 'applications/differential/field/specification/DifferentialPathFieldSpecification.php',
@@ -2606,6 +2607,7 @@
'DifferentialMail' => 'PhabricatorMail',
'DifferentialManiphestTasksFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialNewDiffMail' => 'DifferentialReviewRequestMail',
+ 'DifferentialPHIDTypeDiff' => 'PhabricatorPHIDType',
'DifferentialPHIDTypeRevision' => 'PhabricatorPHIDType',
'DifferentialParseRenderTestCase' => 'PhabricatorTestCase',
'DifferentialPathFieldSpecification' => 'DifferentialFieldSpecification',
Index: src/applications/differential/phid/DifferentialPHIDTypeDiff.php
===================================================================
--- /dev/null
+++ src/applications/differential/phid/DifferentialPHIDTypeDiff.php
@@ -0,0 +1,45 @@
+<?php
+
+final class DifferentialPHIDTypeDiff extends PhabricatorPHIDType {
+
+ const TYPECONST = 'DIFF';
+
+ public function getTypeConstant() {
+ return self::TYPECONST;
+ }
+
+ public function getTypeName() {
+ return pht('Differential Diff');
+ }
+
+ public function newObject() {
+ return new DifferentialDiff();
+ }
+
+ protected function buildQueryForObjects(
+ PhabricatorObjectQuery $query,
+ array $phids) {
+
+ return id(new DifferentialDiffQuery())
+ ->withPHIDs($phids);
+ }
+
+ public function loadHandles(
+ PhabricatorHandleQuery $query,
+ array $handles,
+ array $objects) {
+
+ foreach ($handles as $phid => $handle) {
+ $diff = $objects[$phid];
+
+ $id = $diff->getID();
+
+ $handle->setName(pht('Diff %d', $id));
+ }
+ }
+
+ public function canLoadNamedObject($name) {
+ return false;
+ }
+
+}
Index: src/applications/differential/query/DifferentialDiffQuery.php
===================================================================
--- src/applications/differential/query/DifferentialDiffQuery.php
+++ src/applications/differential/query/DifferentialDiffQuery.php
@@ -4,6 +4,7 @@
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
+ private $phids;
private $revisionIDs;
private $needChangesets = false;
private $needArcanistProjects = false;
@@ -13,6 +14,11 @@
return $this;
}
+ public function withPHIDs(array $phids) {
+ $this->phids = $phids;
+ return $this;
+ }
+
public function withRevisionIDs(array $revision_ids) {
$this->revisionIDs = $revision_ids;
return $this;
@@ -126,6 +132,13 @@
$this->ids);
}
+ if ($this->phids) {
+ $where[] = qsprintf(
+ $conn_r,
+ 'phid IN (%Ls)',
+ $this->phids);
+ }
+
if ($this->revisionIDs) {
$where[] = qsprintf(
$conn_r,
Index: src/applications/differential/storage/DifferentialDiff.php
===================================================================
--- src/applications/differential/storage/DifferentialDiff.php
+++ src/applications/differential/storage/DifferentialDiff.php
@@ -34,6 +34,17 @@
private $arcanistProject = self::ATTACHABLE;
private $revision = self::ATTACHABLE;
+ public function getConfiguration() {
+ return array(
+ self::CONFIG_AUX_PHID => true,
+ ) + parent::getConfiguration();
+ }
+
+ public function generatePHID() {
+ return PhabricatorPHID::generateNewPHID(
+ DifferentialPHIDTypeDiff::TYPECONST);
+ }
+
public function addUnsavedChangeset(DifferentialChangeset $changeset) {
if ($this->changesets === null) {
$this->changesets = array();
Index: src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
===================================================================
--- src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
+++ src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
@@ -1724,6 +1724,18 @@
'type' => 'sql',
'name' => $this->getPatchPath('20131105.buildstep.sql'),
),
+ '20131106.diffphid.1.col.sql' => array(
+ 'type' => 'sql',
+ 'name' => $this->getPatchPath('20131106.diffphid.1.col.sql'),
+ ),
+ '20131106.diffphid.2.mig.php' => array(
+ 'type' => 'php',
+ 'name' => $this->getPatchPath('20131106.diffphid.2.mig.php'),
+ ),
+ '20131106.diffphid.3.key.sql' => array(
+ 'type' => 'sql',
+ 'name' => $this->getPatchPath('20131106.diffphid.3.key.sql'),
+ ),
);
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Mar 13, 3:30 AM (1 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7602483
Default Alt Text
D7513.diff (6 KB)
Attached To
Mode
D7513: Assign PHIDs to all diffs
Attached
Detach File
Event Timeline
Log In to Comment