diff --git a/pandora_console/extras/mr/51.sql b/pandora_console/extras/mr/51.sql index 3398bed0c3..0575fea01e 100644 --- a/pandora_console/extras/mr/51.sql +++ b/pandora_console/extras/mr/51.sql @@ -8,7 +8,7 @@ ALTER TABLE `tlocal_component` ADD COLUMN `percentage_critical` tinyint(1) UNSIG ALTER TABLE `tlocal_component` ADD COLUMN `percentage_warning` tinyint(1) UNSIGNED DEFAULT 0; ALTER TABLE `tpolicy_modules` ADD COLUMN `percentage_warning` tinyint(1) UNSIGNED DEFAULT 0; ALTER TABLE `tpolicy_modules` ADD COLUMN `percentage_critical` tinyint(1) UNSIGNED DEFAULT 0; - +ALTER TABLE `tsync_queue` ADD COLUMN `result` TEXT; ALTER TABLE tagente_modulo MODIFY debug_content TEXT; CREATE TABLE IF NOT EXISTS `talert_calendar` ( diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index ba0c0c32e3..0cec1167dd 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -4089,6 +4089,7 @@ CREATE TABLE IF NOT EXISTS `tsync_queue` ( `operation` text, `table` text, `error` MEDIUMTEXT, + `result` TEXT, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/pandora_console/include/db/mysql.php b/pandora_console/include/db/mysql.php index ce6f814e95..dd3bc26846 100644 --- a/pandora_console/include/db/mysql.php +++ b/pandora_console/include/db/mysql.php @@ -1244,57 +1244,6 @@ function mysql_db_get_all_row_by_steps_sql($new=true, &$result, $sql=null) } -/** - * Starts a database transaction. - */ -function mysql_db_process_sql_begin() -{ - global $config; - - if ($config['mysqli']) { - mysqli_query($config['dbconnection'], 'SET AUTOCOMMIT = 0'); - mysqli_query($config['dbconnection'], 'START TRANSACTION'); - } else { - mysql_query('SET AUTOCOMMIT = 0'); - mysql_query('START TRANSACTION'); - } -} - - -/** - * Commits a database transaction. - */ -function mysql_db_process_sql_commit() -{ - global $config; - - if ($config['mysqli']) { - mysqli_query($config['dbconnection'], 'COMMIT'); - mysqli_query($config['dbconnection'], 'SET AUTOCOMMIT = 1'); - } else { - mysql_query('COMMIT'); - mysql_query('SET AUTOCOMMIT = 1'); - } -} - - -/** - * Rollbacks a database transaction. - */ -function mysql_db_process_sql_rollback() -{ - global $config; - - if ($config['mysqli']) { - mysqli_query($config['dbconnection'], 'ROLLBACK '); - mysqli_query($config['dbconnection'], 'SET AUTOCOMMIT = 1'); - } else { - mysql_query('ROLLBACK '); - mysql_query('SET AUTOCOMMIT = 1'); - } -} - - /** * Get last error. * diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index a4c21d3bc6..a60dc87b02 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -1377,42 +1377,56 @@ function db_process_sql($sql, $rettype='affected_rows', $dbconnection='', $cache break; } - if ($rc !== false) { - if (enterprise_hook('is_metaconsole') === true - && isset($config['centralized_management']) === true - && (bool) $config['centralized_management'] === true - && $dbconnection === '' - ) { - $errors = null; - try { - // Synchronize changes to nodes if needed. - $sync = new Synchronizer(); - if ($sync !== null) { - if ($sync->queue($sql) === false) { - // Launch events per failed query. - $errors = $sync->getLatestErrors(); - if ($errors !== null) { - $errors = join(', ', $errors); - } else { - $errors = ''; - } - } - } - } catch (\Exception $e) { - $errors = $e->getMessage(); - } - - if ($errors !== null) { - // TODO: Generate pandora event. - error_log($errors); - } - } - } + db_sync($dbconnection, $sql, $rc); return $rc; } +/** + * Propagate to nodes. + * + * @param mixed $dbconnection Dbconnection. + * @param mixed $sql Sql. + * @param mixed $rc Rc. + * + * @return void + */ +function db_sync($dbconnection, $sql, $rc) +{ + global $config; + if (enterprise_hook('is_metaconsole') === true + && isset($config['centralized_management']) === true + && (bool) $config['centralized_management'] === true + && $dbconnection === '' + ) { + $errors = null; + try { + // Synchronize changes to nodes if needed. + $sync = new Synchronizer(); + if ($sync !== null) { + if ($sync->queue($sql, $rc) === false) { + // Launch events per failed query. + $errors = $sync->getLatestErrors(); + if ($errors !== null) { + $errors = join(', ', $errors); + } else { + $errors = ''; + } + } + } + } catch (\Exception $e) { + $errors = $e->getMessage(); + } + + if ($errors !== null) { + // TODO: Generate pandora event. + error_log($errors); + } + } +} + + /** * Get all the rows in a table of the database. * @@ -1810,18 +1824,17 @@ function db_process_sql_begin() global $config; switch ($config['dbtype']) { - case 'mysql': - return mysql_db_process_sql_begin(); - - break; case 'postgresql': return postgresql_db_process_sql_begin(); - break; case 'oracle': return oracle_db_process_sql_begin(); - break; + default: + case 'mysql': + db_process_sql('SET AUTOCOMMIT = 0', 'affected_rows', '', false, null, false); + db_process_sql('START TRANSACTION', 'affected_rows', '', false, null, false); + break; } } @@ -1834,18 +1847,17 @@ function db_process_sql_commit() global $config; switch ($config['dbtype']) { - case 'mysql': - return mysql_db_process_sql_commit(); - - break; case 'postgresql': return postgresql_db_process_sql_commit(); - break; case 'oracle': return oracle_db_process_sql_commit(); - break; + default: + case 'mysql': + db_process_sql('COMMIT', 'affected_rows', '', false, null, false); + db_process_sql('SET AUTOCOMMIT = 1', 'affected_rows', '', false, null, false); + break; } } @@ -1858,18 +1870,17 @@ function db_process_sql_rollback() global $config; switch ($config['dbtype']) { - case 'mysql': - return mysql_db_process_sql_rollback(); - - break; case 'postgresql': return postgresql_db_process_sql_rollback(); - break; case 'oracle': return oracle_db_process_sql_rollback(); - break; + default: + case 'mysql': + db_process_sql('ROLLBACK', 'affected_rows', '', false, null, false); + db_process_sql('SET AUTOCOMMIT = 1', 'affected_rows', '', false, null, false); + break; } } @@ -1889,6 +1900,7 @@ function db_print_database_debug() echo '
'.__('Database debug').'
'; + $table = new stdClass(); $table->id = 'database_debug'; $table->cellpadding = '0'; $table->width = '95%'; @@ -1946,18 +1958,15 @@ function db_get_last_error() global $config; switch ($config['dbtype']) { - case 'mysql': - return mysql_db_get_last_error(); - - break; case 'postgresql': return postgresql_db_get_last_error(); - break; case 'oracle': return oracle_db_get_last_error(); - break; + case 'mysql': + default: + return mysql_db_get_last_error(); } } @@ -1975,18 +1984,15 @@ function db_get_type_field_table($table, $field) global $config; switch ($config['dbtype']) { - case 'mysql': - return mysql_db_get_type_field_table($table, $field); - - break; case 'postgresql': return postgresql_db_get_type_field_table($table, $field); - break; case 'oracle': return oracle_db_get_type_field_table($table, $field); - break; + case 'mysql': + default: + return mysql_db_get_type_field_table($table, $field); } } diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index f8b675c9d6..fe475df931 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -4069,6 +4069,7 @@ CREATE TABLE IF NOT EXISTS `tsync_queue` ( `operation` text, `table` text, `error` MEDIUMTEXT, + `result` TEXT, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;