Load procedures (or complex queries) in UMC

This commit is contained in:
fbsanchez 2021-07-21 17:31:03 +02:00
parent 62be3f5830
commit f71ae73c84
3 changed files with 14 additions and 7 deletions

View File

@ -25,7 +25,9 @@ CREATE TABLE IF NOT EXISTS `tsync_queue` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SOURCE './procedures/updateSnmpAlerts.sql';
LOAD ./procedures/updateSnmpAlerts.sql;
CALL updateSnmpAlerts();
DROP PROCEDURE updateSnmpAlerts;
UPDATE `tlink` SET `link` = 'https://pandorafms.com/manual/' WHERE `id_link` = 0000000001;
@ -38,7 +40,7 @@ UPDATE `tuser_task_scheduled` SET
`args`= REPLACE(`args`, 's:15:"first_execution"', 'i:2;s:0:"";i:7;s:3:"PDF";s:15:"first_execution"')
WHERE `id_user_task` = 2;
UPDATE `tconfig` SET `value` = 0 WHERE `token` = `centralized_management`;
UPDATE `tconfig` SET `value` = 0 WHERE `token` = 'centralized_management';
DELETE ta FROM `tagente` ta LEFT JOIN `tgrupo` tg on ta.`id_grupo` = tg.`id_grupo` WHERE tg.`id_grupo` IS NULL;

View File

@ -1,4 +1,3 @@
DELIMITER //
CREATE PROCEDURE updateSnmpAlerts()
BEGIN
DECLARE tokenId INT DEFAULT 0;
@ -33,7 +32,4 @@ BEGIN
UPDATE tconfig SET value = 1 WHERE token = 'update_snmp_alerts_procedure_already_run';
END IF;
END IF;
END//
DELIMITER ;
CALL updateSnmpAlerts();
DROP PROCEDURE updateSnmpAlerts;
END

View File

@ -941,6 +941,15 @@ class Client
$queries = preg_split("/(;\n)|(;\n\r)/", $sql);
foreach ($queries as $query) {
if (empty($query) !== true) {
if (preg_match('/^\s*LOAD\s+(.*)$/i', $query, $matches) > 0) {
$filepath = dirname($mr_file).'/'.$matches[1];
if (file_exists($filepath) === true) {
$query = file_get_contents($filepath);
} else {
throw new \Exception('Cannot load file: '.$filepath);
}
}
if ($dbh->query($query) === false) {
// 1022: Duplicate key in table.
// 1050: Table already defined.