replace cron.php with mahou commands
This commit is contained in:
parent
fda7c71a50
commit
bb21046e73
4 changed files with 85 additions and 40 deletions
46
app/Console/Command/PremiumPurgeCommand.php
Normal file
46
app/Console/Command/PremiumPurgeCommand.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
/**
|
||||
* Holds the purge premium command controller.
|
||||
* @package Sakura
|
||||
*/
|
||||
|
||||
namespace Sakura\Console\Command;
|
||||
|
||||
use CLIFramework\Command;
|
||||
use Sakura\DB;
|
||||
|
||||
/**
|
||||
* Starts up a development server.
|
||||
* @package Sakura
|
||||
* @author Julian van de Groep <me@flash.moe>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
38
app/Console/Command/SessionPurgeCommand.php
Normal file
38
app/Console/Command/SessionPurgeCommand.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* Holds the session purge command controller.
|
||||
* @package Sakura
|
||||
*/
|
||||
|
||||
namespace Sakura\Console\Command;
|
||||
|
||||
use CLIFramework\Command;
|
||||
use Sakura\DB;
|
||||
|
||||
/**
|
||||
* Starts up a development server.
|
||||
* @package Sakura
|
||||
* @author Julian van de Groep <me@flash.moe>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
39
cron.php
39
cron.php
|
@ -1,39 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* Sakura Cron Agent
|
||||
*/
|
||||
|
||||
// Declare Namespace
|
||||
namespace Sakura;
|
||||
|
||||
// Define that this page won't require templating
|
||||
define('SAKURA_NO_TPL', true);
|
||||
|
||||
// Include components
|
||||
require_once 'sakura.php';
|
||||
|
||||
// Clean expired sessions
|
||||
DB::table('sessions')
|
||||
->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();
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
namespace Sakura;
|
||||
|
||||
// Define version and root path
|
||||
define('SAKURA_VERSION', 20160804);
|
||||
define('SAKURA_VERSION', 20160913);
|
||||
define('ROOT', __DIR__ . '/');
|
||||
|
||||
// CLI mode
|
||||
|
|
Reference in a new issue