[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/cache/management/ -> PhabricatorCacheManagementPurgeWorkflow.php (source)

   1  <?php
   2  
   3  final class PhabricatorCacheManagementPurgeWorkflow
   4    extends PhabricatorCacheManagementWorkflow {
   5  
   6    protected function didConstruct() {
   7      $this
   8        ->setName('purge')
   9        ->setSynopsis('Drop data from caches.')
  10        ->setArguments(
  11          array(
  12            array(
  13              'name'    => 'purge-all',
  14              'help'    => 'Purge all caches.',
  15            ),
  16            array(
  17              'name'    => 'purge-remarkup',
  18              'help'    => 'Purge the remarkup cache.',
  19            ),
  20            array(
  21              'name'    => 'purge-changeset',
  22              'help'    => 'Purge the Differential changeset cache.',
  23            ),
  24            array(
  25              'name'    => 'purge-general',
  26              'help'    => 'Purge the general cache.',
  27            ),
  28          ));
  29    }
  30  
  31    public function execute(PhutilArgumentParser $args) {
  32      $console = PhutilConsole::getConsole();
  33  
  34      $purge_all = $args->getArg('purge-all');
  35  
  36      $purge = array(
  37        'remarkup'  => $purge_all || $args->getArg('purge-remarkup'),
  38        'changeset' => $purge_all || $args->getArg('purge-changeset'),
  39        'general'   => $purge_all || $args->getArg('purge-general'),
  40      );
  41  
  42      if (!array_filter($purge)) {
  43        $list = array();
  44        foreach ($purge as $key => $ignored) {
  45          $list[] = "'--purge-".$key."'";
  46        }
  47  
  48        throw new PhutilArgumentUsageException(
  49          "Specify which cache or caches to purge, or use '--purge-all'. ".
  50          "Available caches are: ".implode(', ', $list).". Use '--help' ".
  51          "for more information.");
  52      }
  53  
  54      if ($purge['remarkup']) {
  55        $console->writeOut('Purging remarkup cache...');
  56        $this->purgeRemarkupCache();
  57        $console->writeOut("done.\n");
  58      }
  59  
  60      if ($purge['changeset']) {
  61        $console->writeOut('Purging changeset cache...');
  62        $this->purgeChangesetCache();
  63        $console->writeOut("done.\n");
  64      }
  65  
  66      if ($purge['general']) {
  67        $console->writeOut('Purging general cache...');
  68        $this->purgeGeneralCache();
  69        $console->writeOut("done.\n");
  70      }
  71    }
  72  
  73    private function purgeRemarkupCache() {
  74      $conn_w = id(new PhabricatorMarkupCache())->establishConnection('w');
  75  
  76      queryfx(
  77        $conn_w,
  78        'TRUNCATE TABLE %T',
  79        id(new PhabricatorMarkupCache())->getTableName());
  80    }
  81  
  82    private function purgeChangesetCache() {
  83      $conn_w = id(new DifferentialChangeset())->establishConnection('w');
  84      queryfx(
  85        $conn_w,
  86        'TRUNCATE TABLE %T',
  87        DifferentialChangeset::TABLE_CACHE);
  88    }
  89  
  90    private function purgeGeneralCache() {
  91      $conn_w = id(new PhabricatorMarkupCache())->establishConnection('w');
  92  
  93      queryfx(
  94        $conn_w,
  95        'TRUNCATE TABLE %T',
  96        'cache_general');
  97    }
  98  
  99  }


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