* All apps: symlink files to not yet saved entries were not working

This commit is contained in:
Ralf Becker 2016-08-17 16:05:26 +02:00
parent 41c89e0f7e
commit 366a940030
4 changed files with 26 additions and 15 deletions

View File

@ -178,11 +178,15 @@ var et2_link_to = (function(){ "use strict"; return et2_inputWidget.extend(
// Filemanager select // Filemanager select
var select_attrs = { 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_label: egw.lang('Link'),
button_caption: '' 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); this.vfs_select = et2_createWidget("vfs-select", select_attrs,this);
jQuery(this.vfs_select.getDOMNode()).change( function() { jQuery(this.vfs_select.getDOMNode()).change( function() {
var values = true; var values = true;

View File

@ -248,6 +248,11 @@ class Link extends Etemplate\Widget
public static function link_existing($app_id, $files) public static function link_existing($app_id, $files)
{ {
list($app, $id, $dest_file) = explode(':', $app_id); 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) !== '') if($id && $dest_file && trim($dest_file) !== '')
{ {
$id .= "/$dest_file"; $id .= "/$dest_file";

View File

@ -1197,26 +1197,27 @@ class Link extends Link\Storage
* @param string $app appname to link the file to * @param string $app appname to link the file to
* @param string $id id in $app * @param string $id id in $app
* @param string $file VFS path to link to * @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 // Don't try to link into app dir if there is no id
if(!$id) return; 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!'); error_log(__METHOD__. ' (Link target ' . Vfs::decodePath($file) . ' not found!');
return false; return false;
} }
$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;
} }
$link = Vfs::concat($app_path,Vfs::basename($file)); return Vfs::symlink($file, Vfs::concat($entry_dir, Vfs::basename($file)));
return Vfs::symlink($file,$link);
} }
/** /**
* 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!) * 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!)

View File

@ -1817,8 +1817,9 @@ class infolog_ui
{ {
//echo "<p>writing links for new entry $info_id</p>\n"; _debug_array($content['link_to']['to_id']); //echo "<p>writing links for new entry $info_id</p>\n"; _debug_array($content['link_to']['to_id']);
Link::link('infolog',$info_id,$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 if ($info_link_id && strpos($info_link_id,':') !== false) // updating info_link_id if necessary
{ {
list($app,$id) = explode(':',$info_link_id); list($app,$id) = explode(':',$info_link_id);