diff --git a/list_valid_components/list_valid_components.php b/list_valid_components/list_valid_components.php index 1ed33cf6..9f6c307a 100644 --- a/list_valid_components/list_valid_components.php +++ b/list_valid_components/list_valid_components.php @@ -88,76 +88,29 @@ // For Moodle 2.6 and upwards, we execute this specific code that does not require // the site to be installed (relying on new classes only available since then). -if (load_core_component_from_moodle($options['basedir'])) { - // Get all the plugins and subplugin types. - $types = core_component::get_plugin_types(); - // Sort types in reverse order, so we get subplugins earlier than plugins. - $types = array_reverse($types); - // For each type, get their available implementations. - foreach ($types as $type => $fullpath) { - $plugins = core_component::get_plugin_list($type); - // For each plugin, let's calculate the proper component name and output it. - foreach ($plugins as $plugin => $pluginpath) { - $component = $type . '_' . $plugin; - if (!$options['absolute']) { - $pluginpath = str_replace($options['basedir'] . '/', '', $pluginpath); - } - echo 'plugin,' . $component . ',' . $pluginpath . PHP_EOL; - } - } - - // Get all the subsystems. - $subsystems = core_component::get_core_subsystems(); - $subsystems['core'] = $options['basedir']; // To get the main one too - foreach ($subsystems as $subsystem => $subsystempath) { - if ($subsystem == 'backup') { // Because I want, yes :-P - $subsystempath = $options['basedir'] . '/backup'; - } - // All subsystems are core_ prefixed. - $component = 'core_' . $subsystem; - if ($subsystem === 'core') { // But core. - $component = 'core'; - } - if (!$options['absolute'] and !empty($subsystempath)) { - $subsystempath = str_replace($options['basedir'] . '/', '', $subsystempath); - } - echo 'subsystem,' . $component . ',' . $subsystempath . PHP_EOL; - } - // We are done, end here. - exit(0); +if (!load_core_component_from_moodle($options['basedir'])) { + cli_error('Unable to load core component from moodle dir: ' . $options['basedir']); } -// Up to Moodle 2.5, we use the old global API, that requires the site to be installed -// (the shell script calling this handles those reqs automatically) -// TODO: Once 2.5 is out we can change this by the new core_component::get_xxx() calls. -// until then will be using the deprecated ones. -require(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php'); - -// Get all the plugin and subplugin types -$types = get_plugin_types(true); -// Sort types in reverse order, so we get subplugins earlier than plugins +// Get all the plugins and subplugin types. +$types = core_component::get_plugin_types(); +// Sort types in reverse order, so we get subplugins earlier than plugins. $types = array_reverse($types); -// For each type, get their available implementations +// For each type, get their available implementations. foreach ($types as $type => $fullpath) { - $plugins = get_plugin_list($type); - // For each plugin, let's calculate the proper component name and generate - // the corresponding build.xml file + $plugins = core_component::get_plugin_list($type); + // For each plugin, let's calculate the proper component name and output it. foreach ($plugins as $plugin => $pluginpath) { $component = $type . '_' . $plugin; if (!$options['absolute']) { - // Want relatives, clean dirroot. - $pluginpath = str_replace($CFG->dirroot . '/', '', $pluginpath); - } else { - // Want absolutes, replace dirroot by basedir. - $pluginpath = str_replace($CFG->dirroot, $options['basedir'] , $pluginpath); + $pluginpath = str_replace($options['basedir'] . '/', '', $pluginpath); } echo 'plugin,' . $component . ',' . $pluginpath . PHP_EOL; } } -// Get all the subsystems and -// generate the corresponding build.xml file -$subsystems = get_core_subsystems(true); +// Get all the subsystems. +$subsystems = core_component::get_core_subsystems(); $subsystems['core'] = $options['basedir']; // To get the main one too foreach ($subsystems as $subsystem => $subsystempath) { if ($subsystem == 'backup') { // Because I want, yes :-P @@ -168,15 +121,10 @@ if ($subsystem === 'core') { // But core. $component = 'core'; } - // If it's a subsystem with path. - if (!empty($subsystempath)) { - if (!$options['absolute']) { - // Want relatives, clean dirroot. - $subsystempath = str_replace($CFG->dirroot . '/', '', $subsystempath); - } else { - // Want absolutes, replace dirroot by basedir. - $subsystempath = str_replace($CFG->dirroot, $options['basedir'], $subsystempath); - } + if (!$options['absolute'] and !empty($subsystempath)) { + $subsystempath = str_replace($options['basedir'] . '/', '', $subsystempath); } echo 'subsystem,' . $component . ',' . $subsystempath . PHP_EOL; } +// We are done, end here. +exit(0); diff --git a/phplib/clilib.php b/phplib/clilib.php index d4c39170..45fba5be 100644 --- a/phplib/clilib.php +++ b/phplib/clilib.php @@ -222,7 +222,19 @@ function s($var) { * @return bool false if core_component wasn't able to be loaded. */ function load_core_component_from_moodle($moodledirroot) { - if (!file_exists($moodledirroot . '/lib/classes/component.php')) { + if (file_exists($moodledirroot . '/public/lib/classes/component.php')) { + // Support the Moodle 5.1 'public' directory structure. + $newcfg = (object) [ + 'dirroot' => "{$moodledirroot}/public", + 'root' => $moodledirroot, + 'libdir' => "{$moodledirroot}/public/lib", + ]; + } else if (file_exists($moodledirroot . '/lib/classes/component.php')) { + $newcfg = (object) [ + 'dirroot' => $moodledirroot, + 'libdir' => $moodledirroot . '/lib', + ]; + } else { return false; } @@ -230,12 +242,11 @@ function load_core_component_from_moodle($moodledirroot) { define('MOODLE_INTERNAL', 1); unset($CFG); global $CFG; - $CFG = new stdClass(); - $CFG->dirroot = $moodledirroot; - $CFG->libdir = $CFG->dirroot . '/lib'; + $CFG = $newcfg; $CFG->admin = 'admin'; $CFG->filepermissions = '0666'; - require_once($CFG->dirroot . '/lib/classes/component.php'); + + require_once($CFG->libdir . '/classes/component.php'); return true; }