1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 16:22:43 +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:
vrana 2013-02-01 16:48:10 -08:00
parent ccb206e984
commit 8c99938aad
5 changed files with 56 additions and 16 deletions

View 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";

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_differential.differential_revision
DROP unsubscribed;

View file

@ -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(

View file

@ -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() {

View file

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