Hello developers,
I took a look at CMSimpleSE's (BTW: some very nice additions) restore solution. It is very nice, but I would suggest an even simpler solution: on restore the current content/pagedata will be renamed to the current date/time instead of deleting them. No 'keep' needs to be implemented. More advanced operations could be accomplished by a plugin.
First I like to suggest a tiny change to /cmsimple/login.php, to asure that content and pagedata are synchronized. Line 122ff:
Code: Select all
else if($logout && $adm) {
// cmb: added $backup_date to synchronize content.htm and pagedata.php
$backup_date = date("Ymd_His");
$fn = $backup_date.'_content.htm';
// ...
if(file_exists($pth['folder']['content'].'pagedata.php')){
$fn = $backup_date.'_pagedata.php';
The basically necessary changes to /cmsimple/adm.php. Line 123 (added restore link; slightly rearranged for better readability):
Code: Select all
foreach($fs as $p)
if(preg_match("/\d{3}_content\.htm|\d{3}_pagedata\.php/", $p))
$o .= '<li><a href="'.$sn.'?file='.$p.amp().'action=view">'
.$p.'</a> ('.(round((filesize($pth['folder']['content'].'/'.$p))/102.4)/10).' KB)'
.(preg_match("/\d{3}_content\.htm/", $p)
? ' <a href="'.$sn.'?restore&action='.$p.'">restore</a>'
: '')
.'</li>'."\n";
Line 52ff (added new 'operation'):
Code: Select all
if ($adm) {
if ($restore)$f = 'restore'; // cmb
// ...
if ($f == 'restore') {
cmb_restore();
$f = 'settings'; // to avoid an additional info screen about success/failure of the restore
}
Then somewhere in adm.php the actual restore function has to be added:
Code: Select all
/*
* Restores content.htm and pagedata.php.
*/
function cmb_restore() {
global $pth, $action, $e, $o;
$cdate = date("Ymd_His");
$bdate = substr($action, 0, strlen($cdate));
$dir = $pth['folder']['content'];
// try to rename the 4 files
// rollback on failure (should not fail again, but nonetheless checked)
if (rename($dir.'content.htm', $dir.$cdate.'_content.htm')) {
if (rename($dir.'pagedata.php', $dir.$cdate.'_pagedata.php')) {
if (rename($dir.$bdate.'_content.htm', $dir.'content.htm')) {
if (rename($dir.$bdate.'_pagedata.php', $dir.'pagedata.php')) {
$o .= '<p>Successfully restored '.$bdate.'</p>';
} else {
$success = rename($dir.'content.htm', $dir.$bdate.'_content.htm');
$success &= rename($dir.$cdate, '_pagedata.php', $dir.'pagedata.php');
$success &= rename($dir.$cdate.'_content.htm', $dir.'content.htm');
if ($success) {
$e .= '<li>Restore failed (4)</li>';
} else {
$e .= '<li>OOPS! I\'ve totally mixed up everything!</li>';
}
}
} else {
$success = rename($dir.$cdate, '_pagedata.php', $dir.'pagedata.php');
$success &= rename($dir.$cdate.'_content.htm', $dir.'content.htm');
if ($success) {
$e .= '<li>Restore failed (3)</li>';
} else {
$e .= '<li>OOPS! I\'ve totally mixed up everything!</li>';
}
}
} else {
$success = rename($dir.$cdate.'_content.htm', $dir.'content.htm');
if ($success) {
$e .= '<li>Restore failed (2)</li>';
} else {
$e .= '<li>OOPS! I\'ve totally mixed up everything!</li>';
}
}
} else {
$e .= '<li>Restore failed (1)</li>';
}
}
I've made some tests; seems to work. For inclusion to the core, several adjustments might be necessary, e.g. localization of the output.
Any comments appreciated.
Christoph