Ticket #354: jSession.patch

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

Patch corrigé : le profil jDb n'était pas pris en compte lors de l'enregistrement des donées de session

  • build/manifests/jelix-lib.mn

    old new  
    260260cd lib/jelix-modules/jauth/zones 
    261261! loginform.zone.php 
    262262 
     263cd lib/jelix-modules/jsession/daos 
     264  session.dao.xml 
    263265 
     266 
    264267cd lib/jelix-plugins 
    265268  LICENCE 
    266269  INSTALL 
  • 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 = "jsession~session" 
     152; dao_db_profile = "" 
  • lib/jelix-modules/jsession/daos/session.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="sessions" realname="sessions" 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()" required="true"/> 
     10        <property name="access" fieldname="access" datatype="date" updatepattern="NOW()" insertpattern="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/db/jDbConnection.class.php

    old new  
    6868    function __destruct(){ 
    6969        if($this->_connection !== null){ 
    7070           $this->_disconnect (); 
     71           $this->_connection = null; 
    7172        } 
    7273    } 
    7374 
     
    233234    */ 
    234235    abstract protected function _connect (); 
    235236 
     237 
    236238    /** 
     239     * Do a reconnection if connection is down 
     240     * 
     241     * @author Julien Issler 
     242     */ 
     243    public function reconnect(){ 
     244        if(!$this->_connection){ 
     245            $this->_connection = $this->_connect(); 
     246        } 
     247    } 
     248     
     249     
     250    /** 
    237251    * do a disconnection 
    238252    * (no need to do a test on the connection id) 
    239253    */ 
  • lib/jelix/core/jCoordinator.class.php

    old new  
    33* @package    jelix 
    44* @subpackage core 
    55* @author     Laurent Jouanneau 
    6 * @contributor 
     6* @contributor Julien Issler 
    77* @copyright  2005-2006 laurent Jouanneau 
     8* @copyright  2007 Julien Issler 
    89* @link       http://www.jelix.org 
    910* @licence    GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 
    1011*/ 
     
    8485        } 
    8586        // load configuration data 
    8687        $gJConfig = jConfig::load($configFile); 
     88         
     89        // reference the config file in jSession, because gJConfig no longer exists when the session data is written, and we need it for Dao storage 
     90        jSession::$jConfigFile = $configFile; 
    8791 
    8892        //make sure that the session cookie is only for the current application 
    8993        if(!$gJConfig->shared_session) 
     
    167171 
    168172        $this->request = $request; 
    169173        $this->request->init(); 
    170         session_start(); 
     174        jSession::start(); 
    171175 
    172176        $this->moduleName = $this->request->getParam('module'); 
    173177        $this->actionName = $this->request->getParam('action'); 
  • 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     
     21    protected static $_params; 
     22    public static $jConfigFile; 
     23     
     24    public static function start(){ 
     25        global $gJConfig; 
     26         
     27        if(!isset($gJConfig->sessions)){ 
     28            session_start(); 
     29            return true; 
     30        } 
     31         
     32        self::$_params = $gJConfig->sessions; 
     33         
     34        if(!isset(self::$_params['storage'])){ 
     35            session_start(); 
     36            return true; 
     37        } 
     38         
     39        switch(self::$_params['storage']){ 
     40             
     41            case 'dao': 
     42             
     43                session_set_save_handler( 
     44                    array(__CLASS__,'dao_open'), 
     45                    array(__CLASS__,'dao_close'), 
     46                    array(__CLASS__,'dao_read'), 
     47                    array(__CLASS__,'dao_write'), 
     48                    array(__CLASS__,'dao_destroy'), 
     49                    array(__CLASS__,'dao_gc') 
     50                ); 
     51                break; 
     52                 
     53            case 'files': 
     54                $path = str_replace(array('lib:','app:'), array(LIB_PATH, JELIX_APP_PATH), self::$_params['files_path']); 
     55                session_save_path($path); 
     56                break; 
     57                 
     58            default: 
     59                break;             
     60        } 
     61         
     62        session_start(); 
     63        return true; 
     64    } 
     65     
     66     
     67    protected static function _getDao(){ 
     68         
     69        if(isset(self::$_params['dao_db_profile']) && self::$_params['dao_db_profile']){ 
     70            $dao = jDao::get(self::$_params['dao_selector'], self::$_params['dao_db_profile']); 
     71        } 
     72        else{ 
     73            $dao = jDao::get(self::$_params['dao_selector']); 
     74        } 
     75         
     76        return $dao; 
     77         
     78    } 
     79     
     80    public static function dao_open ($save_path, $session_name) { 
     81        return true; 
     82        } 
     83 
     84        public static function dao_close() { 
     85            return true; 
     86        } 
     87 
     88        public static function dao_read ($id) { 
     89            $dao = self::_getDao(); 
     90               
     91            $session = $dao->get($id); 
     92             
     93            if(!$session){ 
     94                return ''; 
     95            } 
     96             
     97            return $session->data; 
     98        } 
     99 
     100        public static function dao_write ($id, $data) { 
     101            global $gJConfig; 
     102             
     103            $gJConfig = jConfig::load(self::$jConfigFile); 
     104         
     105            if(isset(self::$_params['dao_db_profile']) && self::$_params['dao_db_profile']){ 
     106                $cnx = jDb::getConnection(self::$_params['dao_db_profile']); 
     107        } 
     108        else{ 
     109            $cnx = jDb::getConnection(); 
     110        } 
     111            $cnx->reconnect(); 
     112             
     113            $dao = self::_getDao(); 
     114               
     115            $session = $dao->get($id); 
     116            if(!$session){ 
     117                $session = jDao::createRecord(self::$_params['dao_selector']);    
     118                $session->id = $id; 
     119                $session->data = $data; 
     120                $dao->insert($session);  
     121            } 
     122            else{ 
     123                $session->data = $data; 
     124                $dao->update($session); 
     125            } 
     126             
     127                return true; 
     128 
     129        } 
     130 
     131        public static function dao_destroy ($id) { 
     132 
     133             
     134                if (isset($_COOKIE[session_name()])) { 
     135                   setcookie(session_name(), '', time()-42000, '/'); 
     136                } 
     137        $dao = self::_getDao(); 
     138                $dao->delete($id); 
     139                return true; 
     140        } 
     141 
     142        public static function dao_gc ($maxlifetime) { 
     143 
     144             
     145        $date = new jDateTime(); 
     146            $date->now(); 
     147            $date->sub(0,0,0,0,0,$maxlifetime); 
     148        $dao = self::_getDao(); 
     149        $dao->deleteExpired($date->toString(jDateTime::BD_DTFORMAT)); 
     150 
     151        return true; 
     152        } 
     153     
     154     
     155} 
  • 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 
Download in other formats: Original Format