public function updateAction()
{
$success = false;
$allowUpdate = true;
$updateData = $this->getAllParams();
$asset = Asset::getById($this->getParam("id"));
if ($asset->isAllowed("settings")) {
$asset->setUserModification($this->getUser()->getId());
// if the position is changed the path must be changed || also from the childs
if ($this->getParam("parentId")) {
$parentAsset = Asset::getById($this->getParam("parentId"));
//check if parent is changed i.e. asset is moved
if ($asset->getParentId() != $parentAsset->getId()) {
if (!$parentAsset->isAllowed("create")) {
throw new \Exception("Prevented moving asset - no create permission on new parent ");
}
$intendedPath = $parentAsset->getRealPath();
$pKey = $parentAsset->getKey();
if (!empty($pKey)) {
$intendedPath .= $parentAsset->getKey() . "/";
}
$assetWithSamePath = Asset::getByPath($intendedPath . $asset->getKey());
if ($assetWithSamePath != null) {
$allowUpdate = false;
}
if ($asset->isLocked()) {
$allowUpdate = false;
}
}
}
if ($allowUpdate) {
if ($this->getParam("filename") || $this->getParam("parentId")) {
$asset->getData();
}
if ($this->getParam("filename") != $asset->getFilename() and !$asset->isAllowed("rename")) {
unset($updateData["filename"]);
Logger::debug("prevented renaming asset because of missing permissions ");
}
$asset->setValues($updateData);
try {
$asset->save();
$success = true;
} catch (\Exception $e) {
$this->_helper->json(["success" => false, "message" => $e->getMessage()]);
}
} else {
$msg = "prevented moving asset, asset with same path+key already exists at target location or the asset is locked. ID: " . $asset->getId();
Logger::debug($msg);
$this->_helper->json(["success" => $success, "message" => $msg]);
}
} elseif ($asset->isAllowed("rename") && $this->getParam("filename")) {
//just rename
try {
$asset->setFilename($this->getParam("filename"));
$asset->save();
$success = true;
} catch (\Exception $e) {
$this->_helper->json(["success" => false, "message" => $e->getMessage()]);
}
} else {
Logger::debug("prevented update asset because of missing permissions ");
}
$this->_helper->json(["success" => $success]);
}