mirror of
https://github.com/silverstripe/silverstripe-multiform
synced 2024-10-22 11:05:49 +02:00
BUGFIX Made MultiFormPurgeTask greatly simplified, and workable - it simply deletes all session data after days specified in $session_expiry_days
This commit is contained in:
parent
fce12220b2
commit
9da9a611a0
@ -13,44 +13,38 @@
|
|||||||
class MultiFormPurgeTask extends DailyTask {
|
class MultiFormPurgeTask extends DailyTask {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Days after which unfinished sessions
|
* Days after which sessions expire and
|
||||||
* expire and are automatically deleted
|
* are automatically deleted.
|
||||||
* by a cronjob/ScheduledTask.
|
|
||||||
*
|
*
|
||||||
* @usedby {@link MultiFormPurgeTask}
|
* @usedby {@link MultiFormPurgeTask}
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
public static $session_expiry_days = 7;
|
public static $session_expiry_days = 7;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run this cron task.
|
||||||
|
*
|
||||||
|
* Go through all MultiFormSession records that
|
||||||
|
* are older than the days specified in $session_expiry_days
|
||||||
|
* and delete them.
|
||||||
|
*/
|
||||||
public function run() {
|
public function run() {
|
||||||
$controllers = ClassInfo::subclassesFor('MultiForm');
|
$sessions = $this->getExpiredSessions();
|
||||||
|
if($sessions) foreach($sessions as $session) {
|
||||||
if($controllers) foreach($controllers as $controllerClass) {
|
$session->delete();
|
||||||
$controller = new $controllerClass();
|
|
||||||
$sessions = $controller->getExpiredSessions();
|
|
||||||
$sessionDeleteCount = 0;
|
|
||||||
if($sessions) foreach($sessions as $session) {
|
|
||||||
$session->purgeStoredData();
|
|
||||||
if($session->delete()) $sessionDeleteCount++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all MultiFormSession database records that are older than
|
||||||
|
* the days specified in $session_expiry_days
|
||||||
|
*
|
||||||
|
* @return DataObjectSet
|
||||||
|
*/
|
||||||
protected function getExpiredSessions() {
|
protected function getExpiredSessions() {
|
||||||
$sessions = new DataObjectSet();
|
return DataObject::get(
|
||||||
|
'MultiFormSession',
|
||||||
$implementors = Object::implementors_for_extension('MultiFormObjectDecorator');
|
"DATEDIFF(NOW(), `MultiFormSession`.`Created`) > " . self::$session_expiry_days);
|
||||||
if($implementors) foreach($implementors as $implementorClass) {
|
|
||||||
$sessions->merge(
|
|
||||||
DataObject::get(
|
|
||||||
$implementorClass,
|
|
||||||
"`{$implementorClass}`.`MultiFormIsTemporary` = 1
|
|
||||||
AND DATEDIFF(NOW(), `{$implementorClass}`.`Created`) > " . self::$session_expiry_days
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $sessions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user