* adjust code.
This commit is contained in:
+61
-35
@@ -11,11 +11,17 @@
|
||||
*/
|
||||
class backup extends control
|
||||
{
|
||||
/**
|
||||
* __construct
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->backupPath = $this->app->getCacheRoot() . 'backup/';
|
||||
$this->backupPath = $this->app->getTmpRoot() . 'backup/';
|
||||
if(!is_dir($this->backupPath))
|
||||
{
|
||||
if(!mkdir($this->backupPath, 0777, true)) $this->view->error = sprintf($this->lang->backup->error->noWritable, dirname($this->backupPath));
|
||||
@@ -26,6 +32,12 @@ class backup extends control
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Index
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$backups = array();
|
||||
@@ -37,9 +49,9 @@ class backup extends control
|
||||
$backupFile->time = filemtime($file);
|
||||
$backupFile->name = str_replace('.sql.php', '', basename($file));
|
||||
$backupFile->files[$file] = filesize($file);
|
||||
if(file_exists($this->backupPath . $backupFile->name . '.file.zip'))
|
||||
if(file_exists($this->backupPath . $backupFile->name . '.file.zip.php'))
|
||||
{
|
||||
$backupFile->files[$this->backupPath . $backupFile->name . '.file.zip'] = filesize($this->backupPath . $backupFile->name . '.file.zip');
|
||||
$backupFile->files[$this->backupPath . $backupFile->name . '.file.zip.php'] = filesize($this->backupPath . $backupFile->name . '.file.zip.php');
|
||||
}
|
||||
|
||||
$backups[$backupFile->name] = $backupFile;
|
||||
@@ -53,6 +65,12 @@ class backup extends control
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Backup
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function backup()
|
||||
{
|
||||
set_time_limit(0);
|
||||
@@ -66,26 +84,34 @@ class backup extends control
|
||||
|
||||
$fp = fopen($this->backupPath . $fileName . '.sql.php', 'r');
|
||||
$tmp = fopen($this->backupPath . $fileName . '.sql.php.tmp', 'w');
|
||||
fwrite($tmp, "<?php die();?>\n");
|
||||
fwrite($tmp, "#<?php die()?>;\n");
|
||||
while(($buffer = fgets($fp)) !== false) fwrite($tmp, $buffer);
|
||||
fclose($tmp);
|
||||
fclose($fp);
|
||||
fclose($tmp);
|
||||
rename($this->backupPath . $fileName . '.sql.php.tmp', $this->backupPath . $fileName . '.sql.php');
|
||||
|
||||
if(extension_loaded('zlib'))
|
||||
{
|
||||
$result = $this->backup->backFile($this->backupPath . $fileName . '.file.zip');
|
||||
if(!$result->result)
|
||||
{
|
||||
echo js::alert(sprintf($this->lang->backup->error->backupFile, $result->error));
|
||||
die(js::reload('parent'));
|
||||
}
|
||||
}
|
||||
if(extension_loaded('zlib'))
|
||||
{
|
||||
$result = $this->backup->backFile($this->backupPath . $fileName . '.file.zip.php');
|
||||
if(!$result->result)
|
||||
{
|
||||
echo js::alert(sprintf($this->lang->backup->error->backupFile, $result->error));
|
||||
die(js::reload('parent'));
|
||||
}
|
||||
}
|
||||
|
||||
echo js::alert($this->lang->backup->success->backup);
|
||||
die(js::reload('parent'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore
|
||||
*
|
||||
* @param string $fileName
|
||||
* @param string $confirm
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function restore($fileName, $confirm = 'no')
|
||||
{
|
||||
if($confirm == 'no')
|
||||
@@ -94,28 +120,19 @@ class backup extends control
|
||||
}
|
||||
|
||||
set_time_limit(0);
|
||||
$fp = fopen($this->backupPath . $fileName . '.sql.php', 'r');
|
||||
$tmp = fopen($this->backupPath . $fileName . '.sql', 'w');
|
||||
$line = 0;
|
||||
while(($buffer = fgets($fp)) !== false)
|
||||
{
|
||||
$line++;
|
||||
if($line == 1) continue;
|
||||
fwrite($tmp, $buffer);
|
||||
}
|
||||
fclose($tmp);
|
||||
fclose($fp);
|
||||
$result = $this->backup->restoreSQL($this->backupPath . $fileName . '.sql');
|
||||
unlink($this->backupPath . $fileName . '.sql');
|
||||
|
||||
/* Restore database. */
|
||||
$result = $this->backup->restoreSQL($this->backupPath . $fileName . '.sql.php');
|
||||
if(!$result->result)
|
||||
{
|
||||
echo js::alert(sprintf($this->lang->backup->error->restoreSQL, $result->error));
|
||||
die(js::reload('parent'));
|
||||
}
|
||||
|
||||
if(file_exists($this->backupPath . $fileName . '.file.zip'))
|
||||
/* Restore attatchments. */
|
||||
if(file_exists($this->backupPath . $fileName . '.file.zip.php'))
|
||||
{
|
||||
$result = $this->backup->restoreFile($this->backupPath . $fileName . '.file.zip');
|
||||
$result = $this->backup->restoreFile($this->backupPath . $fileName . '.file.zip.php');
|
||||
if(!$result->result)
|
||||
{
|
||||
echo js::alert(sprintf($this->lang->backup->error->restoreFile, $result->error));
|
||||
@@ -126,19 +143,28 @@ class backup extends control
|
||||
die(js::reload('parent'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @param string $fileName
|
||||
* @param string $confirm
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function delete($fileName, $confirm = 'no')
|
||||
{
|
||||
if($confirm == 'no')
|
||||
{
|
||||
die(js::confirm($this->lang->backup->confirmDelete, inlink('delete', "fileName=$fileName&confirm=yes")));
|
||||
}
|
||||
if($confirm == 'no') die(js::confirm($this->lang->backup->confirmDelete, inlink('delete', "fileName=$fileName&confirm=yes")));
|
||||
|
||||
/* Delete database file. */
|
||||
if(file_exists($this->backupPath . $fileName . '.sql.php') and !unlink($this->backupPath . $fileName . '.sql.php'))
|
||||
{
|
||||
die(js::alert(sprintf($this->lang->backup->error->noDelete, $this->backupPath . $fileName . '.sql.php')));
|
||||
}
|
||||
if(file_exists($this->backupPath . $fileName . '.file.zip') and !unlink($this->backupPath . $fileName . '.file.zip'))
|
||||
|
||||
/* Delete attatchments file. */
|
||||
if(file_exists($this->backupPath . $fileName . '.file.zip.php') and !unlink($this->backupPath . $fileName . '.file.zip.php'))
|
||||
{
|
||||
die(js::alert(sprintf($this->lang->backup->error->noDelete, $this->backupPath . $fileName . '.file.zip')));
|
||||
die(js::alert(sprintf($this->lang->backup->error->noDelete, $this->backupPath . $fileName . '.file.zip.php')));
|
||||
}
|
||||
|
||||
die(js::reload('parent'));
|
||||
|
||||
Reference in New Issue
Block a user