/** * Publish object data changes * Sends JSON reply in the result * and closes the application. */ public function publishAction() { $id = Request::post('id', 'integer', false); $vers = Request::post('vers', 'integer', false); if (!$id || !$vers) { Response::jsonError($this->_lang->WRONG_REQUEST); } $this->_checkCanPublish(); try { $object = new Db_Object($this->_objectName, $id); } catch (Exception $e) { Response::jsonError($this->_lang->CANT_EXEC . '. ' . $e->getMessage()); } $acl = $object->getAcl(); if ($acl && !$acl->canPublish($object)) { Response::jsonError($this->_lang->CANT_PUBLISH); } try { $object->loadVersion($vers); } catch (Exception $e) { Response::jsonError($this->_lang->VERSION_INCOPATIBLE); } if (!$object->publish()) { Response::jsonError($this->_lang->CANT_EXEC); } Response::jsonSuccess(); }
/** * (non-PHPdoc) * @see Backend_Controller_Crud::deleteAction() */ public function deleteAction() { $this->_checkCanDelete(); $id = Request::post('id', 'integer', false); if (!$id) { Response::jsonError($this->_lang->WRONG_REQUEST); } try { $object = new Db_Object($this->_objectName, $id); } catch (Exception $e) { Response::jsonError($this->_lang->WRONG_REQUEST); } $acl = $object->getAcl(); if ($acl && !$acl->canDelete($object)) { Response::jsonError($this->_lang->CANT_DELETE); } $childIds = Model::factory('Page')->getList(false, array('parent_id' => $id), array('id')); if (!empty($childIds)) { Response::jsonError($this->_lang->REMOVE_CHILDREN); } if ($this->_configMain->get('vc_clear_on_delete')) { Model::factory('Vc')->removeItemVc($this->_objectName, $id); } if (!$object->delete()) { Response::jsonError($this->_lang->CANT_EXEC); } Model::factory('Blockmapping')->clearMap($id); Response::jsonSuccess(); }
/** * Get posted data and put it into Db_Object * (in case of failure, JSON error message is sent) * * @param string $objectName * @return Db_Object */ public function getPostedData($objectName) { $id = Request::post('id', 'integer', 0); if ($id) { try { $obj = new Db_Object($objectName, $id); } catch (Exception $e) { Response::jsonError($this->_lang->CANT_EXEC); } } else { try { $obj = new Db_Object($objectName); } catch (Exception $e) { Response::jsonError($this->_lang->CANT_EXEC . '<br>' . $e->getMessage()); } } $acl = $obj->getAcl(); if ($acl && !$acl->canEdit($obj)) { Response::jsonError($this->_lang->CANT_MODIFY); } $posted = Request::postArray(); $fields = $obj->getFields(); $errors = array(); $objectConfig = $obj->getConfig(); $systemFields = $objectConfig->getSystemFieldsConfig(); foreach ($fields as $name) { if ($objectConfig->isRequired($name) && !isset($systemFields[$name]) && (!isset($posted[$name]) || !strlen($posted[$name]))) { $errors[$name] = $this->_lang->CANT_BE_EMPTY; continue; } if ($objectConfig->isBoolean($name) && !isset($posted[$name])) { $posted[$name] = false; } if ($objectConfig->isNull($name) && $objectConfig->isDateField($name) && isset($posted[$name]) && empty($posted[$name])) { $posted[$name] = null; } if (!array_key_exists($name, $posted)) { continue; } if (!$id && (is_string($posted[$name]) && !strlen((string) $posted[$name]) || is_array($posted[$name]) && empty($posted[$name])) && $objectConfig->hasDefault($name)) { continue; } try { $obj->set($name, $posted[$name]); } catch (Exception $e) { $errors[$name] = $this->_lang->INVALID_VALUE; } } if (!empty($errors)) { Response::jsonError($this->_lang->FILL_FORM, $errors); } $errors = $obj->validateUniqueValues(); if (!empty($errors)) { Response::jsonError($this->_lang->FILL_FORM, $errors); } if ($id) { $obj->setId($id); } return $obj; }
/** * Delete object * Sends JSON reply in the result and * closes the application */ public function deleteAction() { $this->_checkCanDelete(); $id = Request::post('id', 'integer', false); if (!$id) { Response::jsonError($this->_lang->WRONG_REQUEST); } try { $object = new Db_Object($this->_objectName, $id); } catch (Exception $e) { Response::jsonError($this->_lang->WRONG_REQUEST); } $acl = $object->getAcl(); if ($acl && !$acl->canDelete($object)) { Response::jsonError($this->_lang->CANT_DELETE); } if ($this->_configMain->get('vc_clear_on_delete')) { Model::factory('Vc')->removeItemVc($this->_objectName, $id); } if (!$object->delete()) { Response::jsonError($this->_lang->CANT_EXEC); } Response::jsonSuccess(); }
/** * Delete object * Sends JSON reply in the result and * closes the application */ public function deleteAction() { $this->_checkCanDelete(); $id = Request::post('id', 'integer', false); if (!$id) { Response::jsonError($this->_lang->get('WRONG_REQUEST')); } try { $object = new Db_Object($this->_objectName, $id); } catch (Exception $e) { Response::jsonError($this->_lang->get('WRONG_REQUEST')); } $acl = $object->getAcl(); if ($acl && !$acl->canDelete($object)) { Response::jsonError($this->_lang->get('CANT_DELETE')); } $fileStorage = Model::factory('Filestorage')->getStorage(); if (!$fileStorage->remove($id)) { Response::jsonError($this->_lang->get('CANT_EXEC')); } Response::jsonSuccess(); }