Changeset View
Changeset View
Standalone View
Standalone View
resources/sql/autopatches/20141107.phriction.policy.2.php
| <?php | <?php | ||||
| $table = new PhrictionDocument(); | $table = new PhrictionDocument(); | ||||
| $conn_w = $table->establishConnection('w'); | $conn_w = $table->establishConnection('w'); | ||||
| echo "Populating Phriction policies.\n"; | echo pht('Populating Phriction policies.')."\n"; | ||||
| $default_view_policy = PhabricatorPolicies::POLICY_USER; | $default_view_policy = PhabricatorPolicies::POLICY_USER; | ||||
| $default_edit_policy = PhabricatorPolicies::POLICY_USER; | $default_edit_policy = PhabricatorPolicies::POLICY_USER; | ||||
| foreach (new LiskMigrationIterator($table) as $doc) { | foreach (new LiskMigrationIterator($table) as $doc) { | ||||
| $id = $doc->getID(); | $id = $doc->getID(); | ||||
| if ($doc->getViewPolicy() && $doc->getEditPolicy()) { | if ($doc->getViewPolicy() && $doc->getEditPolicy()) { | ||||
| echo "Skipping doc $id; already has policy set.\n"; | echo pht('Skipping document %d; already has policy set.', $id)."\n"; | ||||
| continue; | continue; | ||||
| } | } | ||||
| // If this was previously a magical project wiki page (under projects/, but | // If this was previously a magical project wiki page (under projects/, but | ||||
| // not projects/ itself) we need to apply the project policies. Otherwise, | // not projects/ itself) we need to apply the project policies. Otherwise, | ||||
| // apply the default policies. | // apply the default policies. | ||||
| $slug = $doc->getSlug(); | $slug = $doc->getSlug(); | ||||
| $slug = PhabricatorSlug::normalize($slug); | $slug = PhabricatorSlug::normalize($slug); | ||||
| Show All 9 Lines | $project = id(new PhabricatorProjectQuery()) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| if ($project) { | if ($project) { | ||||
| $view_policy = nonempty($project->getViewPolicy(), $default_view_policy); | $view_policy = nonempty($project->getViewPolicy(), $default_view_policy); | ||||
| $edit_policy = nonempty($project->getEditPolicy(), $default_edit_policy); | $edit_policy = nonempty($project->getEditPolicy(), $default_edit_policy); | ||||
| $project_name = $project->getName(); | $project_name = $project->getName(); | ||||
| echo "Migrating doc $id to project policy $project_name...\n"; | echo pht( | ||||
| "Migrating document %d to project policy %s...\n", | |||||
| $id, | |||||
| $project_name); | |||||
| $doc->setViewPolicy($view_policy); | $doc->setViewPolicy($view_policy); | ||||
| $doc->setEditPolicy($edit_policy); | $doc->setEditPolicy($edit_policy); | ||||
| $doc->save(); | $doc->save(); | ||||
| continue; | continue; | ||||
| } | } | ||||
| } | } | ||||
| echo "Migrating doc $id to default install policy...\n"; | echo pht('Migrating document %d to default install policy...', $id)."\n"; | ||||
| $doc->setViewPolicy($default_view_policy); | $doc->setViewPolicy($default_view_policy); | ||||
| $doc->setEditPolicy($default_edit_policy); | $doc->setEditPolicy($default_edit_policy); | ||||
| $doc->save(); | $doc->save(); | ||||
| } | } | ||||
| echo "Done.\n"; | echo pht('Done.')."\n"; | ||||