Skip to content

Commit 880e4c7

Browse files
author
Marius Burkard
committed
- added undelete to datalog history viewer
1 parent f08ea8f commit 880e4c7

File tree

6 files changed

+33
-9
lines changed

6 files changed

+33
-9
lines changed

interface/lib/classes/db_mysql.inc.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,9 @@ public function datalogInsert($tablename, $insert_data, $index_field) {
759759

760760
$old_rec = array();
761761
$index_value = $this->insertID();
762+
if(!$index_value && isset($insert_data[$index_field])) {
763+
$index_value = $insert_data[$index_field];
764+
}
762765
$new_rec = $this->queryOneRecord("SELECT * FROM ?? WHERE ?? = ?", $tablename, $index_field, $index_value);
763766
$this->datalogSave($tablename, 'INSERT', $index_field, $index_value, $old_rec, $new_rec);
764767

interface/web/monitor/dataloghistory_undo.php

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,36 @@
5050

5151
$old_record = $app->db->queryOneRecord('SELECT * FROM ?? WHERE ??=?', $record['dbtable'], $dbidx[0], $dbidx[1]);
5252

53-
if (is_array($old_record)) {
54-
if(!$data = unserialize(stripslashes($record['data']))) {
55-
$data = unserialize($record['data']);
53+
if($record['action'] === 'u') {
54+
if (is_array($old_record)) {
55+
if(!$data = unserialize(stripslashes($record['data']))) {
56+
$data = unserialize($record['data']);
57+
}
58+
59+
$new_record = $data['old'];
60+
61+
$app->db->datalogUpdate($record['dbtable'], $new_record, $dbidx[0], $dbidx[1]);
62+
63+
$app->tpl->setVar('success', true);
64+
} else {
65+
$app->tpl->setVar('success', false);
5666
}
67+
} elseif($record['action'] === 'd') {
68+
if(is_array($old_record)) {
69+
$app->tpl->setVar('success', false);
70+
$app->tpl->setVar('error_txt', $wb['error_undelete_txt']);
71+
} else {
72+
if(!$data = unserialize(stripslashes($record['data']))) {
73+
$data = unserialize($record['data']);
74+
}
5775

58-
$new_record = $data['old'];
76+
$new_record = $data['old'];
77+
/* TODO: maybe check some data, e. g. server_id -> server still there?, sys_groupid -> sys_group/sys_user still there? */
5978

60-
$app->db->datalogUpdate($record['dbtable'], $new_record, $dbidx[0], $dbidx[1]);
79+
$app->db->datalogInsert($record['dbtable'], $new_record, $dbidx[0]);
6180

62-
$app->tpl->setVar('success', true);
63-
} else {
64-
$app->tpl->setVar('success', false);
81+
$app->tpl->setVar('success', true);
82+
}
6583
}
6684

6785
$app->tpl_defaults();

interface/web/monitor/dataloghistory_view.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
}
110110

111111
$app->tpl->setVar($out);
112+
$app->tpl->setVar('can_undo', ($out['action_char'] === 'u' || $out['action_char'] === 'd'));
112113

113114
$app->tpl_defaults();
114115
$app->tpl->pparse();

interface/web/monitor/lib/lang/de_dataloghistory_undo.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
$wb['list_head_txt'] = 'Datalog-History-Eintrag';
33
$wb['success_txt'] = 'Erfolgreich zurückgesetzt';
44
$wb['error_txt'] = 'Fehler beim Zurücksetzen: Eintrag existiert nicht mehr';
5+
$wb['error_undelete_txt'] = 'Fehler beim Wiederherstellen: Eintrag mit dieser Id existiert bereits';
56
$wb['btn_cancel_txt'] = 'Zurück';
67
?>

interface/web/monitor/lib/lang/en_dataloghistory_undo.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
$wb['list_head_txt'] = 'Data Log History Entry';
33
$wb['success_txt'] = 'Undo successful';
44
$wb['error_txt'] = 'Error during undo: Record does not exist anymore';
5+
$wb['error_undelete_txt'] = 'Error during undelete: Record with primary id already existing.';
56
$wb['btn_cancel_txt'] = 'Back';
67
?>

interface/web/monitor/templates/dataloghistory_view.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ <h2><tmpl_var name="fields_deleted_txt"></h2>
116116

117117
<div class="clear">
118118
<div class="right">
119-
<tmpl_if name='action_char' value='u'>
119+
<tmpl_if name='can_undo'>
120120
<a class="btn btn-default formbutton-danger formbutton-narrow" href="javascript: ISPConfig.confirm_action('monitor/dataloghistory_undo.php?id={tmpl_var name='id'}','{tmpl_var name='undo_confirmation_txt'}');"> {tmpl_var name='undo_txt'}</a>
121121
</tmpl_if>
122122
<button class="btn btn-default formbutton-default" type="button" value="{tmpl_var name='btn_cancel_txt'}" data-load-content="monitor/dataloghistory_list.php">{tmpl_var name='btn_cancel_txt'}</button>

0 commit comments

Comments
 (0)