Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cache-edit-mapping and cache-add-redis-store for Moodle 405 #501

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

owngr
Copy link

@owngr owngr commented Oct 10, 2024

Related issue: #500

I'm quite newby with PHP so it might not be the best solution.

cache-edit-mapping

[10-Oct-2024 16:28:36 Europe/Berlin] PHP Warning:  session_set_save_handler(): Session save handler cannot be changed when a session is active in /var/www/html/lib/classes/session/redis.php on line 235

Warning: session_set_save_handler(): Session save handler cannot be changed when a session is active in /var/www/html/lib/classes/session/redis.php on line 235
[10-Oct-2024 16:28:36 Europe/Berlin] Default exception handler: Setting up of redis session failed. Please notify the server administrator. Debug:
Error code: redissessionhandlerproblem
* line 237 of /lib/classes/session/redis.php: core\session\exception thrown
* line 750 of /lib/classes/session/redis.php: call to core\session\redis->init()
* line 688 of /lib/classes/session/redis.php: call to core\session\redis->init_redis_if_required()
* line 996 of /lib/classes/session/manager.php: call to core\session\redis->destroy()
* line 636 of /lib/classes/session/manager.php: call to core\session\manager::destroy()
* line 4078 of /lib/moodlelib.php: call to core\session\manager::login_user()
* line 303 of /opt/moosh/moosh.php: call to complete_user_login()

!!! Setting up of redis session failed. Please notify the server administrator. !!!

Therefore I added the following code in order to avoid a login, I couldn't find a better solution:

public function bootstrapLevel() {
  return self::$BOOTSTRAP_FULL_NO_ADMIN_CHECK;
}

cache-add-redis-store

  • renamed the classes to fit Moodle 405
  • added the following new params disabled by default
    • encryption
    • cafile
    • encryption
  • I had the same issue with the login as cache-edit-mapping and therefore disabled the login

Use 3 digit versions number

I started by naming the folder Moodle45 but still received errors because moosh was using Moodle310 cache-add-redis-store.

Moodle started using 3 digits number version for branch in version.php with Moodle 310.

Therefore, when I tried to use the 45 version it would pickup Moodle 310 as 310 > 45 as you can see here:

 /opt/moosh/moosh.php -v --no-user-check cache-add-redis-store --key-prefix="cache_" "redis" "$MAAS_REDIS_HOST"
Top Moodle dir: /var/www/html
Current working dir: /var/www/html
Relative Moodle dir:
Processing command option 'help''
Processing command option 'password''
Processing command option 'key-prefix''
'key-prefix' option is set on the command line to 'cache_'
Moodle version detected: 405
Command: add-redis-store (cache)
Options:
	help (): ''
	key-prefix (): 'cache_'
Arguments:
	redis redis-master
[10-Oct-2024 12:04:11 Europe/Berlin] PHP Warning:  require_once(/var/www/html/cache/locallib.php): Failed to open stream: No such file or directory in /opt/moosh/Moosh/Command/Moodle310/Cache/CacheAddRedisStore.php on line 37

Warning: require_once(/var/www/html/cache/locallib.php): Failed to open stream: No such file or directory in /opt/moosh/Moosh/Command/Moodle310/Cache/CacheAddRedisStore.php on line 37

The only way to make moosh pickup the right version was to refractor the whole numbering to start using 3 digit.

@rimkov
Copy link

rimkov commented Nov 4, 2024

we have the same problem, no moosh command works. i can work around the problem by commenting out the line
$CFG->session_handler_class = '\core\session\redis';
in the config.php

moodle 4.5.0
php 8.1
moosh 1.14

@benyovszky
Copy link
Contributor

Same here; all commands are failing. I do not want to add self::$BOOTSTRAP_FULL_NO_ADMIN_CHECK; for every command that I use, I need a most maintainable solution.
moodle 4.5.0
php 8.2
moosh 1.21 and 1.24

Removing the config items means failing back to the standard session management, and that works, obviously.

I spent some hours to find a proper way to start a session from moosh, but already with the defined handler, in my case it is redis. No luck so far.

@tmuras
Copy link
Owner

tmuras commented Jan 14, 2025

@benyovszky could you try the latest version and option
--no-login / -l
This will try to run command without logging in as admin.

@benyovszky
Copy link
Contributor

I have no access currently to my dev env, but ommitting the login means that we loose logging. And if i have redis based session caching configured I need to set this no-login flag for all commands, means I loose logging for all moosh based modification, that I would not accept as a trade-off.

@benyovszky
Copy link
Contributor

@tmuras I have tested the commit (3b0ae7d) The results are as I expected:

  • With the new switch, you can execute commands, even if a custom session handler is set in config.
  • If the switch is set on, there is no user info in log entries.
  • If a custom session handler is set, every command needs the -l switch. Otherwise, you get the original error.

@tmuras
Copy link
Owner

tmuras commented Jan 19, 2025

"If the switch is set on, there is no user info in log entries."
The log that you're not getting there (but you'd link to) is a user login entry? Or do you mean that other log entries that are inserted into Moodle log do not have user information? Can you give me an example?

I'm not sure how to handle it well by default. I now think it's a bit unusual to login user when executing CLI script - Moodle scripts do not do it. Perhaps the default should be to (whenever possible) execute the CLI script without performing any user login - unless the option like --user= is given.

@tmuras
Copy link
Owner

tmuras commented Jan 19, 2025

we have the same problem, no moosh command works. i can work around the problem by commenting out the line $CFG->session_handler_class = '\core\session\redis'; in the config.php

moodle 4.5.0 php 8.1 moosh 1.14

In the latest commit I've added -o / --options option.
You can use it to override, NULL-ify or unset any CFG setting defined in config.php.
For example
moosh -o session_handler_class=unset

Have a look if that works for you @benyovszky and @rimkov .
If yes, then you could create a moosh wrapper script that will always run moosh with that option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants