From 8d7a9b72841fb4084bca8e26e6c516df32ee4b7c Mon Sep 17 00:00:00 2001 From: nathangray Date: Mon, 17 Apr 2017 09:48:25 -0600 Subject: [PATCH] Move VFS widget file handling from Etemplate/Widget/Customfields to Storage/Customfields, to avoid errors with CalDAV/CardDAV not being able to find Etemplate/Widget/Customfields --- api/src/Etemplate/Widget/Customfields.php | 54 ----------------------- api/src/Storage.php | 2 +- api/src/Storage/Customfields.php | 53 ++++++++++++++++++++++ calendar/inc/class.calendar_so.inc.php | 2 +- infolog/inc/class.infolog_so.inc.php | 2 +- 5 files changed, 56 insertions(+), 57 deletions(-) diff --git a/api/src/Etemplate/Widget/Customfields.php b/api/src/Etemplate/Widget/Customfields.php index 7824388a91..d8f00b13c0 100644 --- a/api/src/Etemplate/Widget/Customfields.php +++ b/api/src/Etemplate/Widget/Customfields.php @@ -417,58 +417,4 @@ class Customfields extends Transformer //error_log(__METHOD__."() $form_name $field: ".array2string($value).' --> '.array2string($value)); } } - - /** - * Handle any uploaded files that weren't dealt with immediately when uploaded. - * This usually happens for new entries, where we don't have the entry's ID - * to properly file it in the VFS. Files are stored temporarily until we - * have the ID, then here we move the files to their proper location. - * - * @staticvar array $_customfields List of custom field data, kept to avoid - * loading it multiple times if called again. - * - * @param string $app Current application - * @param string $entry_id Application ID of the new entry - * @param Array $values Array of entry data, including custom fields. - * File information from the VFS widget (via self::validate()) will be found & - * dealt with. Successful or not, the value is cleared to avoid trying to insert it into - * the database, which would generate errors. - * @param Array $customfields Pass the custom field list if you have it to avoid loading it again - */ - public static function handle_files($app, $entry_id, &$values, &$customfields = array()) - { - if(!is_array($values) || !$entry_id) return; - - if(!$customfields) - { - static $_customfields = array(); - if(!$_customfields[$app]) - { - $_customfields[$app] = Api\Storage\Customfields::get($app); - } - $customfields = $_customfields[$app]; - } - foreach ($customfields as $field_name => $field) - { - if($field['type'] == 'filemanager') - { - $value =& $values[static::$prefix.$field_name]; - static::handle_file($entry_id, $field, $value); - unset($values[static::$prefix.$field_name]); - } - } - } - - protected static function handle_file($entry_id, $field, $value) - { - $path = Vfs::get_vfs_path($field['app'].":$entry_id:".$field['label']); - if($path) - { - foreach($value as $file) - { - $file['tmp_name'] = Api\Vfs::PREFIX.$file['path']; - Vfs::store_file($path, $file); - } - } - } } diff --git a/api/src/Storage.php b/api/src/Storage.php index 9bf8e26f52..cd2a3d2ed1 100644 --- a/api/src/Storage.php +++ b/api/src/Storage.php @@ -220,7 +220,7 @@ class Storage extends Storage\Base { $id = isset($data[$this->autoinc_id]) ? $data[$this->autoinc_id] : $data[$this->db_key_cols[$this->autoinc_id]]; - \EGroupware\Api\Etemplate\Widget\Customfields::handle_files($this->app, $id, $data, $this->customfields); + \EGroupware\Api\Storage\Customfields::handle_files($this->app, $id, $data, $this->customfields); foreach (array_keys((array)$this->customfields) as $name) { diff --git a/api/src/Storage/Customfields.php b/api/src/Storage/Customfields.php index 1f83b27a17..4690833b0e 100755 --- a/api/src/Storage/Customfields.php +++ b/api/src/Storage/Customfields.php @@ -544,6 +544,59 @@ class Customfields implements \IteratorAggregate self::$db = $GLOBALS['egw_setup']->db; } } + + /** + * Handle any uploaded files that weren't dealt with immediately when uploaded. + * This usually happens for new entries, where we don't have the entry's ID + * to properly file it in the VFS. Files are stored temporarily until we + * have the ID, then here we move the files to their proper location. + * + * @staticvar array $_customfields List of custom field data, kept to avoid + * loading it multiple times if called again. + * + * @param string $app Current application + * @param string $entry_id Application ID of the new entry + * @param Array $values Array of entry data, including custom fields. + * File information from the VFS widget (via self::validate()) will be found & + * dealt with. Successful or not, the value is cleared to avoid trying to insert it into + * the database, which would generate errors. + * @param Array $customfields Pass the custom field list if you have it to avoid loading it again + */ + public static function handle_files($app, $entry_id, &$values, &$customfields = array()) + { + if(!is_array($values) || !$entry_id) return; + + if(!$customfields) + { + static $_customfields = array(); + if(!$_customfields[$app]) + { + $_customfields[$app] = Api\Storage\Customfields::get($app); + } + $customfields = $_customfields[$app]; + } + foreach ($customfields as $field_name => $field) + { + if($field['type'] == 'filemanager' && $value =& $values[Api\Storage::CF_PREFIX.$field_name]) + { + static::handle_file($entry_id, $field, $value); + unset($values[Api\Storage::CF_PREFIX.$field_name]); + } + } + } + + protected static function handle_file($entry_id, $field, $value) + { + $path = Api\Etemplate\Widget\Vfs::get_vfs_path($field['app'].":$entry_id:".$field['label']); + if($path) + { + foreach($value as $file) + { + $file['tmp_name'] = Api\Vfs::PREFIX.$file['path']; + Api\Etemplate\Widget\Vfs::store_file($path, $file); + } + } + } } Customfields::init_static(); diff --git a/calendar/inc/class.calendar_so.inc.php b/calendar/inc/class.calendar_so.inc.php index 425edafa8c..950882fd93 100644 --- a/calendar/inc/class.calendar_so.inc.php +++ b/calendar/inc/class.calendar_so.inc.php @@ -1632,7 +1632,7 @@ ORDER BY cal_user_type, cal_usre_id $this->participants($cal_id,$event['cal_participants'],!$cal_id ? false : $change_since); } // Custom fields - Api\Etemplate\Widget\Customfields::handle_files('calendar', $cal_id, $event); + Api\Storage\Customfields::handle_files('calendar', $cal_id, $event); foreach($event as $name => $value) { diff --git a/infolog/inc/class.infolog_so.inc.php b/infolog/inc/class.infolog_so.inc.php index b4af05a4a0..488be33649 100644 --- a/infolog/inc/class.infolog_so.inc.php +++ b/infolog/inc/class.infolog_so.inc.php @@ -632,7 +632,7 @@ class infolog_so $to_delete = array(); // Deal with files in new entries - Api\Etemplate\Widget\Customfields::handle_files('infolog',$info_id,$values); + Api\Storage\Customfields::handle_files('infolog',$info_id,$values); foreach($values as $key => $val) {