* finish task #7083.

This commit is contained in:
wangyidong
2020-04-28 13:22:32 +08:00
parent 442d70773a
commit 43c181767b
8 changed files with 87 additions and 35 deletions

View File

@@ -16,17 +16,19 @@ class zfile
* *
* @param string $from * @param string $from
* @param string $to * @param string $to
* @param bool $showDetails
* @access public * @access public
* @return array copied files. * @return array copied files.
*/ */
public function copyDir($from, $to) public function copyDir($from, $to, $showDetails = true)
{ {
static $copiedFiles = array(); static $copiedFiles = array();
$count = $size = 0;
if(!is_dir($from) or !is_readable($from)) return $copiedFiles; if(!is_dir($from) or !is_readable($from)) return array($copiedFiles, $count, $size);
if(!is_dir($to)) if(!is_dir($to))
{ {
if(!is_writable(dirname($to))) return $copiedFiles; if(!is_writable(dirname($to))) return array($copiedFiles, $count, $size);
mkdir($to); mkdir($to);
} }
@@ -41,21 +43,23 @@ class zfile
$fullEntry = $from . $entry; $fullEntry = $from . $entry;
if(is_file($fullEntry)) if(is_file($fullEntry))
{ {
if(file_exists($to . $entry)) if(file_exists($to . $entry)) unlink($to . $entry);
{
unlink($to . $entry);
}
copy($fullEntry, $to . $entry); copy($fullEntry, $to . $entry);
$copiedFiles[] = $to . $entry; if($showDetails) $copiedFiles[] = $to . $entry;
$count += 1;
$size += filesize($fullEntry);
} }
else else
{ {
$nextFrom = $from . $entry; $nextFrom = $from . $entry;
$nextTo = $to . $entry; $nextTo = $to . $entry;
$this->copyDir($nextFrom, $nextTo); $result = $this->copyDir($nextFrom, $nextTo, $showDetails);
$count += $result[1];
$size += $result[2];
} }
} }
return $copiedFiles; return array($copiedFiles, $count, $size);
} }
/** /**

View File

@@ -151,6 +151,7 @@ class backup extends control
{ {
$rmFunc = is_file($file) ? 'removeFile' : 'removeDir'; $rmFunc = is_file($file) ? 'removeFile' : 'removeDir';
$zfile->{$rmFunc}($file); $zfile->{$rmFunc}($file);
if($rmFunc == 'removeDir') $this->backup->processSummary($file, 0, 0, 'delete');
} }
} }
} }
@@ -274,6 +275,7 @@ class backup extends control
{ {
$zfile = $this->app->loadClass('zfile'); $zfile = $this->app->loadClass('zfile');
$zfile->removeDir($this->backupPath . $fileName . '.file'); $zfile->removeDir($this->backupPath . $fileName . '.file');
$this->backup->processSummary($this->backupPath . $fileName . '.file', 0, 0, 'delete');
} }
/* Delete code file. */ /* Delete code file. */
@@ -289,6 +291,7 @@ class backup extends control
{ {
$zfile = $this->app->loadClass('zfile'); $zfile = $this->app->loadClass('zfile');
$zfile->removeDir($this->backupPath . $fileName . '.code'); $zfile->removeDir($this->backupPath . $fileName . '.code');
$this->backup->processSummary($this->backupPath . $fileName . '.code', 0, 0, 'delete');
} }
die(js::reload('parent')); die(js::reload('parent'));
@@ -357,7 +360,7 @@ class backup extends control
{ {
session_write_close(); session_write_close();
$files = glob($this->backupPath . '/*'); $files = glob($this->backupPath . '/*.*');
rsort($files); rsort($files);
$fileName = basename($files[0]); $fileName = basename($files[0]);
@@ -373,18 +376,11 @@ class backup extends control
} }
$attachFileName = $this->backup->getBackupFile($fileName, 'file'); $attachFileName = $this->backup->getBackupFile($fileName, 'file');
if($attachFileName) if($attachFileName) $message = sprintf($this->lang->backup->progressAttach);
{
$fileSize = $this->backup->getBackupSize($attachFileName);
$message = sprintf($this->lang->backup->progressAttach, $this->backup->processFileSize($fileSize));
}
$codeFileName = $this->backup->getBackupFile($fileName, 'code'); $codeFileName = $this->backup->getBackupFile($fileName, 'code');
if($codeFileName) if($codeFileName) $message = sprintf($this->lang->backup->progressCode);
{
$fileSize = $this->backup->getBackupSize($codeFileName);
$message = sprintf($this->lang->backup->progressCode, $this->backup->processFileSize($fileSize));
}
die($message); die($message);
} }
} }

View File

@@ -20,8 +20,8 @@ $lang->backup->settingList['nosafe'] = 'Do not prevent downloading PHP file head
$lang->backup->waitting = '<span id="backupType"></span> In Arbeit. Bitte warten...'; $lang->backup->waitting = '<span id="backupType"></span> In Arbeit. Bitte warten...';
$lang->backup->progressSQL = '<p>SQL backup: %s is backed up.</p>'; $lang->backup->progressSQL = '<p>SQL backup: %s is backed up.</p>';
$lang->backup->progressAttach = '<p>SQL backup is completed.</p><p>Attachment backup: %s is backed up.</p>'; $lang->backup->progressAttach = '<p>SQL backup is completed.</p><p>Attachment backing up.</p>';
$lang->backup->progressCode = '<p>SQL backup is completed.</p><p>Attachment backup is completed.</p><p>Code backup: %s is backed up.</p>'; $lang->backup->progressCode = '<p>SQL backup is completed.</p><p>Attachment backup is completed.</p><p>Code backing up.</p>';
$lang->backup->confirmDelete = 'Möchten Sie das Backup löschen'; $lang->backup->confirmDelete = 'Möchten Sie das Backup löschen';
$lang->backup->confirmRestore = 'Möchten Sie das Backup wiederherstellen?'; $lang->backup->confirmRestore = 'Möchten Sie das Backup wiederherstellen?';
$lang->backup->holdDays = 'Behalten der letzen %s Tage der Backups'; $lang->backup->holdDays = 'Behalten der letzen %s Tage der Backups';

View File

@@ -20,8 +20,8 @@ $lang->backup->settingList['nosafe'] = 'Do not prevent downloading PHP file head
$lang->backup->waitting = '<span id="backupType"></span> is ongoing. Please wait...'; $lang->backup->waitting = '<span id="backupType"></span> is ongoing. Please wait...';
$lang->backup->progressSQL = '<p>SQL backup: %s is backed up.</p>'; $lang->backup->progressSQL = '<p>SQL backup: %s is backed up.</p>';
$lang->backup->progressAttach = '<p>SQL backup is completed.</p><p>Attachment backup: %s is backed up.</p>'; $lang->backup->progressAttach = '<p>SQL backup is completed.</p><p>Attachment backing up.</p>';
$lang->backup->progressCode = '<p>SQL backup is completed.</p><p>Attachment backup is completed.</p><p>Code backup: %s is backed up.</p>'; $lang->backup->progressCode = '<p>SQL backup is completed.</p><p>Attachment backup is completed.</p><p>Code backing up.</p>';
$lang->backup->confirmDelete = 'Do you want to delete the backup?'; $lang->backup->confirmDelete = 'Do you want to delete the backup?';
$lang->backup->confirmRestore = 'Do you want to restore the backup?'; $lang->backup->confirmRestore = 'Do you want to restore the backup?';
$lang->backup->holdDays = 'Hold last %s days of backup'; $lang->backup->holdDays = 'Hold last %s days of backup';

View File

@@ -20,8 +20,8 @@ $lang->backup->settingList['nosafe'] = 'Ne pas prévenir du téléchargement par
$lang->backup->waitting = '<span id="backupType"></span> est en cours. Patientez s´il vous plait...'; $lang->backup->waitting = '<span id="backupType"></span> est en cours. Patientez s´il vous plait...';
$lang->backup->progressSQL = '<p>SQL backup: %s est sauvegardé.</p>'; $lang->backup->progressSQL = '<p>SQL backup: %s est sauvegardé.</p>';
$lang->backup->progressAttach = '<p>SQL backup est terminé.</p><p>Attachment backup: %s est sauvegardé avec succès.</p>'; $lang->backup->progressAttach = '<p>SQL backup est terminé.</p><p>Attachment backing up.</p>';
$lang->backup->progressCode = '<p>SQL backup est terminé.</p><p>Attachment backup est terminé.</p><p>Code backup: %s est sauvegardé avec succès.</p>'; $lang->backup->progressCode = '<p>SQL backup est terminé.</p><p>Attachment backup est terminé.</p><p>Code backing up.</p>';
$lang->backup->confirmDelete = 'Voulez-vous supprimer la sauvegarde ?'; $lang->backup->confirmDelete = 'Voulez-vous supprimer la sauvegarde ?';
$lang->backup->confirmRestore = 'Voulez-vous restaurer la sauvegarde ?'; $lang->backup->confirmRestore = 'Voulez-vous restaurer la sauvegarde ?';
$lang->backup->holdDays = 'conserver les derniers %s jours de backup'; $lang->backup->holdDays = 'conserver les derniers %s jours de backup';

View File

@@ -20,8 +20,8 @@ $lang->backup->settingList['nosafe'] = '不需要防下载PHP文件头';
$lang->backup->waitting = '<span id="backupType"></span>正在进行中,请稍候...'; $lang->backup->waitting = '<span id="backupType"></span>正在进行中,请稍候...';
$lang->backup->progressSQL = '<p>SQL备份中已备份%s</p>'; $lang->backup->progressSQL = '<p>SQL备份中已备份%s</p>';
$lang->backup->progressAttach = '<p>SQL备份完成</p><p>附件备份中,已备份%s</p>'; $lang->backup->progressAttach = '<p>SQL备份完成</p><p>附件备份中</p>';
$lang->backup->progressCode = '<p>SQL备份完成</p><p>附件备份完成</p><p>代码备份中,已备份%s</p>'; $lang->backup->progressCode = '<p>SQL备份完成</p><p>附件备份完成</p><p>代码备份中</p>';
$lang->backup->confirmDelete = '是否删除备份?'; $lang->backup->confirmDelete = '是否删除备份?';
$lang->backup->confirmRestore = '是否还原该备份?'; $lang->backup->confirmRestore = '是否还原该备份?';
$lang->backup->holdDays = '备份保留最近 %s 天'; $lang->backup->holdDays = '备份保留最近 %s 天';

View File

@@ -38,8 +38,9 @@ class backupModel extends model
$return->error = ''; $return->error = '';
if(!is_dir($backupFile)) mkdir($backupFile, 0777, true); if(!is_dir($backupFile)) mkdir($backupFile, 0777, true);
$zfile = $this->app->loadClass('zfile'); $zfile = $this->app->loadClass('zfile');
$zfile->copyDir($this->app->getAppRoot() . 'www/data/', $backupFile); $result = $zfile->copyDir($this->app->getAppRoot() . 'www/data/', $backupFile, $showDetails = false);
$this->processSummary($backupFile, $result[1], $result[2]);
return $return; return $return;
} }
@@ -71,22 +72,29 @@ class backupModel extends model
$fileList = array_merge($fileList, $wwwFileList); $fileList = array_merge($fileList, $wwwFileList);
if(!is_dir($backupFile)) mkdir($backupFile, 0777, true); if(!is_dir($backupFile)) mkdir($backupFile, 0777, true);
$zfile = $this->app->loadClass('zfile'); $zfile = $this->app->loadClass('zfile');
$allCount = 0;
$allSize = 0;
foreach($fileList as $codeFile) foreach($fileList as $codeFile)
{ {
$file = trim(str_replace($appRoot, '', $codeFile), DS); $file = trim(str_replace($appRoot, '', $codeFile), DS);
if(is_dir($codeFile)) if(is_dir($codeFile))
{ {
if(!is_dir($backupFile . DS . $file)) mkdir($backupFile . DS . $file, 0777, true); if(!is_dir($backupFile . DS . $file)) mkdir($backupFile . DS . $file, 0777, true);
$zfile->copyDir($codeFile, $backupFile . DS . $file); $result = $zfile->copyDir($codeFile, $backupFile . DS . $file, $showDetails = false);
$allCount += $result[1];
$allSize += $result[2];
} }
else else
{ {
$dirName = dirname($file); $dirName = dirname($file);
if(!is_dir($backupFile . DS . $dirName)) mkdir($backupFile . DS . $dirName, 0777, true); if(!is_dir($backupFile . DS . $dirName)) mkdir($backupFile . DS . $dirName, 0777, true);
$zfile->copyFile($codeFile, $backupFile . DS . $file); $zfile->copyFile($codeFile, $backupFile . DS . $file);
$allCount += 1;
$allSize += filesize($codeFile);
} }
} }
$this->processSummary($backupFile, $allCount, $allSize);
return $return; return $return;
} }
@@ -153,7 +161,7 @@ class backupModel extends model
elseif(is_dir($backupFile)) elseif(is_dir($backupFile))
{ {
$zfile = $this->app->loadClass('zfile'); $zfile = $this->app->loadClass('zfile');
$zfile->copyDir($backupFile, $this->app->getAppRoot() . 'www/data/'); $zfile->copyDir($backupFile, $this->app->getAppRoot() . 'www/data/', $showDetails = false);
} }
return $return; return $return;
@@ -255,6 +263,15 @@ class backupModel extends model
{ {
$zfile = $this->app->loadClass('zfile'); $zfile = $this->app->loadClass('zfile');
if(!is_dir($backupFile)) return $zfile->getFileSize($backupFile); if(!is_dir($backupFile)) return $zfile->getFileSize($backupFile);
$summaryFile = dirname($backupFile) . DS . 'summary';
if(file_exists($summaryFile))
{
$summary = json_decode(file_get_contents(dirname($backupFile) . DS . 'summary'), 'true');
$fileName = basename($backupFile);
if(isset($summary[$fileName])) return $summary[$fileName]['size'];
}
return 0; return 0;
} }
@@ -320,4 +337,39 @@ class backupModel extends model
return $fileSize . $bit; return $fileSize . $bit;
} }
/**
* Process backup summary.
*
* @param string $file
* @param int $count
* @param int $size
* @param string $action
* @access public
* @return bool
*/
public function processSummary($file, $count, $size, $action = 'add')
{
$backupPath = dirname($file);
$fileName = basename($file);
$summaryFile = $backupPath . DS . 'summary';
if(!file_exists($summaryFile) and touch($summaryFile)) return false;
$summary = json_decode(file_get_contents($summaryFile), true);
if(empty($summary)) $summary = array();
if($action == 'add')
{
$summary[$fileName]['count'] = $count;
$summary[$fileName]['size'] = $size;
}
else
{
unset($summary[$fileName]);
}
if(file_put_contents($summaryFile, json_encode($summary))) return true;
return false;
}
} }

View File

@@ -575,7 +575,7 @@ class extensionModel extends model
foreach($pathes as $path) foreach($pathes as $path)
{ {
if($path == 'db' or $path == 'doc' or $path == 'hook' or $path == '..' or $path == '.') continue; if($path == 'db' or $path == 'doc' or $path == 'hook' or $path == '..' or $path == '.') continue;
$copiedFiles = $this->classFile->copyDir($extensionDir . $path, $appRoot . $path); list($copiedFiles) = $this->classFile->copyDir($extensionDir . $path, $appRoot . $path);
} }
foreach($copiedFiles as $key => $copiedFile) foreach($copiedFiles as $key => $copiedFile)
{ {