alert template schedule pandora_enterprise#3943

This commit is contained in:
Daniel Barbero Martin 2022-01-31 16:50:48 +01:00
parent c02abbc508
commit 15ada66942
6 changed files with 48 additions and 35 deletions

View File

@ -3,9 +3,14 @@ ALTER TABLE `tpolicy_queue` MODIFY COLUMN `progress` int(10) NOT NULL default '0
CREATE INDEX `IDX_tservice_element` ON `tservice_element`(`id_service`,`id_agente_modulo`);
ALTER TABLE `talert_templates` ADD COLUMN `schedule` TEXT DEFAULT NULL;
ALTER TABLE `tevent_alert` ADD COLUMN `schedule` TEXT DEFAULT NULL;
SOURCE procedures/alertTemplates.sql;
CALL `migrateRanges`();
DROP PROCEDURE `migrateRanges`;
SOURCE procedures/alertEvents.sql;
CALL `migrateEventRanges`();
DROP PROCEDURE `migrateEventRanges`;
COMMIT;

View File

@ -0,0 +1,40 @@
CREATE PROCEDURE migrateEventRanges()
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE i INT;
DECLARE r TEXT;
DECLARE cur1 CURSOR FOR SELECT `id` FROM `tevent_alert`;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
UPDATE `tevent_alert` SET `schedule` = '{"monday":_1_,"tuesday":_2_,"wednesday":_3_,"thursday":_4_,"friday":_5_,"saturday":_6_,"sunday":_7_}';
UPDATE `tevent_alert` SET `time_from` = "00:00:00", `time_to` = "00:00:00" WHERE `time_from` = `time_to`;
OPEN cur1;
read_loop: LOOP
FETCH cur1 INTO i;
IF done THEN
LEAVE read_loop;
END IF;
SELECT concat('[{"start":"', `time_from`, '","end":"', `time_to`, '"}]') into r FROM `tevent_alert` WHERE `id` = i;
UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_1_", r) WHERE `monday` > 0 AND `id` = i;
UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_2_", r) WHERE `tuesday` > 0 AND `id` = i;
UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_3_", r) WHERE `wednesday` > 0 AND `id` = i;
UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_4_", r) WHERE `thursday` > 0 AND `id` = i;
UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_5_", r) WHERE `friday` > 0 AND `id` = i;
UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_6_", r) WHERE `saturday` > 0 AND `id` = i;
UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_7_", r) WHERE `sunday` > 0 AND `id` = i;
UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_1_", '""') WHERE `monday` = 0 AND `id` = i;
UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_2_", '""') WHERE `tuesday` = 0 AND `id` = i;
UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_3_", '""') WHERE `wednesday` = 0 AND `id` = i;
UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_4_", '""') WHERE `thursday` = 0 AND `id` = i;
UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_5_", '""') WHERE `friday` = 0 AND `id` = i;
UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_6_", '""') WHERE `saturday` = 0 AND `id` = i;
UPDATE `tevent_alert` SET `schedule` = REPLACE(`schedule`, "_7_", '""') WHERE `sunday` = 0 AND `id` = i;
END LOOP;
CLOSE cur1;
END ;

View File

@ -617,7 +617,7 @@ if ($step == 2) {
$table->colspan[1][1] = 3;
$table->data[1][1] = ui_print_warning_message(
[
'message' => __('Not selected any day'),
'message' => __('No alert has been scheduled yet'),
'force_style' => 'display:none;',
],
'',

View File

@ -1059,39 +1059,6 @@ function alerts_get_alert_template_time_to($id_alert_template)
}
/**
* Get alert template in weekday format.
*
* @param int Id of an alert template.
*
* @return mixed Alert template in weekday format or false if something goes wrong.
*/
function alerts_get_alert_template_weekdays($id_alert_template)
{
$alert = alerts_get_alert_template($id_alert_template);
if ($alert === false) {
return false;
}
$retval = [];
$days = [
'monday',
'tuesday',
'wednesday',
'thursday',
'friday',
'saturday',
'sunday',
];
foreach ($days as $day) {
$retval[$day] = (bool) $alert[$day];
}
return $retval;
}
/**
* Get recovery_notify of talert_templates table.
*

View File

@ -364,7 +364,7 @@ function save_data_input(calendar) {
// eslint-disable-next-line no-unused-vars
function loadEventBBDD(events) {
if (events === null || events === "") {
if (events == undefined || events === null || events === "") {
$(".warning").show();
return {};
}

View File

@ -3051,6 +3051,7 @@ CREATE TABLE IF NOT EXISTS `tevent_alert` (
`id_template_fields` int(10) unsigned NOT NULL default 0,
`last_evaluation` bigint(20) NOT NULL default 0,
`pool_occurrences` int unsigned not null default 0,
`schedule` text default null,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;