Dotclear

Ticket #1040: loadsettings2.patch

File loadsettings2.patch, 3.5 KB (added by bruno, 15 years ago)

(patch qui n'oublie pas des settings)

  • class.dc.namespace.php

     
    3333      
    3434     @param    name      <b>string</b>       ID for this namespace 
    3535     */ 
    36      public function __construct(&$core, $blog_id, $name) 
     36     public function __construct(&$core, $blog_id, $name, $rs=null) 
    3737     { 
    3838          if (preg_match('/^[a-zA-Z][a-zA-Z0-9]+$/',$name)) { 
    3939               $this->ns = $name; 
     
    4545          $this->table = $core->prefix.'setting'; 
    4646          $this->blog_id =& $blog_id; 
    4747           
    48           $this->getSettings(); 
     48          $this->getSettings($rs); 
    4949     } 
    5050      
    51      private function getSettings() 
    52      { 
    53           $strReq = 'SELECT blog_id, setting_id, setting_value, '. 
    54                     'setting_type, setting_label '. 
    55                     'FROM '.$this->table.' '. 
    56                     "WHERE (blog_id = '".$this->con->escape($this->blog_id)."' ". 
    57                     'OR blog_id IS NULL) '. 
    58                     "AND setting_ns = '".$this->con->escape($this->ns)."' ". 
    59                     'ORDER BY setting_id DESC '; 
     51     private function getSettings($rs=null) 
     52     {     
     53          if ($rs == null) { 
     54               $strReq = 'SELECT blog_id, setting_id, setting_value, '. 
     55                         'setting_type, setting_label, setting_ns '. 
     56                         'FROM '.$this->table.' '. 
     57                         "WHERE (blog_id = '".$this->con->escape($this->blog_id)."' ". 
     58                         'OR blog_id IS NULL) '. 
     59                         "AND setting_ns = '".$this->con->escape($this->ns)."' ". 
     60                         'ORDER BY setting_id DESC '; 
    6061           
    61           try { 
    62                $rs = $this->con->select($strReq); 
    63           } catch (Exception $e) { 
    64                trigger_error(__('Unable to retrieve settings:').' '.$this->con->error(), E_USER_ERROR); 
     62               try { 
     63                    $rs = $this->con->select($strReq); 
     64               } catch (Exception $e) { 
     65                    trigger_error(__('Unable to retrieve settings:').' '.$this->con->error(), E_USER_ERROR); 
     66               } 
    6567          } 
    66            
    6768          while ($rs->fetch()) 
    6869          { 
     70               if ($rs->f('setting_ns') != $this->ns){ 
     71                    break; 
     72               } 
    6973               $id = trim($rs->f('setting_id')); 
    7074               $value = $rs->f('setting_value'); 
    7175               $type = $rs->f('setting_type'); 
  • class.dc.settings.php

     
    4141          $this->con =& $core->con; 
    4242          $this->table = $core->prefix.'setting'; 
    4343          $this->blog_id =& $blog_id; 
    44            
    45           $this->getNamespaces(); 
     44          $this->loadSettings(); 
    4645     } 
    4746      
    48      private function getNamespaces() 
     47     /** 
     48     Retrieves all namespaces (and their settings) from database, with one query.  
     49     */ 
     50     private function loadSettings() 
    4951     { 
    50           $strReq = 'SELECT DISTINCT setting_ns '. 
     52          $strReq = 'SELECT blog_id, setting_id, setting_value, '. 
     53                    'setting_type, setting_label, setting_ns '. 
    5154                    'FROM '.$this->table.' '. 
    5255                    "WHERE blog_id = '".$this->con->escape($this->blog_id)."' ". 
    5356                    'OR blog_id IS NULL '. 
    54                     'ORDER BY setting_ns'; 
    55            
     57                    'ORDER BY setting_ns ASC, setting_id DESC'; 
    5658          try { 
    5759               $rs = $this->con->select($strReq); 
    5860          } catch (Exception $e) { 
    5961               trigger_error(__('Unable to retrieve namespaces:').' '.$this->con->error(), E_USER_ERROR); 
    6062          } 
    61            
    62           while ($rs->fetch()) 
    63           { 
     63          do { 
    6464               $ns = trim($rs->f('setting_ns')); 
    65                $this->namespaces[$ns] = new dcNamespace($GLOBALS['core'], $this->blog_id, $ns); 
    66           } 
     65               if (!$rs->isStart()) { 
     66                    // we have to go up 1 step, since namespaces construction performs a fetch() 
     67                    // at very first time 
     68                    $rs->movePrev(); 
     69               } 
     70               $this->namespaces[$ns] = new dcNamespace($GLOBALS['core'], $this->blog_id, $ns,$rs); 
     71          } while(!$rs->isStart()); 
     72     } 
    6773           
    68           return true; 
    69      } 
    7074      
    7175     /** 
    7276     Create a new namespace. If the namespace already exists, return it without modification. 

Sites map