Skip to content

Commit

Permalink
Merge branch 'MDL-37877-m25' of git://github.com/ankitagarwal/moodle …
Browse files Browse the repository at this point in the history
…into MOODLE_25_STABLE
  • Loading branch information
Damyon Wiese committed Oct 15, 2013
2 parents f12a481 + f2793fa commit 5d56f7d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
20 changes: 19 additions & 1 deletion backup/moodle2/backup_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,25 @@ protected function define_execution() {
$zippacker = get_file_packer('application/zip');

// Zip files
$zippacker->archive_to_pathname($files, $zipfile);
$result = $zippacker->archive_to_pathname($files, $zipfile, true, $this);

// Something went wrong.
if ($result === false) {
@unlink($zipfile);
throw new backup_step_exception('error_zip_packing', '', 'An error was encountered while trying to generate backup zip');
}
// 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);
} catch (backup_helper_exception $e) {
@unlink($zipfile);
throw new backup_step_exception('error_zip_packing', '', $e->debuginfo);
}

// If any progress happened, end it.
if ($this->startedprogress) {
$this->task->get_progress()->end_progress();
}
}
}

Expand Down
35 changes: 27 additions & 8 deletions backup/util/helper/backup_cron_helper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,11 @@ public static function launch_automated_backup($course, $starttime, $userid) {

$outcome = self::BACKUP_STATUS_OK;
$config = get_config('backup');
$bc = new backup_controller(backup::TYPE_1COURSE, $course->id, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_AUTOMATED, $userid);
$dir = $config->backup_auto_destination;
$storage = (int)$config->backup_auto_storage;

$bc = new backup_controller(backup::TYPE_1COURSE, $course->id, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO,
backup::MODE_AUTOMATED, $userid);

try {

Expand All @@ -399,27 +403,28 @@ public static function launch_automated_backup($course, $starttime, $userid) {
}
}

// Set the default filename
// Set the default filename.
$format = $bc->get_format();
$type = $bc->get_type();
$id = $bc->get_id();
$users = $bc->get_plan()->get_setting('users')->get_value();
$anonymised = $bc->get_plan()->get_setting('anonymize')->get_value();
$bc->get_plan()->get_setting('filename')->set_value(backup_plan_dbops::get_default_backup_filename($format, $type, $id, $users, $anonymised));
$bc->get_plan()->get_setting('filename')->set_value(backup_plan_dbops::get_default_backup_filename($format, $type,
$id, $users, $anonymised));

$bc->set_status(backup::STATUS_AWAITING);

$bc->execute_plan();
$results = $bc->get_results();
$outcome = self::outcome_from_results($results);
$file = $results['backup_destination']; // may be empty if file already moved to target location
$dir = $config->backup_auto_destination;
$storage = (int)$config->backup_auto_storage;
$file = $results['backup_destination']; // May be empty if file already moved to target location.
if (!file_exists($dir) || !is_dir($dir) || !is_writable($dir)) {
$dir = null;
}
if ($file && !empty($dir) && $storage !== 0) {
$filename = backup_plan_dbops::get_default_backup_filename($format, $type, $course->id, $users, $anonymised, !$config->backup_shortname);
// Copy file only if there was no error.
if ($file && !empty($dir) && $storage !== 0 && $outcome != self::BACKUP_STATUS_ERROR) {
$filename = backup_plan_dbops::get_default_backup_filename($format, $type, $course->id, $users, $anonymised,
!$config->backup_shortname);
if (!$file->copy_content_to($dir.'/'.$filename)) {
$outcome = self::BACKUP_STATUS_ERROR;
}
Expand All @@ -435,6 +440,20 @@ public static function launch_automated_backup($course, $starttime, $userid) {
$outcome = self::BACKUP_STATUS_ERROR;
}

// Delete the backup file immediately if something went wrong.
if ($outcome === self::BACKUP_STATUS_ERROR) {

// Delete the file from file area if exists.
if (!empty($file)) {
$file->delete();
}

// Delete file from external storage if exists.
if ($storage !== 0 && !empty($filename) && file_exists($dir.'/'.$filename)) {
@unlink($dir.'/'.$filename);
}
}

$bc->destroy();
unset($bc);

Expand Down

0 comments on commit 5d56f7d

Please sign in to comment.