2013-05-20 19:16:35 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorCacheManagementPurgeWorkflow
|
2013-12-27 22:15:48 +01:00
|
|
|
extends PhabricatorCacheManagementWorkflow {
|
2013-05-20 19:16:35 +02:00
|
|
|
|
|
|
|
protected function didConstruct() {
|
|
|
|
$this
|
|
|
|
->setName('purge')
|
2015-05-22 09:27:56 +02:00
|
|
|
->setSynopsis(pht('Drop data from caches.'))
|
2013-05-20 19:16:35 +02:00
|
|
|
->setArguments(
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'name' => 'purge-all',
|
2015-05-22 09:27:56 +02:00
|
|
|
'help' => pht('Purge all caches.'),
|
2013-05-20 19:16:35 +02:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'purge-remarkup',
|
2015-05-22 09:27:56 +02:00
|
|
|
'help' => pht('Purge the remarkup cache.'),
|
2013-05-20 19:16:35 +02:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'purge-changeset',
|
2015-05-22 09:27:56 +02:00
|
|
|
'help' => pht('Purge the Differential changeset cache.'),
|
2013-05-20 19:16:35 +02:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'purge-general',
|
2015-05-22 09:27:56 +02:00
|
|
|
'help' => pht('Purge the general cache.'),
|
2013-05-20 19:16:35 +02:00
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(PhutilArgumentParser $args) {
|
|
|
|
$console = PhutilConsole::getConsole();
|
|
|
|
|
|
|
|
$purge_all = $args->getArg('purge-all');
|
|
|
|
|
|
|
|
$purge = array(
|
|
|
|
'remarkup' => $purge_all || $args->getArg('purge-remarkup'),
|
|
|
|
'changeset' => $purge_all || $args->getArg('purge-changeset'),
|
|
|
|
'general' => $purge_all || $args->getArg('purge-general'),
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!array_filter($purge)) {
|
|
|
|
$list = array();
|
|
|
|
foreach ($purge as $key => $ignored) {
|
|
|
|
$list[] = "'--purge-".$key."'";
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new PhutilArgumentUsageException(
|
2015-05-22 09:27:56 +02:00
|
|
|
pht(
|
|
|
|
"Specify which cache or caches to purge, or use '%s'. Available ".
|
|
|
|
"caches are: %s. Use '%s' for more information.",
|
|
|
|
'--purge-all',
|
|
|
|
implode(', ', $list),
|
|
|
|
'--help'));
|
2013-05-20 19:16:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($purge['remarkup']) {
|
2015-05-22 09:27:56 +02:00
|
|
|
$console->writeOut(pht('Purging remarkup cache...'));
|
2013-05-20 19:16:35 +02:00
|
|
|
$this->purgeRemarkupCache();
|
2015-05-22 09:27:56 +02:00
|
|
|
$console->writeOut("%s\n", pht('Done.'));
|
2013-05-20 19:16:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($purge['changeset']) {
|
2015-05-22 09:27:56 +02:00
|
|
|
$console->writeOut(pht('Purging changeset cache...'));
|
2013-05-20 19:16:35 +02:00
|
|
|
$this->purgeChangesetCache();
|
2015-05-22 09:27:56 +02:00
|
|
|
$console->writeOut("%s\n", pht('Done.'));
|
2013-05-20 19:16:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($purge['general']) {
|
2015-05-22 09:27:56 +02:00
|
|
|
$console->writeOut(pht('Purging general cache...'));
|
2013-05-20 19:16:35 +02:00
|
|
|
$this->purgeGeneralCache();
|
2015-05-22 09:27:56 +02:00
|
|
|
$console->writeOut("%s\n", pht('Done.'));
|
2013-05-20 19:16:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function purgeRemarkupCache() {
|
|
|
|
$conn_w = id(new PhabricatorMarkupCache())->establishConnection('w');
|
|
|
|
|
|
|
|
queryfx(
|
|
|
|
$conn_w,
|
|
|
|
'TRUNCATE TABLE %T',
|
|
|
|
id(new PhabricatorMarkupCache())->getTableName());
|
|
|
|
}
|
|
|
|
|
|
|
|
private function purgeChangesetCache() {
|
|
|
|
$conn_w = id(new DifferentialChangeset())->establishConnection('w');
|
|
|
|
queryfx(
|
|
|
|
$conn_w,
|
|
|
|
'TRUNCATE TABLE %T',
|
|
|
|
DifferentialChangeset::TABLE_CACHE);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function purgeGeneralCache() {
|
|
|
|
$conn_w = id(new PhabricatorMarkupCache())->establishConnection('w');
|
|
|
|
|
|
|
|
queryfx(
|
|
|
|
$conn_w,
|
|
|
|
'TRUNCATE TABLE %T',
|
|
|
|
'cache_general');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|