Planned downtime copy.

This commit is contained in:
Calvo 2022-01-28 10:59:08 +01:00
parent 0b119af949
commit 11dc743dac
2 changed files with 41 additions and 25 deletions

View File

@ -423,10 +423,11 @@ if ($create_downtime || $update_downtime) {
if ($downtime_copy) { if ($downtime_copy) {
$result = planned_downtimes_copy($id_downtime); $result = planned_downtimes_copy($id_downtime);
if ($result === true) { if ($result['id_downtime'] !== false) {
ui_print_success_message(__('Successfully copied')); $id_downtime = $result['id_downtime'];
ui_print_success_message($result['success']);
} else { } else {
ui_print_error_message(__('Could not be copied')); ui_print_error_message(__($result['error']));
} }
} }

View File

@ -928,12 +928,12 @@ function planned_downtimes_copy($id_downtime)
['id' => $id_downtime] ['id' => $id_downtime]
); );
$planned_agents = db_get_row_filter( $planned_agents = db_get_all_rows_filter(
'tplanned_downtime_agents', 'tplanned_downtime_agents',
['id_downtime' => $id_downtime] ['id_downtime' => $id_downtime]
); );
$planned_modules = db_get_row_filter( $planned_modules = db_get_all_rows_filter(
'tplanned_downtime_modules', 'tplanned_downtime_modules',
['id_downtime' => $id_downtime] ['id_downtime' => $id_downtime]
); );
@ -949,22 +949,34 @@ function planned_downtimes_copy($id_downtime)
$planned_downtime['name'] = __('Coy of ').$planned_downtime['name']; $planned_downtime['name'] = __('Coy of ').$planned_downtime['name'];
// Insert new downtime // Insert new downtime
$result = db_process_sql_insert( $result['id_downtime'] = db_process_sql_insert(
'tplanned_downtime', 'tplanned_downtime',
$planned_downtime $planned_downtime
); );
if ($result === false) { if ($result === false) {
return false; $result['error'] = __('Could not be copied');
return $result;
} else {
$result['success'] = __('Successfully copied');
} }
if ($planned_agents !== false) { if ($planned_agents !== false) {
// Unser id. foreach ($planned_agents as $planned_agent) {
unset($planned_agents['id']); // Unset id.
$result = db_process_sql_insert( 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', 'tplanned_downtime_agents',
$planned_agents $planned_agent
); );
if ($result === false) {
$return['error'] = __('Error adding agents to copied downtime');
break;
}
}
} }
if ($result === false) { if ($result === false) {
@ -974,18 +986,21 @@ function planned_downtimes_copy($id_downtime)
if ((bool) $planned_agents['all_modules'] === false if ((bool) $planned_agents['all_modules'] === false
&& $planned_modules !== false && $planned_modules !== false
) { ) {
// Unser id. foreach ($planned_modules as $planned_module) {
unset($planned_modules['id']); // Unset id.
$result = db_process_sql_insert( unset($planned_module['id']);
'tplanned_downtime_agents', // Set id_planned downtime
$planned_agents $planned_module['id_downtime'] = $result['id_downtime'];
$result['id_modules'][] = db_process_sql_insert(
'tplanned_downtime_moduless',
$planned_module
); );
}
if ($result === false) { if ($result === false) {
return false; $return['error'] = __('Error adding module to copied downtime');
break;
}
}
} }
return true; return $result;
} }