properly handle duplicate names when moving a document/folder

This commit is contained in:
Uwe Steinmann 2020-01-13 09:32:22 +01:00
parent 699152d95b
commit bb38dc7b22

View File

@ -1062,6 +1062,11 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$objdest = $this->reverseLookup($options["dest"]); $objdest = $this->reverseLookup($options["dest"]);
$newdocname = ''; $newdocname = '';
/* if the destіnation could not be found, then a folder/document shall
* be renamed. In that case the source object is moved into the ѕame
* or different folder under a new name.
* $objdest will store the new destination folder afterwards
*/
if(!$objdest) { if(!$objdest) {
/* check if at least the dest directory exists */ /* check if at least the dest directory exists */
$dirname = dirname($options['dest']); $dirname = dirname($options['dest']);
@ -1112,13 +1117,17 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
/* Set the new Folder of the source object */ /* Set the new Folder of the source object */
if(get_class($objsource) == $this->dms->getClassname('document')) { if(get_class($objsource) == $this->dms->getClassname('document')) {
/* Check if name already exists in the folder */ /* Check if name already exists in the folder */
/*
if(!$settings->_enableDuplicateDocNames) { if(!$settings->_enableDuplicateDocNames) {
if($objdest->hasDocumentByName($objsource->getName())) { if($newdocname) {
return "403 Forbidden"; if($objdest->hasDocumentByName($newdocname)) {
return "403 Forbidden";
}
} else {
if($objdest->hasDocumentByName($objsource->getName())) {
return "403 Forbidden";
}
} }
} }
*/
$oldFolder = $objsource->getFolder(); $oldFolder = $objsource->getFolder();
if($objsource->setFolder($objdest)) { if($objsource->setFolder($objdest)) {
@ -1153,8 +1162,14 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
} elseif(get_class($objsource) == $this->dms->getClassname('folder')) { } elseif(get_class($objsource) == $this->dms->getClassname('folder')) {
/* Check if name already exists in the folder */ /* Check if name already exists in the folder */
if(!$settings->_enableDuplicateSubFolderNames) { if(!$settings->_enableDuplicateSubFolderNames) {
if($objdest->hasSubFolderByName($objsource->getName())) { if($newdocname) {
return "403 Forbidden"; if($objdest->hasSubFolderByName($newdocname)) {
return "403 Forbidden";
}
} else {
if($objdest->hasSubFolderByName($objsource->getName())) {
return "403 Forbidden";
}
} }
} }
$oldFolder = $objsource->getParent(); $oldFolder = $objsource->getParent();
@ -1176,7 +1191,7 @@ class HTTP_WebDAV_Server_SeedDMS extends HTTP_WebDAV_Server
$params['old_folder_path'] = $oldFolder->getFolderPathPlain(); $params['old_folder_path'] = $oldFolder->getFolderPathPlain();
$params['new_folder_path'] = $objdest->getFolderPathPlain(); $params['new_folder_path'] = $objdest->getFolderPathPlain();
$params['username'] = $this->user->getFullName(); $params['username'] = $this->user->getFullName();
$params['url'] = "http".((isset($_SERVER['HTTPS']) && (strcmp($_SERVER['HTTPS'],'off')!=0)) ? "s" : "")."://".$_SERVER['HTTP_HOST'].$settings->_httpRoot."out/out.ViewFolder.php?folderid=".$folder->getID(); $params['url'] = "http".((isset($_SERVER['HTTPS']) && (strcmp($_SERVER['HTTPS'],'off')!=0)) ? "s" : "")."://".$_SERVER['HTTP_HOST'].$settings->_httpRoot."out/out.ViewFolder.php?folderid=".$objsource->getID();
$params['sitename'] = $settings->_siteName; $params['sitename'] = $settings->_siteName;
$params['http_root'] = $settings->_httpRoot; $params['http_root'] = $settings->_httpRoot;
$this->notifier->toList($this->user, $nl["users"], $subject, $message, $params); $this->notifier->toList($this->user, $nl["users"], $subject, $message, $params);