* Add a preference so you can choose where merged documents are put

This commit is contained in:
nathan 2021-09-30 12:01:37 -06:00
parent fdf6422da7
commit 1dc9dd0c6b
2 changed files with 60 additions and 25 deletions

View File

@ -32,6 +32,9 @@ use ZipArchive;
*/ */
abstract class Merge abstract class Merge
{ {
const PREF_STORE_LOCATION = "merge_store_path";
/** /**
* Instance of the addressbook_bo class * Instance of the addressbook_bo class
* *
@ -2434,20 +2437,21 @@ abstract class Merge
{ {
throw new Api\Exception\AssertionFailed("Unable to generate merge file\n" . $result); throw new Api\Exception\AssertionFailed("Unable to generate merge file\n" . $result);
} }
// Put it into the vfs using user's configured home dir if writable, // Put it into the vfs using user's preferred directory if writable,
// or expected home dir (/home/username) if not // or expected home dir (/home/username) if not
$target = $_target = (Vfs::is_writable(Vfs::get_home_dir()) ? $target = $document_merge->get_save_path($filename);
Vfs::get_home_dir() :
"/home/{$GLOBALS['egw_info']['user']['account_lid']}" // Make sure we won't overwrite something already there
) . "/$filename";
$target = Vfs::make_unique($target); $target = Vfs::make_unique($target);
copy($result, Vfs::PREFIX . $target); copy($result, Vfs::PREFIX . $target);
unlink($result); unlink($result);
// Find out what to do with it // Find out what to do with it
$editable_mimes = array(); $editable_mimes = array();
try { try
if (class_exists('EGroupware\\collabora\\Bo') && {
if(class_exists('EGroupware\\collabora\\Bo') &&
$GLOBALS['egw_info']['user']['apps']['collabora'] && $GLOBALS['egw_info']['user']['apps']['collabora'] &&
($discovery = \EGroupware\collabora\Bo::discover()) && ($discovery = \EGroupware\collabora\Bo::discover()) &&
$GLOBALS['egw_info']['user']['preferences']['filemanager']['merge_open_handler'] != 'download' $GLOBALS['egw_info']['user']['preferences']['filemanager']['merge_open_handler'] != 'download'
@ -2469,7 +2473,7 @@ abstract class Merge
$converted_path = ''; $converted_path = '';
$convert = new Conversion(); $convert = new Conversion();
$convert->convert($target, $converted_path, 'pdf', $error); $convert->convert($target, $converted_path, 'pdf', $error);
if($error) if($error)
{ {
error_log(__METHOD__ . "({$_REQUEST['document']}) $target => $converted_path Error in PDF conversion: $error"); error_log(__METHOD__ . "({$_REQUEST['document']}) $target => $converted_path Error in PDF conversion: $error");
@ -2496,7 +2500,7 @@ abstract class Merge
} }
/** /**
* Generate a filename for the merged file * Generate a filename for the merged file, without extension
* *
* Default is just the name of the template * Default is just the name of the template
* @return string * @return string
@ -2506,6 +2510,30 @@ abstract class Merge
return ''; return '';
} }
/**
* Return a path where we can save the generated file
* Takes into account user preference.
*
* @param string $filename The name of the generated file, including extension
* @return string
*/
protected function get_save_path($filename) : string
{
// Default is home directory
$target = (Vfs::is_writable(Vfs::get_home_dir()) ?
Vfs::get_home_dir() :
"/home/{$GLOBALS['egw_info']['user']['account_lid']}"
);
// Check for a configured preferred directory
if(($pref = $GLOBALS['egw_info']['user']['preferences']['filemanager'][Merge::PREF_STORE_LOCATION]) && Vfs::is_writable($pref))
{
$target = $pref;
}
return $target . "/$filename";
}
/** /**
* Get all ids for when they try to do 'Select All', then merge into document * Get all ids for when they try to do 'Select All', then merge into document
* *

View File

@ -161,27 +161,34 @@ class filemanager_hooks
'forced' => 'yes', 'forced' => 'yes',
), ),
'showusers' => array( 'showusers' => array(
'type' => 'select', 'type' => 'select',
'name' => 'showusers', 'name' => 'showusers',
'values' => $yes_no, 'values' => $yes_no,
'label' => lang('Show link "%1" in side box menu?',lang('Users and groups')), 'label' => lang('Show link "%1" in side box menu?', lang('Users and groups')),
'xmlrpc' => True, 'xmlrpc' => True,
'admin' => False, 'admin' => False,
'forced' => 'yes', 'forced' => 'yes',
), ),
); );
$settings[Api\Storage\Merge::PREF_STORE_LOCATION] = array(
'type' => 'vfs_dir',
'size' => 60,
'label' => 'Directory for storing merged documents',
'name' => Api\Storage\Merge::PREF_STORE_LOCATION,
'help' => lang('When you merge entries into documents, they will be stored here. If no directory is provided, they will be stored in %1', Vfs::get_home_dir())
);
$settings['default_document'] = array( $settings['default_document'] = array(
'type' => 'vfs_file', 'type' => 'vfs_file',
'size' => 60, 'size' => 60,
'label' => 'Default document to insert entries', 'label' => 'Default document to insert entries',
'name' => 'default_document', 'name' => 'default_document',
'help' => lang('If you specify a document (full vfs path) here, %1 displays an extra document icon for each entry. That icon allows to download the specified document with the data inserted.',lang('filemanager')).' '. 'help' => lang('If you specify a document (full vfs path) here, %1 displays an extra document icon for each entry. That icon allows to download the specified document with the data inserted.', lang('filemanager')) . ' ' .
lang('The document can contain placeholder like {{%1}}, to be replaced with the data.', 'name').' '. lang('The document can contain placeholder like {{%1}}, to be replaced with the data.', 'name') . ' ' .
lang('The following document-types are supported:'). implode(',',Api\Storage\Merge::get_file_extensions()), lang('The following document-types are supported:') . implode(',', Api\Storage\Merge::get_file_extensions()),
'run_lang' => false, 'run_lang' => false,
'xmlrpc' => True, 'xmlrpc' => True,
'admin' => False, 'admin' => False,
); );
$settings['document_dir'] = array( $settings['document_dir'] = array(
'type' => 'vfs_dirs', 'type' => 'vfs_dirs',