From d1c2d068103bf6c68106255e292b34cd0a1176ae Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 13 Dec 2010 02:37:46 +0000 Subject: [PATCH] * copying (or reinstating earlier versions) of files now also copies the properties (MyStylite #975) --- phpgwapi/inc/class.egw_vfs.inc.php | 62 +++++++++++++++---- .../inc/class.sqlfs_stream_wrapper.inc.php | 4 +- 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/phpgwapi/inc/class.egw_vfs.inc.php b/phpgwapi/inc/class.egw_vfs.inc.php index 87d7630009..77fdd107d9 100644 --- a/phpgwapi/inc/class.egw_vfs.inc.php +++ b/phpgwapi/inc/class.egw_vfs.inc.php @@ -38,7 +38,7 @@ * - boolean egw_vfs::umount($path) to unmount a path or url * * The stream wrapper interface allows to access hugh files in junks to not be limited by the - * memory_limit setting of php. To do you should path a resource to the opened file and not the content: + * memory_limit setting of php. To do you should pass the opened file as resource and not the content: * * $file = egw_vfs::fopen('/home/user/somefile','r'); * $content = fread($file,1024); @@ -180,20 +180,60 @@ class egw_vfs extends vfs_stream_wrapper { $ret = false; + $old_props = self::file_exists($to) ? self::propfind($to,null) : array(); + if (($from_fp = self::fopen($from,'r')) && ($to_fp = self::fopen($to,'w'))) { $ret = stream_copy_to_stream($from_fp,$to_fp) !== false; } - if ($from_fp) - { - fclose($from_fp); - } - if ($to_fp) - { - fclose($to_fp); - } - return $ret; + if ($from_fp) + { + fclose($from_fp); + } + if ($to_fp) + { + fclose($to_fp); + + if ($ret) // successful copyied file + { + // copy properties (eg. file comment), if there are any and evtl. existing old properties + $props = self::propfind($from,null); + + foreach($old_props as $prop) + { + if (!self::find_prop($props,$prop)) + { + $prop['val'] = null; // null = delete prop + $props[] = $prop; + } + } + if ($props) self::proppatch($to, $props); + } + } + return $ret; + } + + /** + * Find a specific property in an array of properties (eg. returned by propfind) + * + * @param array &$props + * @param array|string $name property array or name + * @param string $ns=self::DEFAULT_PROP_NAMESPACE namespace, only if $prop is no array + * @return &array reference to property in $props or null if not found + */ + static function &find_prop(array &$props,$name,$ns=self::DEFAULT_PROP_NAMESPACE) + { + if (is_array($name)) + { + $ns = $name['ns']; + $name = $name['name']; + } + foreach($props as &$prop) + { + if ($prop['name'] == $name && $prop['ns'] == $ns) return $prop; + } + return null; } /** @@ -864,7 +904,7 @@ class egw_vfs extends vfs_stream_wrapper * Store properties for a single ressource (file or dir) * * @param string $path string with path - * @param array $props array or array with values for keys 'name', 'ns', 'val' (null to delete the prop) + * @param array $props array of array with values for keys 'name', 'ns', 'val' (null to delete the prop) * @return boolean true if props are updated, false otherwise (eg. ressource not found) */ static function proppatch($path,array $props) diff --git a/phpgwapi/inc/class.sqlfs_stream_wrapper.inc.php b/phpgwapi/inc/class.sqlfs_stream_wrapper.inc.php index d077472fb5..b7236c6552 100644 --- a/phpgwapi/inc/class.sqlfs_stream_wrapper.inc.php +++ b/phpgwapi/inc/class.sqlfs_stream_wrapper.inc.php @@ -1709,7 +1709,7 @@ class sqlfs_stream_wrapper implements iface_stream_wrapper * Store properties for a single ressource (file or dir) * * @param string|int $path string with path or integer fs_id - * @param array $props array or array with values for keys 'name', 'ns', 'val' (null to delete the prop) + * @param array $props array of array with values for keys 'name', 'ns', 'val' (null to delete the prop) * @return boolean true if props are updated, false otherwise (eg. ressource not found) */ static function proppatch($path,array $props) @@ -1812,7 +1812,7 @@ class sqlfs_stream_wrapper implements iface_stream_wrapper } if (!is_array($path_ids)) { - $props = $props[$row['fs_id']]; + $props = $props[$row['fs_id']] ? $props[$row['fs_id']] : array(); // return empty array for no props } elseif ($props && isset($stat)) // need to map fs_id's to pathes {