Ticket #1040: loadsettings2.patch
File loadsettings2.patch, 3.5 KB (added by bruno, 15 years ago) |
---|
-
class.dc.namespace.php
33 33 34 34 @param name <b>string</b> ID for this namespace 35 35 */ 36 public function __construct(&$core, $blog_id, $name )36 public function __construct(&$core, $blog_id, $name, $rs=null) 37 37 { 38 38 if (preg_match('/^[a-zA-Z][a-zA-Z0-9]+$/',$name)) { 39 39 $this->ns = $name; … … 45 45 $this->table = $core->prefix.'setting'; 46 46 $this->blog_id =& $blog_id; 47 47 48 $this->getSettings( );48 $this->getSettings($rs); 49 49 } 50 50 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 '; 60 61 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 } 65 67 } 66 67 68 while ($rs->fetch()) 68 69 { 70 if ($rs->f('setting_ns') != $this->ns){ 71 break; 72 } 69 73 $id = trim($rs->f('setting_id')); 70 74 $value = $rs->f('setting_value'); 71 75 $type = $rs->f('setting_type'); -
class.dc.settings.php
41 41 $this->con =& $core->con; 42 42 $this->table = $core->prefix.'setting'; 43 43 $this->blog_id =& $blog_id; 44 45 $this->getNamespaces(); 44 $this->loadSettings(); 46 45 } 47 46 48 private function getNamespaces() 47 /** 48 Retrieves all namespaces (and their settings) from database, with one query. 49 */ 50 private function loadSettings() 49 51 { 50 $strReq = 'SELECT DISTINCT setting_ns '. 52 $strReq = 'SELECT blog_id, setting_id, setting_value, '. 53 'setting_type, setting_label, setting_ns '. 51 54 'FROM '.$this->table.' '. 52 55 "WHERE blog_id = '".$this->con->escape($this->blog_id)."' ". 53 56 'OR blog_id IS NULL '. 54 'ORDER BY setting_ns'; 55 57 'ORDER BY setting_ns ASC, setting_id DESC'; 56 58 try { 57 59 $rs = $this->con->select($strReq); 58 60 } catch (Exception $e) { 59 61 trigger_error(__('Unable to retrieve namespaces:').' '.$this->con->error(), E_USER_ERROR); 60 62 } 61 62 while ($rs->fetch()) 63 { 63 do { 64 64 $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 } 67 73 68 return true;69 }70 74 71 75 /** 72 76 Create a new namespace. If the namespace already exists, return it without modification.