From a76efbcac8f1005edb4a70c3990aff51c4ff8183 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Tue, 9 Jul 2013 16:57:37 +0800 Subject: [PATCH 1/2] MDL-38366 repository: get_option() returns proper values Previously, even when a specific setting had to be returned, this method would return an empty array. Now, the behaviour is the same whether some options or none are set: if the requested setting is not found null is returned. --- repository/lib.php | 12 ++++++------ repository/upgrade.txt | 5 +++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/repository/lib.php b/repository/lib.php index c3b17f24a71..ca78900ebec 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -2163,10 +2163,11 @@ abstract class repository implements cacheable_object { } /** - * Get settings for repository instance + * Get settings for repository instance. * - * @param string $config - * @return array Settings + * @param string $config a specific option to get. + * @return mixed returns an array of options. If $config is not empty, then it returns that option, + * or null if the option does not exist. */ public function get_option($config = '') { global $DB; @@ -2175,13 +2176,12 @@ abstract class repository implements cacheable_object { $entries = $DB->get_records('repository_instance_config', array('instanceid' => $this->id)); $cache->set('ops:'. $this->id, $entries); } + $ret = array(); - if (empty($entries)) { - return $ret; - } foreach($entries as $entry) { $ret[$entry->name] = $entry->value; } + if (!empty($config)) { if (isset($ret[$config])) { return $ret[$config]; diff --git a/repository/upgrade.txt b/repository/upgrade.txt index 739fa814ee6..fdaed9f9f2f 100644 --- a/repository/upgrade.txt +++ b/repository/upgrade.txt @@ -3,6 +3,11 @@ information provided here is intended especially for developers. Full details of the repository API are available on Moodle docs: http://docs.moodle.org/dev/Repository_API +=== 2.6 === + +* get_option() now always return null when the first parameter ($config) is not empty, and + no value was found for this $config. Previously this could sometimes return an empty array(). + === 2.5 === * repository::append_suffix() has been deprecated, use repository::get_unused_filename() if you need From c122f484c50f2e686a3f82260efa84c49d16579d Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Wed, 10 Jul 2013 13:46:25 +0800 Subject: [PATCH 2/2] MDL-38366 repository_filesystem: Prevent use of empty subdir --- repository/filesystem/lib.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/repository/filesystem/lib.php b/repository/filesystem/lib.php index 522fe52a44f..5730492a0fe 100644 --- a/repository/filesystem/lib.php +++ b/repository/filesystem/lib.php @@ -48,9 +48,14 @@ class repository_filesystem extends repository { public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) { global $CFG; parent::__construct($repositoryid, $context, $options); - $root = $CFG->dataroot.'/repository/'; + $root = $CFG->dataroot . '/repository/'; $subdir = $this->get_option('fs_path'); - $this->root_path = $root . $subdir . '/'; + + $this->root_path = $root; + if (!empty($subdir)) { + $this->root_path .= $subdir . '/'; + } + if (!empty($options['ajax'])) { if (!is_dir($this->root_path)) { $created = mkdir($this->root_path, $CFG->directorypermissions, true);