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:
Sean Harvey 2008-07-02 00:39:40 +00:00
parent fce12220b2
commit 9da9a611a0

View File

@ -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($controllers) foreach($controllers as $controllerClass) {
$controller = new $controllerClass();
$sessions = $controller->getExpiredSessions();
$sessionDeleteCount = 0;
if($sessions) foreach($sessions as $session) { if($sessions) foreach($sessions as $session) {
$session->purgeStoredData(); $session->delete();
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;
} }
} }