mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-09 16:32:39 +01:00
Convert revision unsubscribers to edges
Test Plan: Ran the migration on a single revision, verified DB, called `loadUnsubscribedPHIDs()`. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D4786
This commit is contained in:
parent
ccb206e984
commit
8c99938aad
5 changed files with 56 additions and 16 deletions
33
resources/sql/patches/20130201.revisionunsubscribed.php
Normal file
33
resources/sql/patches/20130201.revisionunsubscribed.php
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
echo "Migrating Differential unsubscribed users to edges...\n";
|
||||
$table = new DifferentialRevision();
|
||||
$table->openTransaction();
|
||||
|
||||
// We couldn't use new LiskMigrationIterator($table) because the $unsubscribed
|
||||
// property gets deleted.
|
||||
$revs = queryfx_all(
|
||||
$table->establishConnection('w'),
|
||||
'SELECT id, phid, unsubscribed FROM differential_revision');
|
||||
|
||||
foreach ($revs as $rev) {
|
||||
echo ".";
|
||||
|
||||
$unsubscribed = json_decode($rev['unsubscribed']);
|
||||
if (!$unsubscribed) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$editor = new PhabricatorEdgeEditor();
|
||||
$editor->setSuppressEvents(true);
|
||||
foreach ($unsubscribed as $user_phid => $_) {
|
||||
$editor->addEdge(
|
||||
$rev['phid'],
|
||||
PhabricatorEdgeConfig::TYPE_OBJECT_HAS_UNSUBSCRIBER,
|
||||
$user_phid);
|
||||
}
|
||||
$editor->save();
|
||||
}
|
||||
|
||||
$table->saveTransaction();
|
||||
echo "Done.\n";
|
2
resources/sql/patches/20130201.revisionunsubscribed.sql
Normal file
2
resources/sql/patches/20130201.revisionunsubscribed.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE {$NAMESPACE}_differential.differential_revision
|
||||
DROP unsubscribed;
|
|
@ -238,7 +238,7 @@ final class DifferentialRevisionEditor extends PhabricatorEditor {
|
|||
$diff);
|
||||
$adapter->setExplicitCCs($new['ccs']);
|
||||
$adapter->setExplicitReviewers($new['rev']);
|
||||
$adapter->setForbiddenCCs($revision->getUnsubscribedPHIDs());
|
||||
$adapter->setForbiddenCCs($revision->loadUnsubscribedPHIDs());
|
||||
|
||||
$xscript = HeraldEngine::loadAndApplyRules($adapter);
|
||||
$xscript_uri = '/herald/transcript/'.$xscript->getID().'/';
|
||||
|
@ -500,12 +500,10 @@ final class DifferentialRevisionEditor extends PhabricatorEditor {
|
|||
|
||||
self::addCC($revision, $phid, $reason);
|
||||
|
||||
$unsubscribed = $revision->getUnsubscribed();
|
||||
if (isset($unsubscribed[$phid])) {
|
||||
unset($unsubscribed[$phid]);
|
||||
$revision->setUnsubscribed($unsubscribed);
|
||||
$revision->save();
|
||||
}
|
||||
$type = PhabricatorEdgeConfig::TYPE_OBJECT_HAS_UNSUBSCRIBER;
|
||||
id(new PhabricatorEdgeEditor())
|
||||
->removeEdge($revision->getPHID(), $type, $phid)
|
||||
->save();
|
||||
}
|
||||
|
||||
public static function removeCCAndUpdateRevision(
|
||||
|
@ -515,12 +513,10 @@ final class DifferentialRevisionEditor extends PhabricatorEditor {
|
|||
|
||||
self::removeCC($revision, $phid, $reason);
|
||||
|
||||
$unsubscribed = $revision->getUnsubscribed();
|
||||
if (empty($unsubscribed[$phid])) {
|
||||
$unsubscribed[$phid] = true;
|
||||
$revision->setUnsubscribed($unsubscribed);
|
||||
$revision->save();
|
||||
}
|
||||
$type = PhabricatorEdgeConfig::TYPE_OBJECT_HAS_UNSUBSCRIBER;
|
||||
id(new PhabricatorEdgeEditor())
|
||||
->addEdge($revision->getPHID(), $type, $phid)
|
||||
->save();
|
||||
}
|
||||
|
||||
public static function addCC(
|
||||
|
|
|
@ -17,7 +17,6 @@ final class DifferentialRevision extends DifferentialDAO {
|
|||
|
||||
protected $lineCount;
|
||||
protected $attached = array();
|
||||
protected $unsubscribed = array();
|
||||
|
||||
protected $mailKey;
|
||||
protected $branchName;
|
||||
|
@ -264,8 +263,10 @@ final class DifferentialRevision extends DifferentialDAO {
|
|||
return idx($this->relationships, $relation, array());
|
||||
}
|
||||
|
||||
public function getUnsubscribedPHIDs() {
|
||||
return array_keys($this->getUnsubscribed());
|
||||
public function loadUnsubscribedPHIDs() {
|
||||
return PhabricatorEdgeQuery::loadDestinationPHIDs(
|
||||
$this->phid,
|
||||
PhabricatorEdgeConfig::TYPE_OBJECT_HAS_UNSUBSCRIBER);
|
||||
}
|
||||
|
||||
public function getPrimaryReviewer() {
|
||||
|
|
|
@ -1097,6 +1097,14 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
|
|||
'type' => 'sql',
|
||||
'name' => $this->getPatchPath('20130127.altheraldtranscript.sql'),
|
||||
),
|
||||
'20130201.revisionunsubscribed.php' => array(
|
||||
'type' => 'php',
|
||||
'name' => $this->getPatchPath('20130201.revisionunsubscribed.php'),
|
||||
),
|
||||
'20130201.revisionunsubscribed.sql' => array(
|
||||
'type' => 'sql',
|
||||
'name' => $this->getPatchPath('20130201.revisionunsubscribed.sql'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue