add parameters keepfile and dryrun to import drop folder task

This commit is contained in:
Uwe Steinmann 2023-10-14 13:47:27 +02:00
parent 1085401ccf
commit 568718f023

View File

@ -914,63 +914,71 @@ class SeedDMS_ImportDropFolderTask extends SeedDMS_SchedulerTaskBase { /* {{{ */
foreach($files as $file) {
$logger->log('Task \'import_dropfolder\': import \''.($file[0] ? $file[0].DIRECTORY_SEPARATOR : '').$file[1].'\' for user \''.$user->getLogin().'\'', PEAR_LOG_INFO);
$mimetype = SeedDMS_Core_File::mimetype($dir.DIRECTORY_SEPARATOR.$file[0].$file[1]);
$lastDotIndex = strrpos($file[1], ".");
if (is_bool($lastDotIndex) && !$lastDotIndex) $filetype = ".";
else $filetype = substr($file[1], $lastDotIndex);
if(empty($taskparams['dryrun'])) {
$mimetype = SeedDMS_Core_File::mimetype($dir.DIRECTORY_SEPARATOR.$file[0].$file[1]);
$lastDotIndex = strrpos($file[1], ".");
if (is_bool($lastDotIndex) && !$lastDotIndex) $filetype = ".";
else $filetype = substr($file[1], $lastDotIndex);
$expires = false;
if($settings->_presetExpirationDate) {
$expires = strtotime($settings->_presetExpirationDate);
}
$controller = Controller::factory('AddDocument', array('dms'=>$dms, 'user'=>$user));
$controller->setParam('documentsource', 'importdropfolder');
$controller->setParam('folder', $folder);
$controller->setParam('fulltextservice', $fulltextservice);
$controller->setParam('name', $file[1]);
$controller->setParam('comment', '');
$controller->setParam('expires', $expires);
$controller->setParam('keywords', '');
$controller->setParam('categories', []);
$controller->setParam('owner', $user);
$controller->setParam('userfiletmp', $dir.DIRECTORY_SEPARATOR.$file[0].$file[1]);
$controller->setParam('userfilename', $file[1]);
$controller->setParam('filetype', $filetype);
$controller->setParam('userfiletype', $mimetype);
$minmax = $folder->getDocumentsMinMax();
$deviation = rand(10, 1000)/10;
if($settings->_defaultDocPosition == 'start')
$controller->setParam('sequence', $minmax['min'] - $deviation);
else
$controller->setParam('sequence', $minmax['max'] + $deviation);
$controller->setParam('reviewers', []);
$controller->setParam('approvers', []);
$controller->setParam('reqversion', 1);
$controller->setParam('versioncomment', '');
$controller->setParam('attributes', []);
$controller->setParam('attributesversion', array());
$controller->setParam('workflow', null);
$controller->setParam('notificationgroups', array());
$controller->setParam('notificationusers', array());
$controller->setParam('initialdocumentstatus', $settings->_initialDocumentStatus);
$controller->setParam('maxsizeforfulltext', $settings->_maxSizeForFullText);
$controller->setParam('defaultaccessdocs', $settings->_defaultAccessDocs);
if(!$document = $controller()) {
$err = $controller->getErrorMsg();
if(is_string($err))
$errmsg = getMLText($err);
elseif(is_array($err)) {
$errmsg = getMLText($err[0], $err[1]);
} else {
$errmsg = $err;
$expires = false;
if($settings->_presetExpirationDate) {
$expires = strtotime($settings->_presetExpirationDate);
}
$logger->log('Task \'import_dropfolder\': import of \''.($file[0] ? $file[0].DIRECTORY_SEPARATOR : '').$file[1].'\' for user \''.$user->getLogin().'\' failed', PEAR_LOG_ERR);
} else {
// Send notification to subscribers of folder.
if($notifier) {
$notifier->sendNewDocumentMail($document, $user);
$controller = Controller::factory('AddDocument', array('dms'=>$dms, 'user'=>$user));
$controller->setParam('documentsource', 'importdropfolder');
$controller->setParam('folder', $folder);
$controller->setParam('fulltextservice', $fulltextservice);
$controller->setParam('name', $file[1]);
$controller->setParam('comment', '');
$controller->setParam('expires', $expires);
$controller->setParam('keywords', '');
$controller->setParam('categories', []);
$controller->setParam('owner', $user);
$controller->setParam('userfiletmp', $dir.DIRECTORY_SEPARATOR.$file[0].$file[1]);
$controller->setParam('userfilename', $file[1]);
$controller->setParam('filetype', $filetype);
$controller->setParam('userfiletype', $mimetype);
$minmax = $folder->getDocumentsMinMax();
$deviation = rand(10, 1000)/10;
if($settings->_defaultDocPosition == 'start')
$controller->setParam('sequence', $minmax['min'] - $deviation);
else
$controller->setParam('sequence', $minmax['max'] + $deviation);
$controller->setParam('reviewers', []);
$controller->setParam('approvers', []);
$controller->setParam('reqversion', 1);
$controller->setParam('versioncomment', '');
$controller->setParam('attributes', []);
$controller->setParam('attributesversion', array());
$controller->setParam('workflow', null);
$controller->setParam('notificationgroups', array());
$controller->setParam('notificationusers', array());
$controller->setParam('initialdocumentstatus', $settings->_initialDocumentStatus);
$controller->setParam('maxsizeforfulltext', $settings->_maxSizeForFullText);
$controller->setParam('defaultaccessdocs', $settings->_defaultAccessDocs);
if(!$document = $controller()) {
$err = $controller->getErrorMsg();
if(is_string($err))
$errmsg = getMLText($err);
elseif(is_array($err)) {
$errmsg = getMLText($err[0], $err[1]);
} else {
$errmsg = $err;
}
$logger->log('Task \'import_dropfolder\': import of \''.($file[0] ? $file[0].DIRECTORY_SEPARATOR : '').$file[1].'\' for user \''.$user->getLogin().'\' failed', PEAR_LOG_ERR);
} else {
// Send notification to subscribers of folder.
if($notifier) {
$notifier->sendNewDocumentMail($document, $user);
}
/* Remove the file, unless it shall stay in the drop folder */
if(empty($taskparams['keepfile'])) {
if(file_exists($dir.DIRECTORY_SEPARATOR.$file[0].$file[1])) {
unlink($dir.DIRECTORY_SEPARATOR.$file[0].$file[1]);
}
}
}
}
}
@ -996,12 +1004,22 @@ class SeedDMS_ImportDropFolderTask extends SeedDMS_SchedulerTaskBase { /* {{{ */
array(
'name'=>'recursive',
'type'=>'boolean',
'description'=> 'If set, import documents from sub foldrers in drop folder directory.',
'description'=> 'If set, import documents from sub folders in drop folder directory.',
),
array(
'name'=>'targetfolder',
'type'=>'folder',
'description'=> getMLText('task_import_drop_folder_targetfolder_desc'),
'description'=> getMLText('task_core_importdropfolder_targetfolder_desc'),
),
array(
'name'=>'keepfile',
'type'=>'boolean',
'description'=> getMLText('task_core_importdropfolder_keepfile_desc'),
),
array(
'name'=>'dryrun',
'type'=>'boolean',
'description'=> getMLText('task_core_importdropfolder_dryrun_desc'),
),
);
} /* }}} */