function write_setting($data) { global $CFG; /// TODO: Need code here that will move the current Moodle directory structure to the new location. if (empty($data)) { $data = $this->get_defaultsetting(); } /// Validate the path, if we can. if ($repo = repository_factory::factory('alfresco')) { if ($repo->is_configured() && $repo->verify_setup()) { if (alfresco_validate_path($data)) { // $newuuid = alfresco_uuid_from_path($data); $newuuid = $repo->get_uuid_from_path($data); if ($newuuid != $repo->muuid && !alfresco_root_move($repo->muuid, $newuuid)) { return get_string('couldnotmoveroot', 'repository_alfresco'); } else { return parent::write_setting($data); } } else { return get_string('invalidpath', 'repository_alfresco'); } } } /// If the repository is not configured correctly, we just have to assume the /// path is valid as we can't connect to verify. return parent::write_setting($data); }
/** * 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); }
public function test_preventexecpath() { $this->resetAfterTest(); set_config('preventexecpath', 0); set_config('execpath', null, 'abc_cde'); $this->assertFalse(get_config('abc_cde', 'execpath')); $setting = new admin_setting_configexecutable('abc_cde/execpath', 'some desc', '', '/xx/yy'); $setting->write_setting('/oo/pp'); $this->assertSame('/oo/pp', get_config('abc_cde', 'execpath')); // Prevent changes. set_config('preventexecpath', 1); $setting->write_setting('/mm/nn'); $this->assertSame('/oo/pp', get_config('abc_cde', 'execpath')); // Use default in install. set_config('execpath', null, 'abc_cde'); $setting->write_setting('/mm/nn'); $this->assertSame('/xx/yy', get_config('abc_cde', 'execpath')); // Use empty value if no default. $setting = new admin_setting_configexecutable('abc_cde/execpath', 'some desc', '', null); set_config('execpath', null, 'abc_cde'); $setting->write_setting('/mm/nn'); $this->assertSame('', get_config('abc_cde', 'execpath')); // This also affects admin_setting_configfile and admin_setting_configdirectory. set_config('preventexecpath', 0); set_config('execpath', null, 'abc_cde'); $this->assertFalse(get_config('abc_cde', 'execpath')); $setting = new admin_setting_configfile('abc_cde/execpath', 'some desc', '', '/xx/yy'); $setting->write_setting('/oo/pp'); $this->assertSame('/oo/pp', get_config('abc_cde', 'execpath')); // Prevent changes. set_config('preventexecpath', 1); $setting->write_setting('/mm/nn'); $this->assertSame('/oo/pp', get_config('abc_cde', 'execpath')); // Use default in install. set_config('execpath', null, 'abc_cde'); $setting->write_setting('/mm/nn'); $this->assertSame('/xx/yy', get_config('abc_cde', 'execpath')); // Use empty value if no default. $setting = new admin_setting_configfile('abc_cde/execpath', 'some desc', '', null); set_config('execpath', null, 'abc_cde'); $setting->write_setting('/mm/nn'); $this->assertSame('', get_config('abc_cde', 'execpath')); set_config('preventexecpath', 0); set_config('execpath', null, 'abc_cde'); $this->assertFalse(get_config('abc_cde', 'execpath')); $setting = new admin_setting_configdirectory('abc_cde/execpath', 'some desc', '', '/xx/yy'); $setting->write_setting('/oo/pp'); $this->assertSame('/oo/pp', get_config('abc_cde', 'execpath')); // Prevent changes. set_config('preventexecpath', 1); $setting->write_setting('/mm/nn'); $this->assertSame('/oo/pp', get_config('abc_cde', 'execpath')); // Use default in install. set_config('execpath', null, 'abc_cde'); $setting->write_setting('/mm/nn'); $this->assertSame('/xx/yy', get_config('abc_cde', 'execpath')); // Use empty value if no default. $setting = new admin_setting_configdirectory('abc_cde/execpath', 'some desc', '', null); set_config('execpath', null, 'abc_cde'); $setting->write_setting('/mm/nn'); $this->assertSame('', get_config('abc_cde', 'execpath')); }