1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02:00
phorge-phorge/resources/sql/autopatches/20141107.phriction.policy.2.php
epriestley 2e13a31722 Make Phriction policy migration even more robust
We have at least one project with `null` as a viewPolicy. This should get
sorted out separately, but make the migration robust against it.

Auditors: btrahan
2014-11-07 15:44:19 -08:00

50 lines
1.4 KiB
PHP

<?php
$table = new PhrictionDocument();
$conn_w = $table->establishConnection('w');
echo "Populating Phriction policies.\n";
$default_view_policy = PhabricatorPolicies::getMostOpenPolicy();
$default_edit_policy = PhabricatorPolicies::POLICY_USER;
foreach (new LiskMigrationIterator($table) as $doc) {
$id = $doc->getID();
if ($doc->getViewPolicy() && $doc->getEditPolicy()) {
echo "Skipping doc $id; already has policy set.\n";
continue;
}
// project documents get the project policy
if (PhrictionDocument::isProjectSlug($doc->getSlug())) {
$project_slug =
PhrictionDocument::getProjectSlugIdentifier($doc->getSlug());
$project_slugs = array($project_slug);
$project = id(new PhabricatorProjectQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withPhrictionSlugs($project_slugs)
->executeOne();
if ($project) {
$view_policy = nonempty($project->getViewPolicy(), $default_view_policy);
$edit_policy = nonempty($project->getEditPolicy(), $default_edit_policy);
$project_name = $project->getName();
echo "Migrating doc $id to project policy $project_name...\n";
$doc->setViewPolicy($view_policy);
$doc->setEditPolicy($edit_policy);
$doc->save();
continue;
}
}
echo "Migrating doc $id to default install policy...\n";
$doc->setViewPolicy($default_view_policy);
$doc->setEditPolicy($default_edit_policy);
$doc->save();
}
echo "Done.\n";