From e243c8c448982dfd071490585096c043cb56cb65 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Mon, 23 Aug 2010 14:24:38 +0000 Subject: [PATCH] NOMDL Added new core function to get a component version --- lib/adminlib.php | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/lib/adminlib.php b/lib/adminlib.php index 610558c4f1d..d9362cb8a12 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -274,6 +274,83 @@ function uninstall_plugin($type, $name) { echo $OUTPUT->notification(get_string('success'), 'notifysuccess'); } +/** + * Returns the version of installed component + * + * @param string $component component name + * @param string $source either 'disk' or 'installed' - where to get the version information from + * @return string|bool version number or false if the component is not found + */ +function get_component_version($component, $source='installed') { + global $CFG, $DB; + + list($type, $name) = normalize_component($component); + + // moodle core or a core subsystem + if ($type === 'core') { + if ($source === 'installed') { + if (empty($CFG->version)) { + return false; + } else { + return $CFG->version; + } + } else { + if (!is_readable($CFG->dirroot.'/version.php')) { + return false; + } else { + include($CFG->dirroot.'/version.php'); + return $version; + } + } + } + + // activity module + if ($type === 'mod') { + if ($source === 'installed') { + return $DB->get_field('modules', 'version', array('name'=>$name)); + } else { + $mods = get_plugin_list('mod'); + if (empty($mod[$name]) or !is_readable($mod[$name].'/version.php')) { + return false; + } else { + $module = new stdclass(); + include($mod[$name].'/version.php'); + return $module->version; + } + } + } + + // block + if ($type === 'block') { + if ($source === 'installed') { + return $DB->get_field('block', 'version', array('name'=>$name)); + } else { + $blocks = get_plugin_list('block'); + if (empty($blocks[$name]) or !is_readable($blocks[$name].'/version.php')) { + return false; + } else { + $plugin = new stdclass(); + include($blocks[$name].'/version.php'); + return $plugin->version; + } + } + } + + // all other plugin types + if ($source === 'installed') { + return get_config($type.'_'.$name, 'version'); + } else { + $plugins = get_plugin_list($type); + if (empty($plugins[$name])) { + return false; + } else { + $plugin = new stdclass(); + include($plugins[$name].'/version.php'); + return $plugin->version; + } + } +} + /** * Delete all plugin tables *