/** * Delete news * * @param integer $id * @return boolean */ public function delete($id) { $repo = $this->store()->getRepository('news'); $repo->appendLockTables(['tbl_news_category_link']); $entity = $this->finder()->filter(['ID' => $id])->get(); if ($entity === false) { $repo->rollback(); throw new \RuntimeException("Error news is not found."); } $event = $this->store()->getEvent(); if ($this->string()->length($event) > 0) { $event = 'OnPost' . $this->string()->ucwords($event) . 'Delete'; Event::on($event, function ($id) { if (!NewsCategoryLink::deleteAllByNewsId($id)) { throw new \RuntimeException("Error delete link on news category."); } }); } return $this->store()->delete($repo, $entity); }