From: Tim Düsterhus Date: Fri, 15 Mar 2019 13:12:50 +0000 (+0100) Subject: Add SessionHandler::deleteIfNew() X-Git-Tag: 5.2.0_Alpha_1~176^2~8^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=69596588355f92ee1eff0b50c4a4ebab0bc4cfe7;p=GitHub%2FWoltLab%2FWCF.git Add SessionHandler::deleteIfNew() see #2851 --- diff --git a/wcfsetup/install/files/lib/action/BackgroundQueuePerformAction.class.php b/wcfsetup/install/files/lib/action/BackgroundQueuePerformAction.class.php index f5f05c9db9..b711c5a2d1 100644 --- a/wcfsetup/install/files/lib/action/BackgroundQueuePerformAction.class.php +++ b/wcfsetup/install/files/lib/action/BackgroundQueuePerformAction.class.php @@ -33,9 +33,7 @@ class BackgroundQueuePerformAction extends AbstractAction { } } echo BackgroundQueueHandler::getInstance()->getRunnableCount(); - if (WCF::getSession()->isFirstVisit() && !WCF::getUser()->userID) { - WCF::getSession()->delete(); - } + WCF::getSession()->deleteIfNew(); exit; } } diff --git a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php index 2f3dd2c8c4..f70c52f17d 100644 --- a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php +++ b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php @@ -989,6 +989,25 @@ class SessionHandler extends SingletonFactory { $this->disableUpdate(); } + /** + * Deletes this session if: + * - it is newly created in this request, and + * - it belongs to a guest. + * + * This method is useful if you have controllers that are likely to be + * accessed by a user agent that is not going to re-use sessions (e.g. + * curl in a cronjob). It immediately remove the session that was created + * just for that request and that is not going to be used ever again. + * + * @since 5.2 + */ + public function deleteIfNew() { + if (!$this->isFirstVisit()) return; + if ($this->getUser()->userID) return; + + $this->delete(); + } + /** * Returns currently active language id. *