@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3$table = new PhrictionDocument();
4$conn_w = $table->establishConnection('w');
5
6echo pht('Populating Phriction policies.')."\n";
7
8$default_view_policy = PhabricatorPolicies::POLICY_USER;
9$default_edit_policy = PhabricatorPolicies::POLICY_USER;
10
11foreach (new LiskMigrationIterator($table) as $doc) {
12 $id = $doc->getID();
13
14 if ($doc->getViewPolicy() && $doc->getEditPolicy()) {
15 echo pht('Skipping document %d; already has policy set.', $id)."\n";
16 continue;
17 }
18
19 $new_view_policy = $default_view_policy;
20 $new_edit_policy = $default_edit_policy;
21
22 // If this was previously a magical project wiki page (under projects/, but
23 // not projects/ itself) we need to apply the project policies. Otherwise,
24 // apply the default policies.
25 $slug = $doc->getSlug();
26 $slug = PhabricatorSlug::normalize($slug);
27 $prefix = 'projects/';
28 if (($slug != $prefix) && (strncmp($slug, $prefix, strlen($prefix)) === 0)) {
29 $parts = explode('/', $slug);
30
31 $project_slug = $parts[1];
32 $project_slug = PhabricatorSlug::normalizeProjectSlug($project_slug);
33
34 $project_slugs = array($project_slug);
35 $project = id(new PhabricatorProjectQuery())
36 ->setViewer(PhabricatorUser::getOmnipotentUser())
37 ->withSlugs($project_slugs)
38 ->executeOne();
39
40 if ($project) {
41 $view_policy = nonempty($project->getViewPolicy(), $default_view_policy);
42 $edit_policy = nonempty($project->getEditPolicy(), $default_edit_policy);
43
44 $new_view_policy = $view_policy;
45 $new_edit_policy = $edit_policy;
46 }
47 }
48
49 echo pht('Migrating document %d to new policy...', $id)."\n";
50
51 queryfx(
52 $conn_w,
53 'UPDATE %R SET viewPolicy = %s, editPolicy = %s
54 WHERE id = %d',
55 $table,
56 $new_view_policy,
57 $new_edit_policy,
58 $id);
59}
60
61echo pht('Done.')."\n";