From f10fdbcd5fd18beffa1ac0acaac37f837b3a3a19 Mon Sep 17 00:00:00 2001 From: Tomek Muras Date: Fri, 10 Jan 2025 07:03:20 +0100 Subject: [PATCH] Revert "#108310 add changes to loading config file and add new option to fix session issue for Moodle4.5" This reverts commit b81c588a06fb7b85a6e73d55c1b0272fdf6c20af. --- .../Moodle45/Cache/CacheAddRedisStore.php | 70 ------------------- moosh.php | 65 +++++++---------- 2 files changed, 24 insertions(+), 111 deletions(-) delete mode 100644 Moosh/Command/Moodle45/Cache/CacheAddRedisStore.php diff --git a/Moosh/Command/Moodle45/Cache/CacheAddRedisStore.php b/Moosh/Command/Moodle45/Cache/CacheAddRedisStore.php deleted file mode 100644 index c062680d..00000000 --- a/Moosh/Command/Moodle45/Cache/CacheAddRedisStore.php +++ /dev/null @@ -1,70 +0,0 @@ - - * - * Add new instance "Test" with server set to "localhost" - * @example moosh cache-add-redis-store "Test" "localhost" - * - * Add new instance "Test2" with server set to "localhost", password set to "123456" and key prefix set to "key_" - * @example moosh cache-add-redis-store --password "123456" -k "key_" "Test2" "localhost" - * - * @copyright 2012 onwards Tomasz Muras - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @introduced 2021-01-29 - * @author Jakub Kleban - */ - -namespace Moosh\Command\Moodle45\Cache; -use Moosh\MooshCommand; - -class CacheAddRedisStore extends MooshCommand { - - public function __construct() { - parent::__construct('add-redis-store', 'cache'); - - $this->addArgument('name'); - $this->addArgument('server'); - $this->addOption('p|password:', "The server connection password"); - $this->addOption('k|key-prefix:', "The key prefix"); - } - - public function execute() { - global $CFG; - - $options = $this->expandedOptions; - - //Get store configuration - $cacheconfig = new \core_cache\config(); - if (!$cacheconfig->load()){ - cli_error("Unable to load configuration!"); - } - - $data = new \stdClass(); - $data->plugin = 'redis'; - $data->editing = 0; - $data->name = $this->arguments[0]; - $data->lock = null; - $data->server = $this->arguments[1]; - $data->password = $options['password']; - $data->prefix = $options['key-prefix']; - $data->serializer = 1; - $data->compressor = 0; - $data->encryption = null; - $data->cafile = null; - $data->clustermode = null; - - $adminhelper = \cache_factory::instance()->get_administration_display_helper(); - $config = $adminhelper->get_store_configuration_from_data($data); - - $writer = \cache_config_writer::instance(); - - if (array_key_exists($data->name, $cacheconfig->get_all_stores())){ - cli_error("Duplicate name specificed for cache plugin instance $data->name. You must provide a unique name."); - } - - $writer->add_store_instance($data->name, $data->plugin, $config); - - exit(0); - } -} \ No newline at end of file diff --git a/moosh.php b/moosh.php index 55624e64..fb5d3be2 100755 --- a/moosh.php +++ b/moosh.php @@ -42,7 +42,6 @@ $appspecs->add('u|user:', "Moodle user, by default ADMIN"); $appspecs->add('n|no-user-check', "Don't check if Moodle data is owned by the user running script"); $appspecs->add('t|performance', "Show performance information including timings"); -$appspecs->add('o|options:', "Change any setting in config.php"); $appspecs->add('h|help', "Show global help."); $appspecs->add('list-commands', "Show all possible commands"); @@ -194,34 +193,32 @@ function cli_error($text, $errorcode = 1) { */ $subcommand = $subcommands[$subcommand]; $bootstrap_level = $subcommand->bootstrapLevel(); - -// Manually retrieve the information from config.php -$config = []; -if(!file_exists($top_dir . '/config.php')) { - cli_error('config.php not found.'); -} -exec("php -w " . $top_dir . "/config.php", $config); -if (count($config) == 0) { - cli_error("config.php does not look right to me."); -} -$config = implode("\n", $config); -$config = str_ireplace('has('verbose')) { - echo '$CFG - '; - print_r($CFG); -} - if ($bootstrap_level === MooshCommand::$BOOTSTRAP_NONE ) { - // Do nothing really. + // Do nothing really. } else if($bootstrap_level === MooshCommand::$BOOTSTRAP_DB_ONLY) { + // Manually retrieve the information from config.php + // and create $DB object. + $config = []; + if(!file_exists($top_dir . '/config.php')) { + cli_error('config.php not found.'); + } + exec("php -w " . $top_dir . "/config.php", $config); + if (count($config) == 0) { + cli_error("config.php does not look right to me."); + } + $config = implode("\n", $config); + $config = str_ireplace('has('verbose')) { + echo '$CFG - '; + print_r($CFG); + } - // create $DB object $CFG->libdir = $moosh_dir . "/includes/moodle/lib/"; $CFG->debugdeveloper = false; @@ -253,25 +250,11 @@ function string_exists() { define('ABORT_AFTER_CONFIG', true); } - $CFG->dirroot = $top_dir; - - if ($app_options->has('options')) { - $option_value = $app_options['options']->value; - list($key, $value) = explode('=', $option_value, 2); - - if (isset($CFG->$key)) { - if ($value == 'null') { - $value = null; - } - $CFG->$key = $value; - } - } - if (!$top_dir) { echo "Could not find Moodle installation!\n"; exit(1); } - require_once($top_dir . "/lib/setup.php"); + require_once($top_dir . '/config.php'); $shell_user = false; if (!$app_options->has('no-user-check')) {