2014-11-08 00:35:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
$table = new PhrictionDocument();
|
|
|
|
$conn_w = $table->establishConnection('w');
|
|
|
|
|
|
|
|
echo "Populating Phriction policies.\n";
|
|
|
|
|
2014-11-08 00:46:02 +01:00
|
|
|
$default_view_policy = PhabricatorPolicies::POLICY_USER;
|
2014-11-08 00:35:28 +01:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
2014-11-12 02:55:27 +01:00
|
|
|
// If this was previously a magical project wiki page (under projects/, but
|
|
|
|
// not projects/ itself) we need to apply the project policies. Otherwise,
|
|
|
|
// apply the default policies.
|
|
|
|
$slug = $doc->getSlug();
|
|
|
|
$slug = PhabricatorSlug::normalize($slug);
|
|
|
|
$prefix = 'projects/';
|
|
|
|
if (($slug != $prefix) && (strncmp($slug, $prefix, strlen($prefix)) === 0)) {
|
|
|
|
$parts = explode('/', $slug);
|
|
|
|
$project_slug = $parts[1].'/';
|
2014-11-08 00:35:28 +01:00
|
|
|
|
|
|
|
$project_slugs = array($project_slug);
|
|
|
|
$project = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
|
|
|
->withPhrictionSlugs($project_slugs)
|
|
|
|
->executeOne();
|
|
|
|
|
2014-11-08 00:42:16 +01:00
|
|
|
if ($project) {
|
2014-11-08 00:44:19 +01:00
|
|
|
|
|
|
|
$view_policy = nonempty($project->getViewPolicy(), $default_view_policy);
|
|
|
|
$edit_policy = nonempty($project->getEditPolicy(), $default_edit_policy);
|
|
|
|
|
2014-11-08 00:42:16 +01:00
|
|
|
$project_name = $project->getName();
|
|
|
|
echo "Migrating doc $id to project policy $project_name...\n";
|
2014-11-08 00:44:19 +01:00
|
|
|
$doc->setViewPolicy($view_policy);
|
|
|
|
$doc->setEditPolicy($edit_policy);
|
2014-11-08 00:42:16 +01:00
|
|
|
$doc->save();
|
|
|
|
continue;
|
|
|
|
}
|
2014-11-08 00:35:28 +01:00
|
|
|
}
|
2014-11-08 00:42:16 +01:00
|
|
|
|
|
|
|
echo "Migrating doc $id to default install policy...\n";
|
|
|
|
$doc->setViewPolicy($default_view_policy);
|
|
|
|
$doc->setEditPolicy($default_edit_policy);
|
|
|
|
$doc->save();
|
2014-11-08 00:35:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
echo "Done.\n";
|