From 9da9a611a0b5e40886ef417fb6336e66e5ce3363 Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Wed, 2 Jul 2008 00:39:40 +0000 Subject: [PATCH] BUGFIX Made MultiFormPurgeTask greatly simplified, and workable - it simply deletes all session data after days specified in $session_expiry_days --- code/MultiFormPurgeTask.php | 52 ++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/code/MultiFormPurgeTask.php b/code/MultiFormPurgeTask.php index b78d53e..c406c97 100644 --- a/code/MultiFormPurgeTask.php +++ b/code/MultiFormPurgeTask.php @@ -13,44 +13,38 @@ class MultiFormPurgeTask extends DailyTask { /** - * Days after which unfinished sessions - * expire and are automatically deleted - * by a cronjob/ScheduledTask. + * Days after which sessions expire and + * are automatically deleted. * * @usedby {@link MultiFormPurgeTask} * @var int */ 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() { - $controllers = ClassInfo::subclassesFor('MultiForm'); - - if($controllers) foreach($controllers as $controllerClass) { - $controller = new $controllerClass(); - $sessions = $controller->getExpiredSessions(); - $sessionDeleteCount = 0; - if($sessions) foreach($sessions as $session) { - $session->purgeStoredData(); - if($session->delete()) $sessionDeleteCount++; - } + $sessions = $this->getExpiredSessions(); + if($sessions) foreach($sessions as $session) { + $session->delete(); } } - + + /** + * Return all MultiFormSession database records that are older than + * the days specified in $session_expiry_days + * + * @return DataObjectSet + */ protected function getExpiredSessions() { - $sessions = new DataObjectSet(); - - $implementors = Object::implementors_for_extension('MultiFormObjectDecorator'); - 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; + return DataObject::get( + 'MultiFormSession', + "DATEDIFF(NOW(), `MultiFormSession`.`Created`) > " . self::$session_expiry_days); } }