phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] CVS: phpgwapi/inc class.vfs_sql.inc.php,1.22,1.23


From: Jason Wies <address@hidden>
Subject: [Phpgroupware-cvs] CVS: phpgwapi/inc class.vfs_sql.inc.php,1.22,1.23
Date: Mon, 26 Aug 2002 00:20:36 -0400

Update of /cvsroot/phpgroupware/phpgwapi/inc
In directory subversions:/tmp/cvs-serv21390/phpgwapi/inc

Modified Files:
        class.vfs_sql.inc.php 
Log Message:
Add support of storing file contents in the database

Index: class.vfs_sql.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/class.vfs_sql.inc.php,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -r1.22 -r1.23
*** class.vfs_sql.inc.php       24 Jun 2002 04:02:14 -0000      1.22
--- class.vfs_sql.inc.php       26 Aug 2002 04:20:33 -0000      1.23
***************
*** 93,96 ****
--- 93,97 ----
                var $meta_types;
                var $now;
+               var $file_actions;
  
                /*!
***************
*** 131,136 ****
                                'link_directory',
                                'link_name',
!                               'version'
                        );
        
                        /*
--- 132,154 ----
                                'link_directory',
                                'link_name',
!                               'version',
!                               'content'
                        );
+ 
+                       /*
+                          Decide whether to use any actual filesystem calls 
(fopen(), fread(),
+                          unlink(), rmdir(), touch(), etc.).  If not, then 
we're working completely
+                          in the database.
+                       */
+                       $conf = CreateObject('phpgwapi.config', 'phpgwapi');
+                       $conf->read_repository();
+                       if ($conf->config_data['file_store_contents'] == 
'filesystem' || !$conf->config_data['file_store_contents'])
+                       {
+                               $this->file_actions = 1;
+                       }
+                       else
+                       {
+                               $this->file_actions = 0;
+                       }
        
                        /*
***************
*** 375,379 ****
                        for ($i = 0; list ($attribute, $value) = each 
($file_array); $i++)
                        {
!                               if ($attribute == 'file_id')
                                {
                                        continue;
--- 393,397 ----
                        for ($i = 0; list ($attribute, $value) = each 
($file_array); $i++)
                        {
!                               if ($attribute == 'file_id' || $attribute == 
'content')
                                {
                                        continue;
***************
*** 1389,1400 ****
                        }
  
!                       if ($fp = fopen ($p->real_full_path, 'rb'))
                        {
!                               $contents = fread ($fp, filesize 
($p->real_full_path));
!                               fclose ($fp);
                        }
                        else
                        {
!                               $contents = False;
                        }
  
--- 1407,1433 ----
                        }
  
!                       $conf = CreateObject('phpgwapi.config', 'phpgwapi');
!                       $conf->read_repository();
!                       if ($this->file_actions || $p->outside)
                        {
!                               if ($fp = fopen ($p->real_full_path, 'rb'))
!                               {
!                                       $contents = fread ($fp, filesize 
($p->real_full_path));
!                                       fclose ($fp);
!                               }
!                               else
!                               {
!                                       $contents = False;
!                               }
                        }
                        else
                        {
!                               $ls_array = $this->ls (array(
!                                               'string'        => 
$p->fake_full_path,
!                                               'relatives'     => array 
($p->mask),
!                                       )
!                               );
! 
!                               $contents = $ls_array[0]['content'];
                        }
  
***************
*** 1467,1479 ****
                        );
  
!                       if ($fp = fopen ($p->real_full_path, 'wb'))
                        {
!                               fwrite ($fp, $data['content'], strlen 
($data['content']));
!                               fclose ($fp);
  
!                               $this->set_attributes (array(
                                                'string'        => 
$p->fake_full_path,
                                                'relatives'     => array 
($p->mask),
!                                               'attributes'    => array 
('size' => filesize ($p->real_full_path))
                                        )
                                );
--- 1500,1537 ----
                        );
  
!                       $conf = CreateObject('phpgwapi.config', 'phpgwapi');
!                       $conf->read_repository();
!                       if ($this->file_actions)
                        {
!                               if ($fp = fopen ($p->real_full_path, 'wb'))
!                               {
!                                       fwrite ($fp, $data['content'], strlen 
($data['content']));
!                                       fclose ($fp);
!                                       $write_ok = 1;
!                               }
!                       }
  
!                       if ($write_ok || !$this->file_actions)
!                       {
!                               if ($this->file_actions)
!                               {
!                                       $set_attributes_array = array(
!                                               'size' => filesize 
($p->real_full_path)
!                                       );
!                               }
!                               else
!                               {
!                                       $set_attributes_array = array (
!                                               'size'  => strlen 
($data['content']),
!                                               'content'       => 
$data['content']
!                                       );
!                               }
! 
! 
!                               $this->set_attributes (array
!                                       (
                                                'string'        => 
$p->fake_full_path,
                                                'relatives'     => array 
($p->mask),
!                                               'attributes'    => 
$set_attributes_array
                                        )
                                );
***************
*** 1529,1541 ****
                        umask (000);
  
!                       /*
!                          PHP's touch function will automatically decide 
whether to
!                          create the file or set the modification time
!                       */
!                       $rr = @touch ($p->real_full_path);
! 
!                       if ($p->outside)
                        {
!                               return $rr;
                        }
  
--- 1587,1602 ----
                        umask (000);
  
!                       if ($this->file_actions)
                        {
!                               /*
!                                  PHP's touch function will automatically 
decide whether to
!                                  create the file or set the modification time
!                               */
!                               $rr = @touch ($p->real_full_path);
! 
!                               if ($p->outside)
!                               {
!                                       return $rr;
!                               }
                        }
  
***************
*** 1700,1706 ****
                        )
                        {
!                               if (!copy ($f->real_full_path, 
$t->real_full_path))
                                {
!                                       return False;
                                }
  
--- 1761,1782 ----
                        )
                        {
!                               if ($this->file_actions)
                                {
!                                       if (!copy ($f->real_full_path, 
$t->real_full_path))
!                                       {
!                                               return False;
!                                       }
! 
!                                       $size = filesize ($t->real_full_path);
!                               }
!                               else
!                               {
!                                       $content = $this->read (array(
!                                                       'string'        => 
$f->fake_full_path,
!                                                       'relatives'     => 
array ($f->mask)
!                                               )
!                                       );
! 
!                                       $size = strlen ($content);
                                }
  
***************
*** 1710,1715 ****
                                }
  
-                               $size = filesize ($t->real_full_path);
- 
                                $ls_array = $this->ls (array(
                                                'string'        => 
$f->fake_full_path,
--- 1786,1789 ----
***************
*** 1730,1745 ****
                                        $query = $GLOBALS['phpgw']->db->query 
("UPDATE phpgw_vfs SET owner_id='$this->working_id', 
directory='$t->fake_leading_dirs_clean', name='$t->fake_name_clean' WHERE 
owner_id='$this->working_id' AND directory='$t->fake_leading_dirs_clean' AND 
name='$t->fake_name_clean'" . $this->extra_sql (VFS_SQL_UPDATE), __LINE__, 
__FILE__);
  
                                        $this->set_attributes(array(
                                                'string'        => 
$t->fake_full_path,
                                                'relatives'     => array 
($t->mask),
!                                               'attributes'    => array (
!                                                                       
'createdby_id' => $account_id,
!                                                                       
'created' => $this->now,
!                                                                       'size' 
=> $size,
!                                                                       
'mime_type' => $record['mime_type'],
!                                                                       
'deleteable' => $record['deleteable'],
!                                                                       
'comment' => $record['comment'],
!                                                                       'app' 
=> $record['app']
!                                                               )
                                                )
                                        );
--- 1804,1826 ----
                                        $query = $GLOBALS['phpgw']->db->query 
("UPDATE phpgw_vfs SET owner_id='$this->working_id', 
directory='$t->fake_leading_dirs_clean', name='$t->fake_name_clean' WHERE 
owner_id='$this->working_id' AND directory='$t->fake_leading_dirs_clean' AND 
name='$t->fake_name_clean'" . $this->extra_sql (VFS_SQL_UPDATE), __LINE__, 
__FILE__);
  
+                                       $set_attributes_array = array (
+                                               'createdby_id' => $account_id,
+                                               'created' => $this->now,
+                                               'size' => $size,
+                                               'mime_type' => 
$record['mime_type'],
+                                               'deleteable' => 
$record['deleteable'],
+                                               'comment' => $record['comment'],
+                                               'app' => $record['app']
+                                       );
+ 
+                                       if (!$this->file_actions)
+                                       {
+                                               
$set_attributes_array['content'] = $content;
+                                       }
+ 
                                        $this->set_attributes(array(
                                                'string'        => 
$t->fake_full_path,
                                                'relatives'     => array 
($t->mask),
!                                               'attributes'    => 
$set_attributes_array
                                                )
                                        );
***************
*** 1760,1775 ****
                                        );
  
                                        $this->set_attributes(array(
!                                               'string'        => 
$t->fake_full_path,
!                                               'relatives'     => array 
($t->mask),
!                                               'attributes'    => array (
!                                                                       
'createdby_id' => $account_id,
!                                                                       
'created' => $this->now,
!                                                                       'size' 
=> $size,
!                                                                       
'mime_type' => $record['mime_type'],
!                                                                       
'deleteable' => $record['deleteable'],
!                                                                       
'comment' => $record['comment'],
!                                                                       'app' 
=> $record['app']
!                                                               )
                                                )
                                        );
--- 1841,1863 ----
                                        );
  
+                                       $set_attributes_array = array (
+                                               'createdby_id' => $account_id,
+                                               'created' => $this->now,
+                                               'size' => $size,
+                                               'mime_type' => 
$record['mime_type'],
+                                               'deleteable' => 
$record['deleteable'],
+                                               'comment' => $record['comment'],
+                                               'app' => $record['app']
+                                       );
+ 
+                                       if (!$this->file_actions)
+                                       {
+                                               
$set_attributes_array['content'] = $content;
+                                       }
+ 
                                        $this->set_attributes(array(
!                                                       'string'        => 
$t->fake_full_path,
!                                                       'relatives'     => 
array ($t->mask),
!                                                       'attributes'    => 
$set_attributes_array
                                                )
                                        );
***************
*** 2025,2029 ****
                                );
  
!                               $rr = rename ($f->real_full_path, 
$t->real_full_path);
  
                                /*
--- 2113,2120 ----
                                );
  
!                               if ($this->file_actions)
!                               {
!                                       $rr = rename ($f->real_full_path, 
$t->real_full_path);
!                               }
  
                                /*
***************
*** 2130,2134 ****
                        )
                        {
!                               $rr = unlink ($p->real_full_path);
  
                                if ($rr)
--- 2221,2232 ----
                        )
                        {
!                               if ($this->file_actions)
!                               {
!                                       $rr = unlink ($p->real_full_path);
!                               }
!                               else
!                               {
!                                       $rr = True;
!                               }
  
                                if ($rr)
***************
*** 2156,2160 ****
  
                                $query = $GLOBALS['phpgw']->db->query ("DELETE 
FROM phpgw_vfs WHERE directory='".$p->fake_leading_dirs_clean."' AND 
name='".$p->fake_name_clean."'".$this->extra_sql (array ('query_type' => 
VFS_SQL_DELETE)), __LINE__, __FILE__);
!                               $rr = unlink ($p->real_full_path);
  
                                if ($query || $rr)
--- 2254,2266 ----
  
                                $query = $GLOBALS['phpgw']->db->query ("DELETE 
FROM phpgw_vfs WHERE directory='".$p->fake_leading_dirs_clean."' AND 
name='".$p->fake_name_clean."'".$this->extra_sql (array ('query_type' => 
VFS_SQL_DELETE)), __LINE__, __FILE__);
! 
!                               if ($this->file_actions)
!                               {
!                                       $rr = unlink ($p->real_full_path);
!                               }
!                               else
!                               {
!                                       $rr = True;
!                               }
  
                                if ($query || $rr)
***************
*** 2226,2230 ****
                                                )
                                        );
!                                       rmdir ($path->real_full_path);
                                }
  
--- 2332,2340 ----
                                                )
                                        );
! 
!                                       if ($this->file_actions)
!                                       {
!                                               rmdir ($path->real_full_path);
!                                       }
                                }
  
***************
*** 2239,2243 ****
                                $query = $GLOBALS['phpgw']->db->query ("DELETE 
FROM phpgw_vfs WHERE directory='$p->fake_leading_dirs_clean' AND 
name='$p->fake_name_clean'" . $this->extra_sql (array ('query_type' => 
VFS_SQL_DELETE)), __LINE__, __FILE__);
  
!                               rmdir ($p->real_full_path);
  
                                return True;
--- 2349,2356 ----
                                $query = $GLOBALS['phpgw']->db->query ("DELETE 
FROM phpgw_vfs WHERE directory='$p->fake_leading_dirs_clean' AND 
name='$p->fake_name_clean'" . $this->extra_sql (array ('query_type' => 
VFS_SQL_DELETE)), __LINE__, __FILE__);
  
!                               if ($this->file_actions)
!                               {
!                                       rmdir ($p->real_full_path);
!                               }
  
                                return True;
***************
*** 2302,2308 ****
                        umask (000);
  
!                       if (address@hidden ($p->real_full_path, 0770))
                        {
!                               return False;
                        }
  
--- 2415,2424 ----
                        umask (000);
  
!                       if ($this->file_actions)
                        {
!                               if (address@hidden ($p->real_full_path, 0770))
!                               {
!                                       return False;
!                               }
                        }
  
***************
*** 2450,2469 ****
                @param attributes keyed array of attributes.  key is attribute 
name, value is attribute value
                @result Boolean True/False
!               @discussion Valid attributes are:
!                               owner_id
!                               createdby_id
!                               modifiedby_id
!                               created
!                               modified
!                               size
!                               mime_type
!                               deleteable
!                               comment
!                               app
!                               link_directory
!                               link_name
!                               version
!                               name
!                               directory
                */
                function set_attributes ($data)
--- 2566,2570 ----
                @param attributes keyed array of attributes.  key is attribute 
name, value is attribute value
                @result Boolean True/False
!               @discussion Valid attributes are list in vfs->attributes
                */
                function set_attributes ($data)





reply via email to

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