mirror of
https://github.com/e107inc/e107.git
synced 2025-08-06 06:38:00 +02:00
Issue #5382 History/Revert changes.
This commit is contained in:
@@ -75,7 +75,7 @@ class admin_history_ui extends e_admin_ui
|
||||
'history_table' => array ( 'title' => 'Table', 'type' => 'text', 'data' => 'safestr', 'width' => 'auto', 'filter' => true, 'help' => '', 'readParms' => [], 'writeParms' => [], 'class' => 'left', 'thclass' => 'left',),
|
||||
'history_record_id' => array ( 'title' => LAN_ID, 'type' => 'number', 'data' => 'int', 'width' => '5%', 'help' => '', 'readParms' => [], 'writeParms' => [], 'class' => 'left', 'thclass' => 'left',),
|
||||
'history_action' => array ( 'title' => 'Action', 'type' => 'dropdown', 'data' => 'int', 'width' => 'auto', 'filter' => true, 'help' => '', 'readParms' => [], 'writeParms' => [], 'class' => 'left', 'thclass' => 'left', 'batch' => false,),
|
||||
'history_data' => array ( 'title' => 'Data', 'type' => 'method', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => [], 'writeParms' => [], 'class' => 'history-data left', 'thclass' => 'left', 'filter' => false, 'batch' => false,),
|
||||
'history_data' => array ( 'title' => 'Changed Data', 'type' => 'method', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => [], 'writeParms' => [], 'class' => 'history-data left', 'thclass' => 'left', 'filter' => false, 'batch' => false,),
|
||||
'history_user_id' => array ( 'title' => LAN_USER, 'type' => 'user', 'data' => 'int', 'width' => '5%', 'filter' => true, 'help' => '', 'readParms' => [], 'writeParms' => [], 'class' => 'left', 'thclass' => 'left',),
|
||||
'history_restored' => array ( 'title' => "Restored", 'type' => 'datestamp', 'data' => 'int', 'width' => '5%', 'filter' => true, 'help' => '', 'readParms' => [], 'writeParms' => [], 'class' => 'center', 'thclass' => 'center',),
|
||||
|
||||
@@ -94,7 +94,8 @@ class admin_history_ui extends e_admin_ui
|
||||
{
|
||||
$this->fields['history_action']['writeParms']['optArray'] = [
|
||||
'delete' => "<span class='label label-danger'>". LAN_DELETE."</span>",
|
||||
'update' => "<span class='label label-success'>". LAN_UPDATE."</span>"
|
||||
'update' => "<span class='label label-success'>". LAN_UPDATE."</span>",
|
||||
'restore' => "<span class='label label-warning'>Restore</span>"
|
||||
];
|
||||
|
||||
|
||||
@@ -134,16 +135,24 @@ class admin_history_ui extends e_admin_ui
|
||||
$pid = $historyRow['history_pid'];
|
||||
$recordId = $historyRow['history_record_id'];
|
||||
|
||||
|
||||
|
||||
if (!empty($originalTable) && !empty($originalData) && !empty($pid) && !empty($recordId))
|
||||
{
|
||||
|
||||
if($action === 'insert')
|
||||
{
|
||||
$originalData[$pid] = (int) $recordId;
|
||||
$result = $db->replace($originalTable, $originalData);
|
||||
}
|
||||
else
|
||||
else // update
|
||||
{
|
||||
$backup = $db->retrieve($originalTable, '*', $pid. ' = '.(int) $recordId);
|
||||
if($changes = array_diff_assoc($originalData, $backup))
|
||||
{
|
||||
$old_changed_data = array_intersect_key($backup, $changes);
|
||||
$this->backupToHistory($originalTable, $pid, $recordId, 'restore', $old_changed_data, false);
|
||||
}
|
||||
|
||||
$originalData['WHERE'] = $pid .' = '. (int) $recordId;
|
||||
$result = $db->update($originalTable, $originalData);
|
||||
}
|
||||
@@ -153,6 +162,10 @@ class admin_history_ui extends e_admin_ui
|
||||
$message->addSuccess("The record (ID: $id) has been successfully restored to the $originalTable table.", 'default', true);
|
||||
$db->update('admin_history', "history_restored = ".time()." WHERE history_id = $id");
|
||||
}
|
||||
elseif($result === 0)
|
||||
{
|
||||
$message->addInfo("No changes made", 'default', true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$message->addError("Failed to restore the record (ID: $id) to the $originalTable table.", 'default', true);
|
||||
@@ -325,7 +338,7 @@ class admin_history_form_ui extends e_admin_form_ui
|
||||
$text .= "<button class='btn btn-default' type='submit' name='$name' title='{$restoreTitle}'><i class='admin-ui-option fa fa-undo fa-2x fa-fw'></i></button>";
|
||||
}
|
||||
|
||||
$att['readParms']['editClass'] = 999; // disable it.
|
||||
$att['readParms']['editClass'] = 999; // disable it.
|
||||
$text .= $this->renderValue('options', $value, $att, $id);
|
||||
|
||||
// End options group
|
||||
|
@@ -216,7 +216,7 @@ history_id int(10) unsigned NOT NULL auto_increment,
|
||||
history_table varchar(64) NOT NULL default '',
|
||||
history_pid varchar(64) NOT NULL default '',
|
||||
history_record_id int(10) unsigned NOT NULL default '0',
|
||||
history_action enum('delete','update') NOT NULL,
|
||||
history_action enum('delete','restore','update') NOT NULL,
|
||||
history_data JSON DEFAULT NULL,
|
||||
history_user_id int(10) unsigned NOT NULL default '0',
|
||||
history_datestamp int(10) unsigned NOT NULL default '0',
|
||||
|
@@ -124,6 +124,9 @@ $ADMIN_ICONS_TEMPLATE['E_16_PLUGIN'] = "<i class='S16 e-plugins-1
|
||||
$ADMIN_ICONS_TEMPLATE['E_16_PLUGMANAGER'] = "<i class='S16 e-plugmanager-16'></i>";
|
||||
$ADMIN_ICONS_TEMPLATE['E_16_THEMEMANAGER'] = "<i class='S16 e-themes-16'></i>";
|
||||
|
||||
$ADMIN_ICONS_TEMPLATE['E_16_UNDO'] = "<img class='icon S16' src='" . e_IMAGE . "admin_images/undo_16.png' alt='' />";
|
||||
$ADMIN_ICONS_TEMPLATE['E_32_UNDO'] = "<img class='icon S32' src='" . e_IMAGE . "admin_images/undo_32.png' alt='' />";
|
||||
|
||||
$ADMIN_ICONS_TEMPLATE['ADMIN_WARNING_ICON'] = "<i class='fa fa-warning text-warning'></i>";
|
||||
$ADMIN_ICONS_TEMPLATE['ADMIN_GRID_ICON'] = "<i class='fa fa-th'></i>";
|
||||
$ADMIN_ICONS_TEMPLATE['ADMIN_LIST_ICON'] = "<i class='fas fa-list'></i>";
|
||||
|
@@ -4587,15 +4587,19 @@ class e_admin_controller_ui extends e_admin_controller
|
||||
* @param int $id The ID of the specific record being backed up.
|
||||
* @param string $action The action performed on the record (e.g., 'update' or 'delete').
|
||||
* @param array $data An associative array of field data to be included in the history record.
|
||||
* @param bool $posted Whether the data has been posted and requires additional filter based on current $fields values or not.
|
||||
* @return bool True on successful creation of the backup record, false on failure.
|
||||
*/
|
||||
protected function backupToHistory($table, $pid, $id, $action, $data)
|
||||
protected function backupToHistory($table, $pid, $id, $action, $data, $posted = true)
|
||||
{
|
||||
foreach($data as $field=>$var)
|
||||
if($posted)
|
||||
{
|
||||
if(empty($this->fields[$field]['data'])) // exclude data not in the table.
|
||||
foreach($data as $field=>$var)
|
||||
{
|
||||
unset($data[$field]);
|
||||
if(empty($this->fields[$field]['data'])) // exclude data not in the table.
|
||||
{
|
||||
unset($data[$field]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -960,6 +960,8 @@ i.e-cat_users-32{ background-position: -555px 0; width: 32px; height: 32px; }
|
||||
// 7 => array(e_ADMIN.'download.php', ADLAN_24, ADLAN_25, 'R', 3, E_16_DOWNL, E_32_DOWNL),
|
||||
8 => array(e_ADMIN_ABS.'emoticon.php', ADLAN_58, ADLAN_59, 'F', 1, E_16_EMOTE, E_32_EMOTE),
|
||||
// 9 => array(e_ADMIN.'filemanager.php', ADLAN_30, ADLAN_31, '6', 5, E_16_FILE, E_32_FILE), // replaced by media-manager
|
||||
9 => array(e_ADMIN.'history.php', LAN_HISTORY, LAN_HISTORY, '7', 4, E_16_UNDO, E_32_UNDO),
|
||||
|
||||
10 => array(e_ADMIN_ABS.'frontpage.php', ADLAN_60, ADLAN_61, 'G', 1, E_16_FRONT, E_32_FRONT),
|
||||
11 => array(e_ADMIN_ABS.'image.php', LAN_MEDIAMANAGER, LAN_MEDIAMANAGER, 'A', 5, E_16_IMAGES, E_32_IMAGES),
|
||||
12 => array(e_ADMIN_ABS.'links.php', LAN_NAVIGATION, ADLAN_139, 'I', 1, E_16_LINKS, E_32_LINKS),
|
||||
|
@@ -1964,11 +1964,13 @@ class e_userperms
|
||||
|
||||
// Tools
|
||||
"Y" => array(ADLAN_147,E_16_INSPECT, E_32_INSPECT), // File inspector
|
||||
"7" => array(defset('LAN_HISTORY', 'History'), E_16_UNDO, E_32_UNDO), // History/Undo
|
||||
"9" => array(ADLAN_40, E_16_MAINTAIN, E_32_MAINTAIN), // Take Down site for Maintenance
|
||||
"O" => array(ADLAN_149,E_16_NOTIFY, E_32_NOTIFY), // Notify
|
||||
"U" => array(ADLAN_157,E_16_CRON, E_32_CRON), // Schedule Tasks
|
||||
"S" => array(ADLAN_155,E_16_ADMINLOG, E_32_ADMINLOG), // System Logging
|
||||
|
||||
|
||||
// Manage
|
||||
"B" => array(LAN_COMMENTMAN,E_16_COMMENT, E_32_COMMENT), // Moderate Comments
|
||||
"6" => array(LAN_MEDIAMANAGER,E_16_FILE, E_32_FILE), // File-Manager - Upload /manage files -
|
||||
|
@@ -601,4 +601,6 @@ define("LAN_META_DESCRIPTION", "Meta Description");
|
||||
|
||||
define("LAN_SYSTEM_NOTIFICATIONS_X", "[x] System Notification(s)");
|
||||
define("LAN_PHP_OUTDATED", "Your website is currently running an [outdated version of PHP], which may pose a security risk. If your plugins will allow it, we recommend upgrading to [x] to ensure that your website is secure and up-to-date.");
|
||||
define("LAN_DATABASE_UPDATE", "An update is available for your database. We recommend [running this update] as soon as possible to ensure that your database is secure and up-to-date.");
|
||||
define("LAN_DATABASE_UPDATE", "An update is available for your database. We recommend [running this update] as soon as possible to ensure that your database is secure and up-to-date.");
|
||||
|
||||
define("LAN_HISTORY", "History");
|
||||
|
Reference in New Issue
Block a user