* Backup code.

This commit is contained in:
daitingting
2017-04-28 13:59:34 +08:00
parent ba39e66cc3
commit 3650af33e4
4 changed files with 65 additions and 0 deletions
+25
View File
@@ -56,6 +56,10 @@ class backup extends control
{
$backupFile->files[$this->backupPath . $backupFile->name . '.file.zip.php'] = abs(filesize($this->backupPath . $backupFile->name . '.file.zip.php'));
}
if(file_exists($this->backupPath . $backupFile->name . '.code.zip.php'))
{
$backupFile->files[$this->backupPath . $backupFile->name . '.code.zip.php'] = abs(filesize($this->backupPath . $backupFile->name . '.code.zip.php'));
}
$backups[$backupFile->name] = $backupFile;
}
@@ -110,6 +114,21 @@ class backup extends control
}
}
$this->backup->addFileHeader($this->backupPath . $fileName . '.file.zip.php');
$result = $this->backup->backCode($this->backupPath . $fileName . '.code.zip.php');
if(!$result->result)
{
if($reload == 'yes')
{
echo js::alert(sprintf($this->lang->backup->error->backupCode, $result->error));
die(js::reload('parent'));
}
else
{
printf($this->lang->backup->error->backupCode, $result->error);
}
}
$this->backup->addFileHeader($this->backupPath . $fileName . '.code.zip.php');
}
/* Delete expired backup. */
@@ -201,6 +220,12 @@ class backup extends control
die(js::alert(sprintf($this->lang->backup->error->noDelete, $this->backupPath . $fileName . '.file.zip.php')));
}
/* Delete code file. */
if(file_exists($this->backupPath . $fileName . '.code.zip.php') and !unlink($this->backupPath . $fileName . '.code.zip.php'))
{
die(js::alert(sprintf($this->lang->backup->error->noDelete, $this->backupPath . $fileName . '.code.zip.php')));
}
die(js::reload('parent'));
}
+1
View File
@@ -27,3 +27,4 @@ $lang->backup->error->noDelete = "%s cannot be deleted. Please modify the per
$lang->backup->error->restoreSQL = "Database library restoring failed. Error %s.";
$lang->backup->error->restoreFile = "File restoring failed. Error %s.";
$lang->backup->error->backupFile = "File backup failed. Error %s.";
$lang->backup->error->backupCode = "Code backup failed. Error %s.";
+1
View File
@@ -27,3 +27,4 @@ $lang->backup->error->noDelete = "文件 %s 无法删除,修改权限或手
$lang->backup->error->restoreSQL = "数据库还原失败,错误:%s";
$lang->backup->error->restoreFile = "附件还原失败,错误:%s";
$lang->backup->error->backupFile = "附件备份失败,错误:%s";
$lang->backup->error->backupCode = "代码备份失败,错误:%s";
+38
View File
@@ -49,6 +49,44 @@ class backupModel extends model
return $return;
}
/**
* Backup code.
*
* @param string $backupFile
* @access public
* @return object
*/
public function backCode($backupFile)
{
$return = new stdclass();
$return->result = true;
$return->error = '';
$appRoot = $this->app->getAppRoot();
$fileList = glob($appRoot . '*');
$wwwFileList = glob($appRoot . 'www/*');
$tmpFile = array_search($appRoot . 'tmp', $fileList);
$wwwFile = array_search($appRoot . 'www', $fileList);
$dataFile = array_search($appRoot . 'www/data', $wwwFileList);
unset($fileList[$tmpFile]);
unset($fileList[$wwwFile]);
unset($wwwFileList[$dataFile]);
$fileList = array_merge($fileList, $wwwFileList);
$this->app->loadClass('pclzip', true);
$zip = new pclzip($backupFile);
$zip->create($fileList, PCLZIP_OPT_REMOVE_PATH, $appRoot);
if($zip->errorCode() != 0)
{
$return->result = false;
$return->error = $zip->errorInfo();
}
return $return;
}
/**
* Restore SQL
*