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.
This commit is contained in:
Frederic Massart 2013-07-09 16:57:37 +08:00
parent f8be9f9e73
commit a76efbcac8
2 changed files with 11 additions and 6 deletions

View File

@ -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];

View File

@ -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