* adjust code for backup.
This commit is contained in:
@@ -192,4 +192,40 @@ class zfile
|
||||
{
|
||||
return rename($from, $to);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file size.
|
||||
*
|
||||
* @param string $file
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function getFileSize($file)
|
||||
{
|
||||
return abs(filesize($file));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get directory size.
|
||||
*
|
||||
* @param string $dir
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function getDirSize($dir)
|
||||
{
|
||||
$size = 0;
|
||||
foreach(glob("$dir/*") as $file)
|
||||
{
|
||||
if(is_dir($file))
|
||||
{
|
||||
$size += $this->getDirSize($file);
|
||||
}
|
||||
else
|
||||
{
|
||||
$size += $this->getFileSize($file);
|
||||
}
|
||||
}
|
||||
return $size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class backup extends control
|
||||
{
|
||||
parent::__construct($moduleName, $methodName);
|
||||
|
||||
$this->backupPath = empty($this->config->backup->settingDir) ? $this->app->getTmpRoot() . 'backup/' : $this->config->backup->settingDir;
|
||||
$this->backupPath = empty($this->config->backup->settingDir) ? $this->app->getTmpRoot() . 'backup' . DS : $this->config->backup->settingDir;
|
||||
if(!is_dir($this->backupPath))
|
||||
{
|
||||
if(!mkdir($this->backupPath, 0777, true)) $this->view->error = sprintf($this->lang->backup->error->noWritable, dirname($this->backupPath));
|
||||
@@ -127,7 +127,7 @@ class backup extends control
|
||||
|
||||
$backFileName = $this->backupPath . $fileName . '.file';
|
||||
if(!$nozip) $backFileName .= '.zip';
|
||||
if(!$nosafe) $backFileName .= '.php';
|
||||
if(!$nozip and !$nosafe) $backFileName .= '.php';
|
||||
|
||||
$result = $this->backup->backFile($backFileName);
|
||||
if(!$result->result)
|
||||
@@ -146,7 +146,7 @@ class backup extends control
|
||||
|
||||
$backFileName = $this->backupPath . $fileName . '.code';
|
||||
if(!$nozip) $backFileName .= '.zip';
|
||||
if(!$nosafe) $backFileName .= '.php';
|
||||
if(!$nozip and !$nosafe) $backFileName .= '.php';
|
||||
|
||||
$result = $this->backup->backCode($backFileName);
|
||||
if(!$result->result)
|
||||
@@ -353,8 +353,11 @@ class backup extends control
|
||||
if(isset($data->setting)) $setting = $data->setting;
|
||||
$this->loadModel('setting')->setItem('system.backup.setting', $setting);
|
||||
|
||||
$settingDir = $data->settingDir;
|
||||
if($data->settingDir == $this->app->getTmpRoot() . 'backup/') $settingDir = '';
|
||||
$settingDir = rtrim($data->settingDir, DS) . DS;
|
||||
if(!is_dir($settingDir) and mkdir($settingDir, 0777, true)) die(js::alert($this->lang->backup->error->noCreateDir));
|
||||
if(!is_writable($settingDir)) die(js::alert($this->lang->backup->error->noWritable));
|
||||
|
||||
if($data->settingDir == $this->app->getTmpRoot() . 'backup' . DS) $settingDir = '';
|
||||
$this->setting->setItem('system.backup.settingDir', $settingDir);
|
||||
|
||||
die(js::reload('parent.parent'));
|
||||
|
||||
@@ -12,9 +12,11 @@ $lang->backup->time = 'Date';
|
||||
$lang->backup->files = 'Files';
|
||||
$lang->backup->size = 'Size';
|
||||
|
||||
$lang->backup->setting = 'Setting';
|
||||
$lang->backup->setting = 'Setting';
|
||||
$lang->backup->settingDir = 'Backup Directory';
|
||||
$lang->backup->settingList['nofile'] = 'Not backup file and code.';
|
||||
$lang->backup->settingList['nozip'] = 'Only copy file';
|
||||
$lang->backup->settingList['nozip'] = 'Only copy file, Uncompressed';
|
||||
$lang->backup->settingList['nosafe'] = 'No need to prevent downloading PHP file header.';
|
||||
|
||||
$lang->backup->waitting = '<span id="backupType"></span> In Progress. Please wait...';
|
||||
$lang->backup->confirmDelete = 'Do you want to delete the backup?';
|
||||
@@ -27,6 +29,7 @@ $lang->backup->success->backup = 'Done!';
|
||||
$lang->backup->success->restore = 'Restored!';
|
||||
|
||||
$lang->backup->error = new stdclass();
|
||||
$lang->backup->error->noCreateDir = 'Directory is not exists, and can not create it';
|
||||
$lang->backup->error->noWritable = "<code>%s</code> is not writable! Please check the privilege, or backup cannot be done.";
|
||||
$lang->backup->error->noDelete = "%s cannot be deleted. Please modify the privilege or manually delete it.";
|
||||
$lang->backup->error->restoreSQL = "Database library restoration failed. Error %s.";
|
||||
|
||||
@@ -16,8 +16,8 @@ $lang->backup->size = '大小';
|
||||
$lang->backup->setting = '设置';
|
||||
$lang->backup->settingDir = '备份目录';
|
||||
$lang->backup->settingList['nofile'] = '不备份附件和代码';
|
||||
$lang->backup->settingList['nozip'] = '只拷贝文件';
|
||||
$lang->backup->settingList['nosafe'] = '不需要防下载设置';
|
||||
$lang->backup->settingList['nozip'] = '只拷贝文件,不压缩';
|
||||
$lang->backup->settingList['nosafe'] = '不需要防下载PHP文件头';
|
||||
|
||||
$lang->backup->waitting = '<span id="backupType"></span>正在进行中,请稍候...';
|
||||
$lang->backup->progressSQL = '<p>SQL备份中,已备份%s</p>';
|
||||
@@ -33,6 +33,7 @@ $lang->backup->success->backup = '备份成功!';
|
||||
$lang->backup->success->restore = '还原成功!';
|
||||
|
||||
$lang->backup->error = new stdclass();
|
||||
$lang->backup->error->noCreateDir = '备份目录不存在,也无法创建该目录';
|
||||
$lang->backup->error->noWritable = "<code>%s</code> 不可写!请检查该目录权限,否则无法备份。";
|
||||
$lang->backup->error->noDelete = "文件 %s 无法删除,修改权限或手工删除。";
|
||||
$lang->backup->error->restoreSQL = "数据库还原失败,错误:%s";
|
||||
|
||||
+5
-15
@@ -186,7 +186,7 @@ class backupModel extends model
|
||||
public function addFileHeader($fileName)
|
||||
{
|
||||
$firstline = false;
|
||||
$die = "<?php die();?>\n";
|
||||
$die = "<?php die();?" . ">\n";
|
||||
$fileSize = filesize($fileName);
|
||||
|
||||
$fh = fopen($fileName, 'c+');
|
||||
@@ -229,7 +229,7 @@ class backupModel extends model
|
||||
public function removeFileHeader($fileName)
|
||||
{
|
||||
$firstline = false;
|
||||
$die = "<?php die();?>\n";
|
||||
$die = "<?php die();?" . ">\n";
|
||||
$fileSize = filesize($fileName);
|
||||
|
||||
$fh = fopen($fileName, 'c+');
|
||||
@@ -270,18 +270,8 @@ class backupModel extends model
|
||||
*/
|
||||
public function getDirSize($dir)
|
||||
{
|
||||
$size = 0;
|
||||
foreach(glob("$dir/*") as $file)
|
||||
{
|
||||
if(is_dir($file))
|
||||
{
|
||||
$size += $this->getDirSize($file);
|
||||
}
|
||||
else
|
||||
{
|
||||
$size += abs(filesize($file));
|
||||
}
|
||||
}
|
||||
return $size;
|
||||
$zfile = $this->app->loadClass('zfile');
|
||||
if(!is_dir($dir)) return $zfile->getFileSize($dir);
|
||||
return $zfile->getDirSize($dir);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user