Skip to content

Instantly share code, notes, and snippets.

@rfreebern
Created September 17, 2018 15:31
Show Gist options
  • Save rfreebern/09a593517534919071a0ff7f98c833b9 to your computer and use it in GitHub Desktop.
Save rfreebern/09a593517534919071a0ff7f98c833b9 to your computer and use it in GitHub Desktop.
Old script to move Phabricator projects to root to allow reorganization
#!/usr/bin/env php
<?php
// See <https://secure.phabricator.com/T10350> for discussion.
require_once 'scripts/__init_script__.php';
$args = new PhutilArgumentParser($argv);
$args->parseStandardArguments();
$args->parse(
array(
array(
'name' => 'project',
'param' => 'project',
'help' => pht(
'The project to move to root.'),
)
));
$project_name = $args->getArg('project');
if (!$project_name) {
throw new PhutilArgumentUsageException(
pht(
'Choose which project to move to root with --project.'));
}
$project = load_project($project_name);
if (!$project->getParentProjectPHID()) {
throw new PhutilArgumentUsageException(
pht(
'The selected project is already root-level. '.
'This script can only move non-root-level projects beneath other projects.'));
}
if ($project->getHasSubprojects() || $project->getHasMilestones()) {
throw new PhutilArgumentUsageException(
pht(
'The selected project has subprojects or milestones of its own. '.
'This script can not move entire trees of projects. Move each '.
'subproject or milestone to root first, then move this one.'));
}
$project->setParentProjectPHID(null);
$project->attachParentProject(null);
$project->setMilestoneNumber(null);
$project->setProjectPathKey(null);
$project->save();
echo tsprintf(
"%s\n",
pht('Done.'));
function load_project($name) {
$viewer = PhabricatorUser::getOmnipotentUser();
$project = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->withSlugs(array($name))
->executeOne();
if ($project) {
return $project;
}
$project = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->withPHIDs(array($name))
->executeOne();
if ($project) {
return $project;
}
$project = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->withIDs(array($name))
->executeOne();
if ($project) {
return $project;
}
throw new Exception(
pht(
'Unknown project "%s"! Use a hashtags, PHID, or ID to choose a project.',
$name));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment