* finish task #5073.

This commit is contained in:
wangyidong
2018-11-08 14:57:58 +08:00
parent 004f1fc6fa
commit 3a2155ae11
8 changed files with 204 additions and 23 deletions
+1
View File
@@ -1,3 +1,4 @@
<?php
$config->backup = new stdclass();
$config->backup->holdDays = 14;
$config->backup->setting = '';
+60 -5
View File
@@ -60,6 +60,14 @@ class backup extends control
{
$backupFile->files[$this->backupPath . $backupFile->name . '.code.zip.php'] = abs(filesize($this->backupPath . $backupFile->name . '.code.zip.php'));
}
if(file_exists($this->backupPath . $backupFile->name . '.file'))
{
$backupFile->files[$this->backupPath . $backupFile->name . '.file'] = $this->backup->getDirSize($this->backupPath . $backupFile->name . '.file');
}
if(file_exists($this->backupPath . $backupFile->name . '.code'))
{
$backupFile->files[$this->backupPath . $backupFile->name . '.code'] = $this->backup->getDirSize($this->backupPath . $backupFile->name . '.code');
}
$backups[$backupFile->name] = $backupFile;
}
@@ -98,9 +106,14 @@ class backup extends control
}
$this->backup->addFileHeader($this->backupPath . $fileName . '.sql.php');
if(extension_loaded('zlib'))
if((extension_loaded('zlib') or strpos($this->config->backup->setting, 'nozip') !== false) and strpos($this->config->backup->setting, 'nofile') === false)
{
$result = $this->backup->backFile($this->backupPath . $fileName . '.file.zip.php');
$nozip = strpos($this->config->backup->setting, 'nozip') !== false;
$backFileName = $this->backupPath . $fileName . '.file';
if(!$nozip) $backFileName .= '.zip.php';
$result = $this->backup->backFile($backFileName);
if(!$result->result)
{
if($reload == 'yes')
@@ -113,9 +126,11 @@ class backup extends control
printf($this->lang->backup->error->backupFile, $result->error);
}
}
$this->backup->addFileHeader($this->backupPath . $fileName . '.file.zip.php');
if(!$nozip) $this->backup->addFileHeader($backFileName);
$result = $this->backup->backCode($this->backupPath . $fileName . '.code.zip.php');
$backFileName = $this->backupPath . $fileName . '.code';
if(!$nozip) $backFileName .= '.zip.php';
$result = $this->backup->backCode($backFileName);
if(!$result->result)
{
if($reload == 'yes')
@@ -128,7 +143,7 @@ class backup extends control
printf($this->lang->backup->error->backupCode, $result->error);
}
}
$this->backup->addFileHeader($this->backupPath . $fileName . '.code.zip.php');
if(!$nozip) $this->backup->addFileHeader($backFileName);
}
/* Delete expired backup. */
@@ -182,6 +197,12 @@ class backup extends control
if(!$result->result) $this->send(array('result' => 'fail', 'message' => sprintf($this->lang->backup->error->resotreFile, $result->error)));
}
if(file_exists($this->backupPath . $fileName . '.file'))
{
$result = $this->backup->restoreFile($this->backupPath . $fileName . '.file');
if(!$result->result) $this->send(array('result' => 'fail', 'message' => sprintf($this->lang->backup->error->resotreFile, $result->error)));
}
$this->send(array('result' => 'success', 'message' => $this->lang->backup->success->restore));
}
@@ -215,6 +236,20 @@ class backup extends control
die(js::alert(sprintf($this->lang->backup->error->noDelete, $this->backupPath . $fileName . '.code.zip.php')));
}
/* Delete attatchments dir. */
if(file_exists($this->backupPath . $fileName . '.file'))
{
$zfile = $this->app->loadClass('zfile');
$zfile->removeDir($this->backupPath . $fileName . '.file');
}
/* Delete code dir. */
if(file_exists($this->backupPath . $fileName . '.code'))
{
$zfile = $this->app->loadClass('zfile');
$zfile->removeDir($this->backupPath . $fileName . '.code');
}
die(js::reload('parent'));
}
@@ -235,4 +270,24 @@ class backup extends control
$this->display();
}
/**
* Setting backup
*
* @access public
* @return void
*/
public function setting()
{
if(strtolower($this->server->request_method) == "post")
{
$data = fixer::input('post')->join('setting', ',')->get();
$setting = '';
if(isset($data->setting)) $setting = $data->setting;
$this->loadModel('setting')->setItem('system.backup.setting', $setting);
die(js::reload('parent.parent'));
}
$this->display();
}
}
+15
View File
@@ -0,0 +1,15 @@
$(function()
{
$('#settingnofile').change(function()
{
if($(this).prop('checked'))
{
$('#settingnozip').closest('.checkbox-primary').hide();
}
else
{
$('#settingnozip').closest('.checkbox-primary').show();
}
})
$('#settingnofile').change();
});
+4
View File
@@ -12,6 +12,10 @@ $lang->backup->time = 'Date';
$lang->backup->files = 'Files';
$lang->backup->size = 'Size';
$lang->backup->setting = 'Setting';
$lang->backup->settingList['nofile'] = 'Not backup file and code.';
$lang->backup->settingList['nozip'] = 'Only copy file';
$lang->backup->waitting = '<span id="backupType"></span> In Progress. Please wait...';
$lang->backup->confirmDelete = 'Do you want to delete the backup?';
$lang->backup->confirmRestore = 'Do you want to restore the backup?';
+4
View File
@@ -12,6 +12,10 @@ $lang->backup->time = '备份时间';
$lang->backup->files = '备份文件';
$lang->backup->size = '大小';
$lang->backup->setting = '设置';
$lang->backup->settingList['nofile'] = '不备份附件和代码';
$lang->backup->settingList['nozip'] = '只拷贝文件';
$lang->backup->waitting = '<span id="backupType"></span>正在进行中,请稍候...';
$lang->backup->confirmDelete = '是否删除备份?';
$lang->backup->confirmRestore = '是否还原该备份?';
+84 -17
View File
@@ -37,13 +37,23 @@ class backupModel extends model
$return->result = true;
$return->error = '';
$this->app->loadClass('pclzip', true);
$zip = new pclzip($backupFile);
$zip->create($this->app->getAppRoot() . 'www/data/', PCLZIP_OPT_REMOVE_PATH, $this->app->getAppRoot() . 'www/data/');
if($zip->errorCode() != 0)
$nozip = strpos($this->config->backup->setting, 'nozip') !== false;
if(!$nozip)
{
$return->result = false;
$return->error = $zip->errorInfo();
$this->app->loadClass('pclzip', true);
$zip = new pclzip($backupFile);
$zip->create($this->app->getAppRoot() . 'www/data/', PCLZIP_OPT_REMOVE_PATH, $this->app->getAppRoot() . 'www/data/');
if($zip->errorCode() != 0)
{
$return->result = false;
$return->error = $zip->errorInfo();
}
}
else
{
if(!is_dir($backupFile)) mkdir($backupFile, 0777, true);
$zfile = $this->app->loadClass('zfile');
$zfile->copyDir($this->app->getAppRoot() . 'www/data/', $backupFile);
}
return $return;
@@ -75,13 +85,37 @@ class backupModel extends model
$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)
$nozip = strpos($this->config->backup->setting, 'nozip') !== false;
if(!$nozip)
{
$return->result = false;
$return->error = $zip->errorInfo();
$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();
}
}
else
{
if(!is_dir($backupFile)) mkdir($backupFile, 0777, true);
$zfile = $this->app->loadClass('zfile');
foreach($fileList as $codeFile)
{
$file = trim(str_replace($appRoot, '', $codeFile), DS);
if(is_dir($codeFile))
{
if(!is_dir($backupFile . DS . $flle)) mkdir($backupFile . DS . $flle, 0777, true);
$zfile->copyDir($codeFile, $backupFile . DS . $file);
}
else
{
$dirName = dirname($file);
if(!is_dir($backupFile . DS . $dirName)) mkdir($backupFile . DS . $dirName, 0777, true);
$zfile->copyFile($codeFile, $backupFile . DS . $file);
}
}
}
return $return;
@@ -113,12 +147,21 @@ class backupModel extends model
$return->result = true;
$return->error = '';
$this->app->loadClass('pclzip', true);
$zip = new pclzip($backupFile);
if($zip->extract(PCLZIP_OPT_PATH, $this->app->getAppRoot() . 'www/data/') == 0)
$nozip = strpos($this->config->backup->setting, 'nozip') !== false;
if(!$nozip)
{
$return->result = false;
$return->error = $zip->errorInfo();
$this->app->loadClass('pclzip', true);
$zip = new pclzip($backupFile);
if($zip->extract(PCLZIP_OPT_PATH, $this->app->getAppRoot() . 'www/data/') == 0)
{
$return->result = false;
$return->error = $zip->errorInfo();
}
}
else
{
$zfile = $this->app->loadClass('zfile');
$zfile->copyDir($backupFile, $this->app->getAppRoot() . 'www/data/');
}
return $return;
@@ -208,4 +251,28 @@ class backupModel extends model
fclose($fh);
return true;
}
/**
* Get dir 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 += abs(filesize($file));
}
}
return $size;
}
}
+4 -1
View File
@@ -21,7 +21,10 @@
<div class='btn-toolbar pull-left'>
<span class='btn btn-link btn-active-text'><span class='text'><?php echo $lang->backup->common;?></span></span>
</div>
<div class='btn-toolbar pull-right'><?php common::printIcon('backup', 'backup', 'reload=yes', '', 'button', 'cloud', 'hiddenwin', 'backup');?></div>
<div class='btn-toolbar pull-right'>
<?php common::printIcon('backup', 'setting', '', '', 'button', '', '', 'iframe', '', "data-width=400px");?>
<?php common::printIcon('backup', 'backup', 'reload=yes', '', 'button', 'cloud', 'hiddenwin', 'backup');?>
</div>
</div>
<div id='mainContent' class='main-content'>
+32
View File
@@ -0,0 +1,32 @@
<?php
/**
* The setting view file of backup module of ZenTaoPMS.
*
* @copyright Copyright 2009-2015 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Yidong Wang <yidong@cnezsoft.com>
* @package backup
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.lite.html.php';?>
<div id='mainContent' class='main-content'>
<div class='main-header'>
<h2><?php echo $lang->backup->setting;?></h2>
</div>
<form method='post' target='hiddenwin'>
<table class='w-p100'>
<tr>
<td style='height:50px;vertical-align:top'>
<div class='input-group'>
<?php echo html::checkbox('setting', $lang->backup->settingList, isset($config->backup->setting) ? $config->backup->setting : '');?>
</div>
</td>
</tr>
<tr><td><?php echo html::submitButton('', '', 'btn btn-primary');?></td></tr>
</table>
</form>
</div>
<?php include '../../common/view/footer.lite.html.php';?>