* 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
{
const PREF_STORE_LOCATION = "merge_store_path";
/**
* Instance of the addressbook_bo class
*
@ -2434,19 +2437,20 @@ 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 {
try
{
if(class_exists('EGroupware\\collabora\\Bo') &&
$GLOBALS['egw_info']['user']['apps']['collabora'] &&
($discovery = \EGroupware\collabora\Bo::discover()) &&
@ -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
*

View File

@ -171,6 +171,13 @@ class filemanager_hooks
),
);
$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,