phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] CVS: etemplate/inc class.boetemplate.inc.php,1.17,1.1


From: Ralf Becker <address@hidden>
Subject: [Phpgroupware-cvs] CVS: etemplate/inc class.boetemplate.inc.php,1.17,1.18 class.soetemplate.inc.php,1.12,1.13 class.uietemplate.inc.php,1.18,1.19
Date: Tue, 24 Sep 2002 06:01:00 -0400

Update of /cvsroot/phpgroupware/etemplate/inc
In directory subversions:/tmp/cvs-serv5031

Modified Files:
        class.boetemplate.inc.php class.soetemplate.inc.php 
        class.uietemplate.inc.php 
Log Message:
improved the cache-handeling:
- works now with versioning (only via the db-storage, not files)
- removed a lot unnecessary db- and/or filesystem accesses

Index: class.boetemplate.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/etemplate/inc/class.boetemplate.inc.php,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -r1.17 -r1.18
*** class.boetemplate.inc.php   22 Sep 2002 08:05:17 -0000      1.17
--- class.boetemplate.inc.php   24 Sep 2002 10:00:58 -0000      1.18
***************
*** 409,423 ****
                }
  
                /*!
!               @function read
!               @abstract Reads an eTemplate from the cache or database / 
filesystem (and updates the cache)
!               @param as discripted in soetemplate::read
!               @result True if a fitting template is found, else False
                */
!               function 
read($name,$template='default',$lang='default',$group=0,$version='')
                {
!                       $cname = ($template == '' ? 'default' : 
$template).'/'.$name.($lang == 'default' ? '' : '.'.$lang);
  
!                       if 
(isset($GLOBALS['phpgw_info']['etemplate']['cache'][$cname]))
                        {
                                reset($this->db_cols);
--- 409,469 ----
                }
  
+ 
+               function 
cache_name($name='',$template='default',$lang='default')
+               {
+                       if (empty($name))
+                       {
+                               $name     = $this->name;
+                               $template = $this->template;
+                               $lang     = $this->lang;
+                       }
+                       elseif (is_array($name))
+                       {
+                               $template = $name['template'];
+                               $lang     = $name['lang'];
+                               $name     = $name['name'];
+                       }
+                       if (empty($template))
+                       {
+                               $template = 'default';
+                       }
+                       $cname = $template . '/' . $name . (!empty($lang) && 
$lang != 'default' ? '.' . $lang : '');
+                       //echo "cache_name('$name','$template','$lang') = 
'$cname'";
+ 
+                       return $cname;
+               }
+ 
                /*!
!               @function store_in_cache()
!               @abstract stores the etemplate in the cache in phpgw_info
                */
!               function store_in_cache()
                {
!                       //echo 
"<p>store_in_cache('$this->name','$this->template','$this->lang','$this->version')</p>\n";
!                       
$GLOBALS['phpgw_info']['etemplate']['cache'][$this->cache_name()] = 
$this->as_array(1);
!               }
  
!               function 
in_cache($name,$template='default',$lang='default',$group=0,$version='')
!               {
!                       $cname = $this->cache_name($name,$template,$lang);
!                       if (is_array($name))
!                       {
!                               $version = $name['version'];
!                               $name    = $name['name'];
!                       }
!                       if 
(!isset($GLOBALS['phpgw_info']['etemplate']['cache'][$cname]) ||
!                           !empty($version) && 
$GLOBALS['phpgw_info']['etemplate']['cache'][$cname]['version'] != $version)
!                       {
!                               //echo " NOT found in cache</p>\n";
!                               return False;
!                       }
!                       //echo " found in cache</p>\n";
!                       return $cname;
!               }
! 
!               function 
read_from_cache($name,$template='default',$lang='default',$group=0,$version='')
!               {
!                       //if (is_array($name)) $version = $name['version']; 
echo "<p>read_from_cache(,,,version='$version'): ";
!                       if ($cname = 
$this->in_cache($name,$template,$lang,$group))
                        {
                                reset($this->db_cols);
***************
*** 428,441 ****
                                $this->rows = count($this->data) - 1;
                                $this->cols = count($this->data[1]); // 1 = 
first row, not 0
-                               echo "\n<!-- $cname read from cache -->\n";
                                return True;
                        }
!                       if 
(!soetemplate::read($name,$template,$lang,$group,$version))
!                               return False;
! 
!                       echo "\n<!-- $cname read & cache updated -->\n";
!                       $GLOBALS['phpgw_info']['etemplate']['cache'][$cname] = 
$this->as_array(1);
  
!                       return true;
                }
  
--- 474,499 ----
                                $this->rows = count($this->data) - 1;
                                $this->cols = count($this->data[1]); // 1 = 
first row, not 0
                                return True;
                        }
!                       return False;
!               }
  
!               /*!
!               @function read
!               @abstract Reads an eTemplate from the cache or database / 
filesystem (and updates the cache)
!               @param as discripted in soetemplate::read
!               @result True if a fitting template is found, else False
!               */
!               function 
read($name,$template='default',$lang='default',$group=0,$version='')
!               {
!                       if 
(!$this->read_from_cache($name,$template,$lang,$group,$version))
!                       {
!                               if 
(!soetemplate::read($name,$template,$lang,$group,$version))
!                               {
!                                       return False;
!                               }
!                               $this->store_in_cache();
!                       }
!                       return True;
                }
  
***************
*** 448,458 ****
                function 
save($name='',$template='.',$lang='.',$group='',$version='.')
                {
!                       $result = 
soetemplate::save($name,$template,$lang,$group,$version);
! 
!                       if ($result)
                        {
!                               $cname = ($template == '' ? 'default' : 
$template).'/'.$name.($lang == 'default' ? '' : '.'.$lang);
! 
!                               
$GLOBALS['phpgw_info']['etemplate']['cache'][$cname] = $this->as_array(1);
                        }
                        return $result;
--- 506,512 ----
                function 
save($name='',$template='.',$lang='.',$group='',$version='.')
                {
!                       if ($result = 
soetemplate::save($name,$template,$lang,$group,$version))
                        {
!                               $this->store_in_cache();
                        }
                        return $result;

Index: class.soetemplate.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/etemplate/inc/class.soetemplate.inc.php,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** class.soetemplate.inc.php   22 Sep 2002 17:55:17 -0000      1.12
--- class.soetemplate.inc.php   24 Sep 2002 10:00:58 -0000      1.13
***************
*** 43,46 ****
--- 43,47 ----
                        'writeLangFile' => True
                );
+               var $debug;             // =1 show some debug-messages, = 
'app.name' show messages only for eTemplate 'app.name'
                var $name;              // name of the template, e.g. 
'infolog.edit'
                var $template;  // '' = default (not 'default')
***************
*** 75,79 ****
                        $this->db_cols = $this->db_key_cols + 
$this->db_data_cols;
  
!                       
$this->read($name,$template,$lang,$group,$version,$rows,$cols);
                }
  
--- 76,87 ----
                        $this->db_cols = $this->db_key_cols + 
$this->db_data_cols;
  
!                       if (empty($name))
!                       {
!                               
$this->init($name,$template,$lang,$group,$version,$rows,$cols);
!                       }
!                       else
!                       {
!                               
$this->read($name,$template,$lang,$group,$version,$rows,$cols);
!                       }
                }
  
***************
*** 158,162 ****
                {
                        $this->init($name,$template,$lang,$group,$version);
! 
                        if 
($GLOBALS['phpgw_info']['server']['eTemplate-source'] == 'files' && 
$this->readfile())
                        {
--- 166,173 ----
                {
                        $this->init($name,$template,$lang,$group,$version);
!                       if ($this->debug == 1 || $this->debug == $this->name)
!                       {
!                               echo 
"<p>soetemplate::read('$this->name','$this->template','$this->lang','$this->version')</p>\n";
!                       }
                        if 
($GLOBALS['phpgw_info']['server']['eTemplate-source'] == 'files' && 
$this->readfile())
                        {
***************
*** 202,209 ****
                        $sql .= " ORDER BY et_lang DESC,et_template 
DESC,et_version DESC";
  
                        $this->db->query($sql,__LINE__,__FILE__);
                        if (!$this->db->next_record())
                        {
!                               return $this->readfile();
                        }
                        $this->db2obj();
--- 213,225 ----
                        $sql .= " ORDER BY et_lang DESC,et_template 
DESC,et_version DESC";
  
+                       if ($this->debug == $this->name)
+                       {
+                               echo "<p>soetemplate::read: sql='$sql'</p>\n";
+                       }
                        $this->db->query($sql,__LINE__,__FILE__);
                        if (!$this->db->next_record())
                        {
!                               $version = $this->version;
!                               return $this->readfile() && (empty($version) || 
$version == $this->version);
                        }
                        $this->db2obj();
***************
*** 230,234 ****
                        if ($this->name == '' || $app == '' || $name == '' || 
address@hidden($file) || !($f = @fopen($file,'r')))
                        {
!                               //echo "<p>Can't open '$file' !!!</p>\n";
                                return False;
                        }
--- 246,253 ----
                        if ($this->name == '' || $app == '' || $name == '' || 
address@hidden($file) || !($f = @fopen($file,'r')))
                        {
!                               if ($this->debug == 1 || $this->debug == 
$this->name)
!                               {
!                                       echo "<p>Can't open '$file' !!!</p>\n";
!                               }
                                return False;
                        }
***************
*** 240,244 ****
                                $this->xul_io = 
CreateObject('etemplate.xul_io');
                        }
!                       if ($this->xul_io->import(&$this,$xul) != '')
                        {
                                return False;
--- 259,263 ----
                                $this->xul_io = 
CreateObject('etemplate.xul_io');
                        }
!                       if (!is_array($this->xul_io->import(&$this,$xul)))
                        {
                                return False;

Index: class.uietemplate.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/etemplate/inc/class.uietemplate.inc.php,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -r1.18 -r1.19
*** class.uietemplate.inc.php   17 Sep 2002 12:28:37 -0000      1.18
--- class.uietemplate.inc.php   24 Sep 2002 10:00:58 -0000      1.19
***************
*** 52,56 ****
                        $this->sbox = CreateObject('etemplate.sbox2');  // 
older version is in the api
  
!                       if (!$this->read($name,$template,$lang,$group,$version))
                        {
                                
$this->init($name,$template,$lang,$group,$version,$rows,$cols);
--- 52,56 ----
                        $this->sbox = CreateObject('etemplate.sbox2');  // 
older version is in the api
  
!                       if (empty($name) || 
!$this->read($name,$template,$lang,$group,$version))
                        {
                                
$this->init($name,$template,$lang,$group,$version,$rows,$cols);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]