<?php declare(strict_types = 0);
class CControllerHousekeepingUpdate extends CController {
protected function checkInput(): bool {
$fields = [
'hk_trends' => 'db config.hk_trends|time_unit 0,'.implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR]),
'hk_trends_global' => 'db config.hk_trends_global|in 1',
'hk_trends_mode' => 'db config.hk_trends_mode',
'hk_history' => 'db config.hk_history|time_unit 0,'.implode(':', [SEC_PER_HOUR, 25 * SEC_PER_YEAR]),
'hk_history_global' => 'db config.hk_history_global|in 1',
'hk_history_mode' => 'db config.hk_history_mode',
'hk_sessions' => 'db config.hk_sessions|time_unit '.implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR]),
'hk_sessions_mode' => 'db config.hk_sessions_mode|in 1',
'hk_services' => 'db config.hk_services|time_unit '.implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR]),
'hk_services_mode' => 'db config.hk_services_mode|in 1',
'hk_events_autoreg' => 'db config.hk_events_autoreg|time_unit '.implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR]),
'hk_events_discovery' => 'db config.hk_events_discovery|time_unit '.implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR]),
'hk_events_internal' => 'db config.hk_events_internal|time_unit '.implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR]),
'hk_events_trigger' => 'db config.hk_events_trigger|time_unit '.implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR]),
'hk_events_service' => 'db config.hk_events_service|time_unit '.implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR]),
'hk_events_mode' => 'db config.hk_events_mode|in 1',
'compression_status' => 'db config.compression_status|in 1',
'compress_older' => 'db config.compress_older|time_unit '.implode(':', [7 * SEC_PER_DAY, 25 * SEC_PER_YEAR])
];
$ret = $this->validateInput($fields);
if (!$ret) {
switch ($this->getValidationError()) {
case self::VALIDATION_ERROR:
$response = new CControllerResponseRedirect(
(new CUrl('zabbix.php'))->setArgument('action', 'housekeeping.edit')
);
$response->setFormData($this->getInputAll() + [
'hk_events_mode' => '0',
'hk_services_mode' => '0',
'hk_sessions_mode' => '0',
'hk_history_mode' => '0',
'hk_history_global' => '0',
'hk_trends_mode' => '0',
'hk_trends_global' => '0',
'compression_status' => '0'
]);
CMessageHelper::setErrorTitle(_('Cannot update configuration'));
$this->setResponse($response);
break;
case self::VALIDATION_FATAL_ERROR:
$this->setResponse(new CControllerResponseFatal());
break;
}
}
return $ret;
}
protected function checkPermissions(): bool {
return $this->checkAccess(CRoleHelper::UI_ADMINISTRATION_HOUSEKEEPING);
}
protected function doAction(): void {
$hk = [
CHousekeepingHelper::HK_EVENTS_MODE => $this->getInput('hk_events_mode', 0),
CHousekeepingHelper::HK_SERVICES_MODE => $this->getInput('hk_services_mode', 0),
CHousekeepingHelper::HK_SESSIONS_MODE => $this->getInput('hk_sessions_mode', 0),
CHousekeepingHelper::HK_HISTORY_MODE => $this->getInput('hk_history_mode', 0),
CHousekeepingHelper::HK_HISTORY_GLOBAL => $this->getInput('hk_history_global', 0),
CHousekeepingHelper::HK_TRENDS_MODE => $this->getInput('hk_trends_mode', 0),
CHousekeepingHelper::HK_TRENDS_GLOBAL => $this->getInput('hk_trends_global', 0)
];
if ($hk[CHousekeepingHelper::HK_EVENTS_MODE] == 1) {
$this->getInputs($hk, [CHousekeepingHelper::HK_EVENTS_TRIGGER, CHousekeepingHelper::HK_EVENTS_SERVICE,
CHousekeepingHelper::HK_EVENTS_INTERNAL, CHousekeepingHelper::HK_EVENTS_DISCOVERY,
CHousekeepingHelper::HK_EVENTS_AUTOREG
]);
}