2014-11-08 00:35:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
$table = new PhrictionDocument();
|
|
|
|
$conn_w = $table->establishConnection('w');
|
|
|
|
|
2015-05-22 09:27:56 +02:00
|
|
|
echo pht('Populating Phriction policies.')."\n";
|
2014-11-08 00:35:28 +01:00
|
|
|
|
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()) {
|
2015-05-22 09:27:56 +02:00
|
|
|
echo pht('Skipping document %d; already has policy set.', $id)."\n";
|
2014-11-08 00:35:28 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-04-15 16:59:44 +02:00
|
|
|
$new_view_policy = $default_view_policy;
|
|
|
|
$new_edit_policy = $default_edit_policy;
|
|
|
|
|
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);
|
2015-10-13 02:02:58 +02:00
|
|
|
|
|
|
|
$project_slug = $parts[1];
|
|
|
|
$project_slug = PhabricatorSlug::normalizeProjectSlug($project_slug);
|
2014-11-08 00:35:28 +01:00
|
|
|
|
|
|
|
$project_slugs = array($project_slug);
|
|
|
|
$project = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
2015-10-13 02:02:58 +02:00
|
|
|
->withSlugs($project_slugs)
|
2014-11-08 00:35:28 +01:00
|
|
|
->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);
|
|
|
|
|
2020-04-15 16:59:44 +02:00
|
|
|
$new_view_policy = $view_policy;
|
|
|
|
$new_edit_policy = $edit_policy;
|
2014-11-08 00:42:16 +01:00
|
|
|
}
|
2014-11-08 00:35:28 +01:00
|
|
|
}
|
2014-11-08 00:42:16 +01:00
|
|
|
|
2020-04-15 16:59:44 +02:00
|
|
|
echo pht('Migrating document %d to new policy...', $id)."\n";
|
|
|
|
|
|
|
|
queryfx(
|
|
|
|
$conn_w,
|
|
|
|
'UPDATE %R SET viewPolicy = %s, editPolicy = %s
|
|
|
|
WHERE id = %d',
|
|
|
|
$table,
|
|
|
|
$new_view_policy,
|
|
|
|
$new_edit_policy,
|
|
|
|
$id);
|
2014-11-08 00:35:28 +01:00
|
|
|
}
|
|
|
|
|
2015-05-22 09:27:56 +02:00
|
|
|
echo pht('Done.')."\n";
|