tmuras / moosh

Moosh
GNU General Public License v3.0
234 stars 177 forks source link

Moodle 4.5 incompatibility if redis session handler is configured. #503

Open benyovszky opened 1 week ago

benyovszky commented 1 week ago

Actual behaviour

I have a moodle instance with confiured redis session cache in config.php: $CFG->session_handler_class = '\core\session\redis';

Then I execute ANY moosh command, it fails:

root@install:/var/www/mdl# sudo -u www-data /opt/moosh/moosh.php filter-set multilang 1

Warning: session_set_save_handler(): Session save handler cannot be changed when a session is active in /var/www/mdl/lib/classes/session/redis.php on line 235 !!! Setting up of redis session failed. Please notify the server administrator. !!! !! Error code: redissessionhandlerproblem !! !! Stack trace: * line 237 of /lib/classes/session/redis.php: core\session\exception thrown

Expected behaviour

Run, without error.

Steps to reproduce

benyovszky commented 1 week ago

Related:

tmuras commented 6 days ago

What if we add a global option to moosh to over-write any $CFG setting in config.php? For example if you run: moosh -o "session_handler_class=NULL" moosh would then unset $CFG->session_handler_class

benyovszky commented 6 days ago
benyovszky commented 5 days ago

Ok, I have found a solution: Just add the following to moosh.php at line 299, right before session_start(); \core\session\manager::destroy_all(); There is no further modification needed.

This will force the script to use the configured session handler before starting the session. Otherwise, the built-in file handler will be used.

I'm pretty sure that with better knowledge or further investigation, a cleaner solution can be found to force moodle to use the session handler from moosh when starting the session.