From 3650af33e488fcf8ec0a01a39dc75b04181ed390 Mon Sep 17 00:00:00 2001 From: daitingting Date: Fri, 28 Apr 2017 13:59:34 +0800 Subject: [PATCH] * Backup code. --- module/backup/control.php | 25 ++++++++++++++++++++++++ module/backup/lang/en.php | 1 + module/backup/lang/zh-cn.php | 1 + module/backup/model.php | 38 ++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+) diff --git a/module/backup/control.php b/module/backup/control.php index 26682c89b0..0f9c268a53 100644 --- a/module/backup/control.php +++ b/module/backup/control.php @@ -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')); } diff --git a/module/backup/lang/en.php b/module/backup/lang/en.php index df62e32eef..c80c82b839 100644 --- a/module/backup/lang/en.php +++ b/module/backup/lang/en.php @@ -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."; diff --git a/module/backup/lang/zh-cn.php b/module/backup/lang/zh-cn.php index c91f0515d1..579bf502b1 100644 --- a/module/backup/lang/zh-cn.php +++ b/module/backup/lang/zh-cn.php @@ -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"; diff --git a/module/backup/model.php b/module/backup/model.php index 4010d8e492..2606d10d67 100644 --- a/module/backup/model.php +++ b/module/backup/model.php @@ -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 *