forked from extern/egroupware
Enable symlinking VFS files to not yet existing entries
This commit is contained in:
parent
57240d4e8a
commit
ae491c0810
@ -225,17 +225,10 @@ class etemplate_widget_link extends etemplate_widget
|
||||
public static function link_existing($app_id, $files)
|
||||
{
|
||||
list($app, $id) = explode(':', $app_id);
|
||||
$app_path = "/apps/$app/$id";
|
||||
|
||||
if(!is_array($files)) $files = array($files);
|
||||
foreach($files as $target) {
|
||||
if (!egw_vfs::stat($target))
|
||||
{
|
||||
return lang('Link target %1 not found!',egw_vfs::decodePath($target));
|
||||
break;
|
||||
}
|
||||
$link = egw_vfs::concat($app_path,egw_vfs::basename($target));
|
||||
egw_vfs::symlink($target,$link);
|
||||
egw_link::link_file($app, $id, $target);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,14 +190,25 @@ var et2_link_to = et2_inputWidget.extend(
|
||||
}
|
||||
this.vfs_select = et2_createWidget("vfs-select", select_attrs,this);
|
||||
$j(this.vfs_select.getDOMNode()).change( function() {
|
||||
self.getRoot().iterateOver(
|
||||
function(widget) {
|
||||
if(widget.id == self.id) {
|
||||
widget._get_links();
|
||||
}
|
||||
},
|
||||
self, et2_link_list
|
||||
);
|
||||
var values = true;
|
||||
// If entry not yet saved, store for linking on server
|
||||
if(!self.options.value.to_id || typeof self.options.value.to_id == 'object')
|
||||
{
|
||||
values = self.options.value.to_id || {};
|
||||
var files = self.vfs_select.getValue();
|
||||
for(var i = 0; i < files.length; i++)
|
||||
{
|
||||
values['link:'+files[i]] = {
|
||||
app: 'link',
|
||||
id: files[i],
|
||||
type: 'unknown',
|
||||
icon: 'link',
|
||||
remark: '',
|
||||
title: files[i]
|
||||
};
|
||||
}
|
||||
}
|
||||
self._link_result(values);
|
||||
});
|
||||
|
||||
// File upload
|
||||
@ -329,7 +340,6 @@ var et2_link_to = et2_inputWidget.extend(
|
||||
if(typeof success == "object")
|
||||
{
|
||||
// Save as appropriate in value
|
||||
var i = 0;
|
||||
if(typeof this.options.value != "object")
|
||||
{
|
||||
this.options.value = {};
|
||||
|
@ -106,6 +106,12 @@ class egw_link extends solink
|
||||
* appname used for returned attached files (!= 'filemanager'!)
|
||||
*/
|
||||
const VFS_APPNAME = 'file'; // pseudo-appname for own file-attachments in vfs, this is NOT the vfs-app
|
||||
|
||||
/**
|
||||
* appname used for linking existing files to VFS
|
||||
*/
|
||||
const VFS_LINK = 'link';
|
||||
|
||||
/**
|
||||
* Baseurl for the attachments in the vfs
|
||||
*/
|
||||
@ -309,6 +315,10 @@ class egw_link extends solink
|
||||
{
|
||||
$link_id = self::attach_file($app1,$id1,$link['id'],$link['remark']);
|
||||
}
|
||||
else if ($link['app'] == self::VFS_LINK)
|
||||
{
|
||||
$link_id = self::link_file($app1,$id1, $link['id'],$link['remark']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$link_id = solink::link($app1,$id1,$link['app'],$link['id'],
|
||||
@ -343,6 +353,14 @@ class egw_link extends solink
|
||||
}
|
||||
return $link_id;
|
||||
}
|
||||
if ($app1 == self::VFS_LINK)
|
||||
{
|
||||
return self::link_file($app2,$id2,$id1,$remark);
|
||||
}
|
||||
elseif ($app2 == self::VFS_LINK)
|
||||
{
|
||||
return self::link_file($app1,$id1,$id2,$remark);
|
||||
}
|
||||
if ($app1 == self::VFS_APPNAME)
|
||||
{
|
||||
return self::attach_file($app2,$id2,$id1,$remark);
|
||||
@ -368,7 +386,7 @@ class egw_link extends solink
|
||||
*/
|
||||
static function temp_link_id($app,$id)
|
||||
{
|
||||
return $app.':'.($app != self::VFS_APPNAME ? $id : $id['name']);
|
||||
return $app.':'.($app != self::VFS_APPNAME && $app != self::VFS_LINK ? $id : $id['name']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1139,6 +1157,29 @@ class egw_link extends solink
|
||||
return $Ok ? -$Ok['ino'] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Links the entry to an existing file in the VFS
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
static function link_file($app,$id,$file,$comment='')
|
||||
{
|
||||
$app_path = self::vfs_path($app,$id);
|
||||
$ok = true;
|
||||
if (file_exists($app_path) || ($Ok = mkdir($app_path,0,true)))
|
||||
{
|
||||
if (!egw_vfs::stat($file))
|
||||
{
|
||||
error_log(__METHOD__. ' (Link target ' . egw_vfs::decodePath($file) . ' not found!');
|
||||
return false;
|
||||
}
|
||||
$link = egw_vfs::concat($app_path,egw_vfs::basename($file));
|
||||
}
|
||||
return egw_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!)
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user