Added cli.php command for purging caches

This commit is contained in:
Bofh 2022-12-13 12:06:30 +01:00
parent 29b6186c8e
commit b2cf09a6cd
1 changed files with 33 additions and 0 deletions

33
cli.php
View File

@ -68,19 +68,52 @@ function cli__users($args) {
echo $msg."\n"; echo $msg."\n";
} }
function cli__cache($args) {
$help = function() {
cli__help(false);
echo ' cache prune|purge|delete Delete all application caches'."\n";
die;
};
$msg = null;
switch ($args[0]) {
case 'prune':
case 'purge':
case 'delete':
foreach (scandir(filedb_getdir('cache')) as $fil) {
if (in_array($fil, ['.','..']))
continue;
filedb_del('cache', $fil);
}
$msg = 'Application cache has been succesfully purged';
break;
case 'help':
default:
$help();
}
if ($msg != nulL)
echo $msg."\n";
}
function cli__help($full=true) { function cli__help($full=true) {
echo 'APub Control cli.php 1.0 author: bofh@nogafam.es'."\n"; echo 'APub Control cli.php 1.0 author: bofh@nogafam.es'."\n";
echo "\n"; echo "\n";
echo ' Parameters:'."\n"; echo ' Parameters:'."\n";
if ($full === false) return; if ($full === false) return;
echo ' users <help> Add/delete/modify web application users'."\n"; echo ' users <help> Add/delete/modify web application users'."\n";
echo ' cache <help> Handle all the web application caches'."\n";
die; die;
} }
if (count($argv) <= 1)
cli__help();
switch ($argv[1]) { switch ($argv[1]) {
case 'users': case 'users':
cli__users(array_slice($argv, 2)); cli__users(array_slice($argv, 2));
break; break;
case 'cache':
cli__cache(array_slice($argv, 2));
break;
case 'help': case 'help':
cli__help(); cli__help();
break; break;