Merge branch 'ent-8276-copiado-paradas-planificadas' into 'develop'

Planned downtime copy.

See merge request artica/pandorafms!4662
This commit is contained in:
Daniel Rodriguez 2022-02-02 09:36:18 +00:00
commit 2ed2fdfd6c
3 changed files with 160 additions and 57 deletions

View File

@ -135,6 +135,7 @@ $first_create = (int) get_parameter('first_create');
$create_downtime = (int) get_parameter('create_downtime'); $create_downtime = (int) get_parameter('create_downtime');
$update_downtime = (int) get_parameter('update_downtime'); $update_downtime = (int) get_parameter('update_downtime');
$edit_downtime = (int) get_parameter('edit_downtime'); $edit_downtime = (int) get_parameter('edit_downtime');
$downtime_copy = (int) get_parameter('downtime_copy');
$id_downtime = (int) get_parameter('id_downtime'); $id_downtime = (int) get_parameter('id_downtime');
$id_agent = (int) get_parameter('id_agent'); $id_agent = (int) get_parameter('id_agent');
@ -420,6 +421,16 @@ if ($create_downtime || $update_downtime) {
} }
} }
if ($downtime_copy) {
$result = planned_downtimes_copy($id_downtime);
if ($result['id_downtime'] !== false) {
$id_downtime = $result['id_downtime'];
ui_print_success_message($result['success']);
} else {
ui_print_error_message(__($result['error']));
}
}
// Have any data to show ? // Have any data to show ?
if ($id_downtime > 0) { if ($id_downtime > 0) {
// Columns of the table tplanned_downtime. // Columns of the table tplanned_downtime.

View File

@ -405,6 +405,7 @@ else {
if ($write_permisson || $manage_permisson) { if ($write_permisson || $manage_permisson) {
$table->head['stop'] = __('Stop downtime'); $table->head['stop'] = __('Stop downtime');
$table->head['copy'] = __('Copy');
$table->head['edit'] = __('Edit'); $table->head['edit'] = __('Edit');
$table->head['delete'] = __('Delete'); $table->head['delete'] = __('Delete');
} }
@ -492,6 +493,8 @@ else {
if (check_acl_restricted_all($config['id_user'], $downtime['id_group'], 'AW') if (check_acl_restricted_all($config['id_user'], $downtime['id_group'], 'AW')
|| check_acl_restricted_all($config['id_user'], $downtime['id_group'], 'AD') || check_acl_restricted_all($config['id_user'], $downtime['id_group'], 'AD')
) { ) {
// Copy.
$data['copy'] = '<a href="index.php?sec=extensions&sec2=godmode/agentes/planned_downtime.editor&downtime_copy=1&id_downtime='.$downtime['id'].'">'.html_print_image('images/copy.png', true, ['title' => __('Copy'), 'class' => 'invert_filter']).'</a>';
// Edit. // Edit.
$data['edit'] = '<a href="index.php?sec=extensions&sec2=godmode/agentes/planned_downtime.editor&edit_downtime=1&id_downtime='.$downtime['id'].'">'.html_print_image('images/config.png', true, ['title' => __('Update'), 'class' => 'invert_filter']).'</a>'; $data['edit'] = '<a href="index.php?sec=extensions&sec2=godmode/agentes/planned_downtime.editor&edit_downtime=1&id_downtime='.$downtime['id'].'">'.html_print_image('images/config.png', true, ['title' => __('Update'), 'class' => 'invert_filter']).'</a>';
// Delete. // Delete.
@ -504,6 +507,8 @@ else {
if (check_acl_restricted_all($config['id_user'], $downtime['id_group'], 'AW') if (check_acl_restricted_all($config['id_user'], $downtime['id_group'], 'AW')
|| check_acl_restricted_all($config['id_user'], $downtime['id_group'], 'AD') || check_acl_restricted_all($config['id_user'], $downtime['id_group'], 'AD')
) { ) {
// Copy.
$data['copy'] = '<a href="index.php?sec=extensions&sec2=godmode/agentes/planned_downtime.editor&downtime_copy=1&id_downtime='.$downtime['id'].'">'.html_print_image('images/copy.png', true, ['title' => __('Copy'), 'class' => 'invert_filter']).'</a>';
// Edit. // Edit.
$data['edit'] = '<a href="index.php?sec=extensions&sec2=godmode/agentes/planned_downtime.editor&edit_downtime=1&id_downtime='.$downtime['id'].'">'.html_print_image('images/config.png', true, ['title' => __('Update'), 'class' => 'invert_filter']).'</a>'; $data['edit'] = '<a href="index.php?sec=extensions&sec2=godmode/agentes/planned_downtime.editor&edit_downtime=1&id_downtime='.$downtime['id'].'">'.html_print_image('images/config.png', true, ['title' => __('Update'), 'class' => 'invert_filter']).'</a>';
// Delete. // Delete.
@ -513,11 +518,13 @@ else {
$data['delete'] = ''; $data['delete'] = '';
} }
} else { } else {
$data['copy'] = '';
$data['edit'] = ''; $data['edit'] = '';
$data['delete'] = ''; $data['delete'] = '';
} }
} else { } else {
$data['stop'] = ''; $data['stop'] = '';
$data['copy'] = '';
$data['edit'] = ''; $data['edit'] = '';
$data['delete'] = ''; $data['delete'] = '';
} }

View File

@ -919,3 +919,88 @@ function delete_planned_downtimes($filter)
return $return; return $return;
} }
function planned_downtimes_copy($id_downtime)
{
$planned_downtime = db_get_row_filter(
'tplanned_downtime',
['id' => $id_downtime]
);
$planned_agents = db_get_all_rows_filter(
'tplanned_downtime_agents',
['id_downtime' => $id_downtime]
);
$planned_modules = db_get_all_rows_filter(
'tplanned_downtime_modules',
['id_downtime' => $id_downtime]
);
if ($planned_downtime === false) {
return false;
}
// Unset id.
unset($planned_downtime['id']);
// Change copy name.
$planned_downtime['name'] = __('Copy of ').$planned_downtime['name'];
// Insert new downtime
$result['id_downtime'] = db_process_sql_insert(
'tplanned_downtime',
$planned_downtime
);
if ($result === false) {
$result['error'] = __('Could not be copied');
return $result;
} else {
$result['success'] = __('Successfully copied');
}
if ($planned_agents !== false) {
foreach ($planned_agents as $planned_agent) {
// Unset id.
unset($planned_agent['id']);
// Set id_planned downtime
$planned_agent['id_downtime'] = $result['id_downtime'];
$result['id_agents'][] = db_process_sql_insert(
'tplanned_downtime_agents',
$planned_agent
);
if ($result === false) {
$return['error'] = __('Error adding agents to copied downtime');
break;
}
}
}
if ($result === false) {
return false;
}
if ((bool) $planned_agents['all_modules'] === false
&& $planned_modules !== false
) {
foreach ($planned_modules as $planned_module) {
// Unset id.
unset($planned_module['id']);
// Set id_planned downtime
$planned_module['id_downtime'] = $result['id_downtime'];
$result['id_modules'][] = db_process_sql_insert(
'tplanned_downtime_moduless',
$planned_module
);
if ($result === false) {
$return['error'] = __('Error adding module to copied downtime');
break;
}
}
}
return $result;
}