Page MenuHomePhabricator

"Unexpected request" when trying to run maintenance script in Wikimini
Closed, ResolvedPublic2 Estimated Story Points

Description

In Wikimini, when I try to run a maintenance script, the scripts ends immediately and prints "Unexpected request" with no line break.
It does hoever show the help message when using --help, but the script never runs when using it normally.
It seems to be the same with all maintenane scripts, although I only checked cleanupPreferences, update, undelete and eval.php.

Event Timeline

Raphoraph triaged this task as Medium priority.Apr 25 2023, 2:36 AM
Raphoraph created this task.

Uhm.

It's possible that it needs an explicit --conf. Can you retry with that?

Also, it may need to - somehow - receive the current domain, in order to guess the current database name.

Feel free to try that. Then I will further investigate if possible

Raphoraph changed the task status from Open to In Progress.Jun 26 2023, 10:27 PM

Also, it may need to - somehow - receive the current domain, in order to guess the current database name.

The issue comes from here. The "Unexpected request" comes from the LocalSettings.php, which fails to exploit MW_DB in order to get some constants (WIKIMINI_PROJECT_UID and WIKIMINI_DOMAIN if I recall correctly) right, and thus reports an error. I've started to adapt the script but I don't see how transmit the domain (and also, the domain should not change the database, or is it?). I can run my maintenance script for now but we need to rewrite the LocalSettings file.

I see that you changed a bit the script to consider MW_DB, I think that is a great idea, thanks

Yes, that's how I managed to make the maintenance script run: using MW_DB
as intended, putting the database name we work on in it through the --wiki
argument. The script checks it and parses it.

However I've commented out my change so to not make them permanent since
there are unstable and do not handle all situations.

ValerioBoz-WMCH claimed this task.
ValerioBoz-WMCH moved this task from Backlog to Done on the Wikimini.org board.

I'm very happy because I've found a SURPRISINGLY-KISS solution \o/

but I'm sad because I've invested 2 hours of troubleshooting to discover this. And, trust me, you don't want to know how stupid the solution was. You will start screaming for 5 minutes after you will end this message.

So. The solution is... Instead of this:

./maintenance/deleteBatch.php

Just this (!)

HTTP_HOST=es.wikimini.org ./maintenance/deleteBatch.php

This has sense since our snippet works in this way.

/**
 * define WIKIMINI_PROJECT_UID e.g. 'stock'
 * define WIKIMINI_MAIN_DOMAIN e.g. 'wikimini.org'
 */
( function() {

        // host declared by the client
        // From script you can use a command like
        //
        //    HTTP_HOST=es.wikimini.org ./maintenance/something.php asd"
        //
        $host = $_SERVER['HTTP_HOST'] ?? null;

        // split the host in subdomain and rest of the domain
        $parts = explode( '.', $host, 2 );

...

And the $_SERVER automagically receive things from environment variables and our domain-base matcher just works out-of-the-box, without any change (!)

Weirdness: