From 366a9400305fd9e65d87f3c40306b66b24fd6322 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 17 Aug 2016 16:05:26 +0200 Subject: [PATCH] * All apps: symlink files to not yet saved entries were not working --- api/js/etemplate/et2_widget_link.js | 8 ++++++-- api/src/Etemplate/Widget/Link.php | 5 +++++ api/src/Link.php | 25 +++++++++++++------------ infolog/inc/class.infolog_ui.inc.php | 3 ++- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/api/js/etemplate/et2_widget_link.js b/api/js/etemplate/et2_widget_link.js index 75d3864571..fdfc79b1ca 100644 --- a/api/js/etemplate/et2_widget_link.js +++ b/api/js/etemplate/et2_widget_link.js @@ -178,11 +178,15 @@ var et2_link_to = (function(){ "use strict"; return et2_inputWidget.extend( // Filemanager select var select_attrs = { - method: 'EGroupware\\Api\\Etemplate\\Widget\\Link::link_existing', - method_id: function() { return self.options.value.to_app + ':' + self.options.value.to_id;}, button_label: egw.lang('Link'), button_caption: '' }; + // only set server-side callback, if we have a real application-id (not null or array) + // otherwise it only gives an error on server-side + if (self.options.value.to_id && typeof self.options.value.to_id != 'object') { + select_attrs.method = 'EGroupware\\Api\\Etemplate\\Widget\\Link::link_existing'; + select_attrs.method_id = self.options.value.to_app + ':' + self.options.value.to_id; + } this.vfs_select = et2_createWidget("vfs-select", select_attrs,this); jQuery(this.vfs_select.getDOMNode()).change( function() { var values = true; diff --git a/api/src/Etemplate/Widget/Link.php b/api/src/Etemplate/Widget/Link.php index 7a8a0eee4d..afedccb0ce 100644 --- a/api/src/Etemplate/Widget/Link.php +++ b/api/src/Etemplate/Widget/Link.php @@ -248,6 +248,11 @@ class Link extends Etemplate\Widget public static function link_existing($app_id, $files) { list($app, $id, $dest_file) = explode(':', $app_id); + + if (empty($app_id) || empty($id)) + { + return; // cant do anything + } if($id && $dest_file && trim($dest_file) !== '') { $id .= "/$dest_file"; diff --git a/api/src/Link.php b/api/src/Link.php index 0829e11273..64573784b3 100644 --- a/api/src/Link.php +++ b/api/src/Link.php @@ -1197,26 +1197,27 @@ class Link extends Link\Storage * @param string $app appname to link the file to * @param string $id id in $app * @param string $file VFS path to link to - * @param string $comment ='' comment to add to the link + * @return boolean true on success, false on failure */ - static function link_file($app,$id,$file)//,$comment='') + static function link_file($app,$id,$file) { // Don't try to link into app dir if there is no id if(!$id) return; - $app_path = self::vfs_path($app,$id); - $ok = true; - if (Vfs::file_exists($app_path) || ($ok = Vfs::mkdir($app_path,0,true))) + if (!Vfs::stat($file)) { - if (!Vfs::stat($file)) - { - error_log(__METHOD__. ' (Link target ' . Vfs::decodePath($file) . ' not found!'); - return false; - } + error_log(__METHOD__. ' (Link target ' . Vfs::decodePath($file) . ' not found!'); + return false; } - $link = Vfs::concat($app_path,Vfs::basename($file)); - return Vfs::symlink($file,$link); + $entry_dir = self::vfs_path($app, $id); + if (!file_exists($entry_dir) && !mkdir($entry_dir, 0, true)) + { + error_log(__METHOD__."($app,$id,".array2string($file).") Can't mkdir $entry_dir!"); + return false; + } + + return Vfs::symlink($file, Vfs::concat($entry_dir, Vfs::basename($file))); } /** * deletes a single or all attached files of an entry (for all there's no acl check, as the entry probably not exists any more!) diff --git a/infolog/inc/class.infolog_ui.inc.php b/infolog/inc/class.infolog_ui.inc.php index d68af7eac2..b728daddec 100644 --- a/infolog/inc/class.infolog_ui.inc.php +++ b/infolog/inc/class.infolog_ui.inc.php @@ -1817,8 +1817,9 @@ class infolog_ui { //echo "

writing links for new entry $info_id

\n"; _debug_array($content['link_to']['to_id']); Link::link('infolog',$info_id,$content['link_to']['to_id']); - $content['link_to']['to_id'] = $info_id; } + $content['link_to']['to_id'] = $info_id; + if ($info_link_id && strpos($info_link_id,':') !== false) // updating info_link_id if necessary { list($app,$id) = explode(':',$info_link_id);