protected function requestInit() { if ($this->isInitialized) { return; } eZExecution::setCleanExit(false); $scriptStartTime = microtime(true); $GLOBALS['eZRedirection'] = false; $this->access = eZSiteAccess::current(); eZDebug::setScriptStart($scriptStartTime); eZDebug::addTimingPoint("Script start"); $this->uri = eZURI::instance(eZSys::requestURI()); $GLOBALS['eZRequestedURI'] = $this->uri; // Be able to do general events early in process ezpEvent::getInstance()->notify('request/preinput', array($this->uri)); // Initialize module loading $this->siteBasics['module-repositories'] = eZModule::activeModuleRepositories(); eZModule::setGlobalPathList($this->siteBasics['module-repositories']); // make sure we get a new $ini instance now that it has been reset $ini = eZINI::instance(); // start: eZCheckValidity // pre check, setup wizard related so needs to be before session/db init // TODO: Move validity check in the constructor? Setup is not meant to be launched at each (sub)request is it? if ($ini->variable('SiteAccessSettings', 'CheckValidity') === 'true') { $this->check = array('module' => 'setup', 'function' => 'init'); // Turn off some features that won't bee needed yet $this->siteBasics['policy-check-omit-list'][] = 'setup'; $this->siteBasics['show-page-layout'] = $ini->variable('SetupSettings', 'PageLayout'); $this->siteBasics['validity-check-required'] = true; $this->siteBasics['session-required'] = $this->siteBasics['user-object-required'] = false; $this->siteBasics['db-required'] = $this->siteBasics['no-cache-adviced'] = $this->siteBasics['url-translator-allowed'] = false; $this->siteBasics['site-design-override'] = $ini->variable('SetupSettings', 'OverrideSiteDesign'); $this->access = eZSiteAccess::change(array('name' => 'setup', 'type' => eZSiteAccess::TYPE_URI)); eZTranslatorManager::enableDynamicTranslations(); } // stop: eZCheckValidity if ($this->siteBasics['session-required']) { // Check if this should be run in a cronjob if ($ini->variable('Session', 'BasketCleanup') !== 'cronjob') { eZSession::addCallback('destroy_pre', function (eZDBInterface $db, $key, $escapedKey) { $basket = eZBasket::fetch($key); if ($basket instanceof eZBasket) { $basket->remove(); } }); eZSession::addCallback('gc_pre', function (eZDBInterface $db, $time) { eZBasket::cleanupExpired($time); }); eZSession::addCallback('cleanup_pre', function (eZDBInterface $db) { eZBasket::cleanup(); }); } // addCallBack to update session id for shop basket on session regenerate eZSession::addCallback('regenerate_post', function (eZDBInterface $db, $escNewKey, $escOldKey) { $db->query("UPDATE ezbasket SET session_id='{$escNewKey}' WHERE session_id='{$escOldKey}'"); }); // TODO: Session starting should be made only once in the constructor $this->sessionInit(); } // if $this->siteBasics['db-required'], open a db connection and check that db is connected if ($this->siteBasics['db-required'] && !eZDB::instance()->isConnected()) { $this->warningList[] = array('error' => array('type' => 'kernel', 'number' => eZError::KERNEL_NO_DB_CONNECTION), 'text' => 'No database connection could be made, the system might not behave properly.'); } // eZCheckUser: pre check, RequireUserLogin & FORCE_LOGIN related so needs to be after session init if (!isset($this->check)) { $this->check = eZUserLoginHandler::preCheck($this->siteBasics, $this->uri); } ezpEvent::getInstance()->notify('request/input', array($this->uri)); // Initialize with locale settings // TODO: Move to constructor? Is it relevant to init the locale/charset for each (sub)requests? $this->languageCode = eZLocale::instance()->httpLocaleCode(); $phpLocale = trim($ini->variable('RegionalSettings', 'SystemLocale')); if ($phpLocale != '') { setlocale(LC_ALL, explode(',', $phpLocale)); } $this->httpCharset = eZTextCodec::httpCharset(); // TODO: are these parameters supposed to vary across potential sub-requests? $this->site = array('title' => $ini->variable('SiteSettings', 'SiteName'), 'design' => $ini->variable('DesignSettings', 'SiteDesign'), 'http_equiv' => array('Content-Type' => 'text/html; charset=' . $this->httpCharset, 'Content-language' => $this->languageCode)); // Read role settings $this->siteBasics['policy-check-omit-list'] = array_merge($this->siteBasics['policy-check-omit-list'], $ini->variable('RoleSettings', 'PolicyOmitList')); $this->isInitialized = true; }
<?php // // Definition of Session_GC Cronjob /** * File containing the session_gc.php cronjob * * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 * @version //autogentag// * @package kernel */ /** * Cronjob to garbage collect expired sessions as defined by site.ini[Session]SessionTimeout * (the expiry time is calculated when session is created / updated) * These are normally automatically removed by the session gc in php, but on some linux distroes * based on debian this does not work because the custom way session gc is handled. * * Also make sure you run basket_cleanup if you use the shop! * * @package eZCronjob * @see eZsession */ // Functions for session to make sure baskets are cleaned up function eZSessionBasketGarbageCollector($db, $time) { eZBasket::cleanupExpired($time); } // Fill in hooks eZSession::addCallback('gc_pre', 'eZSessionBasketGarbageCollector'); eZSession::garbageCollector();
} function eZSessionBasketEmpty($db) { eZBasket::cleanup(); } // Fill in hooks eZSession::addCallback('destroy_pre', 'eZSessionBasketDestroy'); eZSession::addCallback('gc_pre', 'eZSessionBasketGarbageCollector'); eZSession::addCallback('cleanup_pre', 'eZSessionBasketCleanup'); } // addCallBack to update session id for shop basket on session regenerate function eZSessionBasketRegenerate($db, $escNewKey, $escOldKey, $escUserID) { $db->query("UPDATE ezbasket SET session_id='{$escNewKey}' WHERE session_id='{$escOldKey}'"); } eZSession::addCallback('regenerate_post', 'eZSessionBasketRegenerate'); if ($ini->variable('Session', 'ForceStart') === 'enabled') { eZSession::start(); } else { eZSession::lazyStart(); } // let session specify if db is required $dbRequired = eZSession::getHandlerInstance()->dbRequired(); } // if $dbRequired, open a db connection and check that db is connected if ($dbRequired && !eZDB::instance()->isConnected()) { $warningList[] = array('error' => array('type' => 'kernel', 'number' => eZError::KERNEL_NO_DB_CONNECTION), 'text' => 'No database connection could be made, the system might not behave properly.'); } // eZCheckUser: pre check, RequireUserLogin & FORCE_LOGIN related so needs to be after session init if (!isset($check)) { $check = eZUserLoginHandler::preCheck($siteBasics, $uri);