2014-12-08 13:43:04 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Implementation of EditFolder controller
|
|
|
|
*
|
|
|
|
* @category DMS
|
|
|
|
* @package SeedDMS
|
|
|
|
* @license GPL 2
|
|
|
|
* @version @version@
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2010-2013 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class which does the busines logic for editing a folder
|
|
|
|
*
|
|
|
|
* @category DMS
|
|
|
|
* @package SeedDMS
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2010-2013 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
class SeedDMS_Controller_EditFolder extends SeedDMS_Controller_Common {
|
|
|
|
|
|
|
|
public function run() {
|
|
|
|
$dms = $this->params['dms'];
|
|
|
|
$user = $this->params['user'];
|
|
|
|
$settings = $this->params['settings'];
|
2020-12-14 06:53:29 +00:00
|
|
|
$fulltextservice = $this->params['fulltextservice'];
|
2014-12-08 13:43:04 +00:00
|
|
|
$folder = $this->params['folder'];
|
|
|
|
|
2017-10-12 13:40:38 +00:00
|
|
|
if(false === $this->callHook('preEditFolder')) {
|
|
|
|
if(empty($this->errormsg))
|
|
|
|
$this->errormsg = 'hook_preEditFolder_failed';
|
|
|
|
return null;
|
2014-12-08 13:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$result = $this->callHook('editFolder', $folder);
|
|
|
|
if($result === null) {
|
2017-10-12 13:40:38 +00:00
|
|
|
$name = $this->params['name'];
|
2014-12-08 13:43:04 +00:00
|
|
|
if(($oldname = $folder->getName()) != $name)
|
|
|
|
if(!$folder->setName($name))
|
|
|
|
return false;
|
|
|
|
|
2017-10-12 13:40:38 +00:00
|
|
|
$comment = $this->params['comment'];
|
2014-12-08 13:43:04 +00:00
|
|
|
if(($oldcomment = $folder->getComment()) != $comment)
|
|
|
|
if(!$folder->setComment($comment))
|
|
|
|
return false;
|
|
|
|
|
2017-10-12 13:40:38 +00:00
|
|
|
$attributes = $this->params['attributes'];
|
2014-12-08 13:43:04 +00:00
|
|
|
$oldattributes = $folder->getAttributes();
|
|
|
|
if($attributes) {
|
|
|
|
foreach($attributes as $attrdefid=>$attribute) {
|
|
|
|
$attrdef = $dms->getAttributeDefinition($attrdefid);
|
2019-12-13 14:00:04 +00:00
|
|
|
if(null === ($ret = $this->callHook('validateAttribute', $attrdef, $attribute))) {
|
2014-12-08 13:43:04 +00:00
|
|
|
if($attribute) {
|
2022-06-07 15:43:59 +00:00
|
|
|
switch($attrdef->getType()) {
|
|
|
|
case SeedDMS_Core_AttributeDefinition::type_date:
|
|
|
|
$attribute = date('Y-m-d', makeTsFromDate($attribute));
|
|
|
|
break;
|
|
|
|
}
|
2022-07-27 07:37:58 +00:00
|
|
|
if(!$attrdef->validate($attribute, $folder, false)) {
|
2016-10-27 07:19:35 +00:00
|
|
|
$this->errormsg = getAttributeValidationText($attrdef->getValidationError(), $attrdef->getName(), $attribute);
|
2015-04-15 14:12:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-10-27 07:19:35 +00:00
|
|
|
|
2014-12-08 13:43:04 +00:00
|
|
|
if(!isset($oldattributes[$attrdefid]) || $attribute != $oldattributes[$attrdefid]->getValue()) {
|
|
|
|
if(!$folder->setAttributeValue($dms->getAttributeDefinition($attrdefid), $attribute))
|
|
|
|
return false;
|
|
|
|
}
|
2016-10-27 08:55:33 +00:00
|
|
|
} elseif($attrdef->getMinValues() > 0) {
|
|
|
|
$this->errormsg = getMLText("attr_min_values", array("attrname"=>$attrdef->getName()));
|
2022-09-20 06:23:04 +00:00
|
|
|
return false;
|
2014-12-08 13:43:04 +00:00
|
|
|
} elseif(isset($oldattributes[$attrdefid])) {
|
|
|
|
if(!$folder->removeAttribute($dms->getAttributeDefinition($attrdefid)))
|
|
|
|
return false;
|
|
|
|
}
|
2019-12-13 14:00:04 +00:00
|
|
|
} else {
|
|
|
|
if($ret === false)
|
|
|
|
return false;
|
|
|
|
}
|
2014-12-08 13:43:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach($oldattributes as $attrdefid=>$oldattribute) {
|
|
|
|
if(!isset($attributes[$attrdefid])) {
|
|
|
|
if(!$folder->removeAttribute($dms->getAttributeDefinition($attrdefid)))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-12 13:40:38 +00:00
|
|
|
$sequence = $this->params['sequence'];
|
2014-12-08 13:43:04 +00:00
|
|
|
if(strcasecmp($sequence, "keep")) {
|
|
|
|
if($folder->setSequence($sequence)) {
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-14 06:53:29 +00:00
|
|
|
if($fulltextservice && ($index = $fulltextservice->Indexer()) && $folder) {
|
|
|
|
$idoc = $fulltextservice->IndexedDocument($folder);
|
|
|
|
if(false !== $this->callHook('preIndexFolder', $folder, $idoc)) {
|
2021-01-08 09:07:12 +00:00
|
|
|
$lucenesearch = $fulltextservice->Search();
|
|
|
|
if($hit = $lucenesearch->getFolder((int) $folder->getId())) {
|
|
|
|
$index->delete($hit->id);
|
|
|
|
}
|
2020-12-14 06:53:29 +00:00
|
|
|
$index->addDocument($idoc);
|
|
|
|
$index->commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-17 17:25:39 +00:00
|
|
|
} elseif($result === false) {
|
|
|
|
if(empty($this->errormsg))
|
|
|
|
$this->errormsg = 'hook_editFolder_failed';
|
|
|
|
return false;
|
|
|
|
}
|
2014-12-08 13:43:04 +00:00
|
|
|
|
2021-07-08 12:19:36 +00:00
|
|
|
if(false === $this->callHook('postEditFolder')) {
|
2019-01-17 17:25:39 +00:00
|
|
|
}
|
2014-12-08 13:43:04 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|