Ticket #354: jSession.2.patch

File jSession.2.patch, 9.9 kB (added by Julien, 1 year ago)

patch modifié, avec session_write_close(), sans hack de jDb

  • build/manifests/jelix-lib.mn

    old new  
    8282   jaclsubject.dao.xml 
    8383   jaclusergroup.dao.xml 
    8484   jaclgroupsofuser.dao.xml 
     85   jsession.dao.xml 
    8586cd lib/jelix/core-modules/jelix/install/sql 
    8687  delete.mysql.sql 
    8788  install_jacl.schema.mysql.sql 
    8889  install_jacl.datas.mysql.sql 
     90  install_jsession.schema.mysql.sql 
    8991cd lib/jelix/core-modules/jelix/locales/en_US 
    9092  acldb.ISO-8859-1.properties 
    9193  acldb.UTF-8.properties 
  • build/manifests/jelix-no-opt.mn

    old new  
    1111  jResponse.class.php 
    1212* jSelector.class.php 
    1313* jUrl.class.php 
     14  jSession.class.php 
    1415 
    1516cd lib/jelix/db 
    1617  jDbConnection.class.php 
  • lib/jelix-scripts/commands/createapp.cmd.php

    old new  
    7070       $this->createDir(JELIX_APP_VAR_PATH.'themes/'); 
    7171       $this->createDir(JELIX_APP_VAR_PATH.'themes/default/'); 
    7272       $this->createDir(JELIX_APP_VAR_PATH.'uploads/'); 
     73       $this->createDir(JELIX_APP_VAR_PATH.'sessions/'); 
    7374       $this->createDir(JELIX_APP_PATH.'modules'); 
    7475       $this->createDir(JELIX_APP_PATH.'plugins'); 
    7576       $this->createDir(JELIX_APP_PATH.'plugins/coord/'); 
  • lib/jelix-scripts/templates/var/config/defaultconfig.ini.php.tpl

    old new  
    135135 
    136136[acl] 
    137137driver = db 
     138 
     139 
     140[sessions] 
     141; Use alternative storage engines for sessions 
     142; 
     143; usage : 
     144; 
     145; storage = "files" 
     146; files_path = "app:var/sessions/" 
     147; 
     148; or 
     149; 
     150; storage = "dao" 
     151; dao_selector = "jelix~jsession" 
     152; dao_db_profile = "" 
  • lib/jelix/core/jSession.class.php

    old new  
     1<?php 
     2/** 
     3* @package    jelix 
     4* @subpackage core 
     5* @author     Julien Issler 
     6* @contributor 
     7* @copyright  2007 Julien Issler 
     8* @link       http://www.jelix.org 
     9* @licence    GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 
     10*/ 
     11 
     12/** 
     13 * session management class of the jelix core 
     14 * 
     15 * @package  jelix 
     16 * @subpackage core 
     17 */ 
     18class jSession { 
     19 
     20    protected static $_params; 
     21 
     22    public static function start(){ 
     23        $params = $GLOBALS['gJConfig']->sessions; 
     24 
     25        if(!isset($params['storage'])){ 
     26            session_start(); 
     27            return true; 
     28        } 
     29 
     30        switch($params['storage']){ 
     31 
     32            case 'dao': 
     33                session_set_save_handler( 
     34                    array(__CLASS__,'daoOpen'), 
     35                    array(__CLASS__,'daoClose'), 
     36                    array(__CLASS__,'daoRead'), 
     37                    array(__CLASS__,'daoWrite'), 
     38                    array(__CLASS__,'daoDestroy'), 
     39                    array(__CLASS__,'daoGarbageCollector') 
     40                ); 
     41                self::$_params = $params; 
     42                break; 
     43 
     44            case 'files': 
     45                $path = str_replace(array('lib:','app:'), array(LIB_PATH, JELIX_APP_PATH), $params['files_path']); 
     46                session_save_path($path); 
     47                break; 
     48 
     49            default: 
     50                break; 
     51        } 
     52 
     53        session_start(); 
     54        return true; 
     55    } 
     56 
     57 
     58    public static function end(){ 
     59        session_write_close(); 
     60        return true; 
     61    } 
     62 
     63 
     64    protected static function _getDao(){ 
     65        if(isset(self::$_params['dao_db_profile']) && self::$_params['dao_db_profile']){ 
     66            $dao = jDao::get(self::$_params['dao_selector'], self::$_params['dao_db_profile']); 
     67        } 
     68        else{ 
     69            $dao = jDao::get(self::$_params['dao_selector']); 
     70        } 
     71        return $dao; 
     72    } 
     73 
     74 
     75    public static function daoOpen ($save_path, $session_name) { 
     76        return true; 
     77    } 
     78 
     79 
     80    public static function daoClose() { 
     81        return true; 
     82    } 
     83 
     84 
     85    public static function daoRead ($id) { 
     86        $session = self::_getDao()->get($id); 
     87 
     88        if(!$session){ 
     89            return ''; 
     90        } 
     91 
     92        return $session->data; 
     93    } 
     94 
     95 
     96    public static function daoWrite ($id, $data) { 
     97        $dao = self::_getDao(); 
     98 
     99        $session = $dao->get($id); 
     100        if(!$session){ 
     101            $session = jDao::createRecord(self::$_params['dao_selector']); 
     102            $session->id = $id; 
     103            $session->data = $data; 
     104            $dao->insert($session); 
     105        } 
     106        else{ 
     107            $session->data = $data; 
     108            $dao->update($session); 
     109        } 
     110 
     111        return true; 
     112    } 
     113 
     114 
     115    public static function daoDestroy ($id) { 
     116        if (isset($_COOKIE[session_name()])) { 
     117           setcookie(session_name(), '', time()-42000, '/'); 
     118        } 
     119 
     120        $dao = self::_getDao()->delete($id); 
     121        return true; 
     122    } 
     123 
     124 
     125    public static function daoGarbageCollector ($maxlifetime) { 
     126        $date = new jDateTime(); 
     127        $date->now(); 
     128        $date->sub(0,0,0,0,0,$maxlifetime); 
     129        self::_getDao()->deleteExpired($date->toString(jDateTime::BD_DTFORMAT)); 
     130        return true; 
     131    } 
     132 
     133} 
     134?> 
  • lib/jelix/core/jCoordinator.class.php

    old new  
    8686        $gJConfig = jConfig::load($configFile); 
    8787 
    8888        //make sure that the session cookie is only for the current application 
    89         if(!$gJConfig->shared_session
     89        if(!$gJConfig->sessions['shared_session']
    9090            session_set_cookie_params ( 0 , $gJConfig->urlengine['basePath']); 
    9191 
    9292        // set Error and exception handler 
     
    167167 
    168168        $this->request = $request; 
    169169        $this->request->init(); 
    170         session_start(); 
     170        jSession::start(); 
    171171 
    172172        $this->moduleName = $this->request->getParam('module'); 
    173173        $this->actionName = $this->request->getParam('action'); 
     
    242242        } 
    243243 
    244244        jContext::pop(); 
     245        jSession::end(); 
    245246    } 
    246247 
    247248    /** 
  • lib/jelix/core/defaultconfig.ini.php

    old new  
    1919 
    2020theme = default 
    2121use_error_handler = on 
    22 shared_session = off 
    2322 
     23 
    2424[plugins] 
    2525 
    2626[responses] 
     
    181181 
    182182[acl] 
    183183driver = db 
     184 
     185 
     186[sessions] 
     187shared_session = off 
  • lib/jelix/init.php

    old new  
    1818* @copyright 2007 Julien Issler 
    1919* @link http://www.copix.org 
    2020#else 
    21 * @contributor Loic Mathaud 
     21* @contributor Loic Mathaud, Julien Issler 
    2222* @copyright 2005-2007 Jouanneau laurent 
     23* @copyright 2007 Julien Issler 
    2324#endif 
    2425* @link     http://www.jelix.org 
    2526* @licence  GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 
     
    9091#includephp core/jResponse.class.php 
    9192#includephp core/jLocale.class.php 
    9293#includephp core/jIncluder.class.php 
     94#includephp core/jSession.class.php 
    9395#ifnot ENABLE_PHP_JELIX 
    9496#includephp core/jICoordPlugin.iface.php 
    9597#endif 
     
    108110require (JELIX_LIB_CORE_PATH . 'jResponse.class.php'); 
    109111require (JELIX_LIB_CORE_PATH . 'jLocale.class.php'); 
    110112require (JELIX_LIB_CORE_PATH . 'jIncluder.class.php'); 
     113require (JELIX_LIB_CORE_PATH . 'jSession.class.php'); 
    111114#ifnot ENABLE_PHP_JELIX 
    112115require (JELIX_LIB_CORE_PATH . 'jICoordPlugin.iface.php'); 
    113116#endif 
  • lib/jelix/core-modules/jelix/daos/jsession.dao.xml

    old new  
     1<?xml version="1.0" encoding="UTF-8"?> 
     2<dao xmlns="http://jelix.org/ns/dao/1.0"> 
     3    <datasources> 
     4        <primarytable name="jsessions" realname="jsessions" primarykey="id" /> 
     5    </datasources> 
     6     
     7    <record> 
     8        <property name="id" fieldname="id" datatype="string"/> 
     9        <property name="creation" fieldname="creation" datatype="date" insertpattern="NOW()" updatepattern="" required="true"/> 
     10        <property name="access" fieldname="access" datatype="date" insertpattern="NOW()" updatepattern="NOW()" required="true"/> 
     11        <property name="data" fieldname="data" datatype="string" required="true"/> 
     12    </record> 
     13 
     14    <factory> 
     15        <method name="deleteExpired" type="delete"> 
     16            <parameter name="date" /> 
     17            <conditions> 
     18                <lt property="access" expr="$date" /> 
     19            </conditions> 
     20        </method> 
     21    </factory> 
     22</dao> 
  • lib/jelix/core-modules/jelix/install/sql/install_jsession.schema.mysql.sql

    old new  
     1DROP TABLE IF EXISTS `jsessions`; 
     2CREATE TABLE `jsessions` ( 
     3  `id` varchar(64) NOT NULL, 
     4  `creation` datetime NOT NULL, 
     5  `access` datetime NOT NULL, 
     6  `data` text NOT NULL, 
     7  PRIMARY KEY  (`id`) 
     8) DEFAULT CHARSET=utf8; 
Download in other formats: Original Format