Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F79803
D7513.diff
All Users
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D7513.diff
View Options
diff --git a/resources/sql/patches/20131106.diffphid.1.col.sql b/resources/sql/patches/20131106.diffphid.1.col.sql
new file mode 100644
--- /dev/null
+++ b/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;
diff --git a/resources/sql/patches/20131106.diffphid.2.mig.php b/resources/sql/patches/20131106.diffphid.2.mig.php
new file mode 100644
--- /dev/null
+++ b/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";
diff --git a/resources/sql/patches/20131106.diffphid.3.key.sql b/resources/sql/patches/20131106.diffphid.3.key.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/patches/20131106.diffphid.3.key.sql
@@ -0,0 +1,2 @@
+ALTER TABLE {$NAMESPACE}_differential.differential_diff
+ ADD UNIQUE KEY `key_phid` (phid);
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/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',
diff --git a/src/applications/differential/phid/DifferentialPHIDTypeDiff.php b/src/applications/differential/phid/DifferentialPHIDTypeDiff.php
new file mode 100644
--- /dev/null
+++ b/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;
+ }
+
+}
diff --git a/src/applications/differential/query/DifferentialDiffQuery.php b/src/applications/differential/query/DifferentialDiffQuery.php
--- a/src/applications/differential/query/DifferentialDiffQuery.php
+++ b/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,
diff --git a/src/applications/differential/storage/DifferentialDiff.php b/src/applications/differential/storage/DifferentialDiff.php
--- a/src/applications/differential/storage/DifferentialDiff.php
+++ b/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();
diff --git a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
--- a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
+++ b/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/x-diff
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/ck/ha/u54zemkn76ukiwvh
Default Alt Text
D7513.diff (7 KB)
Attached To
Mode
D7513: Assign PHIDs to all diffs
Attached
Detach File
Event Timeline
Log In to Comment