diff --git a/classes/processor.php b/classes/processor.php index 8cdc7ac..bad3ff2 100644 --- a/classes/processor.php +++ b/classes/processor.php @@ -620,6 +620,8 @@ protected function archivecourse($obj, $delete = true) { } $archivefile = date("Y-m-d") . "{$suffix}-{$safeshort}.mbz"; + + $rootpath = trim(get_config('tool_coursearchiver', 'coursearchiverrootpath'), "/\\"); $archivepath = trim(str_replace(str_split(':*?"<>|'), '', get_config('tool_coursearchiver', 'coursearchiverpath')), @@ -629,7 +631,7 @@ protected function archivecourse($obj, $delete = true) { $folder = $this->get_archive_folder(); // Final full path of file. - $path = $CFG->dataroot . '/' . $archivepath . '/' . $folder; + $path = $rootpath . '/' . $archivepath . '/' . $folder; // If the path doesn't exist, make it so! if (!is_dir($path)) { @@ -1540,6 +1542,7 @@ public static function get_archivelist($search, $recover = false) { $isadmin = is_siteadmin(); $config = get_config('tool_coursearchiver'); + $rootpath = trim($config->coursearchiverrootpath, "/\\"); $archivepath = trim(str_replace(str_split(':*?"<>|'), '', $config->coursearchiverpath), @@ -1577,7 +1580,7 @@ public static function get_archivelist($search, $recover = false) { $path = $pathinfo['dirname']; // Make sure it is a file. - if (!file_exists($CFG->dataroot . '/' . $archivepath . '/' . $path . '/' . $file)) { + if (!file_exists($rootpath . '/' . $archivepath . '/' . $path . '/' . $file)) { continue; } @@ -1626,14 +1629,16 @@ public static function get_archivelist($search, $recover = false) { */ public static function delete_archives($selected) { global $CFG, $DB; + $config = get_config('tool_coursearchiver'); + $rootpath = trim($config->coursearchiverrootpath, "/\\"); $archivepath = trim(str_replace(str_split(':*?"<>|'), '', $config->coursearchiverpath), "/\\"); $delaydelete = $config->delaydeletesetting; foreach ($selected as $course) { - if (file_exists($CFG->dataroot . '/' . $archivepath . '/' . $course)) { + if (file_exists($rootpath . '/' . $archivepath . '/' . $course)) { $time = new DateTime("now + $delaydelete days", core_date::get_user_timezone_object()); // Check for database entry of file. $sql = 'SELECT * @@ -1661,13 +1666,15 @@ public static function delete_archives($selected) { */ public static function recover_archives($selected) { global $CFG, $DB; + + $rootpath = trim(get_config('tool_coursearchiver', 'coursearchiverrootpath'), "/\\"); $archivepath = trim(str_replace(str_split(':*?"<>|'), '', get_config('tool_coursearchiver', 'coursearchiverpath')), "/\\"); foreach ($selected as $course) { - $file = $CFG->dataroot . '/' . $archivepath . '/' . $course; + $file = $rootpath . '/' . $archivepath . '/' . $course; if (file_exists($file)) { // Check for database entry of file. $sql = 'SELECT * diff --git a/classes/task/cron_task.php b/classes/task/cron_task.php index fa4a0c6..1b5f4a0 100644 --- a/classes/task/cron_task.php +++ b/classes/task/cron_task.php @@ -49,6 +49,7 @@ public function get_name() { public function execute() { global $CFG, $DB; + $rootpath = trim(get_config('tool_coursearchiver', 'coursearchiverrootpath'), "/\\"); $archivepath = trim(str_replace(str_split(':*?"<>|'), '', get_config('tool_coursearchiver', 'coursearchiverpath')), @@ -60,7 +61,7 @@ public function execute() { if ($markedfordeletion = $DB->get_records_sql($sql, array('timetodelete' => time()))) { foreach ($markedfordeletion as $fileinfo) { - $file = $CFG->dataroot . '/' . $archivepath . '/' . $fileinfo->filename; + $file = $rootpath . '/' . $archivepath . '/' . $fileinfo->filename; if (file_exists($file)) { if (unlink($file)) { // Delete file. $DB->delete_records('tool_coursearchiver_archived', array('id' => $fileinfo->id)); diff --git a/db/upgrade.php b/db/upgrade.php index 0690fab..7c598d4 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -139,14 +139,15 @@ function xmldb_tool_coursearchiver_upgrade($oldversion) { } // Fill up the database with previously archived files. + $rootpath = trim(get_config('tool_coursearchiver', 'coursearchiverrootpath'), "/\\"); $archivepath = trim(str_replace(str_split(':*?"<>|'), '', get_config('tool_coursearchiver', 'coursearchiverpath')), "/\\"); - if (file_exists($CFG->dataroot . '/' . $archivepath)) { + if (file_exists($rootpath . '/' . $archivepath)) { $fileinfos = new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($CFG->dataroot . '/' . $archivepath) + new RecursiveDirectoryIterator($rootpath . '/' . $archivepath) ); if (!empty($fileinfos)) { diff --git a/lang/en/tool_coursearchiver.php b/lang/en/tool_coursearchiver.php index 72db8ff..360ab52 100644 --- a/lang/en/tool_coursearchiver.php +++ b/lang/en/tool_coursearchiver.php @@ -210,10 +210,13 @@ Thank you. '; $string['archivewarningsubject'] = 'Notice: Courses will be archived soon.'; +$string['hidewarningsubject'] = 'Notice: Courses will be hidden soon.'; $string['coursearchiverpath'] = 'Folder path to store archived courses'; -$string['coursearchiverpath_help'] = 'This path is relative to the Moodle $CFG->dataroot'; -$string['hidewarningsubject'] = 'Notice: Courses will be hidden soon.'; +$string['coursearchiverpath_help'] = 'This path is relative to the root path'; + +$string['coursearchiverrootpath'] = 'System path that archiver folders are placed in'; +$string['coursearchiverrootpath_help'] = 'Defaults to CFG->dataroot'; $string['optoutmonthssetting'] = 'Course opt out persistence'; $string['optoutmonthssetting_help'] = 'How many months will the opt out apply for each course.'; diff --git a/restorefile.php b/restorefile.php index 64bc207..43a527b 100644 --- a/restorefile.php +++ b/restorefile.php @@ -39,12 +39,13 @@ global $CFG, $DB; +$rootpath = trim(get_config('tool_coursearchiver', 'coursearchiverrootpath'), "/\\"); $archivepath = trim(str_replace(str_split(':*?"<>|'), '', get_config('tool_coursearchiver', 'coursearchiverpath')), "/\\"); -$archive = $CFG->dataroot . '/' . $archivepath . '/' . $filepath . '/' . $filename; +$archive = $rootpath . '/' . $archivepath . '/' . $filepath . '/' . $filename; if (file_exists($archive)) { $context = context_course::instance(SITEID); $fs = get_file_storage(); diff --git a/settings.php b/settings.php index e3d3dfb..4b67232 100644 --- a/settings.php +++ b/settings.php @@ -27,6 +27,14 @@ if ($hassiteconfig) { $settings = new admin_settingpage('tool_coursearchiver', get_string('coursearchiver_settings', 'tool_coursearchiver')); + $name = new lang_string('coursearchiverrootpath', 'tool_coursearchiver'); + $description = new lang_string('coursearchiverrootpath_help', 'tool_coursearchiver'); + $default = $CFG->dataroot; + $settings->add(new admin_setting_configtext('tool_coursearchiver/coursearchiverrootpath', + $name, + $description, + $default)); + $name = new lang_string('coursearchiverpath', 'tool_coursearchiver'); $description = new lang_string('coursearchiverpath_help', 'tool_coursearchiver'); $default = 'CourseArchives'; diff --git a/version.php b/version.php index f8b90c6..bc5514b 100644 --- a/version.php +++ b/version.php @@ -25,8 +25,8 @@ defined('MOODLE_INTERNAL') || die(); $plugin = new stdClass(); -$plugin->version = 2023071200; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2023083000; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2014111000; // Requires this Moodle version. $plugin->component = 'tool_coursearchiver'; // Full name of the plugin (used for diagnostics). -$plugin->release = '4.1.4 (Build: 2016090200)'; +$plugin->release = '4.1.5 (Build: 2016090200)'; $plugin->maturity = MATURITY_STABLE;