[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/files/management/ -> PhabricatorFilesManagementPurgeWorkflow.php (source)

   1  <?php
   2  
   3  final class PhabricatorFilesManagementPurgeWorkflow
   4    extends PhabricatorFilesManagementWorkflow {
   5  
   6    public function didConstruct() {
   7      $this
   8        ->setName('purge')
   9        ->setSynopsis('Delete files with missing data.')
  10        ->setArguments(
  11          array(
  12            array(
  13              'name'      => 'all',
  14              'help'      => 'Update all files.',
  15            ),
  16            array(
  17              'name'      => 'dry-run',
  18              'help'      => 'Show what would be updated.',
  19            ),
  20            array(
  21              'name'      => 'names',
  22              'wildcard'  => true,
  23            ),
  24          ));
  25    }
  26  
  27    public function execute(PhutilArgumentParser $args) {
  28      $console = PhutilConsole::getConsole();
  29  
  30      $iterator = $this->buildIterator($args);
  31      if (!$iterator) {
  32        throw new PhutilArgumentUsageException(
  33          'Either specify a list of files to purge, or use `--all` '.
  34          'to purge all files.');
  35      }
  36  
  37      $is_dry_run = $args->getArg('dry-run');
  38  
  39      foreach ($iterator as $file) {
  40        $fid = 'F'.$file->getID();
  41  
  42        try {
  43          $file->loadFileData();
  44          $okay = true;
  45        } catch (Exception $ex) {
  46          $okay = false;
  47        }
  48  
  49        if ($okay) {
  50          $console->writeOut(
  51            "%s: File data is OK, not purging.\n",
  52            $fid);
  53        } else {
  54          if ($is_dry_run) {
  55            $console->writeOut(
  56              "%s: Would purge (dry run).\n",
  57              $fid);
  58          } else {
  59            $console->writeOut(
  60              "%s: Purging.\n",
  61              $fid);
  62            $file->delete();
  63          }
  64        }
  65      }
  66  
  67      return 0;
  68    }
  69  }


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