diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:31 +0000 |
commit | f66ab8dae2f3d0418759f81a3a64dc9517a62449 (patch) | |
tree | fbff2135e7013f196b891bbde54618eb050e4aaf /application/clicommands/HousekeepingCommand.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-director-f66ab8dae2f3d0418759f81a3a64dc9517a62449.tar.xz icingaweb2-module-director-f66ab8dae2f3d0418759f81a3a64dc9517a62449.zip |
Adding upstream version 1.10.2.upstream/1.10.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | application/clicommands/HousekeepingCommand.php | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/application/clicommands/HousekeepingCommand.php b/application/clicommands/HousekeepingCommand.php new file mode 100644 index 0000000..974e28d --- /dev/null +++ b/application/clicommands/HousekeepingCommand.php @@ -0,0 +1,74 @@ +<?php + +namespace Icinga\Module\Director\Clicommands; + +use Icinga\Exception\MissingParameterException; +use Icinga\Module\Director\Cli\Command; +use Icinga\Module\Director\Db\Housekeeping; +use Icinga\Module\Director\Db\MembershipHousekeeping; + +class HousekeepingCommand extends Command +{ + protected $housekeeping; + + public function tasksAction() + { + if ($pending = $this->params->shift('pending')) { + $tasks = $this->housekeeping()->getPendingTaskSummary(); + } else { + $tasks = $this->housekeeping()->getTaskSummary(); + } + + $len = array_reduce( + $tasks, + function ($max, $task) { + return max( + $max, + strlen($task->title) + strlen($task->name) + 3 + ); + } + ); + + if (count($tasks)) { + print "\n"; + printf(" %-" . $len . "s | %s\n", 'Housekeeping task (name)', 'Count'); + printf("-%-" . $len . "s-|-------\n", str_repeat('-', $len)); + } + + foreach ($tasks as $task) { + printf( + " %-" . $len . "s | %5d\n", + sprintf('%s (%s)', $task->title, $task->name), + $task->count + ); + } + + if (count($tasks)) { + print "\n"; + } + } + + public function runAction() + { + if (!$job = $this->params->shift()) { + throw new MissingParameterException( + 'Job is required, say ALL to run all pending jobs' + ); + } + + if ($job === 'ALL') { + $this->housekeeping()->runAllTasks(); + } else { + $this->housekeeping()->runTask($job); + } + } + + protected function housekeeping() + { + if ($this->housekeeping === null) { + $this->housekeeping = new Housekeeping($this->db()); + } + + return $this->housekeeping; + } +} |