Changeset 481


Ignore:
Timestamp:
May 4, 2014 12:46:59 AM (10 years ago)
Author:
anonymous
Message:

Needed to move the initial this->clear() call back into the constructor.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Prefs.inc.php

    r480 r481  
    2929 * @author  Quinn Comendant <quinn@strangecode.com>
    3030 * @version 3.0
     31 * @todo This class could really benefit from being refactored using the factory pattern, with backend storage mechanisms.
    3132 *
    3233 * Example of use (database storagetype):
     
    5960    private $_params = array(
    6061
    61         // Legacy parameter, superceeded by the 'storagetype' setting.
     62        // Store preferences in one of the available storage mechanisms: session, cookie, database
     63        // This default should remain set to 'session' for legacy support.
     64        'storagetype' => 'session',
     65
     66        // This parameter is only used for legacy support, superceeded by the 'storagetype' setting.
    6267        // Enable database storage. If this is false, all prefs will live only as long as the session.
    6368        'persistent' => null,
    6469
    65         // Store preferences in one of the available storage mechanisms: session, cookie, database
    66         'storagetype' => 'session',
    67 
    6870        // ----------------------------------------------------------
    6971        // Cookie-type settings.
     
    8789        'load_timeout' => 3600,
    8890
    89         // Name of database table to store persistent prefs.
     91        // Name of database table to store prefs.
    9092        'db_table' => 'pref_tbl',
    9193
     
    111113        // Optional initial params.
    112114        $this->setParam($params);
     115
     116        // Initialized the prefs array.
     117        if ('cookie' != $app->getParam('storagetype') && !isset($_SESSION['_prefs'][$this->_ns]['saved'])) {
     118            $this->clear();
     119        }
    113120
    114121        // Run Prefs->save() upon script completion if we're using the database storagetype.
     
    174181
    175182        // Convert the legacy param 'persistent' to 'storagetype=database'.
     183        // Old sites would set 'persistent' to true (use database) or false (use sessions).
     184        // If it is true, we set storagetype=database here.
     185        // If false, we rely on the default, sessions (which is assigned in the params).
    176186        if (isset($params['persistent']) && $params['persistent'] && !isset($params['storagetype'])) {
    177187            $params['storagetype'] = 'database';
     
    206216     * Sets the default values for preferences. If a preference is not explicitly
    207217     * set, the value set here will be used. Can be called multiple times to merge additional
    208      * defaults together. This is mostly only useful for the database storetype, when you have
     218     * defaults together. This is mostly only useful for the database storagetype, when you have
    209219     * values you want to use as default, and those are not stored to the database (so the defaults
    210220     * can be changed later and apply to all users who haven't make s specific setting).
    211      * For the cookie storetype, using setDefaults just sets cookies but only if a cookie with
     221     * For the cookie storagetype, using setDefaults just sets cookies but only if a cookie with
    212222     * the same name is not already set.
    213223     *
     
    267277        case 'session':
    268278        case 'database':
    269             // Initialized the prefs array.
    270             if (!isset($_SESSION['_prefs'][$this->_ns]['saved'])) {
    271                 $this->clear();
    272             }
    273279            // Set a saved preference if...
    274280            // - there isn't a default.
Note: See TracChangeset for help on using the changeset viewer.