1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00
phorge-phorge/resources/sql/autopatches/20160503.repo.04.mirrormigrate.php
epriestley 42eaa88f80 Cut mirroring over to new URIs
Summary:
Ref T10748. This migrates and swaps mirroring to `PhabricatorRepositoryURI`, obsoleting `PhabricatorRepositoryMirror`.

This prevents you from editing, adding or disabling mirrors unless you know a secret URI (until the UI cuts over fully), but existing mirroring is not affected.

Test Plan:
  - Added a mirroring URI to an old repository.
  - Verified it worked with `bin/repository mirror`.
  - Migrated forward.
  - Verified it still worked with `bin/repository mirror`.
  - Wow, mirroring: https://github.com/epriestley/locktopia-mirror

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10748

Differential Revision: https://secure.phabricator.com/D15841
2016-05-04 16:16:16 -07:00

38 lines
959 B
PHP

<?php
$table = new PhabricatorRepository();
$conn_w = $table->establishConnection('w');
$mirrors = queryfx_all(
$conn_w,
'SELECT * FROM %T',
'repository_mirror');
foreach ($mirrors as $mirror) {
$repository_phid = $mirror['repositoryPHID'];
$uri = $mirror['remoteURI'];
$already_exists = id(new PhabricatorRepositoryURI())->loadOneWhere(
'repositoryPHID = %s AND uri = %s',
$repository_phid,
$uri);
if ($already_exists) {
// Decline to migrate stuff that looks like it was already migrated.
continue;
}
$new_uri = PhabricatorRepositoryURI::initializeNewURI()
->setIOType(PhabricatorRepositoryURI::IO_MIRROR)
->setRepositoryPHID($repository_phid)
->setURI($uri)
->setCredentialPHID($mirror['credentialPHID'])
->setDateCreated($mirror['dateCreated'])
->setDateModified($mirror['dateModified'])
->save();
echo tsprintf(
"%s\n",
pht(
'Migrated mirror "%s".',
$uri));
}