2015-09-12 19:57:44 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Sakura Cron Agent
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Declare Namespace
|
|
|
|
namespace Sakura;
|
|
|
|
|
2015-09-14 20:51:23 +00:00
|
|
|
// Check if the script isn't executed by root
|
|
|
|
if (function_exists('posix_getuid')) {
|
|
|
|
if (posix_getuid() === 0) {
|
|
|
|
trigger_error('Running cron as root is disallowed for security reasons.', E_USER_ERROR);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-12 19:57:44 +00:00
|
|
|
// Define that this page won't require templating
|
|
|
|
define('SAKURA_NO_TPL', true);
|
|
|
|
|
2016-01-26 18:09:18 +00:00
|
|
|
// To prevent the CLI from showing up
|
|
|
|
define('SAKURA_CRON', true);
|
|
|
|
|
2015-09-12 19:57:44 +00:00
|
|
|
// Include components
|
2015-12-29 21:52:19 +00:00
|
|
|
require_once 'sakura.php';
|
2015-09-12 19:57:44 +00:00
|
|
|
|
2015-09-14 20:51:23 +00:00
|
|
|
// Clean expired sessions
|
2016-02-18 23:28:44 +00:00
|
|
|
$cleanSessions = DB::prepare('DELETE FROM `{prefix}sessions` WHERE `session_expire` < :time AND `session_remember` != 1');
|
|
|
|
$cleanSessions->execute([
|
|
|
|
'time' => time(),
|
2015-09-14 20:51:23 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Delete notifications that are older than a month but not unread
|
2016-02-18 23:28:44 +00:00
|
|
|
$cleanAlerts = DB::prepare('DELETE FROM `{prefix}notifications` WHERE `alert_timestamp` < :time AND `alert_read` = 1');
|
|
|
|
$cleanAlerts->execute([
|
|
|
|
'time' => (time() - 109500),
|
2015-09-14 20:51:23 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Get expired premium accounts
|
2016-02-18 23:28:44 +00:00
|
|
|
$expiredPremium = DB::prepare('SELECT * FROM `{prefix}premium` WHERE `premium_expire` < :time');
|
|
|
|
$expiredPremium->execute([
|
|
|
|
'time' => time(),
|
2015-09-14 20:51:23 +00:00
|
|
|
]);
|
2016-02-18 23:28:44 +00:00
|
|
|
$expiredPremium = $expiredPremium->fetchAll();
|
2015-09-14 20:51:23 +00:00
|
|
|
|
2015-12-29 21:52:19 +00:00
|
|
|
// Process expired premium accounts, make this not stupid in the future
|
2015-09-14 20:51:23 +00:00
|
|
|
foreach ($expiredPremium as $expired) {
|
2016-02-18 23:28:44 +00:00
|
|
|
Users::updatePremiumMeta($expired->user_id);
|
2015-09-14 20:51:23 +00:00
|
|
|
}
|