Dotclear

Changeset 934:1ab99955f080


Ignore:
Timestamp:
10/29/12 14:46:58 (13 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Add some methods to namespaces (settings) and workspaces (prefs), conservative way, partially fixes #794. Thanks zeiram for patches

Location:
inc/core
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • inc/core/class.dc.namespace.php

    r270 r934  
    259259          } 
    260260     } 
    261       
    262      /** 
    263      Removes an existing setting. Namespace  
     261 
     262     /** 
     263     Rename an existing setting in a Namespace 
     264 
     265     @param    $oldId    <b>string</b>  Current setting name 
     266     @param    $newId    <b>string</b>  New setting name 
     267     @return   <b>boolean</b> 
     268     */ 
     269     public function rename($oldId,$newId) 
     270     { 
     271          if (!$this->ns) { 
     272               throw new Exception(__('No namespace specified')); 
     273          } 
     274           
     275          if (!array_key_exists($oldId,$this->settings) || array_key_exists($newId,$this->settings)) { 
     276               return false; 
     277          } 
     278 
     279          // Rename the setting in the settings array 
     280          $this->settings[$newId] = $this->settings[$oldId]; 
     281          unset($this->settings[$oldId]); 
     282 
     283          // Rename the setting in the database 
     284          $strReq = 'UPDATE '.$this->table. 
     285               " SET setting_id = '".$this->con->escape($newId)."' ". 
     286               " WHERE setting_ns = '".$this->con->escape($this->ns)."' ". 
     287               " AND setting_id = '".$this->con->escape($oldId)."' "; 
     288          $this->con->execute($strReq); 
     289          return true; 
     290     } 
     291 
     292     /** 
     293     Removes an existing setting in a Namespace  
    264294      
    265295     @param    id        <b>string</b>       Setting ID 
     
    286316      
    287317     /** 
     318     Removes all existing settings in a Namespace  
     319      
     320     @param    force_global   <b>boolean</b> Force global pref drop 
     321     */ 
     322     public function dropAll($force_global=false) 
     323     { 
     324          if (!$this->ns) { 
     325               throw new Exception(__('No namespace specified')); 
     326          } 
     327           
     328          $strReq = 'DELETE FROM '.$this->table.' '; 
     329           
     330          if (($force_global) || ($this->blog_id === null)) { 
     331               $strReq .= 'WHERE blog_id IS NULL '; 
     332               $global = true; 
     333          } else { 
     334               $strReq .= "WHERE blog_id = '".$this->con->escape($this->blog_id)."' "; 
     335               $global = false; 
     336          } 
     337           
     338          $strReq .= "AND setting_ns = '".$this->con->escape($this->ns)."' "; 
     339           
     340          $this->con->execute($strReq); 
     341           
     342          $array = $global ? 'global' : 'local'; 
     343          unset($this->{$array.'_settings'}); 
     344          $this->{$array.'_settings'} = array(); 
     345           
     346          $array = $global ? 'local' : 'global'; 
     347          $this->settings = $this->{$array.'_settings'}; 
     348     } 
     349      
     350     /** 
    288351     Returns $settings property content. 
    289352      
  • inc/core/class.dc.prefs.php

    r147 r934  
    9898      
    9999     /** 
     100     Rename a workspace. 
     101 
     102     @param    oldWs     <b>string</b>  Old workspace name 
     103     @param    newws     <b>string</b>  New workspace name 
     104     @return   <b>boolean</b> 
     105     */ 
     106     public function renWorkspace($oldNs,$newNs) 
     107     { 
     108          if (!array_key_exists($oldWs, $this->workspaces) || array_key_exists($newWs, $this->workspaces)) { 
     109               return false; 
     110          } 
     111 
     112          // Rename the workspace in the workspace array 
     113          $this->workspaces[$newWs] = $this->workspaces[$oldWs]; 
     114          unset($this->workspaces[$oldWs]); 
     115 
     116          // Rename the workspace in the database 
     117          $strReq = 'UPDATE '.$this->table. 
     118               " SET pref_ws = '".$this->con->escape($newWs)."' ". 
     119               " WHERE pref_ws = '".$this->con->escape($oldWs)."' "; 
     120          $this->con->execute($strReq); 
     121          return true; 
     122     } 
     123 
     124     /** 
     125     Delete a whole workspace with all preferences pertaining to it. 
     126 
     127     @param    ws   <b>string</b>  Workspace name 
     128     @return   <b>boolean</b> 
     129     */ 
     130     public function delWorkspace($ws) 
     131     { 
     132          if (!array_key_exists($ws, $this->workspaces)) { 
     133               return false; 
     134          } 
     135 
     136          // Remove the workspace from the workspace array 
     137          unset($this->workspaces[$ws]); 
     138 
     139          // Delete all preferences from the workspace in the database 
     140          $strReq = 'DELETE FROM '.$this->table. 
     141               " WHERE pref_ws = '".$this->con->escape($ws)."' "; 
     142          $this->con->execute($strReq); 
     143          return true; 
     144     } 
     145      
     146     /** 
    100147     Returns full workspace with all prefs pertaining to it. 
    101148      
  • inc/core/class.dc.settings.php

    r301 r934  
    9292          return $this->namespaces[$ns]; 
    9393     } 
     94 
     95     /** 
     96     Rename a namespace. 
     97 
     98     @param    oldNs     <b>string</b>  Old namespace name 
     99     @param    newNs     <b>string</b>  New namespace name 
     100     @return   <b>boolean</b> 
     101     */ 
     102     public function renNamespace($oldNs,$newNs) 
     103     { 
     104          if (!array_key_exists($oldNs, $this->namespaces) || array_key_exists($newNs, $this->namespaces)) { 
     105               return false; 
     106          } 
     107 
     108          // Rename the namespace in the namespace array 
     109          $this->namespaces[$newNs] = $this->namespaces[$oldNs]; 
     110          unset($this->namespaces[$oldNs]); 
     111 
     112          // Rename the namespace in the database 
     113          $strReq = 'UPDATE '.$this->table. 
     114               " SET setting_ns = '".$this->con->escape($newNs)."' ". 
     115               " WHERE setting_ns = '".$this->con->escape($oldNs)."' "; 
     116          $this->con->execute($strReq); 
     117          return true; 
     118     } 
     119 
     120     /** 
     121     Delete a whole namespace with all settings pertaining to it. 
     122 
     123     @param    ns   <b>string</b>  Namespace name 
     124     @return   <b>boolean</b> 
     125     */ 
     126     public function delNamespace($ns) 
     127     { 
     128          if (!array_key_exists($ns, $this->namespaces)) { 
     129               return false; 
     130          } 
     131 
     132          // Remove the namespace from the namespace array 
     133          unset($this->namespaces[$ns]); 
     134 
     135          // Delete all settings from the namespace in the database 
     136          $strReq = 'DELETE FROM '.$this->table. 
     137               " WHERE setting_ns = '".$this->con->escape($ns)."' "; 
     138          $this->con->execute($strReq); 
     139          return true; 
     140     } 
    94141      
    95142     /** 
  • inc/core/class.dc.workspace.php

    r147 r934  
    263263          } 
    264264     } 
     265 
     266     /** 
     267     Rename an existing pref in a Workspace 
     268 
     269     @param    $oldId    <b>string</b>  Current pref name 
     270     @param    $newId    <b>string</b>  New pref name 
     271     @return   <b>boolean</b> 
     272     */ 
     273     public function rename($oldId,$newId) 
     274     { 
     275          if (!$this->ws) { 
     276               throw new Exception(__('No workspace specified')); 
     277          } 
     278           
     279          if (!array_key_exists($oldId,$this->prefs) || array_key_exists($newId,$this->prefs)) { 
     280               return false; 
     281          } 
     282 
     283          // Rename the pref in the prefs array 
     284          $this->prefs[$newId] = $this->prefs[$oldId]; 
     285          unset($this->prefs[$oldId]); 
     286 
     287          // Rename the pref in the database 
     288          $strReq = 'UPDATE '.$this->table. 
     289               " SET pref_id = '".$this->con->escape($newId)."' ". 
     290               " WHERE pref_ws = '".$this->con->escape($this->ws)."' ". 
     291               " AND pref_id = '".$this->con->escape($oldId)."' "; 
     292          $this->con->execute($strReq); 
     293          return true; 
     294     } 
    265295      
    266296     /** 
Note: See TracChangeset for help on using the changeset viewer.

Sites map