From bb21046e73592bd778595b99d475bcfd5ba4036c Mon Sep 17 00:00:00 2001 From: flashwave Date: Tue, 13 Sep 2016 15:39:11 +0200 Subject: [PATCH] replace cron.php with mahou commands --- app/Console/Command/PremiumPurgeCommand.php | 46 +++++++++++++++++++++ app/Console/Command/SessionPurgeCommand.php | 38 +++++++++++++++++ cron.php | 39 ----------------- sakura.php | 2 +- 4 files changed, 85 insertions(+), 40 deletions(-) create mode 100644 app/Console/Command/PremiumPurgeCommand.php create mode 100644 app/Console/Command/SessionPurgeCommand.php delete mode 100644 cron.php diff --git a/app/Console/Command/PremiumPurgeCommand.php b/app/Console/Command/PremiumPurgeCommand.php new file mode 100644 index 0000000..d3aac91 --- /dev/null +++ b/app/Console/Command/PremiumPurgeCommand.php @@ -0,0 +1,46 @@ + + */ +class PremiumPurgeCommand extends Command +{ + /** + * A quick description of this command. + * @return string. + */ + public function brief() + { + return 'Purge expired premium.'; + } + + /** + * Purge expired premium subs. + */ + public function execute() + { + $expiredPremium = DB::table('premium') + ->where('premium_expire', '<', time()) + ->get(['user_id']); + + foreach ($expiredPremium as $premium) { + DB::table('premium') + ->where('user_id', $premium->user_id) + ->delete(); + + User::construct($premium->user_id) + ->isPremium(); + } + } +} diff --git a/app/Console/Command/SessionPurgeCommand.php b/app/Console/Command/SessionPurgeCommand.php new file mode 100644 index 0000000..5c99358 --- /dev/null +++ b/app/Console/Command/SessionPurgeCommand.php @@ -0,0 +1,38 @@ + + */ +class SessionPurgeCommand extends Command +{ + /** + * A quick description of this command. + * @return string. + */ + public function brief() + { + return 'Purge expired sessions.'; + } + + /** + * Purges sessions. + */ + public function execute() + { + DB::table('sessions') + ->where('session_expire', '<', time()) + ->where('session_remember', '!=', 1) + ->delete(); + } +} diff --git a/cron.php b/cron.php deleted file mode 100644 index 494b3dd..0000000 --- a/cron.php +++ /dev/null @@ -1,39 +0,0 @@ -where('session_expire', '<', time()) - ->where('session_remember', '!=', 1) - ->delete(); - -// Delete notifications that are older than a month but not unread -DB::table('notifications') - ->where('alert_timestamp', '<', (time() - 109500)) - ->where('alert_read', 1) - ->delete(); - -// Get expired premium accounts -$expiredPremium = DB::table('premium') - ->where('premium_expire', '<', time()) - ->get(['user_id']); - -foreach ($expiredPremium as $premium) { - DB::table('premium') - ->where('user_id', $premium->user_id) - ->delete(); - - User::construct($premium->user_id) - ->isPremium(); -} diff --git a/sakura.php b/sakura.php index 0c18821..4314a41 100644 --- a/sakura.php +++ b/sakura.php @@ -7,7 +7,7 @@ namespace Sakura; // Define version and root path -define('SAKURA_VERSION', 20160804); +define('SAKURA_VERSION', 20160913); define('ROOT', __DIR__ . '/'); // CLI mode