</cronjob>
<cronjob>
- <classname>wcf\system\cronjob\CleanUpCronjobLogCronjob</classname>
- <description>Deletes old entries from cronjob log</description>
+ <classname>wcf\system\cronjob\DailyCleanUpCronjob</classname>
+ <description>Daily Cleanup</description>
<startminute>0</startminute>
- <starthour>12</starthour>
+ <starthour>1</starthour>
<startdom>*</startdom>
<startmonth>*</startmonth>
<startdow>*</startdow>
</cronjob>
<cronjob>
- <classname>wcf\system\cronjob\CleanUpSessionLogCronjob</classname>
- <description>Deletes old entries from session log</description>
+ <classname>wcf\system\cronjob\HourlyCleanUpCronjob</classname>
+ <description>Hourly Cleanup</description>
<startminute>0</startminute>
- <starthour>10</starthour>
+ <starthour>*</starthour>
<startdom>*</startdom>
<startmonth>*</startmonth>
<startdow>*</startdow>
<active>1</active>
- <canbeedited>0</canbeedited>
- <canbedisabled>0</canbedisabled>
+ <canbeedited>1</canbeedited>
+ <canbedisabled>1</canbedisabled>
</cronjob>
<cronjob>
- <classname>wcf\system\cronjob\CleanupListenerCronjob</classname>
- <description>Executes the cleanup system</description>
- <startminute>5,20,35,50</startminute>
+ <classname>wcf\system\cronjob\SessionCleanUpCronjob</classname>
+ <description>Deletes expired sessions</description>
+ <startminute>*/30</startminute>
<starthour>*</starthour>
<startdom>*</startdom>
<startmonth>*</startmonth>
<startdow>*</startdow>
<active>1</active>
- <canbeedited>0</canbeedited>
- <canbedisabled>0</canbedisabled>
+ <canbeedited>1</canbeedited>
+ <canbedisabled>1</canbedisabled>
</cronjob>
</import>
</data>
\ No newline at end of file
<?php
namespace wcf\data\acp\session;
use wcf\data\DatabaseObjectEditor;
+use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\WCF;
/**
return parent::update($parameters);
}
+
+ /**
+ * Deletes active sessions of the given users.
+ *
+ * @param array<integer> $userIDs
+ */
+ public static function deleteUserSessions(array $userIDs = array()) {
+ $conditionBuilder = new PreparedStatementConditionBuilder();
+ if (count($userIDs)) $conditionBuilder->add('userID IN (?)', array($userIDs));
+
+ $sql = "DELETE FROM ".call_user_func(array(static::$baseClass, 'getDatabaseTableName'))."
+ ".$conditionBuilder;
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute($conditionBuilder->getParameters());
+ }
+
+ /**
+ * Deletes the expired sessions.
+ *
+ * @param integer $timestamp
+ */
+ public static function deleteExpiredSessions($timestamp) {
+ $sql = "DELETE FROM ".call_user_func(array(static::$baseClass, 'getDatabaseTableName'))."
+ WHERE lastActivityTime < ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute(array($timestamp));
+ }
}
--- /dev/null
+<?php
+namespace wcf\system\cronjob;
+use wcf\data\cronjob\Cronjob;
+use wcf\system\event\EventHandler;
+
+/**
+ * Provides a default implementation for cronjobs.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2012 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package com.woltlab.wcf
+ * @subpackage system.cronjob
+ * @category Community Framework
+ */
+abstract class AbstractCronjob implements ICronjob {
+ /**
+ * @see wcf\system\cronjob\ICronjob::execute()
+ */
+ public function execute(Cronjob $cronjob) {
+ EventHandler::getInstance()->fireAction($this, 'execute');
+ }
+}
+++ /dev/null
-<?php
-namespace wcf\system\cronjob;
-use wcf\data\cronjob\Cronjob;
-use wcf\system\WCF;
-
-/**
- * Deletes old entries from cronjob log.
- *
- * @author Marcel Werk
- * @copyright 2001-2011 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package com.woltlab.wcf
- * @subpackage system.cronjob
- * @category Community Framework
- */
-class CleanUpCronjobLogCronjob implements ICronjob {
- /**
- * @see wcf\system\ICronjob::execute()
- */
- public function execute(Cronjob $cronjob) {
- $sql = "DELETE FROM wcf".WCF_N."_cronjob_log
- WHERE execTime < ?";
- $statement = WCF::getDB()->prepareStatement($sql);
- $statement->execute(array(
- (TIME_NOW - (86400 * 7))
- ));
- }
-}
+++ /dev/null
-<?php
-namespace wcf\system\cronjob;
-use wcf\data\cronjob\Cronjob;
-use wcf\system\WCF;
-
-/**
- * Deletes old entries from session log.
- *
- * @author Marcel Werk
- * @copyright 2001-2011 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package com.woltlab.wcf
- * @subpackage system.cronjob
- * @category Community Framework
- */
-class CleanUpSessionLogCronjob implements ICronjob {
- /**
- * @see wcf\system\ICronjob::execute()
- */
- public function execute(Cronjob $cronjob) {
- // delete access log
- $sql = "DELETE FROM wcf".WCF_N."_acp_session_access_log
- WHERE sessionLogID IN (
- SELECT sessionLogID
- FROM wcf".WCF_N."_acp_session_log
- WHERE lastActivityTime < ?
- )";
- $statement = WCF::getDB()->prepareStatement($sql);
- $statement->execute(array(
- (TIME_NOW - (86400 * 30))
- ));
-
- // delete session log
- $sql = "DELETE FROM wcf".WCF_N."_acp_session_log
- WHERE lastActivityTime < ?";
- $statement = WCF::getDB()->prepareStatement($sql);
- $statement->execute(array(
- (TIME_NOW - (86400 * 30))
- ));
- }
-}
--- /dev/null
+<?php
+namespace wcf\system\cronjob;
+use wcf\data\cronjob\Cronjob;
+use wcf\system\WCF;
+
+/**
+ * Cronjob for a daily system cleanup.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2012 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package com.woltlab.wcf
+ * @subpackage system.cronjob
+ * @category Community Framework
+ */
+class DailyCleanUpCronjob extends AbstractCronjob {
+ /**
+ * @see wcf\system\cronjob\ICronjob::execute()
+ */
+ public function execute(Cronjob $cronjob) {
+ parent::execute($cronjob);
+
+ // clean up cronjob log
+ $sql = "DELETE FROM wcf".WCF_N."_cronjob_log
+ WHERE execTime < ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute(array(
+ (TIME_NOW - (86400 * 7))
+ ));
+
+ // clean up session access log
+ $sql = "DELETE FROM wcf".WCF_N."_acp_session_access_log
+ WHERE sessionLogID IN (
+ SELECT sessionLogID
+ FROM wcf".WCF_N."_acp_session_log
+ WHERE lastActivityTime < ?
+ )";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute(array(
+ (TIME_NOW - (86400 * 30))
+ ));
+
+ // clean up session log
+ $sql = "DELETE FROM wcf".WCF_N."_acp_session_log
+ WHERE lastActivityTime < ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute(array(
+ (TIME_NOW - (86400 * 30))
+ ));
+ }
+}
--- /dev/null
+<?php
+namespace wcf\system\cronjob;
+use wcf\data\cronjob\Cronjob;
+use wcf\system\WCF;
+
+/**
+ * Cronjob for a hourly system cleanup.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2012 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package com.woltlab.wcf
+ * @subpackage system.cronjob
+ * @category Community Framework
+ */
+class HourlyCleanUpCronjob extends AbstractCronjob {
+ /**
+ * @see wcf\system\cronjob\ICronjob::execute()
+ */
+ public function execute(Cronjob $cronjob) {
+ parent::execute($cronjob);
+
+ // TODO
+ }
+}
--- /dev/null
+<?php
+namespace wcf\system\cronjob;
+use wcf\data\acp\session\ACPSessionEditor;
+use wcf\data\cronjob\Cronjob;
+use wcf\data\session\SessionEditor;
+use wcf\system\WCF;
+
+/**
+ * Deletes expired sesions.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2012 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package com.woltlab.wcf
+ * @subpackage system.cronjob
+ * @category Community Framework
+ */
+class SessionCleanUpCronjob extends AbstractCronjob {
+ /**
+ * @see wcf\system\cronjob\ICronjob::execute()
+ */
+ public function execute(Cronjob $cronjob) {
+ parent::execute($cronjob);
+
+ ACPSessionEditor::deleteExpiredSessions(TIME_NOW - SESSION_TIMEOUT);
+ SessionEditor::deleteExpiredSessions(TIME_NOW - SESSION_TIMEOUT);
+ }
+}
// call shouldInit event
if (!defined('NO_IMPORTS')) {
- EventHandler::getInstance()->fireAction($this, 'shouldInit');
+ EventHandler::getInstance()->fireAction($this, 'beforeInit');
}
$this->init();
// call didInit event
if (!defined('NO_IMPORTS')) {
- EventHandler::getInstance()->fireAction($this, 'didInit');
+ EventHandler::getInstance()->fireAction($this, 'afterInit');
}
}
$this->user = new User(null);
}
+ if ($this->user->userID != 0) {
+ // user is no guest
+ // delete all other sessions of this user
+ call_user_func(array($this->sessionEditorClassName, 'deleteUserSessions', array($this->user->userID)));
+ }
+
// save session
$this->session = call_user_func(array($this->sessionEditorClassName, 'create'), array(
'sessionID' => $sessionID,
'packageID' => PACKAGE_ID,
'userID' => $this->user->userID,
+ 'username' => $this->user->username,
'ipAddress' => UserUtil::getIpAddress(),
'userAgent' => UserUtil::getUserAgent(),
'lastActivityTime' => TIME_NOW,
$sessionTable = call_user_func(array($this->sessionClassName, 'getDatabaseTableName'));
if ($user->userID) {
- // user is not a gest, delete all other sessions of this user
+ // user is not a guest, delete all other sessions of this user
$sql = "SELECT sessionID
FROM ".$sessionTable."
WHERE sessionID <> ?