From 71efce13477d4e111ac366764fe342e26de52f45 Mon Sep 17 00:00:00 2001 From: chaideqing Date: Mon, 21 Aug 2023 02:02:25 +0000 Subject: [PATCH] * Refator backup. --- module/backup/control.php | 25 ++++++++++++++++++++----- module/backup/js/index.js | 28 +++++++++++++++++++++------- module/backup/lang/de.php | 3 ++- module/backup/lang/en.php | 3 ++- module/backup/lang/fr.php | 3 ++- module/backup/lang/vi.php | 3 ++- module/backup/lang/zh-cn.php | 3 ++- module/backup/model.php | 9 +++++---- module/backup/view/index.html.php | 8 +++++--- 9 files changed, 61 insertions(+), 24 deletions(-) diff --git a/module/backup/control.php b/module/backup/control.php index dd634962de..f3e2198c67 100644 --- a/module/backup/control.php +++ b/module/backup/control.php @@ -69,17 +69,32 @@ class backup extends control } krsort($backups); - $diskSapce = $this->backup->checkDiskSpace($this->backupPath); - $alertTips = sprintf($this->lang->backup->insufficientDisk, round($diskSapce / (1024 * 1024 * 1024), 2)); - - $this->view->diskSapce = $diskSapce; - $this->view->alertTips = $alertTips; $this->view->title = $this->lang->backup->common; $this->view->position[] = $this->lang->backup->common; $this->view->backups = $backups; $this->display(); } + /** + * Ajax get disk space. + * + * @access public + * @return void + */ + public function ajaxGetkDiskSpace() + { + set_time_limit(0); + session_write_close(); + $diskSapce = $this->backup->getkDiskSpace($this->backupPath); + $diskSapce = explode(',', $diskSapce); + + $space = new stdclass(); + $space->freeSpace = $diskSapce[0]; + $space->needSpace = $diskSapce[1]; + + echo json_encode($space); + } + /** * Backup. * diff --git a/module/backup/js/index.js b/module/backup/js/index.js index 0011d5747a..078926cf89 100644 --- a/module/backup/js/index.js +++ b/module/backup/js/index.js @@ -2,14 +2,28 @@ $(function() { $('.backup').click(function() { - if(diskSapce) + var that = this; + $(that).toggleClass('loading'); + $(that).text(getSpaceLoading); + link = createLink('backup', 'ajaxGetkDiskSpace'); + $.get(link, function(data) { - $('#spaceConfirm').modal('show', 'center'); - } - else - { - backupData(); - } + $(that).toggleClass('loading'); + $(that).text(startBackup); + if(data) + { + if(data.needSpace > data.freeSpace) + { + alertTips = alertTips.replace('NEED_SPACE', (data.needSpace/1024/1024).toFixed(2)); + $('#spaceConfirm').find('p').text(alertTips); + $('#spaceConfirm').modal('show', 'center'); + } + else + { + backupData(); + } + } + }, 'json'); }); $('.rmPHPHeader').click(function() diff --git a/module/backup/lang/de.php b/module/backup/lang/de.php index fdb205c660..52a4965e0b 100644 --- a/module/backup/lang/de.php +++ b/module/backup/lang/de.php @@ -36,9 +36,10 @@ $lang->backup->confirmRestore = 'Möchten Sie das Backup wiederherstellen?'; $lang->backup->holdDays = 'Behalten der letzen %s Tage der Backups'; $lang->backup->copiedFail = 'Copy failed files: '; $lang->backup->restoreTip = 'Nur Dateien und Datenbanken können wiederhergestellt werden. Code kann manuell wieder hergestellt werden.'; -$lang->backup->insufficientDisk = 'Disk space less than%.2fG, it may cause insufficient backup space or affect the use, please process it and try again.'; +$lang->backup->insufficientDisk = 'Disk space less thanNEED_SPACEG, it may cause insufficient backup space or affect the use, please process it and try again.'; $lang->backup->ongoBackup = 'ongoing backup'; $lang->backup->cancelBackup = 'cancel backup'; +$lang->backup->getSpaceLoading = 'Calculate backup space'; $lang->backup->success = new stdclass(); $lang->backup->success->backup = 'Erledigt!'; diff --git a/module/backup/lang/en.php b/module/backup/lang/en.php index b5d639ca8a..d0aba3d73f 100644 --- a/module/backup/lang/en.php +++ b/module/backup/lang/en.php @@ -36,9 +36,10 @@ $lang->backup->confirmRestore = 'Do you want to restore the backup?'; $lang->backup->holdDays = 'Hold last %s days of backup'; $lang->backup->copiedFail = 'Copy failed files: '; $lang->backup->restoreTip = 'Only files and databases can be restored by clicking Restore. Code can be restored manually.'; -$lang->backup->insufficientDisk = 'Disk space less than%.2fG, it may cause insufficient backup space or affect the use, please process it and try again.'; +$lang->backup->insufficientDisk = 'Disk space less thanNEED_SPACEG, it may cause insufficient backup space or affect the use, please process it and try again.'; $lang->backup->ongoBackup = 'ongoing backup'; $lang->backup->cancelBackup = 'cancel backup'; +$lang->backup->getSpaceLoading = 'Calculate backup space'; $lang->backup->success = new stdclass(); $lang->backup->success->backup = 'Done!'; diff --git a/module/backup/lang/fr.php b/module/backup/lang/fr.php index 3d1dce6930..79aad08dfe 100644 --- a/module/backup/lang/fr.php +++ b/module/backup/lang/fr.php @@ -36,9 +36,10 @@ $lang->backup->confirmRestore = 'Voulez-vous restaurer la sauvegarde ?'; $lang->backup->holdDays = 'conserver les derniers %s jours de backup'; $lang->backup->copiedFail = 'Fichiers en échec de copie : '; $lang->backup->restoreTip = 'Seulement les fichiers et les bases peuvent être restaurées en cliquant sur Restaurer. Le code doit être restauré manuellement.'; -$lang->backup->insufficientDisk = 'Disk space less than%.2fG, it may cause insufficient backup space or affect the use, please process it and try again.'; +$lang->backup->insufficientDisk = 'Disk space less thanNEED_SPACEG, it may cause insufficient backup space or affect the use, please process it and try again.'; $lang->backup->ongoBackup = 'ongoing backup'; $lang->backup->cancelBackup = 'cancel backup'; +$lang->backup->getSpaceLoading = 'Calculate backup space'; $lang->backup->success = new stdclass(); $lang->backup->success->backup = 'Terminé avec succès !'; diff --git a/module/backup/lang/vi.php b/module/backup/lang/vi.php index fe81939e94..2bf657eaa8 100644 --- a/module/backup/lang/vi.php +++ b/module/backup/lang/vi.php @@ -33,9 +33,10 @@ $lang->backup->confirmRestore = 'Bạn có muốn khôi phục sao lưu này?' $lang->backup->holdDays = 'Giữ ít nhất %s ngày sao lưu'; $lang->backup->copiedFail = 'Copy failed files: '; $lang->backup->restoreTip = 'Chỉ tập tin và CSDL có thể được khôi phục bằng cách Click Khôi phục. Mã nguồn có thể khôi phục thủ công.'; -$lang->backup->insufficientDisk = 'Không gian đĩa nhỏ hơn%.2fG, Nó có thể gây ra không đủ dung lượng sao lưu hoặc ảnh hưởng đến việc sử dụng, vui lòng xử lý và thử lại.'; +$lang->backup->insufficientDisk = 'Không gian đĩa nhỏ hơnNEED_SPACEG, Nó có thể gây ra không đủ dung lượng sao lưu hoặc ảnh hưởng đến việc sử dụng, vui lòng xử lý và thử lại.'; $lang->backup->ongoBackup = 'tiếp tục sao lưu'; $lang->backup->cancelBackup = 'hủy sao lưu'; +$lang->backup->getSpaceLoading = 'Tính toán không gian dự phòng'; $lang->backup->success = new stdclass(); $lang->backup->success->backup = 'Sao lưu hoàn thành!'; diff --git a/module/backup/lang/zh-cn.php b/module/backup/lang/zh-cn.php index 15873991dd..85c7cf25f5 100644 --- a/module/backup/lang/zh-cn.php +++ b/module/backup/lang/zh-cn.php @@ -36,9 +36,10 @@ $lang->backup->confirmRestore = '是否还原该备份?'; $lang->backup->holdDays = '备份保留最近 %s 天'; $lang->backup->copiedFail = '复制失败的文件:'; $lang->backup->restoreTip = '还原功能只还原附件和数据库,如果需要还原代码,可以手动还原。'; -$lang->backup->insufficientDisk = '磁盘空间小于%.2fG,可能会导致备份空间不足或影响使用,请处理后再试。'; +$lang->backup->insufficientDisk = '磁盘空间小于NEED_SPACEG,可能会导致备份空间不足或影响使用,请处理后再试。'; $lang->backup->ongoBackup = '继续备份'; $lang->backup->cancelBackup = '取消备份'; +$lang->backup->getSpaceLoading = '正在计算备份空间'; $lang->backup->success = new stdclass(); $lang->backup->success->backup = '备份成功!'; diff --git a/module/backup/model.php b/module/backup/model.php index 8950d84a30..976946998c 100644 --- a/module/backup/model.php +++ b/module/backup/model.php @@ -433,18 +433,19 @@ class backupModel extends model } /** - * Check disk space is enough. + * Get disk space. * * @param int $backupPath * @access public * @return int */ - public function checkDiskSpace($backupPath) + public function getkDiskSpace($backupPath) { $nofile = strpos($this->config->backup->setting, 'nofile') !== false; $diskFreeSpace = disk_free_space($backupPath); + $backFileSize = 0; + $zfile = $this->app->loadClass('zfile'); - $backFileSize = 0; if(!$nofile) { @@ -459,6 +460,6 @@ class backupModel extends model ->groupBy('TABLE_SCHEMA') ->fetch('size'); - return ($diskFreeSpace - ($backFileSize + $backSqlSize) > 0) ? 0 : $backFileSize + $backSqlSize; + return $diskFreeSpace . ',' . ($backFileSize + $backSqlSize); } } diff --git a/module/backup/view/index.html.php b/module/backup/view/index.html.php index 82ca40ce93..c9fa7debd9 100644 --- a/module/backup/view/index.html.php +++ b/module/backup/view/index.html.php @@ -31,7 +31,7 @@ if(common::hasPriv('backup', 'backup')) { $backupLink = helper::createLink('backup', 'backup', 'reload=yes'); - echo html::commonButton(" " . $lang->backup->backup, "data-link='{$backupLink}'", 'btn btn-primary backup'); + echo html::commonButton(" " . $lang->backup->backup, "data-link='{$backupLink}'", 'btn btn-primary backup load-indicator'); } ?> @@ -120,7 +120,7 @@