Create a sql query for deleting old bells
Summary
Our nightly run throws an error while deleting old bells. See below. It somehow seems to be working anyway but this doesn't seem to be stable nor efficient. My best guess is, the sql query itself get's too long due to the imploding of bell ids.
Steps to reproduce
Create some test data in your local phpmyadmin. If a decent query works with some it also should work with many bells.
You could check if it works with over 3000 (see below)
Command for nightly run: php -f run.php Maintenance daily
Relevant error messages and/or screenshots
2019-07-17 02:15:06 [INFO] OK
SQL QUERY ERROR URL run.php IN ALTER TABLE fs_bell AUTO_INCREMENT = (SELECT MAX(id) FROM fs_bell) : You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(SELECT MAX(id) FROM fs_bell)' at line 1
2019-07-17 02:15:08 [INFO] 2899 old bells deleted
Possible fixes
In the first query all old bells got fetched with listOldBellIds()
:
https://gitlab.com/foodsharing-dev/foodsharing/blob/master/src/Modules/Maintenance/MaintenanceModel.php#L9
This result is being used to delete bells with two queries here:
https://gitlab.com/foodsharing-dev/foodsharing/blob/master/src/Modules/Maintenance/MaintenanceGateway.php#L9
It looks like there are things done in php here which should be done by sql. Create a query which at best does it all in one sql query with time range (7 days) being set as a parameter.