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

This commit is contained in:
Uwe Steinmann 2020-06-24 21:23:08 +02:00
commit 395d71b705
13 changed files with 4163 additions and 2018 deletions

View File

@ -166,6 +166,8 @@
zip file
- add support for authentication of the rest api by a key
- add support for CORS in the rest api
- fix parsing of file size
- major rework of restapi which has now a swagger specification
--------------------------------------------------------------------------------
Changes in version 5.1.17

View File

@ -869,6 +869,9 @@ class SeedDMS_Core_DMS {
function getDocumentByOriginalFilename($name, $folder=null) { /* {{{ */
if (!$name) return false;
if (!$this->db->createTemporaryTable("ttcontentid")) {
return false;
}
$queryStr = "SELECT `tblDocuments`.*, `tblDocumentLocks`.`userID` as `lockUser` ".
"FROM `tblDocuments` ".
"LEFT JOIN `ttcontentid` ON `ttcontentid`.`document` = `tblDocuments`.`id` ".

View File

@ -986,6 +986,7 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */
} /* }}} */
/**
<<<<<<< HEAD
* Check if document is checked out
*
* @return boolean true if checked out otherwise false
@ -1206,11 +1207,14 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */
/**
* @return int
=======
* @return float
>>>>>>> seeddms-5.1.x
*/
function getSequence() { return $this->_sequence; }
/**
* @param $seq
* @param float $seq
* @return bool
*/
function setSequence($seq) { /* {{{ */

View File

@ -461,7 +461,7 @@ class SeedDMS_Core_User { /* {{{ */
$classname = $dms->getClassname('role');
$role = $classname::getInstance($resArr['role'], $dms);
$user = new self($resArr["id"], $resArr["login"], $resArr["pwd"], $resArr["fullName"], $resArr["email"], $resArr["language"], $resArr["theme"], $resArr["comment"], $role, $resArr["hidden"], $resArr["disabled"], $resArr["pwdExpiration"], $resArr["loginfailures"], $resArr["quota"], $resArr["homefolder"], $resArr["secret"]);
$user = new self((int) $resArr["id"], $resArr["login"], $resArr["pwd"], $resArr["fullName"], $resArr["email"], $resArr["language"], $resArr["theme"], $resArr["comment"], $role, $resArr["hidden"], $resArr["disabled"], $resArr["pwdExpiration"], $resArr["loginfailures"], $resArr["quota"], $resArr["homefolder"], $resArr["secret"]);
$user->setDMS($dms);
return $user;
} /* }}} */
@ -1406,7 +1406,7 @@ class SeedDMS_Core_User { /* {{{ */
$classname = $this->_dms->getClassname('group');
foreach ($resArr as $row) {
/** @var SeedDMS_Core_Group $group */
$group = new $classname($row["id"], $row["name"], $row["comment"]);
$group = new $classname((int) $row["id"], $row["name"], $row["comment"]);
$group->setDMS($this->_dms);
array_push($this->_groups, $group);
}
@ -1507,7 +1507,7 @@ class SeedDMS_Core_User { /* {{{ */
$classname = $this->_dms->getClassname('document');
foreach ($resArr as $row) {
/** @var SeedDMS_Core_Document $document */
$document = new $classname($row["id"], $row["name"], $row["comment"], $row["date"], $row["expires"], $row["owner"], $row["folder"], $row["inheritAccess"], $row["defaultAccess"], $row["lockUser"], $row["keywords"], $row["sequence"]);
$document = new $classname((int) $row["id"], $row["name"], $row["comment"], $row["date"], $row["expires"], $row["owner"], $row["folder"], $row["inheritAccess"], $row["defaultAccess"], $row["lockUser"], $row["keywords"], $row["sequence"]);
$document->setDMS($this->_dms);
$documents[] = $document;
}
@ -1535,7 +1535,7 @@ class SeedDMS_Core_User { /* {{{ */
$classname = $this->_dms->getClassname('document');
foreach ($resArr as $row) {
/** @var SeedDMS_Core_Document $document */
$document = new $classname($row["id"], $row["name"], $row["comment"], $row["date"], $row["expires"], $row["owner"], $row["folder"], $row["inheritAccess"], $row["defaultAccess"], $row["lockUser"], $row["keywords"], $row["sequence"]);
$document = new $classname((int) $row["id"], $row["name"], $row["comment"], $row["date"], $row["expires"], $row["owner"], $row["folder"], $row["inheritAccess"], $row["defaultAccess"], $row["lockUser"], $row["keywords"], $row["sequence"]);
$document->setDMS($this->_dms);
$documents[] = $document;
}
@ -1990,7 +1990,7 @@ class SeedDMS_Core_User { /* {{{ */
$result = array();
if (count($resArr)>0) {
foreach ($resArr as $res) {
$result[] = $this->_dms->getWorkflow($res['id']);
$result[] = $this->_dms->getWorkflow((int) $res['id']);
}
}
@ -2490,7 +2490,7 @@ class SeedDMS_Core_User { /* {{{ */
$categories = array();
foreach ($resArr as $row) {
$cat = new SeedDMS_Core_KeywordCategory($row["id"], $row["owner"], $row["name"]);
$cat = new SeedDMS_Core_KeywordCategory((int) $row["id"], $row["owner"], $row["name"]);
$cat->setDMS($this->_dms);
array_push($categories, $cat);
}

View File

@ -93,13 +93,12 @@ class SeedDMS_Core_File {
* @return bool|int
*/
static function parse_filesize($str) { /* {{{ */
preg_replace('/\s\s+/', ' ', $str);
if(strtoupper(substr($str, -1)) == 'B') {
$value = (int) substr($str, 0, -2);
$unit = substr($str, -2, 1);
} else {
preg_replace('/\s\s+/', '', $str);
if(in_array(strtoupper(substr($str, -1)), array('B','K','M','G'))) {
$value = (int) substr($str, 0, -1);
$unit = substr($str, -1);
$unit = substr($str, -1, 1);
} else {
return (int) $str;
}
switch(strtoupper($unit)) {
case 'G':

View File

@ -1798,6 +1798,8 @@ add method SeedDMS_Core_DatabaseAccess::setLogFp()
<license uri="http://opensource.org/licenses/gpl-license">GPL License</license>
<notes>
- fixed remaining todos
- fixed parsing of file size in SeedDMS_Core_File::parse_filesize()
- fix SeedDMS_Core_DMS::getDocumentByOriginalFilename()
</notes>
</release>
<release>

View File

@ -75,7 +75,7 @@ class SeedDMS_Controller_AddDocument extends SeedDMS_Controller_Common {
}
}
}
$attributes_version = $this->getParam('attributesversion');
if($attributes_version = $this->getParam('attributesversion')) {
foreach($attributes_version as $attrdefid=>$attribute) {
if($attrdef = $dms->getAttributeDefinition($attrdefid)) {
if(null === ($ret = $this->callHook('validateAttribute', $attrdef, $attribute))) {
@ -91,6 +91,7 @@ class SeedDMS_Controller_AddDocument extends SeedDMS_Controller_Common {
}
}
}
}
$workflow = $this->getParam('workflow');
$notificationgroups = $this->getParam('notificationgroups');
$notificationusers = $this->getParam('notificationusers');

View File

@ -75,6 +75,7 @@ if($settings->_enableFullSearch) {
require_once('SeedDMS/Lucene.php');
}
}
$settings->_indexconf = $indexconf;
/* Add root Dir. Needed because the view classes are included
* relative to it.

View File

@ -26,7 +26,6 @@ if(true) {
include("inc/inc.Init.php");
include("inc/inc.Extension.php");
include("inc/inc.DBInit.php");
// include("inc/inc.Authentication.php");
require "vendor/autoload.php";
@ -56,6 +55,11 @@ if(true) {
foreach($GLOBALS['SEEDDMS_HOOKS']['initDMS'] as $hookObj) {
if (method_exists($hookObj, 'addRoute')) {
$hookObj->addRoute(array('dms'=>$dms, 'app'=>$app, 'settings'=>$settings));
} else {
include("inc/inc.Authentication.php");
if (method_exists($hookObj, 'addRouteAfterAuthentication')) {
$hookObj->addRouteAfterAuthentication(array('dms'=>$dms, 'app'=>$app, 'settings'=>$settings, 'user'=>$user));
}
}
}
}

10
restapi/.htaccess Normal file
View File

@ -0,0 +1,10 @@
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
<IfModule mod_header.c>
<Files ~ "^swagger\.yaml">
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "GET"
Header set Access-Control-Allow-Headers "X-Requested-With, Content-Type, Accept, Origin, Authorization"
</Files>
</IfModule>

File diff suppressed because it is too large Load Diff

1915
restapi/swagger.yaml Normal file

File diff suppressed because it is too large Load Diff

View File

@ -51,12 +51,26 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
/**
* Set to true if original file shall be used instead of document name
* This can lead to duplicate file names in a directory because the original
* file name is not unique. You can enforce uniqueness by setting $prefixorgfilename
* to true which will add the document id and version in front of the original
* filename.
*
* @access private
* @var boolean
*/
var $useorgfilename = false;
/**
* Set to true if original file is used and you want to prefix each filename
* by its document id and version, e.g. 12345-1-somefile.pdf
* This is option is only used fi $useorgfilename is set to true.
*
* @access private
* @var boolean
*/
var $prefixorgfilename = true;
/**
* Serve a webdav request
*
@ -209,9 +223,18 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$this->logger->log('reverseLookup: found folder '.$root->getName().' ('.$root->getID().')', PEAR_LOG_DEBUG);
return $root;
} else {
if($this->useorgfilename)
if($this->useorgfilename) {
if($this->prefixorgfilename) {
$tmp = explode('-', $docname, 3);
if(ctype_digit($tmp[0])) {
$document = $this->dms->getDocument((int) $tmp[0]);
} else {
$document = null;
}
} else {
$document = $this->dms->getDocumentByOriginalFilename($docname, $root);
else
}
} else
$document = $this->dms->getDocumentByName($docname, $root);
if($document) {
if($this->logger)
@ -230,9 +253,18 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
}
if($folder) {
if($docname) {
if($this->useorgfilename)
if($this->useorgfilename) {
if($this->prefixorgfilename) {
$tmp = explode('-', $docname, 3);
if(ctype_digit($tmp[0])) {
$document = $this->dms->getDocument((int) $tmp[0]);
} else {
$document = null;
}
} else {
$document = $this->dms->getDocumentByOriginalFilename($docname, $folder);
else
}
} else
$document = $this->dms->getDocumentByName($docname, $folder);
if($document) {
if($this->logger)
@ -454,6 +486,8 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$options['mtime'] = $content->getDate();
$fspath = $this->dms->contentDir.'/'.$content->getPath();
if(!file_exists($fspath))
return false;
// detect resource size
$options['size'] = filesize($fspath);
@ -517,11 +551,9 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$_fullpath .= $last->getName().'/';
}
foreach ($objs as $obj) {
$filename = $obj->getName();
$fullpath = $_fullpath.$filename;
if(get_class($obj) == $this->dms->getClassname('folder')) {
$fullpath .= '/';
$filename .= '/';
$fullpath = $_fullpath.$obj->getName().'/';
$displayname = $obj->getName().'/';
$filesize = 0;
$mtime = $obj->getDate();
} else {
@ -532,16 +564,31 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$mtime = $content->getDate();
$fspath = $this->dms->contentDir.'/'.$content->getPath();
if(file_exists($fspath))
$filesize = filesize($fspath);
if($this->useorgfilename)
$filename = $content->getOriginalFileName();;
else
$filesize = 0;
if($this->useorgfilename) {
/* Add the document id and version to the display name.
* I doesn't harm because for
* accessing the document the full path is used by the browser
*/
if($this->prefixorgfilename) {
$displayname = $obj->getID()."-".$content->getVersion()."-".$content->getOriginalFileName();
$fullpath = $_fullpath.$obj->getID()."-".$content->getVersion()."-".$content->getOriginalFileName();
} else {
$displayname = $content->getOriginalFileName();
$fullpath = $_fullpath.$content->getOriginalFileName();
}
} else {
$displayname = $obj->getName();
$fullpath = $_fullpath.$displayname;
}
}
// $name = htmlspecialchars($filename);
$name = $filename;
printf($format,
number_format($filesize),
strftime("%Y-%m-%d %H:%M:%S", $mtime),
"<a href=\"".$_SERVER['SCRIPT_NAME'].htmlspecialchars($fullpath)."\">".htmlspecialchars($name, ENT_QUOTES)."</a>");
"<a href=\"".$_SERVER['SCRIPT_NAME'].htmlspecialchars($fullpath)."\">".htmlspecialchars($displayname, ENT_QUOTES)."</a>");
}
echo "</pre>";
@ -609,9 +656,18 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$this->logger->log('PUT: file is of type '.$mimetype, PEAR_LOG_INFO);
/* First check whether there is already a file with the same name */
if($this->useorgfilename)
if($this->useorgfilename) {
if($this->prefixorgfilename) {
$tmp = explode('-', $name, 3);
if(ctype_digit($tmp[0])) {
$document = $this->dms->getDocument((int) $tmp[0]);
} else {
$document = null;
}
} else {
$document = $this->dms->getDocumentByOriginalFilename($name, $folder);
else
}
} else
$document = $this->dms->getDocumentByName($name, $folder);
if($document) {
if($this->logger)