1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-03-12 20:34:54 +01:00
phorge-phorge/src/applications/cache/management/PhabricatorCacheManagementPurgeWorkflow.php
epriestley 00a20d3cdc Fix various "strlen(null)" PHP 8.1 issues on "bin/phd" and "bin/drydock" pathways
Summary: Ref T13676. Ref T13588. Fix some issues that prevent "bin/phd" and "bin/drydock" from executing under PHP 8.1, broadly because `null` is being passed to `strlen()`.

Test Plan: Ran `bin/phd debug task` and `bin/drydock ...` under PHP 8.1.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13676, T13588

Differential Revision: https://secure.phabricator.com/D21795
2022-05-03 15:57:15 -07:00

84 lines
2.2 KiB
PHP

<?php
final class PhabricatorCacheManagementPurgeWorkflow
extends PhabricatorCacheManagementWorkflow {
protected function didConstruct() {
$this
->setName('purge')
->setSynopsis(pht('Drop data from readthrough caches.'))
->setArguments(
array(
array(
'name' => 'all',
'help' => pht('Purge all caches.'),
),
array(
'name' => 'caches',
'param' => 'keys',
'help' => pht('Purge a specific set of caches.'),
),
));
}
public function execute(PhutilArgumentParser $args) {
$all_purgers = PhabricatorCachePurger::getAllPurgers();
$is_all = $args->getArg('all');
$key_list = $args->getArg('caches');
if ($is_all && phutil_nonempty_string($key_list)) {
throw new PhutilArgumentUsageException(
pht(
'Specify either "--all" or "--caches", not both.'));
} else if (!$is_all && !phutil_nonempty_string($key_list)) {
throw new PhutilArgumentUsageException(
pht(
'Select caches to purge with "--all" or "--caches". Available '.
'caches are: %s.',
implode(', ', array_keys($all_purgers))));
}
if ($is_all) {
$purgers = $all_purgers;
} else {
$key_list = preg_split('/[\s,]+/', $key_list);
$purgers = array();
foreach ($key_list as $key) {
if (isset($all_purgers[$key])) {
$purgers[$key] = $all_purgers[$key];
} else {
throw new PhutilArgumentUsageException(
pht(
'Cache purger "%s" is not recognized. Available caches '.
'are: %s.',
$key,
implode(', ', array_keys($all_purgers))));
}
}
if (!$purgers) {
throw new PhutilArgumentUsageException(
pht(
'When using "--caches", you must select at least one valid '.
'cache to purge.'));
}
}
$viewer = $this->getViewer();
foreach ($purgers as $key => $purger) {
$purger->setViewer($viewer);
echo tsprintf(
"%s\n",
pht(
'Purging "%s" cache...',
$key));
$purger->purgeCache();
}
return 0;
}
}