From beadba759a95fd81f2ef8220196e3d35971c5d1e Mon Sep 17 00:00:00 2001 From: sam marshall Date: Tue, 11 Nov 2014 16:38:26 +0000 Subject: [PATCH] MDL-48179 Backup progress: Can time out when compressing large backup --- backup/moodle2/backup_stepslib.php | 22 +++++++++++++++++-- .../helper/backup_general_helper.class.php | 8 +++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/backup/moodle2/backup_stepslib.php b/backup/moodle2/backup_stepslib.php index f767133a090..5c91c863840 100644 --- a/backup/moodle2/backup_stepslib.php +++ b/backup/moodle2/backup_stepslib.php @@ -1682,9 +1682,23 @@ class backup_zip_contents extends backup_execution_step implements file_progress // Get the zip packer $zippacker = get_file_packer('application/vnd.moodle.backup'); + // Track overall progress for the 2 long-running steps (archive to + // pathname, get backup information). + $reporter = $this->task->get_progress(); + $reporter->start_progress('backup_zip_contents', 2); + // Zip files $result = $zippacker->archive_to_pathname($files, $zipfile, true, $this); + // If any sub-progress happened, end it. + if ($this->startedprogress) { + $this->task->get_progress()->end_progress(); + $this->startedprogress = false; + } else { + // No progress was reported, manually move it on to the next overall task. + $reporter->progress(1); + } + // Something went wrong. if ($result === false) { @unlink($zipfile); @@ -1692,16 +1706,20 @@ class backup_zip_contents extends backup_execution_step implements file_progress } // Read to make sure it is a valid backup. Refer MDL-37877 . Delete it, if found not to be valid. try { - backup_general_helper::get_backup_information_from_mbz($zipfile); + backup_general_helper::get_backup_information_from_mbz($zipfile, $this); } catch (backup_helper_exception $e) { @unlink($zipfile); throw new backup_step_exception('error_zip_packing', '', $e->debuginfo); } - // If any progress happened, end it. + // If any sub-progress happened, end it. if ($this->startedprogress) { $this->task->get_progress()->end_progress(); + $this->startedprogress = false; + } else { + $reporter->progress(2); } + $reporter->end_progress(); } /** diff --git a/backup/util/helper/backup_general_helper.class.php b/backup/util/helper/backup_general_helper.class.php index e84d2f6f8ac..d9ad80d5b28 100644 --- a/backup/util/helper/backup_general_helper.class.php +++ b/backup/util/helper/backup_general_helper.class.php @@ -230,11 +230,15 @@ abstract class backup_general_helper extends backup_helper { * This will only extract the moodle_backup.xml file from an MBZ * file and then call {@link self::get_backup_information()}. * + * This can be a long-running (multi-minute) operation for large backups. + * Pass a $progress value to receive progress updates. + * * @param string $filepath absolute path to the MBZ file. + * @param file_progress $progress Progress updates * @return stdClass containing information. * @since Moodle 2.4 */ - public static function get_backup_information_from_mbz($filepath) { + public static function get_backup_information_from_mbz($filepath, file_progress $progress = null) { global $CFG; if (!is_readable($filepath)) { throw new backup_helper_exception('missing_moodle_backup_file', $filepath); @@ -245,7 +249,7 @@ abstract class backup_general_helper extends backup_helper { $tmpdir = $CFG->tempdir . '/backup/' . $tmpname; $fp = get_file_packer('application/vnd.moodle.backup'); - $extracted = $fp->extract_to_pathname($filepath, $tmpdir, array('moodle_backup.xml')); + $extracted = $fp->extract_to_pathname($filepath, $tmpdir, array('moodle_backup.xml'), $progress); $moodlefile = $tmpdir . '/' . 'moodle_backup.xml'; if (!$extracted || !is_readable($moodlefile)) { throw new backup_helper_exception('missing_moodle_backup_xml_file', $moodlefile);