From 1dc9dd0c6b46f7fcc4153cc3cf046780e6e6b518 Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 30 Sep 2021 12:01:37 -0600 Subject: [PATCH] * Add a preference so you can choose where merged documents are put --- api/src/Storage/Merge.php | 46 +++++++++++++++---- .../inc/class.filemanager_hooks.inc.php | 39 +++++++++------- 2 files changed, 60 insertions(+), 25 deletions(-) diff --git a/api/src/Storage/Merge.php b/api/src/Storage/Merge.php index 67276f64fc..0b738c062e 100644 --- a/api/src/Storage/Merge.php +++ b/api/src/Storage/Merge.php @@ -32,6 +32,9 @@ use ZipArchive; */ abstract class Merge { + + const PREF_STORE_LOCATION = "merge_store_path"; + /** * 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); } - // 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 - $target = $_target = (Vfs::is_writable(Vfs::get_home_dir()) ? - Vfs::get_home_dir() : - "/home/{$GLOBALS['egw_info']['user']['account_lid']}" - ) . "/$filename"; + $target = $document_merge->get_save_path($filename); + + // Make sure we won't overwrite something already there $target = Vfs::make_unique($target); + copy($result, Vfs::PREFIX . $target); unlink($result); // Find out what to do with it $editable_mimes = array(); - try { - if (class_exists('EGroupware\\collabora\\Bo') && + try + { + if(class_exists('EGroupware\\collabora\\Bo') && $GLOBALS['egw_info']['user']['apps']['collabora'] && ($discovery = \EGroupware\collabora\Bo::discover()) && $GLOBALS['egw_info']['user']['preferences']['filemanager']['merge_open_handler'] != 'download' @@ -2469,7 +2473,7 @@ abstract class Merge $converted_path = ''; $convert = new Conversion(); $convert->convert($target, $converted_path, 'pdf', $error); - + if($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 * @return string @@ -2506,6 +2510,30 @@ abstract class Merge 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 * diff --git a/filemanager/inc/class.filemanager_hooks.inc.php b/filemanager/inc/class.filemanager_hooks.inc.php index 35d15b0767..f13a16696b 100644 --- a/filemanager/inc/class.filemanager_hooks.inc.php +++ b/filemanager/inc/class.filemanager_hooks.inc.php @@ -161,27 +161,34 @@ class filemanager_hooks 'forced' => 'yes', ), 'showusers' => array( - 'type' => 'select', - 'name' => 'showusers', - 'values' => $yes_no, - 'label' => lang('Show link "%1" in side box menu?',lang('Users and groups')), - 'xmlrpc' => True, - 'admin' => False, - 'forced' => 'yes', + 'type' => 'select', + 'name' => 'showusers', + 'values' => $yes_no, + 'label' => lang('Show link "%1" in side box menu?', lang('Users and groups')), + 'xmlrpc' => True, + 'admin' => False, + '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( - 'type' => 'vfs_file', - 'size' => 60, - 'label' => 'Default document to insert entries', - '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')).' '. - 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()), + 'type' => 'vfs_file', + 'size' => 60, + 'label' => 'Default document to insert entries', + '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')) . ' ' . + 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()), 'run_lang' => false, - 'xmlrpc' => True, - 'admin' => False, + 'xmlrpc' => True, + 'admin' => False, ); $settings['document_dir'] = array( 'type' => 'vfs_dirs',