2010-03-22 11:49:04 +01:00
|
|
|
<?php
|
2008-04-18 00:03:51 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Task to clean out all {@link MultiFormSession} objects from the database.
|
2015-11-02 01:38:50 +01:00
|
|
|
*
|
2008-04-18 00:03:51 +02:00
|
|
|
* Setup Instructions:
|
|
|
|
* You need to create an automated task for your system (cronjobs on unix)
|
2013-10-15 05:12:45 +02:00
|
|
|
* which triggers the process() method through cli-script.php:
|
|
|
|
* `php framework/cli-script.php MultiFormPurgeTask`
|
|
|
|
* or
|
|
|
|
* `framework/sake MultiFormPurgeTask`
|
2015-11-02 01:38:50 +01:00
|
|
|
*
|
2008-04-18 00:03:51 +02:00
|
|
|
* @package multiform
|
|
|
|
*/
|
2014-10-23 16:44:12 +02:00
|
|
|
class MultiFormPurgeTask extends BuildTask {
|
2015-11-02 01:38:50 +01:00
|
|
|
|
2008-04-18 00:03:51 +02:00
|
|
|
/**
|
2008-07-02 02:39:40 +02:00
|
|
|
* Days after which sessions expire and
|
|
|
|
* are automatically deleted.
|
2015-11-02 01:38:50 +01:00
|
|
|
*
|
2008-04-18 00:03:51 +02:00
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
public static $session_expiry_days = 7;
|
2008-07-02 02:39:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Run this cron task.
|
2015-11-02 01:38:50 +01:00
|
|
|
*
|
2008-07-02 02:39:40 +02:00
|
|
|
* Go through all MultiFormSession records that
|
|
|
|
* are older than the days specified in $session_expiry_days
|
|
|
|
* and delete them.
|
|
|
|
*/
|
2014-10-23 16:44:12 +02:00
|
|
|
public function run($request) {
|
2008-07-02 02:39:40 +02:00
|
|
|
$sessions = $this->getExpiredSessions();
|
2008-07-02 02:54:22 +02:00
|
|
|
$delCount = 0;
|
2008-07-02 02:39:40 +02:00
|
|
|
if($sessions) foreach($sessions as $session) {
|
2013-10-15 05:12:45 +02:00
|
|
|
$session->delete();
|
|
|
|
$delCount++;
|
2008-04-18 00:03:51 +02:00
|
|
|
}
|
2008-07-02 02:54:22 +02:00
|
|
|
echo $delCount . ' session records deleted that were older than ' . self::$session_expiry_days . ' days.';
|
2008-04-18 00:03:51 +02:00
|
|
|
}
|
2008-07-02 02:39:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return all MultiFormSession database records that are older than
|
|
|
|
* the days specified in $session_expiry_days
|
|
|
|
*
|
|
|
|
* @return DataObjectSet
|
|
|
|
*/
|
2008-04-18 00:03:51 +02:00
|
|
|
protected function getExpiredSessions() {
|
2008-07-02 02:39:40 +02:00
|
|
|
return DataObject::get(
|
|
|
|
'MultiFormSession',
|
2010-03-22 11:49:04 +01:00
|
|
|
"DATEDIFF(NOW(), \"MultiFormSession\".\"Created\") > " . self::$session_expiry_days
|
2008-09-20 11:31:44 +02:00
|
|
|
);
|
2008-04-18 00:03:51 +02:00
|
|
|
}
|
2015-11-02 01:38:50 +01:00
|
|
|
|
2010-03-22 11:49:04 +01:00
|
|
|
}
|