remove procedure and retrocompatibility pandora_enterprise#3943

This commit is contained in:
Daniel Barbero Martin 2022-02-22 13:20:53 +01:00
parent 93cad269c8
commit 237a7feb98
3 changed files with 113 additions and 54 deletions

View File

@ -8,14 +8,6 @@ ALTER TABLE tevent_response ADD COLUMN display_command tinyint(1) default 0;
ALTER TABLE `talert_templates` ADD COLUMN `schedule` TEXT;
ALTER TABLE `tevent_alert` ADD COLUMN `schedule` TEXT;
SOURCE procedures/alertTemplates.sql;
CALL `migrateRanges`();
DROP PROCEDURE `migrateRanges`;
SOURCE procedures/alertEvents.sql;
CALL `migrateEventRanges`();
DROP PROCEDURE `migrateEventRanges`;
ALTER TABLE `tautoconfig` ADD COLUMN `disabled` TINYINT DEFAULT 0;
COMMIT;

View File

@ -61,50 +61,7 @@ if (defined('LAST_STEP') === false) {
}
// Default events calendar.
$default_events_calendar = [
'monday' => [
[
'start' => '00:00:00',
'end' => '00:00:00',
],
],
'tuesday' => [
[
'start' => '00:00:00',
'end' => '00:00:00',
],
],
'wednesday' => [
[
'start' => '00:00:00',
'end' => '00:00:00',
],
],
'thursday' => [
[
'start' => '00:00:00',
'end' => '00:00:00',
],
],
'friday' => [
[
'start' => '00:00:00',
'end' => '00:00:00',
],
],
'saturday' => [
[
'start' => '00:00:00',
'end' => '00:00:00',
],
],
'sunday' => [
[
'start' => '00:00:00',
'end' => '00:00:00',
],
],
];
$default_events_calendar = default_events_calendar($id, 'talert_templates');
if ($duplicate_template === true) {
$source_id = (int) get_parameter('source_id');
@ -485,7 +442,6 @@ $type = '';
$value = '';
$max = '';
$min = '';
$schedule = json_encode(
$default_events_calendar
);
@ -614,7 +570,9 @@ if ($id && ! $create_template) {
$min = $template['min_value'];
$matches = $template['matches_value'];
$schedule = $template['schedule'];
$schedule = json_encode(
$default_events_calendar
);
$special_day = (int) $template['special_day'];
$max_alerts = $template['max_alerts'];
$min_alerts = $template['min_alerts'];

View File

@ -3395,3 +3395,112 @@ function alerts_get_templates_name_array($array_ids)
return $result;
}
function default_events_calendar($id, $table)
{
$result = [
'monday' => [
[
'start' => '00:00:00',
'end' => '00:00:00',
],
],
'tuesday' => [
[
'start' => '00:00:00',
'end' => '00:00:00',
],
],
'wednesday' => [
[
'start' => '00:00:00',
'end' => '00:00:00',
],
],
'thursday' => [
[
'start' => '00:00:00',
'end' => '00:00:00',
],
],
'friday' => [
[
'start' => '00:00:00',
'end' => '00:00:00',
],
],
'saturday' => [
[
'start' => '00:00:00',
'end' => '00:00:00',
],
],
'sunday' => [
[
'start' => '00:00:00',
'end' => '00:00:00',
],
],
];
$days = [
'monday',
'tuesday',
'wednesday',
'thursday',
'friday',
'saturday',
'sunday',
];
// Check Exists.
if (empty($id) === false) {
$sql_default_alert = sprintf(
'SELECT `id`,
`name`,
`time_from`,
`time_to`,
`monday`,
`tuesday`,
`wednesday`,
`thursday`,
`friday`,
`saturday`,
`sunday`,
`schedule`
FROM %s
WHERE id = %d',
$table,
$id
);
$r = db_get_row_sql($sql_default_alert);
if ($r != false) {
// Check Exist schedule.
if (empty($r['schedule']) === false) {
$result = json_decode(io_safe_output($r['schedule']), true);
} else {
// Compatibility mode old.
$result = [];
foreach ($days as $day) {
if ((int) $r[$day] === 1) {
$start = $r['time_from'];
$to = $r['time_to'];
if ($r['time_from'] === $r['time_to']) {
$start = '00:00:00';
$to = '00:00:00';
}
$result[$day][0] = [
'start' => $start,
'end' => $to,
];
}
}
}
}
}
return $result;
}