From 7175f5f726acd9934792980eb674003c5febb448 Mon Sep 17 00:00:00 2001
From: Tobias Reischmann <tobias.reischmann@wi.uni-muenster.de>
Date: Mon, 9 Dec 2019 17:11:01 +0100
Subject: [PATCH] Introduced new config for the backup path of lifecycle
 backups

---
 classes/local/manager/backup_manager.php | 4 ++--
 lang/en/tool_lifecycle.php               | 3 +++
 settings.php                             | 5 +++++
 version.php                              | 2 +-
 4 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/classes/local/manager/backup_manager.php b/classes/local/manager/backup_manager.php
index 89ee086..ab73464 100644
--- a/classes/local/manager/backup_manager.php
+++ b/classes/local/manager/backup_manager.php
@@ -58,7 +58,7 @@ class backup_manager {
             $archivefile = date("Y-m-d") . "-ID-{$recordid}-COURSE-{$courseid}.mbz";
 
             // Path of backup folder.
-            $path = $CFG->dataroot . '/lifecycle_backups';
+            $path = get_config('tool_lifecycle', 'backup_path');
             // If the path doesn't exist, make it so!
             if (!is_dir($path)) {
                 umask(0000);
@@ -119,7 +119,7 @@ class backup_manager {
         $targetfilename = \restore_controller::get_tempdir_name($backuprecord->courseid, get_admin()->id);
         $target = $backuptmpdir . '/' . $targetfilename;
         // Create the location of the actual backup file.
-        $source = $CFG->dataroot . '/lifecycle_backups/' . $backuprecord->backupfile;
+        $source = get_config('tool_lifecycle', 'backup_path') . DIRECTORY_SEPARATOR . $backuprecord->backupfile;
         // Check if the backup file exists.
         if (!file_exists($source)) {
             throw new \moodle_exception('errorbackupfiledoesnotexist', 'tool_lifecycle', $source);
diff --git a/lang/en/tool_lifecycle.php b/lang/en/tool_lifecycle.php
index 95755a1..53ea9c9 100644
--- a/lang/en/tool_lifecycle.php
+++ b/lang/en/tool_lifecycle.php
@@ -34,6 +34,9 @@ $string['config_delay_duration'] = 'Default duration of a course delay';
 $string['config_delay_duration_desc'] = 'This setting defines the default delay duration of a workflow
 in case one of its processes is rolled back or finishes.
 The delay duration determines how long a course will be excepted from being processed again in either of the cases.';
+$string['config_backup_path'] = 'Path of the lifecycle backup folder';
+$string['config_backup_path_desc'] = 'This settings defines the storage location of the backups created by the backup step.
+The path has to be specified as an absolute path on your server.';
 $string['active_processes_list_header'] = 'Active processes';
 $string['adminsettings_heading'] = 'Workflow settings';
 $string['active_manual_workflows_heading'] = 'Active manual workflows';
diff --git a/settings.php b/settings.php
index f2da89c..c4dd329 100644
--- a/settings.php
+++ b/settings.php
@@ -38,6 +38,11 @@ if ($hassiteconfig) {
         get_string('config_delay_duration_desc', 'tool_lifecycle'),
         183 * 24 * 60 * 60)); // Dafault value is 180 days.
 
+    $settings->add(new admin_setting_configtext('tool_lifecycle/backup_path',
+        get_string('config_backup_path', 'tool_lifecycle'),
+        get_string('config_backup_path_desc', 'tool_lifecycle'),
+        $CFG->dataroot . DIRECTORY_SEPARATOR . 'lifecycle_backups'));
+
     $ADMIN->add('lifecycle_category', new tool_lifecycle\admin_page_active_processes());
     $ADMIN->add('lifecycle_category', new tool_lifecycle\admin_page_course_backups());
     $ADMIN->add('lifecycle_category', new tool_lifecycle\admin_page_sublugins());
diff --git a/version.php b/version.php
index 3e1554f..b97f25a 100644
--- a/version.php
+++ b/version.php
@@ -25,7 +25,7 @@
 defined('MOODLE_INTERNAL') || die;
 
 $plugin->maturity = MATURITY_BETA;
-$plugin->version  = 2019120200;
+$plugin->version  = 2019120201;
 $plugin->component = 'tool_lifecycle';
 $plugin->requires = 2017111300; // Require Moodle 3.4 (or above).
 $plugin->release = 'v3.8-r1';
-- 
GitLab