<commit_before><?php

$table = new PhrictionDocument();
$conn_w = $table->establishConnection('w');

echo "Populating Phriction policies.\n";

$default_view_policy = PhabricatorPolicies::getMostOpenPolicy();
$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;
  }

  // project documents get the project policy
  if (PhrictionDocument::isProjectSlug($doc->getSlug())) {

    $project_slug =
      PhrictionDocument::getProjectSlugIdentifier($doc->getSlug());
    $project_slugs = array($project_slug);
    $project = id(new PhabricatorProjectQuery())
      ->setViewer(PhabricatorUser::getOmnipotentUser())
      ->withPhrictionSlugs($project_slugs)
      ->executeOne();

    $project_name = $project->getName();
    echo "Migrating doc $id to project policy $project_name...\n";
    $doc->setViewPolicy($project->getViewPolicy());
    $doc->setEditPolicy($project->getEditPolicy());
    $doc->save();

  // non-project documents get the most open policy possible
  } else {

    echo "Migrating doc $id to default install policy...\n";
    $doc->setViewPolicy($default_view_policy);
    $doc->setEditPolicy($default_edit_policy);
    $doc->save();

  }
}

echo "Done.\n";<commit_msg>Minor, make Phriction migration a little more robust<commit_after><?php

$table = new PhrictionDocument();
$conn_w = $table->establishConnection('w');

echo "Populating Phriction policies.\n";

$default_view_policy = PhabricatorPolicies::getMostOpenPolicy();
$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;
  }

  // project documents get the project policy
  if (PhrictionDocument::isProjectSlug($doc->getSlug())) {

    $project_slug =
      PhrictionDocument::getProjectSlugIdentifier($doc->getSlug());
    $project_slugs = array($project_slug);
    $project = id(new PhabricatorProjectQuery())
      ->setViewer(PhabricatorUser::getOmnipotentUser())
      ->withPhrictionSlugs($project_slugs)
      ->executeOne();

    if ($project) {
      $project_name = $project->getName();
      echo "Migrating doc $id to project policy $project_name...\n";
      $doc->setViewPolicy($project->getViewPolicy());
      $doc->setEditPolicy($project->getEditPolicy());
      $doc->save();
      continue;
    }
  }

  echo "Migrating doc $id to default install policy...\n";
  $doc->setViewPolicy($default_view_policy);
  $doc->setEditPolicy($default_edit_policy);
  $doc->save();
}

echo "Done.\n";
{'fraction_non_alphanumeric': 0.15576991782779565, 'fraction_numerical': 0.0, 'mean_word_length': 4.511811023622047, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '11714', 'n_tokens_mistral': 908, 'n_tokens_neox': 888, 'n_words': 172}