[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/repository/management/ -> PhabricatorRepositoryManagementEditWorkflow.php (source)

   1  <?php
   2  
   3  final class PhabricatorRepositoryManagementEditWorkflow
   4    extends PhabricatorRepositoryManagementWorkflow {
   5  
   6    public function didConstruct() {
   7      $this
   8        ->setName('edit')
   9        ->setExamples('**edit** --as __username__ __repository__ ...')
  10        ->setSynopsis('Edit __repository__, named by callsign.')
  11        ->setArguments(
  12          array(
  13            array(
  14              'name'        => 'repos',
  15              'wildcard'    => true,
  16            ),
  17            array(
  18              'name' => 'as',
  19              'param' => 'user',
  20              'help' => 'Edit as user.',
  21            ),
  22            array(
  23              'name' => 'local-path',
  24              'param' => 'path',
  25              'help' => 'Edit the local path.',
  26            ),
  27          ));
  28    }
  29  
  30    public function execute(PhutilArgumentParser $args) {
  31      $repos = $this->loadRepositories($args, 'repos');
  32  
  33      if (!$repos) {
  34        throw new PhutilArgumentUsageException(
  35          'Specify one or more repositories to edit, by callsign.');
  36      }
  37  
  38      $console = PhutilConsole::getConsole();
  39  
  40      // TODO: It would be nice to just take this action as "Administrator" or
  41      // similar, since that would make it easier to use this script, harder to
  42      // impersonate users, and more clear to viewers what happened. However,
  43      // the omnipotent user doesn't have a PHID right now, can't be loaded,
  44      // doesn't have a handle, etc. Adding all of that is fairly involved, and
  45      // I want to wait for stronger use cases first.
  46  
  47      $username = $args->getArg('as');
  48      if (!$username) {
  49        throw new PhutilArgumentUsageException(
  50          pht('Specify a user to edit as with --as <username>.'));
  51      }
  52  
  53      $actor = id(new PhabricatorPeopleQuery())
  54        ->setViewer($this->getViewer())
  55        ->withUsernames(array($username))
  56        ->executeOne();
  57  
  58      if (!$actor) {
  59        throw new PhutilArgumentUsageException(
  60          pht("No such user '%s'!", $username));
  61      }
  62  
  63      foreach ($repos as $repo) {
  64        $console->writeOut("Editing '%s'...\n", $repo->getCallsign());
  65  
  66        $xactions = array();
  67  
  68        $type_local_path = PhabricatorRepositoryTransaction::TYPE_LOCAL_PATH;
  69  
  70        if ($args->getArg('local-path')) {
  71          $xactions[] = id(new PhabricatorRepositoryTransaction())
  72            ->setTransactionType($type_local_path)
  73            ->setNewValue($args->getArg('local-path'));
  74        }
  75  
  76        if (!$xactions) {
  77          throw new PhutilArgumentUsageException(
  78            pht('Specify one or more fields to edit!'));
  79        }
  80  
  81        $content_source = PhabricatorContentSource::newConsoleSource();
  82  
  83        $editor = id(new PhabricatorRepositoryEditor())
  84          ->setActor($actor)
  85          ->setContentSource($content_source)
  86          ->setContinueOnNoEffect(true)
  87          ->setContinueOnMissingFields(true)
  88          ->applyTransactions($repo, $xactions);
  89      }
  90  
  91      $console->writeOut("Done.\n");
  92  
  93      return 0;
  94    }
  95  
  96  }


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