diff --git a/classes/local/manager/backup_manager.php b/classes/local/manager/backup_manager.php index daf5ae903168dfa2760b748862cdc056b1356c9c..f7752b45b84aa25ebf63d45482c31c323e39bd85 100644 --- a/classes/local/manager/backup_manager.php +++ b/classes/local/manager/backup_manager.php @@ -45,57 +45,51 @@ class backup_manager { */ public static function create_course_backup($courseid) { global $CFG, $DB; - try { - $course = get_course($courseid); - $record = new \stdClass(); - $record->courseid = $courseid; - $record->fullname = $course->fullname; - $record->shortname = $course->shortname; - $recordid = $DB->insert_record('tool_lifecycle_backups', $record, true); - $record->id = $recordid; - - // Build filename. - $archivefile = date("Y-m-d") . "-ID-{$recordid}-COURSE-{$courseid}.mbz"; - - // Path of backup folder. - $path = get_config('tool_lifecycle', 'backup_path'); - // If the path doesn't exist, make it so! - if (!is_dir($path)) { - umask(0000); - // Create the directory for Backups. - if (!mkdir($path, $CFG->directorypermissions, true)) { - throw new \moodle_exception(get_string('errorbackuppath', 'tool_lifecycle')); - } + $course = get_course($courseid); + $record = new \stdClass(); + $record->courseid = $courseid; + $record->fullname = $course->fullname; + $record->shortname = $course->shortname; + $recordid = $DB->insert_record('tool_lifecycle_backups', $record, true); + $record->id = $recordid; + + // Build filename. + $archivefile = date("Y-m-d") . "-ID-{$recordid}-COURSE-{$courseid}.mbz"; + + // Path of backup folder. + $path = get_config('tool_lifecycle', 'backup_path'); + // If the path doesn't exist, make it so! + if (!is_dir($path)) { + umask(0000); + // Create the directory for Backups. + if (!mkdir($path, $CFG->directorypermissions, true)) { + throw new \moodle_exception(get_string('errorbackuppath', 'tool_lifecycle')); } - // Perform Backup. - $bc = new \backup_controller(\backup::TYPE_1COURSE, $courseid, \backup::FORMAT_MOODLE, - \backup::INTERACTIVE_NO, \backup::MODE_AUTOMATED, get_admin()->id); - $bc->execute_plan(); // Execute backup. - $results = $bc->get_results(); // Get the file information needed. - /* @var $file \stored_file instance of the backup file*/ - $file = $results['backup_destination']; - if (!empty($file)) { - $file->copy_content_to($path . DIRECTORY_SEPARATOR . $archivefile); - $file->delete(); - } - $bc->destroy(); - unset($bc); + } + // Perform Backup. + $bc = new \backup_controller(\backup::TYPE_1COURSE, $courseid, \backup::FORMAT_MOODLE, + \backup::INTERACTIVE_NO, \backup::MODE_AUTOMATED, get_admin()->id); + $bc->execute_plan(); // Execute backup. + $results = $bc->get_results(); // Get the file information needed. + /* @var $file \stored_file instance of the backup file*/ + $file = $results['backup_destination']; + if (!empty($file)) { + $file->copy_content_to($path . DIRECTORY_SEPARATOR . $archivefile); + $file->delete(); + } + $bc->destroy(); + unset($bc); - // First check if the file was created. - if (!file_exists($path . DIRECTORY_SEPARATOR . $archivefile)) { - return false; - } + // First check if the file was created. + if (!file_exists($path . DIRECTORY_SEPARATOR . $archivefile)) { + throw new \moodle_exception(get_string('errornobackup', 'tool_lifecycle')); + } - $record->backupfile = $archivefile; - $record->backupcreated = time(); - $DB->update_record('tool_lifecycle_backups', $record, true); + $record->backupfile = $archivefile; + $record->backupcreated = time(); + $DB->update_record('tool_lifecycle_backups', $record, true); - return true; - } catch (\moodle_exception $e) { - debugging('There was a problem during backup!'); - debugging($e->getMessage()); - return false; - } + return true; } /** diff --git a/lang/de/tool_lifecycle.php b/lang/de/tool_lifecycle.php index 7a2b133686c8e7920f786c94d3be3cdc42d0a689..fdafbd56c3354e57b11985613577d9efdc449c8e 100644 --- a/lang/de/tool_lifecycle.php +++ b/lang/de/tool_lifecycle.php @@ -187,3 +187,7 @@ $string['lifecycle_error_notify_task'] = 'Benachrichtigt die Administratoren bei $string['notifyerrorsemailsubject'] = '{$a->amount} neue fehlerhafte tool_lifecycle Prozesse warten darauf, behandelt zu werden!'; $string['notifyerrorsemailcontent'] = '{$a->amount} neue fehlerhafte tool_lifecycle Prozesse warten darauf, behandelt zu werden!' . "\n" . 'Bitte besuchen Sie {$a->url}.'; $string['notifyerrorsemailcontenthtml'] = '{$a->amount} neue fehlerhafte tool_lifecycle Prozesse warten darauf, behandelt zu werden!<br>Bitte besuchen Sie <a href="{$a->url}">die Übersichtsseite</a>.'; +$string['errorbackuppath'] = "Ein Fehler ist aufgetreten beim Versuchen das Backup Verzeichnis zu erstellen. +Ihnen fehlen wahrscheinlich die Berechtigung dazu. Bitte überprüfen Sie den Pfad unter +Seitenadministration/Plugins/Dienstprogramme/Kurs-Lebenszyklus/Allgemein & Subplugins."; +$string['errornobackup'] = "Es wurde kein Backup in dem angegebenen Pfad erstellt."; diff --git a/lang/en/tool_lifecycle.php b/lang/en/tool_lifecycle.php index 933d2e949a3d9839287bb3688efae9e4be0e408e..08d758f2f14e3bd6cf183d2829fd56795bc65fc2 100644 --- a/lang/en/tool_lifecycle.php +++ b/lang/en/tool_lifecycle.php @@ -223,3 +223,6 @@ $string['lifecycle_error_notify_task'] = 'Notify the admin upon errors in tool_l $string['notifyerrorsemailsubject'] = 'There are {$a->amount} new tool_lifecycle process errors waiting to be fixed!'; $string['notifyerrorsemailcontent'] = 'There are {$a->amount} new tool_lifecycle process errors waiting to be fixed!' . "\n" . 'Please review them at {$a->url}.'; $string['notifyerrorsemailcontenthtml'] = 'There are {$a->amount} new tool_lifecycle process errors waiting to be fixed!<br>Please review them at the <a href="{$a->url}">error handling overview</a>.'; +$string['errorbackuppath'] = "Error while trying to create the backup directory. You might be missing the permission to do so. +Please check your path at Site administration/Plugins/Admin tools/Life Cycle/General & subplugins/backup_path."; +$string['errornobackup'] = "No backup was created at the specified directory, reasons unknown.";