Merge branch 'seeddms-5.1.x' into seeddms-6.0.x

This commit is contained in:
Uwe Steinmann 2020-05-25 15:57:49 +02:00
commit 3e45348b31
3 changed files with 120 additions and 70 deletions

View File

@ -70,7 +70,7 @@ if (!isset($_COOKIE["mydms_session"])) {
$dms_session = $_COOKIE["mydms_session"]; $dms_session = $_COOKIE["mydms_session"];
$session = new SeedDMS_Session($db); $session = new SeedDMS_Session($db);
if(!$resArr = $session->load($dms_session)) { if(!$resArr = $session->load($dms_session)) {
setcookie("mydms_session", $dms_session, time()-3600, $settings->_httpRoot); //delete cookie setcookie("mydms_session", $dms_session, array('expires'=>time()-3600, 'path'=>$settings->_httpRoot)); //delete cookie
if(!$isajax) if(!$isajax)
header("Location: " . $settings->_httpRoot . "out/out.Login.php?referuri=".$refer); header("Location: " . $settings->_httpRoot . "out/out.Login.php?referuri=".$refer);
exit; exit;
@ -84,7 +84,7 @@ if((int)$resArr['lastAccess']+60 < time())
/* Load user data */ /* Load user data */
$user = $dms->getUser($resArr["userID"]); $user = $dms->getUser($resArr["userID"]);
if (!is_object($user)) { if (!is_object($user)) {
setcookie("mydms_session", $dms_session, time()-3600, $settings->_httpRoot); //delete cookie setcookie("mydms_session", $dms_session, array('expires'=>time()-3600, 'path'=>$settings->_httpRoot)); //delete cookie
if(!$isajax) if(!$isajax)
header("Location: " . $settings->_httpRoot . "out/out.Login.php?referuri=".$refer); header("Location: " . $settings->_httpRoot . "out/out.Login.php?referuri=".$refer);
exit; exit;
@ -175,5 +175,5 @@ if($settings->_enable2FactorAuthentication && $settings->_guestID != $user->getI
if($settings->_cookieLifetime) { if($settings->_cookieLifetime) {
$lifetime = time() + intval($settings->_cookieLifetime); $lifetime = time() + intval($settings->_cookieLifetime);
/* Turn off http only cookies if jumploader is enabled */ /* Turn off http only cookies if jumploader is enabled */
setcookie("mydms_session", $dms_session, $lifetime, $settings->_httpRoot, null, null, !$settings->_enableLargeFileUpload); setcookie("mydms_session", $dms_session, array('expires'=>$lifetime, 'path'=>$settings->_httpRoot, 'httponly'=>!$settings->_enableLargeFileUpload));
} }

View File

@ -1,40 +1,47 @@
<?php <?php
if(isset($_SERVER['SEEDDMS_HOME'])) { if(isset($_SERVER['SEEDDMS_HOME'])) {
ini_set('include_path', $_SERVER['SEEDDMS_HOME'].'/utils'. PATH_SEPARATOR .ini_get('include_path')); ini_set('include_path', $_SERVER['SEEDDMS_HOME'].'/utils'. PATH_SEPARATOR .ini_get('include_path'));
$myincpath = $_SERVER['SEEDDMS_HOME'];
} else { } else {
ini_set('include_path', dirname($argv[0]). PATH_SEPARATOR .ini_get('include_path')); ini_set('include_path', dirname($argv[0]). PATH_SEPARATOR .ini_get('include_path'));
$myincpath = dirname($argv[0]);
} }
function usage() { /* {{{ */ function usage() { /* {{{ */
echo "Usage:\n"; echo "Usage:\n";
echo " seeddms-adddoc [--config <file>] [-c <comment>] [-k <keywords>] [-s <number>] [-n <name>] [-V <version>] [-s <sequence>] [-t <mimetype>] [-a <attribute=value>] [-h] [-v] -F <folder id> -f <filename>\n"; echo " seeddms-adddoc [--config <file>] [-c <comment>] [-k <keywords>] [-s <number>] [-n <name>] [-V <version>] [-s <sequence>] [-t <mimetype>] [-a <attribute=value>] [-h] [-v] -F <folder id> -D <document id> -f <filename>\n";
echo "\n"; echo "\n";
echo "Description:\n"; echo "Description:\n";
echo " This program uploads a file into a folder of SeedDMS.\n"; echo " This program uploads a file into a folder or updates a document of SeedDMS.\n";
echo "\n"; echo "\n";
echo "Options:\n"; echo "Options:\n";
echo " -h, --help: print usage information and exit.\n"; echo " -h, --help: print usage information and exit.\n";
echo " -v, --version: print version and exit.\n"; echo " -v, --version: print version and exit.\n";
echo " --config: set alternative config file.\n"; echo " --config: set alternative config file.\n";
echo " -F <folder id>: id of folder the file is uploaded to\n"; echo " -F <folder id>: id of folder the file is uploaded to\n";
echo " -c <comment>: set comment for document\n"; echo " -D <document id>: id of document the file is uploaded to.\n";
echo " This will only be used if no folder id is given.\n";
echo " -c <comment>: set comment for document. See [1].\n";
echo " -C <comment>: set comment for version\n"; echo " -C <comment>: set comment for version\n";
echo " -k <keywords>: set keywords for file\n"; echo " -k <keywords>: set keywords for file. See [1].\n";
echo " -K <categories>: set categories for file\n"; echo " -K <categories>: set categories for file. See [1].\n";
echo " -s <number>: set sequence for file (used for ordering files within a folder\n"; echo " -s <number>: set sequence for file (used for ordering files within a folder. See [1].\n";
echo " -n <name>: set name of file\n"; echo " -n <name>: set name of file\n";
echo " -V <version>: set version of file (defaults to 1).\n"; echo " -V <version>: set version of file (defaults to 1). See [2].\n";
echo " -u <user>: login name of user\n"; echo " -u <user>: login name of user\n";
echo " -f <filename>: upload this file\n"; echo " -f <filename>: upload this file\n";
echo " -s <sequence>: set sequence of file\n"; echo " -s <sequence>: set sequence of file. See [1]\n";
echo " -t <mimetype> set mimetype of file manually. Do not do that unless you know\n"; echo " -t <mimetype> set mimetype of file manually. Do not do that unless you know\n";
echo " what you do. If not set, the mimetype will be determined automatically.\n"; echo " what you do. If not set, the mimetype will be determined automatically.\n";
echo " -a <attribute=value>: Set a document attribute; can occur multiple times.\n"; echo " -a <attribute=value>: Set a document attribute; can occur multiple times. See [1].\n";
echo " -A <attribute=value>: Set a version attribute; can occur multiple times.\n"; echo " -A <attribute=value>: Set a version attribute; can occur multiple times.\n";
echo "\n";
echo "[1] This option applies only if a new document is uploaded. It has no effect\n"." if a new document version is uploaded.\n";
echo "[2] If a new document version is uploaded it defaults to the next version number.\n";
} /* }}} */ } /* }}} */
$version = "0.0.1"; $version = "0.0.1";
$shortoptions = "F:c:C:k:K:s:V:u:f:n:t:a:A:hv"; $shortoptions = "D:F:c:C:k:K:s:V:u:f:n:t:a:A:hv";
$longoptions = array('help', 'version', 'config:'); $longoptions = array('help', 'version', 'config:');
if(false === ($options = getopt($shortoptions, $longoptions))) { if(false === ($options = getopt($shortoptions, $longoptions))) {
usage(); usage();
@ -58,14 +65,19 @@ if(isset($options['config'])) {
define('SEEDDMS_CONFIG_FILE', $options['config']); define('SEEDDMS_CONFIG_FILE', $options['config']);
} }
/* Set parent folder */ /* Set parent folder or document */
$folderid = $documentid = 0;
if(isset($options['F'])) { if(isset($options['F'])) {
$folderid = (int) $options['F']; $folderid = (int) $options['F'];
} else { } else {
echo "Missing folder ID\n"; if(isset($options['D'])) {
$documentid = (int) $options['D'];
} else {
echo "Missing folder/document ID\n";
usage(); usage();
exit(1); exit(1);
} }
}
/* Set comment of document */ /* Set comment of document */
$comment = ''; $comment = '';
@ -120,13 +132,13 @@ if(isset($options['V'])) {
if($reqversion<1) if($reqversion<1)
$reqversion=1; $reqversion=1;
include("../inc/inc.Settings.php"); include($myincpath."/inc/inc.Settings.php");
include("../inc/inc.Init.php"); include($myincpath."/inc/inc.Init.php");
include("../inc/inc.Extension.php"); include($myincpath."/inc/inc.Extension.php");
include("../inc/inc.DBInit.php"); include($myincpath."/inc/inc.DBInit.php");
include("../inc/inc.ClassNotificationService.php"); include($myincpath."/inc/inc.ClassNotificationService.php");
include("../inc/inc.ClassEmailNotify.php"); include($myincpath."/inc/inc.ClassEmailNotify.php");
include("../inc/inc.ClassController.php"); include($myincpath."/inc/inc.ClassController.php");
/* Parse categories {{{ */ /* Parse categories {{{ */
$categories = array(); $categories = array();
@ -239,15 +251,18 @@ if(is_readable($filename)) {
} }
$filetype = "." . pathinfo($filename, PATHINFO_EXTENSION); $filetype = "." . pathinfo($filename, PATHINFO_EXTENSION);
} else { } else {
echo "File has zero size\n"; echo "File '".$filename."' has zero size\n";
exit(1); exit(1);
} }
} else { } else {
echo "File is not readable\n"; echo "File '".$filename."' is not readable\n";
exit(1); exit(1);
} }
/* }}} */ /* }}} */
$folder = null;
$document = null;
if($folderid) {
$folder = $dms->getFolder($folderid); $folder = $dms->getFolder($folderid);
if (!is_object($folder)) { if (!is_object($folder)) {
@ -259,6 +274,19 @@ if ($folder->getAccessMode($user) < M_READWRITE) {
echo "Not sufficient access rights\n"; echo "Not sufficient access rights\n";
exit(1); exit(1);
} }
} elseif($documentid) {
$document = $dms->getDocument($documentid);
if (!is_object($document)) {
echo "Could not find specified document\n";
exit(1);
}
if ($document->getAccessMode($user) < M_READWRITE) {
echo "Not sufficient access rights\n";
exit(1);
}
}
if (!is_numeric($sequence)) { if (!is_numeric($sequence)) {
echo "Sequence must be numeric\n"; echo "Sequence must be numeric\n";
@ -282,6 +310,7 @@ if($settings->_enableFullSearch) {
$indexconf = null; $indexconf = null;
} }
if($folder) {
$controller = Controller::factory('AddDocument', array('dms'=>$dms, 'user'=>$user)); $controller = Controller::factory('AddDocument', array('dms'=>$dms, 'user'=>$user));
$controller->setParam('documentsource', 'script'); $controller->setParam('documentsource', 'script');
$controller->setParam('folder', $folder); $controller->setParam('folder', $folder);
@ -318,4 +347,25 @@ if(!$document = $controller->run()) {
echo "Could not add document to folder\n"; echo "Could not add document to folder\n";
exit(1); exit(1);
} }
} elseif($document) {
$controller = Controller::factory('UpdateDocument', array('dms'=>$dms, 'user'=>$user));
$controller->setParam('folder', $document->getFolder());
$controller->setParam('document', $document);
$controller->setParam('index', $index);
$controller->setParam('indexconf', $indexconf);
$controller->setParam('comment', $comment);
$controller->setParam('userfiletmp', $filetmp);
$controller->setParam('userfilename', $filename);
$controller->setParam('filetype', $filetype);
$controller->setParam('userfiletype', $mimetype);
$controller->setParam('reviewers', $reviewers);
$controller->setParam('approvers', $approvers);
$controller->setParam('attributes', $version_attributes);
$controller->setParam('workflow', null);
if(!$content = $controller->run()) {
echo "Could not add version to document\n";
exit(1);
}
}
?> ?>

View File

@ -1,8 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
if [ -z "${SEEDDMS_HOME}" ]; then if [ -z "${SEEDDMS_HOME}" ]; then
echo 'Please set $SEEDDMS_HOME before running this script' parentdir=$(dirname "$0")
exit 1 export SEEDDMS_HOME=$(dirname "$parentdir")
fi fi
exec php -f "${SEEDDMS_HOME}/utils/adddoc.php" -- "${@}" exec php -f "${SEEDDMS_HOME}/utils/adddoc.php" -- "${@}"