mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 06:20:56 +01:00
fcb7286533
Summary: Migrate to `PhabricatorApplicationTransactions` (`ReleephRequestTransactions` applied by `ReleephRequestTransactionalEditor`, instead of `ReleephRequestEvents` created by `ReleephRequestEditor`) and migrate all the old events into transactions. Email is supported in the standard way (no more `ReleephRequestMail`) as well. This also collapses the Releeph request create and edit controllers into one class, as well as breaking everyone's subject-based mail rules by standardising them (but which should be more easily filtered by looking at headers.) Test Plan: * Make requests, then pick them. * Pick and revert the same request so that discovery happens way after `arc` has told Releeph about what's been happening. * Try to pick something that fails to pick in a project with pick instructions (and see the instructions are in the email.) * Load all of FB's Releeph data into my DB and run the `storage upgrade` script. * Request a commit via the "action" in a Differential revision. Reviewers: epriestley Reviewed By: epriestley CC: epriestley, aran, Korvin, wez Maniphest Tasks: T3092, T2720 Differential Revision: https://secure.phabricator.com/D5868
131 lines
4.2 KiB
PHP
131 lines
4.2 KiB
PHP
<?php
|
|
|
|
echo "Migrating Releeph requests events to transactions...\n";
|
|
|
|
$table = new ReleephRequest();
|
|
$table->openTransaction();
|
|
$table->beginReadLocking();
|
|
|
|
foreach (new LiskMigrationIterator($table) as $rq) {
|
|
printf("RQ%d:", $rq->getID());
|
|
|
|
$intents_cursor = array();
|
|
$last_pick_status = null;
|
|
$last_commit_id = null;
|
|
|
|
foreach ($rq->loadEvents() as $event) {
|
|
$author = $event->getActorPHID();
|
|
$details = $event->getDetails();
|
|
|
|
$content_source = PhabricatorContentSource::newForSource(
|
|
PhabricatorContentSource::SOURCE_UNKNOWN,
|
|
array('ReleephRequestEventID' => $event->getID()));
|
|
|
|
$xaction = id(new ReleephRequestTransaction())
|
|
->setObjectPHID($rq->getPHID())
|
|
->setAuthorPHID($author)
|
|
->setContentSource($content_source)
|
|
->setDateCreated($event->getDateCreated())
|
|
->setDateModified($event->getDateModified())
|
|
->setViewPolicy(PhabricatorPolicies::POLICY_PUBLIC)
|
|
->setEditPolicy($author);
|
|
|
|
printf(" %s(#%d)", $event->getType(), $event->getID());
|
|
|
|
switch ($event->getType()) {
|
|
case ReleephRequestEvent::TYPE_COMMENT:
|
|
$xaction
|
|
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
|
->save(); // to generate a PHID
|
|
$comment = id(new ReleephRequestTransactionComment())
|
|
->setAuthorPHID($author)
|
|
->setTransactionPHID($xaction->getPHID())
|
|
->setViewPolicy(PhabricatorPolicies::POLICY_PUBLIC)
|
|
->setEditPolicy($author)
|
|
->setCommentVersion(1)
|
|
->setContent($event->getComment())
|
|
->setContentSource($content_source)
|
|
->save();
|
|
$xaction
|
|
->setCommentPHID($comment->getPHID())
|
|
->setCommentVersion(1);
|
|
break;
|
|
|
|
case ReleephRequestEvent::TYPE_STATUS:
|
|
// Ignore STATUS events; these are legacy events that we no longer
|
|
// support anyway!
|
|
continue 2;
|
|
|
|
case ReleephRequestEvent::TYPE_USER_INTENT:
|
|
$old_intent = idx($intents_cursor, $author);
|
|
$new_intent = $event->getDetail('newIntent');
|
|
$xaction
|
|
->setTransactionType(ReleephRequestTransaction::TYPE_USER_INTENT)
|
|
->setMetadataValue('isAuthoritative', $event->getDetail('wasPusher'))
|
|
->setOldValue($old_intent)
|
|
->setNewValue($new_intent);
|
|
$intents_cursor[$author] = $new_intent;
|
|
break;
|
|
|
|
case ReleephRequestEvent::TYPE_PICK_STATUS:
|
|
$new_pick_status = $event->getDetail('newPickStatus');
|
|
$xaction
|
|
->setTransactionType(ReleephRequestTransaction::TYPE_PICK_STATUS)
|
|
->setOldValue($last_pick_status)
|
|
->setNewValue($new_pick_status);
|
|
$last_pick_status = $new_pick_status;
|
|
break;
|
|
|
|
case ReleephRequestEvent::TYPE_COMMIT:
|
|
$new_commit_id = $event->getDetail('newCommitIdentifier');
|
|
$xaction
|
|
->setTransactionType(ReleephRequestTransaction::TYPE_COMMIT)
|
|
->setMetadataValue('action', $event->getDetail('action'))
|
|
->setOldValue($last_commit_id)
|
|
->setNewValue($new_commit_id);
|
|
$last_commit_id = $new_commit_id;
|
|
break;
|
|
|
|
case ReleephRequestEvent::TYPE_DISCOVERY:
|
|
$xaction
|
|
->setTransactionType(ReleephRequestTransaction::TYPE_DISCOVERY)
|
|
->setNewValue($event->getDetail('newCommitPHID'));
|
|
break;
|
|
|
|
case ReleephRequestEvent::TYPE_CREATE:
|
|
$xaction
|
|
->setTransactionType(ReleephRequestTransaction::TYPE_REQUEST)
|
|
->setOldValue(null)
|
|
->setNewValue($rq->getRequestCommitPHID());
|
|
break;
|
|
|
|
case ReleephRequestEvent::TYPE_MANUAL_ACTION:
|
|
$xaction
|
|
->setTransactionType(
|
|
ReleephRequestTransaction::TYPE_MANUAL_IN_BRANCH);
|
|
switch ($event->getDetail('action')) {
|
|
case 'pick':
|
|
$xaction->setNewValue(1);
|
|
break;
|
|
|
|
case 'revert':
|
|
$xaction->setNewValue(0);
|
|
break;
|
|
}
|
|
break;
|
|
|
|
default:
|
|
throw new Exception(sprintf(
|
|
"Unhandled ReleephRequestEvent type '%s' in RQ%d",
|
|
$event->getType(),
|
|
$rq->getID()));
|
|
}
|
|
|
|
$xaction->save();
|
|
}
|
|
echo("\n");
|
|
}
|
|
|
|
$table->endReadLocking();
|
|
$table->saveTransaction();
|
|
echo "Done.\n";
|