mirror of
https://git.code.sf.net/p/seeddms/code
synced 2024-11-26 07:22:11 +00:00
add support for uploading new document version
This commit is contained in:
parent
36f3ac6ab5
commit
dbfeae23db
|
@ -1,40 +1,47 @@
|
|||
<?php
|
||||
if(isset($_SERVER['SEEDDMS_HOME'])) {
|
||||
ini_set('include_path', $_SERVER['SEEDDMS_HOME'].'/utils'. PATH_SEPARATOR .ini_get('include_path'));
|
||||
$myincpath = $_SERVER['SEEDDMS_HOME'];
|
||||
} else {
|
||||
ini_set('include_path', dirname($argv[0]). PATH_SEPARATOR .ini_get('include_path'));
|
||||
$myincpath = dirname($argv[0]);
|
||||
}
|
||||
|
||||
function usage() { /* {{{ */
|
||||
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 "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 "Options:\n";
|
||||
echo " -h, --help: print usage information and exit.\n";
|
||||
echo " -v, --version: print version and exit.\n";
|
||||
echo " --config: set alternative config file.\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 " -k <keywords>: set keywords for file\n";
|
||||
echo " -K <categories>: set categories for file\n";
|
||||
echo " -s <number>: set sequence for file (used for ordering files within a folder\n";
|
||||
echo " -k <keywords>: set keywords for file. See [1].\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. See [1].\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 " -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 " 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 "\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";
|
||||
$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:');
|
||||
if(false === ($options = getopt($shortoptions, $longoptions))) {
|
||||
usage();
|
||||
|
@ -58,14 +65,19 @@ if(isset($options['config'])) {
|
|||
define('SEEDDMS_CONFIG_FILE', $options['config']);
|
||||
}
|
||||
|
||||
/* Set parent folder */
|
||||
/* Set parent folder or document */
|
||||
$folderid = $documentid = 0;
|
||||
if(isset($options['F'])) {
|
||||
$folderid = (int) $options['F'];
|
||||
} else {
|
||||
echo "Missing folder ID\n";
|
||||
if(isset($options['D'])) {
|
||||
$documentid = (int) $options['D'];
|
||||
} else {
|
||||
echo "Missing folder/document ID\n";
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set comment of document */
|
||||
$comment = '';
|
||||
|
@ -120,13 +132,13 @@ if(isset($options['V'])) {
|
|||
if($reqversion<1)
|
||||
$reqversion=1;
|
||||
|
||||
include("../inc/inc.Settings.php");
|
||||
include("../inc/inc.Init.php");
|
||||
include("../inc/inc.Extension.php");
|
||||
include("../inc/inc.DBInit.php");
|
||||
include("../inc/inc.ClassNotificationService.php");
|
||||
include("../inc/inc.ClassEmailNotify.php");
|
||||
include("../inc/inc.ClassController.php");
|
||||
include($myincpath."/inc/inc.Settings.php");
|
||||
include($myincpath."/inc/inc.Init.php");
|
||||
include($myincpath."/inc/inc.Extension.php");
|
||||
include($myincpath."/inc/inc.DBInit.php");
|
||||
include($myincpath."/inc/inc.ClassNotificationService.php");
|
||||
include($myincpath."/inc/inc.ClassEmailNotify.php");
|
||||
include($myincpath."/inc/inc.ClassController.php");
|
||||
|
||||
/* Parse categories {{{ */
|
||||
$categories = array();
|
||||
|
@ -239,15 +251,18 @@ if(is_readable($filename)) {
|
|||
}
|
||||
$filetype = "." . pathinfo($filename, PATHINFO_EXTENSION);
|
||||
} else {
|
||||
echo "File has zero size\n";
|
||||
echo "File '".$filename."' has zero size\n";
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
echo "File is not readable\n";
|
||||
echo "File '".$filename."' is not readable\n";
|
||||
exit(1);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
$folder = null;
|
||||
$document = null;
|
||||
if($folderid) {
|
||||
$folder = $dms->getFolder($folderid);
|
||||
|
||||
if (!is_object($folder)) {
|
||||
|
@ -259,6 +274,19 @@ if ($folder->getAccessMode($user) < M_READWRITE) {
|
|||
echo "Not sufficient access rights\n";
|
||||
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)) {
|
||||
echo "Sequence must be numeric\n";
|
||||
|
@ -282,6 +310,7 @@ if($settings->_enableFullSearch) {
|
|||
$indexconf = null;
|
||||
}
|
||||
|
||||
if($folder) {
|
||||
$controller = Controller::factory('AddDocument', array('dms'=>$dms, 'user'=>$user));
|
||||
$controller->setParam('documentsource', 'script');
|
||||
$controller->setParam('folder', $folder);
|
||||
|
@ -318,4 +347,25 @@ if(!$document = $controller->run()) {
|
|||
echo "Could not add document to folder\n";
|
||||
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);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if [ -z "${SEEDDMS_HOME}" ]; then
|
||||
echo 'Please set $SEEDDMS_HOME before running this script'
|
||||
exit 1
|
||||
parentdir=$(dirname "$0")
|
||||
export SEEDDMS_HOME=$(dirname "$parentdir")
|
||||
fi
|
||||
|
||||
exec php -f "${SEEDDMS_HOME}/utils/adddoc.php" -- "${@}"
|
||||
|
|
Loading…
Reference in New Issue
Block a user