New networkmaps in progress... (Added new migration system, awesome)

This commit is contained in:
Arturo Gonzalez 2016-10-11 11:14:28 +02:00
parent eb9390cad6
commit 9157c76ba0
2 changed files with 139 additions and 21 deletions

View File

@ -283,34 +283,85 @@ switch ($tab) {
$old_networkmaps_open = array();
if (enterprise_installed()) {
$old_networkmaps_enterprise = db_get_all_rows_sql("SELECT id FROM tnetworkmap_enterprise");
$old_networkmaps_enterprise = db_get_all_rows_sql("SELECT * FROM tnetworkmap_enterprise");
}
$old_networkmaps_open = db_get_all_rows_sql("SELECT id_networkmap FROM tnetwork_map");
$old_networkmaps_open = db_get_all_rows_sql("SELECT * FROM tnetwork_map");
$ent_maps_to_migrate = array();
foreach ($old_networkmaps_enterprise as $old_map_ent) {
if (!map_migrated($old_map_ent['id'])) {
if (enterprise_installed()) {
enterprise_include_once ('include/functions_pandora_networkmap.php');
$return = migrate_older_networkmap_enterprise($old_map_ent['id']);
if (!$return) {
break;
}
}
}
}
foreach ($old_networkmaps_enterprise as $old_map_ent) {
if (!map_migrated($old_map_ent['id'])) {
$return = migrate_older_open_maps($old_map_ent['id']);
}
$old_map_options = json_decode($old_map_ent['options'], true);
if (!$return) {
break;
if (!isset($old_map_options['migrated'])) {
$ent_maps_to_migrate[] = $old_map_ent['id'];
}
}
$open_maps_to_migrate = array();
foreach ($old_networkmaps_open as $old_map_open) {
$text_filter = $old_map_open['text_filter'];
if ($text_filter != "migrated") {
$open_maps_to_migrate[] = $old_map_open['id'];
}
}
if (!empty($ent_maps_to_migrate) || !empty($open_maps_to_migrate)) {
?>
<div id="migration_dialog" style="text-align: center;">
<p style="text-align: center;"><strong>Networkmaps are not migrated, wait while migration is processed...</strong></p>
<br>
<img style="vertical-align: middle;" src="images/spinner.gif">
</div>
<script>
$("#migration_dialog").dialog({
close: function() {document.location.href = document.location.href;}
});
var old_maps_ent = "<?php echo implode(",", $ent_maps_to_migrate); ?>";
var old_maps_open = "<?php echo implode(",", $open_maps_to_migrate); ?>";
if (old_maps_ent == "") {
old_maps_ent = 0;
}
if (old_maps_open == "") {
old_maps_open = 0;
}
var params = [];
params.push("process_migration=1");
params.push("old_maps_ent=" + old_maps_ent);
params.push("old_maps_open=" + old_maps_open);
params.push("page=operation/agentes/pandora_networkmap.view");
jQuery.ajax ({
data: params.join ("&"),
dataType: 'json',
type: 'POST',
url: action="ajax.php",
success: function (data) {
var html_message = "";
if (data['ent'] && data['open']) {
html_message = "<p><strong>Complete migrations without errors</strong></p>"
$("#migration_dialog").html(html_message);
}
else if (data['ent']) {
html_message = "<p><strong>Complete migrations with open maps errors</strong></p>"
$("#migration_dialog").html(html_message);
}
else if (data['open']) {
html_message = "<p><strong>Complete migrations with enterprise maps errors</strong></p>"
$("#migration_dialog").html(html_message);
}
else {
html_message = "<p><strong>Complete migrations with errors</strong></p>"
$("#migration_dialog").html(html_message);
}
}
});
</script>
<?php
}
ui_print_page_header(__('Networkmap'),
"images/op_network.png", false, "network_map_enterprise",
false);

View File

@ -36,6 +36,7 @@ if (is_ajax ()) {
$update_z = (bool)get_parameter('update_z', false);
$module_get_status = (bool)get_parameter('module_get_status', false);
$update_node_alert = (bool)get_parameter('update_node_alert', false);
$process_migration = (bool)get_parameter('process_migration', false);
if ($module_get_status) {
$id = (int)get_parameter('id', 0);
@ -610,6 +611,72 @@ if (is_ajax ()) {
return;
}
if ($process_migration) {
$old_maps_ent = get_parameter('old_maps_ent', true);
$old_maps_open = get_parameter('old_maps_open', true);
$return_data = array();
$return_data['ent'] = true;
if ($old_maps_ent != 0) {
$old_maps_ent = explode(",", $old_maps_ent);
if (enterprise_installed()) {
foreach ($old_maps_ent as $id_ent_map) {
$return = migrate_older_networkmap_enterprise($id_ent_map);
if (!$return) {
$return_data['ent'] = false;
break;
}
else {
$old_networkmap_ent = db_get_row_filter('tnetworkmap_enterprise',
array('id' => $id_ent_map));
$options = json_decode($old_networkmap_ent, true);
$options['migrated'] = "migrated";
$values['options'] = json_encode($options);
$return_update = db_process_sql_update('tnetworkmap_enterprise', $values, array('id' => $id_ent_map));
if (!$return_update) {
$return_data['ent'] = false;
break;
}
}
}
}
}
$return_data['open'] = true;
if ($old_maps_open != 0) {
$old_maps_open = explode(",", $old_maps_open);
foreach ($old_maps_open as $id_open_map) {
$return = migrate_older_open_maps($id_open_map);
if (!$return) {
$return_data['open'] = false;
break;
}
else {
$old_networkmap_open = db_get_row_filter('tnetwork_map',
array('id_networkmap' => $id_open_map));
$values['text_filter'] = "migrated";
$return_update = db_process_sql_update('tnetwork_map', $values, array('id_networkmap' => $id_ent_map));
if (!$return_update) {
$return_data['open'] = false;
break;
}
}
}
}
echo json_encode($return_data);
return;
}
}
//--------------END AJAX------------------------------------------------