Dotclear


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

File:
1 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      
Note: See TracChangeset for help on using the changeset viewer.

Sites map