public function executeRemoveCf() { if ($this->validAjaxRequest() || !$this->request()->isPostRequest()) { Base::end('Invalid request!'); } $ajax = new \AjaxResponse(); $customField = \TermCustomFields::retrieveById($this->request()->get('id')); if (!$customField) { $ajax->message = t("Custom field not found!"); $ajax->type = \AjaxResponse::ERROR; return $this->renderText($ajax->toString()); } $customField->beginTransaction(); if ($customField->delete()) { \PostCustomFields::write()->delete(\PostCustomFields::getTableName())->where('cf_id = ?')->setParameter(1, $customField->getId(), \PDO::PARAM_INT)->execute(); $customField->commit(); $ajax->message = t($customField->getName() . ' was removed!'); $ajax->type = \AjaxResponse::SUCCESS; return $this->renderText($ajax->toString()); } $customField->rollBack(); $ajax->message = t("Could not remove {$customField->getName()}!"); $ajax->type = \AjaxResponse::ERROR; return $this->renderText($ajax->toString()); }
protected function _afterDelete() { parent::_afterDelete(); \PostImages::write()->delete(PostImages::getTableName())->where('`post_id`=:post_id')->setParameter(':post_id', $this->getId(), \PDO::PARAM_INT)->execute(); \PostCustomFields::write()->delete(PostCustomFields::getTableName())->where('`post_id`=:post_id')->setParameter(':post_id', $this->getId(), \PDO::PARAM_INT)->execute(); \PostAttachments::write()->delete(PostAttachments::getTableName())->where('`post_id`=:post_id')->setParameter(':post_id', $this->getId(), \PDO::PARAM_INT)->execute(); \PostProperty::write()->delete(PostProperty::getTableName())->where('`post_id`=:post_id')->setParameter(':post_id', $this->getId(), \PDO::PARAM_INT)->execute(); }