public function updateAction()
{
$success = false;
$allowUpdate = true;
$object = Object::getById($this->getParam("id"));
if ($object instanceof Object\Concrete) {
$object->setOmitMandatoryCheck(true);
}
// this prevents the user from renaming, relocating (actions in the tree) if the newest version isn't the published one
// the reason is that otherwise the content of the newer not published version will be overwritten
if ($object instanceof Object\Concrete) {
$latestVersion = $object->getLatestVersion();
if ($latestVersion && $latestVersion->getData()->getModificationDate() != $object->getModificationDate()) {
$this->_helper->json(["success" => false, "message" => "You can't relocate if there's a newer not published version"]);
}
}
$values = \Zend_Json::decode($this->getParam("values"));
if ($object->isAllowed("settings")) {
if ($values["key"] && $object->isAllowed("rename")) {
$object->setKey($values["key"]);
} elseif ($values["key"] != $object->getKey()) {
Logger::debug("prevented renaming object because of missing permissions ");
}
if ($values["parentId"]) {
$parent = Object::getById($values["parentId"]);
//check if parent is changed
if ($object->getParentId() != $parent->getId()) {
if (!$parent->isAllowed("create")) {
throw new \Exception("Prevented moving object - no create permission on new parent ");
}
$objectWithSamePath = Object::getByPath($parent->getRealFullPath() . "/" . $object->getKey());
if ($objectWithSamePath != null) {
$allowUpdate = false;
$this->_helper->json(["success" => false, "message" => "prevented creating object because object with same path+key already exists"]);
}
if ($object->isLocked()) {
$this->_helper->json(["success" => false, "message" => "prevented moving object, because it is locked: ID: " . $object->getId()]);
}
$object->setParentId($values["parentId"]);
}
}
if (array_key_exists("locked", $values)) {
$object->setLocked($values["locked"]);
}
if ($allowUpdate) {
$object->setModificationDate(time());
$object->setUserModification($this->getUser()->getId());
try {
$object->save();
$success = true;
} catch (\Exception $e) {
Logger::error($e);
$this->_helper->json(["success" => false, "message" => $e->getMessage()]);
}
} else {
Logger::debug("prevented move of object, object with same path+key already exists in this location.");
}
} elseif ($object->isAllowed("rename") && $values["key"]) {
//just rename
try {
$object->setKey($values["key"]);
$object->save();
$success = true;
} catch (\Exception $e) {
Logger::error($e);
$this->_helper->json(["success" => false, "message" => $e->getMessage()]);
}
} else {
Logger::debug("prevented update object because of missing permissions.");
}
$this->_helper->json(["success" => $success]);
}