Put cron task queries into an array.

This commit is contained in:
flash 2019-01-28 09:10:56 +01:00
parent d146cbae61
commit a94ed4ce91

View file

@ -89,16 +89,17 @@ if (PHP_SAPI === 'cli') {
if (realpath($_SERVER['SCRIPT_FILENAME']) === __FILE__) { if (realpath($_SERVER['SCRIPT_FILENAME']) === __FILE__) {
switch ($argv[1] ?? null) { switch ($argv[1] ?? null) {
case 'cron': case 'cron':
$cronTasks = [
// Ensure main role exists. // Ensure main role exists.
db_exec(" "
INSERT IGNORE INTO `msz_roles` INSERT IGNORE INTO `msz_roles`
(`role_id`, `role_name`, `role_hierarchy`, `role_colour`, `role_description`, `role_created`) (`role_id`, `role_name`, `role_hierarchy`, `role_colour`, `role_description`, `role_created`)
VALUES VALUES
(1, 'Member', 1, 1073741824, NULL, NOW()) (1, 'Member', 1, 1073741824, NULL, NOW())
"); ",
// Ensures all users are in the main role. // Ensures all users are in the main role.
db_exec(' "
INSERT INTO `msz_user_roles` INSERT INTO `msz_user_roles`
(`user_id`, `role_id`) (`user_id`, `role_id`)
SELECT `user_id`, 1 FROM `msz_users` as u SELECT `user_id`, 1 FROM `msz_users` as u
@ -108,10 +109,10 @@ if (PHP_SAPI === 'cli') {
WHERE `role_id` = 1 WHERE `role_id` = 1
AND u.`user_id` = ur.`user_id` AND u.`user_id` = ur.`user_id`
) )
'); ",
// Ensures all display_role values are correct with `msz_user_roles` // Ensures all display_role values are correct with `msz_user_roles`
db_exec(' "
UPDATE `msz_users` as u UPDATE `msz_users` as u
SET `display_role` = ( SET `display_role` = (
SELECT ur.`role_id` SELECT ur.`role_id`
@ -128,47 +129,52 @@ if (PHP_SAPI === 'cli') {
WHERE ur.`role_id` = u.`display_role` WHERE ur.`role_id` = u.`display_role`
AND `ur`.`user_id` = u.`user_id` AND `ur`.`user_id` = u.`user_id`
) )
'); ",
// Deletes expired sessions // Deletes expired sessions
db_exec(' "
DELETE FROM `msz_sessions` DELETE FROM `msz_sessions`
WHERE `session_expires` < NOW() WHERE `session_expires` < NOW()
'); ",
// Remove old password reset records, left for a week for possible review // Remove old password reset records, left for a week for possible review
db_exec(' "
DELETE FROM `msz_users_password_resets` DELETE FROM `msz_users_password_resets`
WHERE `reset_requested` < NOW() - INTERVAL 1 WEEK WHERE `reset_requested` < NOW() - INTERVAL 1 WEEK
'); ",
// Cleans up the login history table // Cleans up the login history table
db_exec(' "
DELETE FROM `msz_login_attempts` DELETE FROM `msz_login_attempts`
WHERE `attempt_created` < NOW() - INTERVAL 1 YEAR WHERE `attempt_created` < NOW() - INTERVAL 1 YEAR
'); ",
// Cleans up the audit log table // Cleans up the audit log table
db_exec(' "
DELETE FROM `msz_audit_log` DELETE FROM `msz_audit_log`
WHERE `log_created` < NOW() - INTERVAL 1 YEAR WHERE `log_created` < NOW() - INTERVAL 1 YEAR
'); ",
// Delete ignored forum tracking entries // Delete ignored forum tracking entries
db_exec(' "
DELETE tt FROM `msz_forum_topics_track` as tt DELETE tt FROM `msz_forum_topics_track` as tt
LEFT JOIN `msz_forum_topics` as t LEFT JOIN `msz_forum_topics` as t
ON t.`topic_id` = tt.`topic_id` ON t.`topic_id` = tt.`topic_id`
WHERE t.`topic_bumped` < NOW() - INTERVAL 1 MONTH WHERE t.`topic_bumped` < NOW() - INTERVAL 1 MONTH
'); ",
// Synchronise forum_id // Synchronise forum_id
db_exec(' "
UPDATE `msz_forum_posts` AS p UPDATE `msz_forum_posts` AS p
INNER JOIN `msz_forum_topics` AS t INNER JOIN `msz_forum_topics` AS t
ON t.`topic_id` = p.`topic_id` ON t.`topic_id` = p.`topic_id`
SET p.`forum_id` = t.`forum_id` SET p.`forum_id` = t.`forum_id`
'); ",
];
foreach ($cronTasks as $cronTask) {
db_exec($cronTask);
}
break; break;
case 'migrate': case 'migrate':