catalyst / moodle-tool_abconfig

A way to A/B test config, or slowly turn on config for certain audiences or % of traffic
https://moodle.org/plugins/tool_abconfig
6 stars 4 forks source link

Make it possible to execute experiments on CLI scripts #51

Closed golenkovm closed 2 years ago

golenkovm commented 2 years ago

This is to implement #50

golenkovm commented 2 years ago

It seems like I faced a problem and a bit stuck.

When we run CLI scripts they call config.php first which calls setup.php. However, when after_config is called $USER is still empty. It gets populated later on this call: https://github.com/moodle/moodle/blob/a23f0bff3e1f386ceeb686e1d7ce28d8735769e0/admin/cli/adhoc_task.php#L123

But since there is no require_login() call in CLI scripts tool_abconfig_after_require_login() is not executed.

This makes applying experiments on CLI calls based on user id a bit tricky.

brendanheywood commented 2 years ago

This seems a bit odd to me. CLI scripts either don't have a concept of a user, or they run effectively like sudo as the primary admin user.

If you are manually running a cli script and you want to force the condition of any arbitrary experiment then a better way of passing this in in a very generic way which enabled you to specify which experiment on the cli is using an environment var:

EXPERIMENT_SHORTNAME=conditionset php admin/cli/mycli.php --foo=bar

So this is exactly equivalent to doing ?experimentshortname=conditionset in a web request

Pretty well exactly like how this does it https://tracker.moodle.org/browse/MDL-67081

golenkovm commented 2 years ago

Yeah, you're right. Closing this as Won't fix

brendanheywood commented 2 years ago

@golenkovm I am very happy for this to land using the env var way of turning it on, you could re-push that to this PR or are you going to make a new pr?