MDL-48266 backup: Validate backup_auto_storage config

This commit is contained in:
Frederic Massart
2015-01-22 17:48:07 +08:00
parent da0ef2e4cf
commit 9fdf16a0fc
3 changed files with 41 additions and 2 deletions
+38
View File
@@ -4390,6 +4390,44 @@ class admin_setting_special_backupdays extends admin_setting_configmulticheckbox
}
}
/**
* Special setting for backup auto destination.
*
* @package core
* @subpackage admin
* @copyright 2014 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_special_backup_auto_destination extends admin_setting_configdirectory {
/**
* Calls parent::__construct with specific arguments.
*/
public function __construct() {
parent::__construct('backup/backup_auto_destination', new lang_string('saveto'), new lang_string('backupsavetohelp'), '');
}
/**
* Check if the directory must be set, depending on backup/backup_auto_storage.
*
* Note: backup/backup_auto_storage must be specified BEFORE this setting otherwise
* there will be conflicts if this validation happens before the other one.
*
* @param string $data Form data.
* @return string Empty when no errors.
*/
public function write_setting($data) {
$storage = (int) get_config('backup', 'backup_auto_storage');
if ($storage !== 0) {
if (empty($data) || !file_exists($data) || !is_dir($data) || !is_writable($data) ) {
// The directory must exist and be writable.
return get_string('backuperrorinvaliddestination');
}
}
return parent::write_setting($data);
}
}
/**
* Special debug setting