This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/cron.php

47 lines
1.1 KiB
PHP
Raw Normal View History

<?php
/*
* Sakura Cron Agent
*/
// Declare Namespace
namespace Sakura;
// 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;
}
}
// 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);
// Include components
2015-12-29 21:52:19 +00:00
require_once 'sakura.php';
// Clean expired sessions
Database::delete('sessions', [
'session_expire' => [time(), '<'],
'session_remember' => ['1', '!='],
]);
// Delete notifications that are older than a month but not unread
Database::delete('notifications', [
'alert_timestamp' => [(time() - 109500), '<'],
'alert_read' => ['1', '='],
]);
// Get expired premium accounts
$expiredPremium = Database::fetch('premium', true, [
'premium_expire' => [time(), '<'],
]);
2015-12-29 21:52:19 +00:00
// Process expired premium accounts, make this not stupid in the future
foreach ($expiredPremium as $expired) {
Users::updatePremiumMeta($expired['user_id']);
}