From 8e9171f45aa516f2d91f1deded43849d535cafe3 Mon Sep 17 00:00:00 2001 From: chaideqing Date: Wed, 22 Nov 2023 08:08:55 +0000 Subject: [PATCH] * Refactor backup. --- module/backup/control.php | 4 ++-- module/backup/js/index.js | 2 +- module/backup/model.php | 27 ++++++++++----------------- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/module/backup/control.php b/module/backup/control.php index 1cd940d32c..28af5a1aa2 100644 --- a/module/backup/control.php +++ b/module/backup/control.php @@ -87,11 +87,11 @@ class backup extends control * @access public * @return void */ - public function ajaxGetkDiskSpace() + public function ajaxGetDiskSpace() { set_time_limit(0); session_write_close(); - $diskSapce = $this->backup->getkDiskSpace($this->backupPath); + $diskSapce = $this->backup->getDiskSpace($this->backupPath); $diskSapce = explode(',', $diskSapce); $space = new stdclass(); diff --git a/module/backup/js/index.js b/module/backup/js/index.js index e454ffd2fa..9f4bb530ff 100644 --- a/module/backup/js/index.js +++ b/module/backup/js/index.js @@ -10,7 +10,7 @@ $(function() var that = this; $(that).toggleClass('loading'); $(that).text(getSpaceLoading); - link = createLink('backup', 'ajaxGetkDiskSpace'); + link = createLink('backup', 'ajaxGetDiskSpace'); $.get(link, function(data) { $(that).toggleClass('loading'); diff --git a/module/backup/model.php b/module/backup/model.php index d6ad6c9472..e00bfe947d 100644 --- a/module/backup/model.php +++ b/module/backup/model.php @@ -437,21 +437,19 @@ class backupModel extends model * * @param int $backupPath * @access public - * @return int + * @return string */ - public function getkDiskSpace($backupPath) + public function getDiskSpace($backupPath) { $nofile = strpos($this->config->backup->setting, 'nofile') !== false; $diskFreeSpace = disk_free_space($backupPath); $backFileSize = 0; - $zfile = $this->app->loadClass('zfile'); - if(!$nofile) { $appRoot = $this->app->getAppRoot(); - $appRootSize = $this->getZentaoSize($appRoot); - $backFileSize = $appRootSize - $zfile->getDirSize($appRoot . 'tmp') - $zfile->getDirSize($appRoot . 'www/course'); + $appRootSize = $this->getDirSize($appRoot); + $backFileSize = $appRootSize - $this->getDirSize($appRoot . 'tmp') - $this->getDirSize($appRoot . 'www/data/course'); } $backSqlSize = $this->dao->select('sum(data_length+index_length) as size') @@ -464,26 +462,21 @@ class backupModel extends model } /** - * Get zentao size. + * Get directory size. * - * @param string $appRoot + * @param string $dir * @access public * @return int */ - public function getZentaoSize($appRoot) + public function getDirSize($dir) { + if(!file_exists($dir)) return 0; $totalSize = 0; - $tmpDir = realPath($appRoot . 'tmp/'); - $dataDir = realPath($appRoot . 'www/data/'); - $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($appRoot, RecursiveDirectoryIterator::SKIP_DOTS)); + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS)); foreach($iterator as $file) { - $filePath = $file->getRealPath(); - if(strpos($filePath, $tmpDir) !== 0 and strpos($filePath, $dataDir) !== 0) - { - $totalSize += $file->getSize(); - } + $totalSize += $file->getSize(); } return $totalSize; }