1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-24 15:52:41 +01:00
phorge-phorge/resources/sql/patches/20131020.pxactionmig.php
epriestley 601aaa5a86 Modularize content sources
Summary:
Ref T10537. For Nuance, I want to introduce new sources (like "GitHub" or "GitHub via Nuance" or something) but this needs to modularize eventually.

Split ContentSource apart so applications can add new content sources.

Test Plan:
This change has huge surface area, so I'll hold it until post-release. I think it's fairly safe (and if it does break anything, the breaks should be fatals, not anything subtle or difficult to fix), there's just no reason not to hold it for a few hours.

- Viewed new module page.
- Grepped for all removed functions/constants.
- Viewed some transactions.
- Hovered over timestamps to get content source details.
- Added a comment via Conduit.
- Added a comment via web.
- Ran `bin/storage upgrade --namespace XXXXX --no-quickstart -f` to re-run all historic migrations.
- Generated some objects with `bin/lipsum`.
- Ran a bulk job on some tasks.
- Ran unit tests.

{F1190182}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10537

Differential Revision: https://secure.phabricator.com/D15521
2016-03-26 11:59:45 -07:00

91 lines
2.3 KiB
PHP

<?php
$project_table = new PhabricatorProject();
$conn_w = $project_table->establishConnection('w');
$conn_w->openTransaction();
$src_table = 'project_legacytransaction';
$dst_table = 'project_transaction';
echo pht('Migrating Project transactions to new format...')."\n";
$content_source = PhabricatorContentSource::newForSource(
PhabricatorOldWorldContentSource::SOURCECONST)->serialize();
$rows = new LiskRawMigrationIterator($conn_w, $src_table);
foreach ($rows as $row) {
$id = $row['id'];
$project_id = $row['projectID'];
echo pht('Migrating transaction #%d (Project %d)...', $id, $project_id)."\n";
$project_row = queryfx_one(
$conn_w,
'SELECT phid FROM %T WHERE id = %d',
$project_table->getTableName(),
$project_id);
if (!$project_row) {
continue;
}
$project_phid = $project_row['phid'];
$type_map = array(
'name' => PhabricatorProjectTransaction::TYPE_NAME,
'members' => PhabricatorProjectTransaction::TYPE_MEMBERS,
'status' => PhabricatorProjectTransaction::TYPE_STATUS,
'canview' => PhabricatorTransactions::TYPE_VIEW_POLICY,
'canedit' => PhabricatorTransactions::TYPE_EDIT_POLICY,
'canjoin' => PhabricatorTransactions::TYPE_JOIN_POLICY,
);
$new_type = idx($type_map, $row['transactionType']);
if (!$new_type) {
continue;
}
$xaction_phid = PhabricatorPHID::generateNewPHID(
PhabricatorApplicationTransactionTransactionPHIDType::TYPECONST,
PhabricatorProjectProjectPHIDType::TYPECONST);
queryfx(
$conn_w,
'INSERT IGNORE INTO %T
(phid, authorPHID, objectPHID,
viewPolicy, editPolicy, commentPHID, commentVersion, transactionType,
oldValue, newValue, contentSource, metadata,
dateCreated, dateModified)
VALUES
(%s, %s, %s,
%s, %s, %ns, %d, %s,
%s, %s, %s, %s,
%d, %d)',
$dst_table,
// PHID, Author, Object
$xaction_phid,
$row['authorPHID'],
$project_phid,
// View, Edit, Comment, Version, Type
'public',
$row['authorPHID'],
null,
0,
$new_type,
// Old, New, Source, Meta,
$row['oldValue'],
$row['newValue'],
$content_source,
'{}',
// Created, Modified
$row['dateCreated'],
$row['dateModified']);
}
$conn_w->saveTransaction();
echo pht('Done.')."\n";