mediawiki-extensions-Gadgets/includes/Special
Umherirrender dc84f149bc SpecialGadgetUsage: Fix query for postgres (and improve for mariadb)
The column user_properties.up_value is a text based type in all rdbms.
postgres does not autoconvert strings to numbers, so SUM( up_value )
gives an error when running on postgres.
The use of SUM( up_value ) is also problematic on mariadb/sqlite, as
up_value can be set to any number via the Action API's options module.
This value goes into the sum and produce a wrong result. Using a
non-number value allows to remove the value from the sum and that also
produce a wrong result.

Change the query to exclude the rows which disables a gadget and just
count the "active" ones. Typically there are only rows to disable a
gadget, when the gadget is marked as default, but default gadget are
displayed with the message 'gadgetusage-default' and does not needs to
be counted. In case a gadget was default in the past, there could always
such rows, so be safe and exclude them. That means it is safe to only
count for "active" gadget option usage.
This also allows to remove the up_value condition on the join to
querycachetwo as only rows to enable a gadget are now selected and get
joined to find the active users.

For the join condition use an assoc array, as for database condition the
database class is quoting the value of that array, if that is a string.
In postgres the " is used to quote columns or tables, but not values,
that gives a query error on postgres about the condition.
fixed when using the array style and not "raw" sql.

Define the condition only once as it should be the same for both
queries. Use the new IDatabase::expr function to write that sql piece.

Change-Id: I8dfc3fd5adc4c4bdabceaab20c4b37ffd48e6bee
2024-01-08 18:59:45 +01:00
..
SpecialGadgets.php Use namespaced classes 2024-01-06 17:45:07 +01:00
SpecialGadgetUsage.php SpecialGadgetUsage: Fix query for postgres (and improve for mariadb) 2024-01-08 18:59:45 +01:00