mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-06-18 02:59:27 +00:00
use extensions and controller
This commit is contained in:
parent
f5f28d9e30
commit
ed93657566
|
@ -1,13 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
include("../inc/inc.Settings.php");
|
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("Log.php");
|
include("Log.php");
|
||||||
include("webdav.php");
|
|
||||||
|
|
||||||
$db = new SeedDMS_Core_DatabaseAccess($settings->_dbDriver, $settings->_dbHostname, $settings->_dbUser, $settings->_dbPass, $settings->_dbDatabase);
|
|
||||||
$db->connect() or die ("Could not connect to db-server \"" . $settings->_dbHostname . "\"");
|
|
||||||
$db->getResult("set names 'utf8'");
|
|
||||||
|
|
||||||
$dms = new SeedDMS_Core_DMS($db, $settings->_contentDir.$settings->_contentOffsetDir);
|
|
||||||
|
|
||||||
if($settings->_logFileEnable) {
|
if($settings->_logFileEnable) {
|
||||||
if ($settings->_logFileRotation=="h") $logname=date("YmdH", time());
|
if ($settings->_logFileRotation=="h") $logname=date("YmdH", time());
|
||||||
|
@ -19,6 +18,7 @@ if($settings->_logFileEnable) {
|
||||||
$log = null;
|
$log = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
include("webdav.php");
|
||||||
$server = new HTTP_WebDAV_Server_SeedDMS();
|
$server = new HTTP_WebDAV_Server_SeedDMS();
|
||||||
$server->ServeRequest($dms, $log);
|
$server->ServeRequest($dms, $log);
|
||||||
//$files = array();
|
//$files = array();
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once "HTTP/WebDAV/Server.php";
|
require_once "HTTP/WebDAV/Server.php";
|
||||||
if(!empty($settings->_coreDir))
|
|
||||||
require_once($settings->_coreDir.'/Core.php');
|
|
||||||
else
|
|
||||||
require_once('SeedDMS/Core.php');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SeedDMS access using WebDAV
|
* SeedDMS access using WebDAV
|
||||||
|
@ -270,7 +266,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
|
||||||
$files["files"][] = $this->fileinfo($obj);
|
$files["files"][] = $this->fileinfo($obj);
|
||||||
|
|
||||||
// information for contained resources requested?
|
// information for contained resources requested?
|
||||||
if (get_class($obj) == 'SeedDMS_Core_Folder' && !empty($options["depth"])) {
|
if (get_class($obj) == $this->dms->getClassname('folder') && !empty($options["depth"])) {
|
||||||
|
|
||||||
$subfolders = $obj->getSubFolders();
|
$subfolders = $obj->getSubFolders();
|
||||||
$subfolders = SeedDMS_Core_DMS::filterAccess($subfolders, $this->user, M_READ);
|
$subfolders = SeedDMS_Core_DMS::filterAccess($subfolders, $this->user, M_READ);
|
||||||
|
@ -320,7 +316,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
|
||||||
$info["props"] = array();
|
$info["props"] = array();
|
||||||
|
|
||||||
// type and size (caller already made sure that path exists)
|
// type and size (caller already made sure that path exists)
|
||||||
if (get_class($obj) == 'SeedDMS_Core_Folder') {
|
if (get_class($obj) == $this->dms->getClassname('folder')) {
|
||||||
// modification time
|
// modification time
|
||||||
/* folders do not have a modification time */
|
/* folders do not have a modification time */
|
||||||
$info["props"][] = $this->mkprop("getlastmodified", time());
|
$info["props"][] = $this->mkprop("getlastmodified", time());
|
||||||
|
@ -421,7 +417,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
|
||||||
if (!$obj) return false;
|
if (!$obj) return false;
|
||||||
|
|
||||||
// is this a collection?
|
// is this a collection?
|
||||||
if (get_class($obj) == 'SeedDMS_Core_Folder') {
|
if (get_class($obj) == $this->dms->getClassname('folder')) {
|
||||||
return $this->GetDir($obj, $options);
|
return $this->GetDir($obj, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -502,7 +498,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
|
||||||
foreach ($objs as $obj) {
|
foreach ($objs as $obj) {
|
||||||
$filename = $obj->getName();
|
$filename = $obj->getName();
|
||||||
$fullpath = $_fullpath.$filename;
|
$fullpath = $_fullpath.$filename;
|
||||||
if(get_class($obj) == 'SeedDMS_Core_Folder') {
|
if(get_class($obj) == $this->dms->getClassname('folder')) {
|
||||||
$fullpath .= '/';
|
$fullpath .= '/';
|
||||||
$filename .= '/';
|
$filename .= '/';
|
||||||
$filesize = 0;
|
$filesize = 0;
|
||||||
|
@ -553,7 +549,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
|
||||||
$parent = '';
|
$parent = '';
|
||||||
$folder = $this->reverseLookup($parent.'/');
|
$folder = $this->reverseLookup($parent.'/');
|
||||||
|
|
||||||
if (!$folder || get_class($folder) != "SeedDMS_Core_Folder") {
|
if (!$folder || get_class($folder) != $this->dms->getClassname('folder')) {
|
||||||
return "409 Conflict";
|
return "409 Conflict";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -658,7 +654,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if parent of new folder is a folder */
|
/* Check if parent of new folder is a folder */
|
||||||
if (get_class($folder) != 'SeedDMS_Core_Folder') {
|
if (get_class($folder) != $this->dms->getClassname('folder')) {
|
||||||
return "403 Forbidden";
|
return "403 Forbidden";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -696,6 +692,8 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
|
||||||
*/
|
*/
|
||||||
function DELETE($options) /* {{{ */
|
function DELETE($options) /* {{{ */
|
||||||
{
|
{
|
||||||
|
global $settings, $indexconf;
|
||||||
|
|
||||||
$this->log_options('DELETE', $options);
|
$this->log_options('DELETE', $options);
|
||||||
|
|
||||||
// get folder or document from path
|
// get folder or document from path
|
||||||
|
@ -712,7 +710,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
|
||||||
return "403 Forbidden";
|
return "403 Forbidden";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_class($obj) == 'SeedDMS_Core_Folder') {
|
if (get_class($obj) == $this->dms->getClassname('folder')) {
|
||||||
if($obj->hasDocuments() || $obj->hasSubFolders()) {
|
if($obj->hasDocuments() || $obj->hasSubFolders()) {
|
||||||
return "409 Conflict";
|
return "409 Conflict";
|
||||||
}
|
}
|
||||||
|
@ -720,15 +718,20 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
|
||||||
return "409 Conflict";
|
return "409 Conflict";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// check if user is admin
|
if($settings->_enableFullSearch) {
|
||||||
// only admins may delete documents
|
$index = $indexconf['Indexer']::open($settings->_luceneDir);
|
||||||
/* There is not reason to allow only admins to remove a document
|
$indexconf['Indexer']::init($settings->_stopWordsFile);
|
||||||
if(!$this->user->isAdmin()) {
|
} else {
|
||||||
return "403 Forbidden";
|
$index = null;
|
||||||
|
$indexconf = null;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
if(!$obj->remove()) {
|
$controller = Controller::factory('RemoveDocument');
|
||||||
|
$controller->setParam('document', $obj);
|
||||||
|
$controller->setParam('index', $index);
|
||||||
|
$controller->setParam('indexconf', $indexconf);
|
||||||
|
if(!$controller->run()) {
|
||||||
|
// if(!$obj->remove()) {
|
||||||
return "409 Conflict";
|
return "409 Conflict";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -782,12 +785,12 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
|
||||||
return "403 Forbidden";
|
return "403 Forbidden";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(get_class($objdest) == 'SeedDMS_Core_Document') {
|
if(get_class($objdest) == $this->dms->getClassname('document')) {
|
||||||
/* If destination object is a document it must be overwritten */
|
/* If destination object is a document it must be overwritten */
|
||||||
if (!$options["overwrite"]) {
|
if (!$options["overwrite"]) {
|
||||||
return "412 precondition failed";
|
return "412 precondition failed";
|
||||||
}
|
}
|
||||||
if(get_class($objsource) == 'SeedDMS_Core_Folder') {
|
if(get_class($objsource) == $this->dms->getClassname('folder')) {
|
||||||
return "400 Bad request";
|
return "400 Bad request";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -808,11 +811,11 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
|
||||||
$objsource->remove();
|
$objsource->remove();
|
||||||
|
|
||||||
return "204 No Content";
|
return "204 No Content";
|
||||||
} elseif(get_class($objdest) == 'SeedDMS_Core_Folder') {
|
} elseif(get_class($objdest) == $this->dms->getClassname('folder')) {
|
||||||
/* Set the new Folder of the source object */
|
/* Set the new Folder of the source object */
|
||||||
if(get_class($objsource) == 'SeedDMS_Core_Document')
|
if(get_class($objsource) == $this->dms->getClassname('document'))
|
||||||
$objsource->setFolder($objdest);
|
$objsource->setFolder($objdest);
|
||||||
elseif(get_class($objsource) == 'SeedDMS_Core_Folder')
|
elseif(get_class($objsource) == $this->dms->getClassname('folder'))
|
||||||
$objsource->setParent($objdest);
|
$objsource->setParent($objdest);
|
||||||
else
|
else
|
||||||
return "500 Internal server error";
|
return "500 Internal server error";
|
||||||
|
@ -830,6 +833,8 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
|
||||||
*/
|
*/
|
||||||
function COPY($options, $del=false) /* {{{ */
|
function COPY($options, $del=false) /* {{{ */
|
||||||
{
|
{
|
||||||
|
global $settings, $indexconf;
|
||||||
|
|
||||||
if(!$del)
|
if(!$del)
|
||||||
$this->log_options('COPY', $options);
|
$this->log_options('COPY', $options);
|
||||||
|
|
||||||
|
@ -852,7 +857,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
|
||||||
if (!$objsource)
|
if (!$objsource)
|
||||||
return "404 Not found";
|
return "404 Not found";
|
||||||
|
|
||||||
if (get_class($objsource) == 'SeedDMS_Core_Folder' && ($options["depth"] != "infinity")) {
|
if (get_class($objsource) == $this->dms->getClassname('folder') && ($options["depth"] != "infinity")) {
|
||||||
// RFC 2518 Section 9.2, last paragraph
|
// RFC 2518 Section 9.2, last paragraph
|
||||||
return "400 Bad request";
|
return "400 Bad request";
|
||||||
}
|
}
|
||||||
|
@ -880,12 +885,12 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If destination object is a document it must be overwritten */
|
/* If destination object is a document it must be overwritten */
|
||||||
if(get_class($objdest) == 'SeedDMS_Core_Document') {
|
if(get_class($objdest) == $this->dms->getClassname('document')) {
|
||||||
if (!$options["overwrite"]) {
|
if (!$options["overwrite"]) {
|
||||||
return "412 precondition failed";
|
return "412 precondition failed";
|
||||||
}
|
}
|
||||||
/* Copying a folder into a document makes no sense */
|
/* Copying a folder into a document makes no sense */
|
||||||
if(get_class($objsource) == 'SeedDMS_Core_Folder') {
|
if(get_class($objsource) == $this->dms->getClassname('folder')) {
|
||||||
return "400 Bad request";
|
return "400 Bad request";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -902,12 +907,12 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
|
||||||
$objdest->setName($objsource->getName());
|
$objdest->setName($objsource->getName());
|
||||||
|
|
||||||
return "204 No Content";
|
return "204 No Content";
|
||||||
} elseif(get_class($objdest) == 'SeedDMS_Core_Folder') {
|
} elseif(get_class($objdest) == $this->dms->getClassname('folder')) {
|
||||||
if($this->logger)
|
if($this->logger)
|
||||||
$this->logger->log('COPY: copy \''.$objdest->getName().'\' to folder '.$objdest->getName().'', PEAR_LOG_INFO);
|
$this->logger->log('COPY: copy \''.$objdest->getName().'\' to folder '.$objdest->getName().'', PEAR_LOG_INFO);
|
||||||
|
|
||||||
/* Currently no support for copying folders */
|
/* Currently no support for copying folders */
|
||||||
if(get_class($objsource) == 'SeedDMS_Core_Folder') {
|
if(get_class($objsource) == $this->dms->getClassname('folder')) {
|
||||||
if($this->logger)
|
if($this->logger)
|
||||||
$this->logger->log('COPY: source is a folder '.$objsource->getName().'', PEAR_LOG_INFO);
|
$this->logger->log('COPY: source is a folder '.$objsource->getName().'', PEAR_LOG_INFO);
|
||||||
|
|
||||||
|
@ -921,7 +926,49 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
|
||||||
$content = $objsource->getLatestContent();
|
$content = $objsource->getLatestContent();
|
||||||
$fspath = $this->dms->contentDir.'/'.$content->getPath();
|
$fspath = $this->dms->contentDir.'/'.$content->getPath();
|
||||||
|
|
||||||
if(!$newdoc = $objdest->addDocument($newdocname, '', 0, $this->user, '', array(), $fspath, $content->getOriginalFileName(), $content->getFileType(), $content->getMimeType(), 0, array(), array(), 0, "")) {
|
if($settings->_enableFullSearch) {
|
||||||
|
$index = $indexconf['Indexer']::open($settings->_luceneDir);
|
||||||
|
$indexconf['Indexer']::init($settings->_stopWordsFile);
|
||||||
|
} else {
|
||||||
|
$index = null;
|
||||||
|
$indexconf = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$controller = Controller::factory('AddDocument');
|
||||||
|
$controller->setParam('documentsource', 'webdav');
|
||||||
|
$controller->setParam('folder', $objdest);
|
||||||
|
$controller->setParam('index', $index);
|
||||||
|
$controller->setParam('indexconf', $indexconf);
|
||||||
|
$controller->setParam('name', $newdocname);
|
||||||
|
$controller->setParam('comment', '');
|
||||||
|
$controller->setParam('expires', 0);
|
||||||
|
$controller->setParam('keywords', '');
|
||||||
|
$controller->setParam('categories', array());
|
||||||
|
$controller->setParam('owner', $this->user);
|
||||||
|
$controller->setParam('userfiletmp', $fspath);
|
||||||
|
$controller->setParam('userfilename', $content->getOriginalFileName());
|
||||||
|
$controller->setParam('filetype', $content->getFileType());
|
||||||
|
$controller->setParam('userfiletype', $content->getMimeType());
|
||||||
|
$minmax = $objdest->getDocumentsMinMax();
|
||||||
|
if($settings->_defaultDocPosition == 'start')
|
||||||
|
$controller->setParam('sequence', $minmax['min'] - 1);
|
||||||
|
else
|
||||||
|
$controller->setParam('sequence', $minmax['max'] + 1);
|
||||||
|
$controller->setParam('reviewers', array());
|
||||||
|
$controller->setParam('approvers', array());
|
||||||
|
$controller->setParam('reqversion', 0);
|
||||||
|
$controller->setParam('versioncomment', '');
|
||||||
|
$controller->setParam('attributes', array());
|
||||||
|
$controller->setParam('attributesversion', array());
|
||||||
|
$controller->setParam('workflow', null);
|
||||||
|
$controller->setParam('notificationgroups', array());
|
||||||
|
$controller->setParam('notificationusers', array());
|
||||||
|
$controller->setParam('maxsizeforfulltext', $settings->_maxSizeForFullText);
|
||||||
|
$controller->setParam('defaultaccessdocs', $settings->_defaultAccessDocs);
|
||||||
|
|
||||||
|
if(!$document = $controller->run()) {
|
||||||
|
|
||||||
|
// if(!$newdoc = $objdest->addDocument($newdocname, '', 0, $this->user, '', array(), $fspath, $content->getOriginalFileName(), $content->getFileType(), $content->getMimeType(), 0, array(), array(), 0, "")) {
|
||||||
if($this->logger)
|
if($this->logger)
|
||||||
$this->logger->log('COPY: error copying object', PEAR_LOG_INFO);
|
$this->logger->log('COPY: error copying object', PEAR_LOG_INFO);
|
||||||
return "409 Conflict";
|
return "409 Conflict";
|
||||||
|
@ -1016,7 +1063,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
|
||||||
return "200 OK";
|
return "200 OK";
|
||||||
|
|
||||||
// TODO recursive locks on directories not supported yet
|
// TODO recursive locks on directories not supported yet
|
||||||
if (get_class($obj) == 'SeedDMS_Core_Folder' && !empty($options["depth"])) {
|
if (get_class($obj) == $this->dms->getClassname('folder') && !empty($options["depth"])) {
|
||||||
return "409 Conflict";
|
return "409 Conflict";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1054,7 +1101,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
|
||||||
return "204 No Content";
|
return "204 No Content";
|
||||||
|
|
||||||
// TODO recursive locks on directories not supported yet
|
// TODO recursive locks on directories not supported yet
|
||||||
if (get_class($obj) == 'SeedDMS_Core_Folder' && !empty($options["depth"])) {
|
if (get_class($obj) == $this->dms->getClassname('folder') && !empty($options["depth"])) {
|
||||||
return "409 Conflict";
|
return "409 Conflict";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1091,7 +1138,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
|
||||||
}
|
}
|
||||||
|
|
||||||
// Folders cannot be locked
|
// Folders cannot be locked
|
||||||
if(get_class($obj) == 'SeedDMS_Core_Folder') {
|
if(get_class($obj) == $this->dms->getClassname('folder')) {
|
||||||
if($this->logger)
|
if($this->logger)
|
||||||
$this->logger->log('checkLock: object is a folder', PEAR_LOG_INFO);
|
$this->logger->log('checkLock: object is a folder', PEAR_LOG_INFO);
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user