[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/resources/sql/autopatches/ -> 20141107.phriction.policy.2.php (source)

   1  <?php
   2  
   3  $table = new PhrictionDocument();
   4  $conn_w = $table->establishConnection('w');
   5  
   6  echo "Populating Phriction policies.\n";
   7  
   8  $default_view_policy = PhabricatorPolicies::POLICY_USER;
   9  $default_edit_policy = PhabricatorPolicies::POLICY_USER;
  10  
  11  foreach (new LiskMigrationIterator($table) as $doc) {
  12    $id = $doc->getID();
  13  
  14    if ($doc->getViewPolicy() && $doc->getEditPolicy()) {
  15      echo "Skipping doc $id; already has policy set.\n";
  16      continue;
  17    }
  18  
  19    // If this was previously a magical project wiki page (under projects/, but
  20    // not projects/ itself) we need to apply the project policies. Otherwise,
  21    // apply the default policies.
  22    $slug = $doc->getSlug();
  23    $slug = PhabricatorSlug::normalize($slug);
  24    $prefix = 'projects/';
  25    if (($slug != $prefix) && (strncmp($slug, $prefix, strlen($prefix)) === 0)) {
  26      $parts = explode('/', $slug);
  27      $project_slug = $parts[1].'/';
  28  
  29      $project_slugs = array($project_slug);
  30      $project = id(new PhabricatorProjectQuery())
  31        ->setViewer(PhabricatorUser::getOmnipotentUser())
  32        ->withPhrictionSlugs($project_slugs)
  33        ->executeOne();
  34  
  35      if ($project) {
  36  
  37        $view_policy = nonempty($project->getViewPolicy(), $default_view_policy);
  38        $edit_policy = nonempty($project->getEditPolicy(), $default_edit_policy);
  39  
  40        $project_name = $project->getName();
  41        echo "Migrating doc $id to project policy $project_name...\n";
  42        $doc->setViewPolicy($view_policy);
  43        $doc->setEditPolicy($edit_policy);
  44        $doc->save();
  45        continue;
  46      }
  47    }
  48  
  49    echo "Migrating doc $id to default install policy...\n";
  50    $doc->setViewPolicy($default_view_policy);
  51    $doc->setEditPolicy($default_edit_policy);
  52    $doc->save();
  53  }
  54  
  55  echo "Done.\n";


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1