Index: branches/RC/core/units/admin/admin_tag_processor.php
===================================================================
diff -u -N -r10448 -r10721
--- branches/RC/core/units/admin/admin_tag_processor.php (.../admin_tag_processor.php) (revision 10448)
+++ branches/RC/core/units/admin/admin_tag_processor.php (.../admin_tag_processor.php) (revision 10721)
@@ -916,5 +916,59 @@
if( getArrayValue($params, 'as_preg') ) $ret = preg_quote($ret, '/');
return $ret;
}
+
+ /**
+ * Returns list of all backup file dates formatted
+ * in passed block
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function PrintBackupDates($params)
+ {
+ $datearray=$this->getDirList($this->Application->ConfigValue('Backup_Path'));
+ $ret = '';
+ foreach($datearray as $key => $value)
+ {
+ $params['backuptimestamp'] = $value;
+ $params['backuptime'] = date('F j, Y, g:i a', $value);
+ $ret .= $this->Application->ParseBlock($params);
+ }
+ return $ret;
+ }
+
+ function getDirList ($dirName)
+ {
+ $filedates = array();
+ $d = dir($dirName);
+
+ while($entry = $d->read())
+ {
+ if ($entry != "." && $entry != "..")
+ {
+ if (!is_dir($dirName."/".$entry) && eregi("dump",$entry))
+ {
+ $filedate[]=$this->chopchop($entry);
+ }
+ }
+ }
+ $d->close();
+ rsort($filedate);
+
+ return $filedate;
+
+ }
+
+ function chopchop ($filename)
+ {
+ $p = pathinfo($filename);
+ $ext = '.'.$p["extension"];
+ $filename;
+ $filename= ereg_replace("dump","",$filename);
+ $filename= ereg_replace($ext,"",$filename);
+ return $filename;
+ }
+
}
?>
\ No newline at end of file
Index: branches/RC/core/units/sections/sections_config.php
===================================================================
diff -u -N -r10718 -r10721
--- branches/RC/core/units/sections/sections_config.php (.../sections_config.php) (revision 10718)
+++ branches/RC/core/units/sections/sections_config.php (.../sections_config.php) (revision 10721)
@@ -289,16 +289,6 @@
'SectionPrefix' => 'adm',
),
- 'in-portal:restore' => Array (
- 'parent' => 'in-portal:tools',
- 'icon' => 'in-portal:tool_restore',
- 'label' => 'la_tab_Restore',
- 'url' => Array ('index_file' => 'backup/restore1.php', 'pass' => 'm'),
- 'permissions' => Array ('view'),
- 'priority' => 3,
- 'type' => stTREE,
- ),
-
'in-portal:main_import' => Array (
'parent' => 'in-portal:tools',
'icon' => 'in-portal:tool_import',
Index: branches/RC/core/units/admin/admin_config.php
===================================================================
diff -u -N -r10718 -r10721
--- branches/RC/core/units/admin/admin_config.php (.../admin_config.php) (revision 10718)
+++ branches/RC/core/units/admin/admin_config.php (.../admin_config.php) (revision 10721)
@@ -22,6 +22,7 @@
'system_tools' => Array('format' => '!la_title_SystemTools!'),
'backup' => Array('format' => '!la_performing_backup!'),
+ 'restore' => Array('format' => '!la_performing_restore!'),
'no_permissions' => Array('format' => '!la_title_NoPermissions!'),
@@ -55,16 +56,26 @@
'type' => stTREE,
),
- 'in-portal:backup_new' => Array (
+ 'in-portal:backup' => Array (
'parent' => 'in-portal:tools',
'icon' => 'in-portal:tool_backup',
'label' => 'la_tab_Backup',
'url' => Array ('t' => 'tools/backup1', 'pass' => 'm'),
'permissions' => Array ('view'),
- 'priority' => 2.5,
+ 'priority' => 2,
'type' => stTREE,
),
+ 'in-portal:restore' => Array (
+ 'parent' => 'in-portal:tools',
+ 'icon' => 'in-portal:tool_restore',
+ 'label' => 'la_tab_Restore',
+ 'url' => Array ('t' => 'tools/restore1', 'pass' => 'm'),
+ 'permissions' => Array ('view'),
+ 'priority' => 3,
+ 'type' => stTREE,
+ ),
+
'in-portal:service' => Array(
'parent' => 'in-portal:tools',
'icon' => 'conf_general',
Index: branches/RC/core/admin_templates/img/icons/icon46_tool_restore.gif
===================================================================
diff -u -N
Binary files differ
Index: branches/RC/kernel/units/sections/sections_config.php
===================================================================
diff -u -N -r10718 -r10721
--- branches/RC/kernel/units/sections/sections_config.php (.../sections_config.php) (revision 10718)
+++ branches/RC/kernel/units/sections/sections_config.php (.../sections_config.php) (revision 10721)
@@ -289,16 +289,6 @@
'SectionPrefix' => 'adm',
),
- 'in-portal:restore' => Array (
- 'parent' => 'in-portal:tools',
- 'icon' => 'in-portal:tool_restore',
- 'label' => 'la_tab_Restore',
- 'url' => Array ('index_file' => 'backup/restore1.php', 'pass' => 'm'),
- 'permissions' => Array ('view'),
- 'priority' => 3,
- 'type' => stTREE,
- ),
-
'in-portal:main_import' => Array (
'parent' => 'in-portal:tools',
'icon' => 'in-portal:tool_import',
Index: branches/RC/core/units/admin/admin_events_handler.php
===================================================================
diff -u -N -r10718 -r10721
--- branches/RC/core/units/admin/admin_events_handler.php (.../admin_events_handler.php) (revision 10718)
+++ branches/RC/core/units/admin/admin_events_handler.php (.../admin_events_handler.php) (revision 10721)
@@ -599,7 +599,7 @@
}
/**
- * Stops users import & redirect to import template
+ * Stops Backup & redirect to Backup template
*
* @param kEvent $event
*/
@@ -608,6 +608,16 @@
$event->redirect = 'tools/backup1';
}
+ /**
+ * Stops Restore & redirect to Restore template
+ *
+ * @param kEvent $event
+ */
+ function OnRestoreCancel(&$event)
+ {
+ $event->redirect = 'tools/restore1';
+ }
+
function performBackup()
{
$backupProgress = unserialize($this->Application->RecallVar('adm.backup_status'));
@@ -622,6 +632,10 @@
if ($a_records['num'] < 50) {
$backupProgress['table_num']++;
+ if ($backupProgress['table_names'][$backupProgress['table_num']] == TABLE_PREFIX.'Cache') {
+ $backupProgress['table_num']++;
+ }
+ $backupProgress['record_count'] = 0;
} else {
$backupProgress['record_count']+=50;
}
@@ -684,14 +698,15 @@
$values_sql .= $this->Conn->qstr($field_value).',';
}
$values_sql = preg_replace('/(.*),$/', '\\1', $values_sql);
- $temp .= 'INSERT INTO '.$table.' ('.$fields_sql.') VALUES ('.$values_sql.')';
+ $sql = 'INSERT INTO '.$table.' ('.$fields_sql.') VALUES ('.$values_sql.');';
+ $sql=ereg_replace("\n","\\n", $sql);
+ $sql=ereg_replace("\r","\\r", $sql);
+ $temp .= $sql."\n";
}
- $temp=ereg_replace("\n","\\n", $temp);
- $temp=ereg_replace("\r","\\r", $temp);
if(strlen(TABLE_PREFIX))
{
- $temp = str_replace("INSERT INTO $prefix","INSERT INTO ",$temp);
+ $temp = str_replace("INSERT INTO ".TABLE_PREFIX, "INSERT INTO ", $temp);
}
return Array(
@@ -758,6 +773,284 @@
return $schema_create;
}
+ /**
+ * Deletes one backup file
+ *
+ * @param kEvent $event
+ */
+ function OnDeleteBackup(&$event)
+ {
+ @unlink($this->get_backup_file());
+ }
+ function get_backup_file()
+ {
+ return $this->Application->ConfigValue('Backup_Path').'/dump'.$this->Application->GetVar('backupdate').'.txt';
+ }
+ /**
+ * Starts restore process
+ *
+ * @param kEvent $event
+ */
+ function OnRestore(&$event)
+ {
+ $file = $this->get_backup_file();
+
+ $restoreProgress = Array (
+ 'file_pos' => 0,
+ 'file_name' => $file,
+ 'file_size' => filesize($file),
+ );
+ $this->Application->RemoveVar('adm.restore_success');
+ $this->Application->StoreVar('adm.restore_status', serialize($restoreProgress));
+ $event->redirect = 'tools/restore3';
+ }
+
+ function OnRestoreProgress(&$event)
+ {
+ $done_percent = $this->performRestore();
+
+ if ($done_percent == -3) {
+ $event->redirect = 'tools/restore4';
+ return ;
+ }
+
+ if ($done_percent < 0) {
+ $this->Application->StoreVar('adm.restore_error', 'File read error'); $event->redirect = 'tools/restore4';
+ return ;
+ }
+
+ if ($done_percent == 100) {
+ $this->replaceRestoredFiles();
+ $this->Application->StoreVar('adm.restore_success', 1);
+ $event->redirect = 'tools/restore4';
+ return ;
+ }
+
+ echo $done_percent;
+ $event->status = erSTOP;
+
+ }
+
+ function replaceRestoredFiles()
+ {
+ // gather restored table names
+ $tables = $this->Conn->GetCol('SHOW TABLES');
+ $mask_restore_table = '/^restore'.TABLE_PREFIX.'(.*)$/';
+ foreach($tables as $table)
+ {
+ if( preg_match($mask_restore_table,$table,$rets) )
+ {
+ $old_table = substr($table, 7);
+ $this->Conn->Query('DROP TABLE IF EXISTS '.$old_table);
+ $this->Conn->Query('CREATE TABLE '.$old_table.' LIKE '.$table);
+ $this->Conn->Query('INSERT INTO '.$old_table.' SELECT * FROM '.$table);
+ $this->Conn->Query('DROP TABLE '.$table);
+ }
+ }
+
+ }
+
+ function performRestore()
+ {
+ $restoreProgress = unserialize($this->Application->RecallVar('adm.restore_status'));
+ $filename = $restoreProgress['file_name'];
+ $FileOffset = $restoreProgress['file_pos'];
+ $MaxLines = 200;
+ $size = filesize($filename);
+
+ if($FileOffset > $size) {
+ return -2;
+ }
+
+ $fp = fopen($filename,"r");
+ if(!$fp) {
+ return -1;
+ }
+
+
+ if($FileOffset>0)
+ {
+ fseek($fp,$FileOffset);
+ }
+ else
+ {
+ $EndOfSQL = FALSE;
+ $sql = "";
+ while(!feof($fp) && !$EndOfSQL)
+ {
+ $l = fgets($fp,16384);
+ if(substr($l,0,11)=="INSERT INTO")
+ {
+ $EndOfSQL = TRUE;
+ }
+ else
+ {
+ $sql .= $l;
+ $FileOffset = ftell($fp) - strlen($l);
+ }
+ }
+ if(strlen($sql))
+ {
+ $error = $this->runSchemaText($sql);
+ if ($error != '') {
+
+ $this->Application->StoreVar('adm.restore_error', $error);
+ return -3;
+ }
+ }
+ fseek($fp,$FileOffset);
+ }
+
+ $LinesRead = 0;
+ $sql = "";
+ $AllSql = array();
+ while($LinesRead < $MaxLines && !feof($fp))
+ {
+ $sql = fgets($fp, 16384);
+ if(strlen($sql))
+ {
+ $AllSql[] = $sql;
+ $LinesRead++;
+ }
+ }
+ if(!feof($fp))
+ {
+ $FileOffset = ftell($fp);
+ }
+ else
+ {
+ $FileOffset = $size;
+ }
+ fclose($fp);
+
+ if(count($AllSql)>0) {
+ $error = $this->runSQLText($AllSql);
+ if ($error != '') {
+
+ $this->Application->StoreVar('adm.restore_error', $error);
+ return -3;
+ }
+
+ }
+ $restoreProgress['file_pos'] = $FileOffset;
+ $this->Application->StoreVar('adm.restore_status', serialize($restoreProgress));
+
+ return round($FileOffset/$size * 100);
+// $this->Application->StoreVar('adm.restore_error', 'lalalal');
+// $event->redirect = 'tools/restore4';
+ }
+
+
+ function runSchemaText($sql)
+ {
+ $table_prefix = 'restore'.TABLE_PREFIX;
+// $table_prefix = TABLE_PREFIX;
+ if(strlen($table_prefix))
+ {
+ $what = "CREATE TABLE ";
+ $replace = "CREATE TABLE ".$table_prefix;
+ $sql = ereg_replace($what, $replace, $sql);
+
+ $what = "DROP TABLE ";
+ $replace = "DROP TABLE IF EXISTS ".$table_prefix;
+ $sql = ereg_replace($what, $replace, $sql);
+
+ $what = "INSERT INTO ";
+ $replace = "INSERT INTO ".$table_prefix;
+ $sql = ereg_replace($what, $replace, $sql);
+
+ $what = "UPDATE ";
+ $replace = "UPDATE ".$table_prefix;
+ $sql = ereg_replace($what, $replace, $sql);
+
+ $what = "ALTER TABLE ";
+ $replace = "ALTER TABLE ".$table_prefix;
+ $sql = ereg_replace($what, $replace, $sql);
+ }
+
+ $commands = explode("# --------------------------------------------------------",$sql);
+ if(count($commands)>0)
+ {
+// $query_func = getConnectionInterface('query',$dbo_type);
+// $errorno_func = getConnectionInterface('errorno',$dbo_type);
+// $errormsg_func = getConnectionInterface('errormsg',$dbo_type);
+
+ for($i = 0; $i < count($commands); $i++)
+ {
+ $cmd = $commands[$i];
+ $cmd = trim($cmd);
+ if(strlen($cmd)>0)
+ {
+ $this->Conn->Query($cmd);
+ if($this->Conn->errorCode != 0)
+ {
+ return $this->Conn->errorMessage." COMMAND:
$cmd
";
+ }
+ }
+ }
+ }
+ }
+
+ function runSQLText($allsql)
+ {
+ $line = 0;
+// $query_func = getConnectionInterface('query',$dbo_type);
+// $errorno_func = getConnectionInterface('errorno',$dbo_type);
+// $errormsg_func = getConnectionInterface('errormsg',$dbo_type);
+
+ while($line0 && substr($sql,0,1)!="#")
+ {
+ $table_prefix = 'restore'.TABLE_PREFIX;
+ if(strlen($table_prefix))
+ {
+ $what = "CREATE TABLE ";
+ $replace = "CREATE TABLE ".$table_prefix;
+ $sql = ereg_replace($what, $replace, $sql);
+
+ $what = "DELETE FROM ";
+ $replace = "DELETE FROM ".$table_prefix;
+ $sql = ereg_replace($what, $replace, $sql);
+
+ $what = "DROP TABLE ";
+ $replace = "DROP TABLE IF EXISTS ".$table_prefix;
+ $sql = ereg_replace($what, $replace, $sql);
+
+ $what = "INSERT INTO ";
+ $replace = "INSERT INTO ".$table_prefix;
+ $sql = ereg_replace($what, $replace, $sql);
+
+ $what = "REPLACE INTO ";
+ $replace = "REPLACE INTO ".$table_prefix;
+ $sql = ereg_replace($what, $replace, $sql);
+
+ $what = "UPDATE ";
+ $replace = "UPDATE ".$table_prefix;
+ $sql = ereg_replace($what, $replace, $sql);
+
+ $what = "ALTER TABLE ";
+ $replace = "ALTER TABLE ".$table_prefix;
+ $sql = ereg_replace($what, $replace, $sql);
+ }
+ $sql = trim($sql);
+ if(strlen($sql)>0)
+ {
+ $this->Conn->Query($sql);
+
+ if($this->Conn->errorCode != 0)
+ {
+ return $this->Conn->errorMessage." COMMAND:$sql
";
+ }
+ }
+ }
+ $line++;
+ }
+ }
+
+
+
}
\ No newline at end of file
Index: branches/RC/core/admin_templates/tools/restore1.tpl
===================================================================
diff -u -N
--- branches/RC/core/admin_templates/tools/restore1.tpl (revision 0)
+++ branches/RC/core/admin_templates/tools/restore1.tpl (revision 10721)
@@ -0,0 +1,83 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
Index: branches/RC/core/admin_templates/tools/restore2.tpl
===================================================================
diff -u -N
--- branches/RC/core/admin_templates/tools/restore2.tpl (revision 0)
+++ branches/RC/core/admin_templates/tools/restore2.tpl (revision 10721)
@@ -0,0 +1,83 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
Index: branches/RC/core/admin_templates/tools/restore3.tpl
===================================================================
diff -u -N
--- branches/RC/core/admin_templates/tools/restore3.tpl (revision 0)
+++ branches/RC/core/admin_templates/tools/restore3.tpl (revision 10721)
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: branches/RC/core/admin_templates/tools/restore4.tpl
===================================================================
diff -u -N
--- branches/RC/core/admin_templates/tools/restore4.tpl (revision 0)
+++ branches/RC/core/admin_templates/tools/restore4.tpl (revision 10721)
@@ -0,0 +1,73 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
">
+
+
+
+
+
+
+
+ |
+
+
+
+
\ No newline at end of file