/** * Execute the controller. * * @throws \Exception * @return mixed Return executed result. */ public function execute() { $id = $this->input->get('id'); $authorMapper = new DataMapper('authors'); $return = $this->input->getBase64('return'); $return = $return ? base64_decode($return) : Router::buildHttp('admin:authors'); try { if (!$id) { throw new \Exception('Delete fail'); } $author = $authorMapper->findOne($id); $blog = Blog::get(); $user = User::get(); if ($author->owner) { throw new ValidFailException('You cannot delete owner.'); } if ($user->id != $author->user && $blog->id != $author->blog) { throw new ValidFailException('You cannot delete authors of other blog.'); } $authorMapper->delete(['id' => $id]); } catch (ValidFailException $e) { $this->setRedirect($return, $e->getMessage(), 'danger'); return false; } catch (\Exception $e) { if (WINDWALKER_DEBUG) { throw $e; } $this->setRedirect($return, 'Delete fail', 'danger'); return false; } $this->setRedirect($return, 'Remove Author success', 'success'); return true; }
/** * Execute the controller. * * @throws \Exception * @return mixed Return executed result. */ public function execute() { $id = $this->input->get('id'); $user = User::get(); $blog = Blog::get(); try { if (!$id) { throw new ValidFailException('No ID'); } if (!Author::isAdmin()) { throw new ValidFailException('Access deny'); } $postMapper = new DataMapper('posts'); $post = $postMapper->findOne($id); if ($post->blog != $blog->id) { throw new ValidFailException('You cannot delete post of other blog.'); } $postMapper->delete(['id' => $id]); } catch (ValidFailException $e) { $this->setRedirect(Router::buildHttp('admin:posts'), $e->getMessage(), 'danger'); return false; } catch (\Exception $e) { if (WINDWALKER_DEBUG) { throw $e; } $this->setRedirect(Router::buildHttp('admin:posts'), 'Delete fail', 'danger'); return false; } $this->setRedirect(Router::buildHttp('admin:posts'), 'Delete success', 'success'); return true; }
/** * Execute the controller. * * @throws \Exception * @return mixed Return executed result. */ public function execute() { $id = $this->input->get('id'); $blogMapper = new DataMapper('blogs'); $authorMapper = new DataMapper('authors'); $catMapper = new DataMapper('categories'); $postMapper = new DataMapper('posts'); try { if (!$id) { throw new \Exception('Delete fail'); } $author = $authorMapper->findOne(['blog' => $id, 'user' => User::get()->id]); if (!$author->owner) { throw new ValidFailException('Only owner can remove blog.'); } $blogMapper->delete(['id' => $id]); $authorMapper->delete(['blog' => $id]); $catMapper->delete(['blog' => $id]); $postMapper->delete(['blog' => $id]); } catch (ValidFailException $e) { $this->setRedirect(Router::buildHttp('admin:blogs'), $e->getMessage(), 'danger'); return false; } catch (\Exception $e) { if (WINDWALKER_DEBUG) { throw $e; } $this->setRedirect(Router::buildHttp('admin:blogs'), 'Delete fail', 'danger'); return false; } $this->setRedirect(Router::buildHttp('admin:blogs'), 'Delete Blog success', 'success'); return true; }
/** * Execute the controller. * * @throws \Exception * @return mixed Return executed result. */ public function execute() { $id = $this->input->get('id'); $blog = Blog::get(); try { $catMapper = new DataMapper('categories'); $category = $catMapper->findOne($id); if ($category->blog != $blog->id) { throw new ValidFailException('You cannot delete category of other blog.'); } $catMapper->delete(['id' => $id]); } catch (ValidFailException $e) { $this->setRedirect(Router::buildHttp('admin:categories'), $e->getMessage(), 'error'); return false; } catch (\Exception $e) { if (WINDWALKER_DEBUG) { throw $e; } $this->setRedirect(Router::buildHttp('admin:categories'), 'Delete fail', 'error'); return false; } $this->setRedirect(Router::buildHttp('admin:categories'), 'Delete success', 'success'); return true; }
/** * Method to test delete(). * * @return void * * @covers Windwalker\DataMapper\AbstractDataMapper::delete */ public function testDelete() { $this->instance->delete(array('id' => 16)); $this->assertFalse($this->loadToData('SELECT * FROM ww_flower WHERE id = 16')); }
/** * Delete records by where conditions. * * @param mixed $conditions Where conditions, you can use array or Compare object. * Example: * - `array('id' => 5)` => id = 5 * - `new GteCompare('id', 20)` => 'id >= 20' * - `new Compare('id', '%Flower%', 'LIKE')` => 'id LIKE "%Flower%"' * * @return boolean Will be always true. */ public function delete($conditions) { $this->observers->update('onBeforeDelete', array(&$conditions)); $result = parent::delete($conditions); $this->observers->update('onAfterDelete', array(&$result)); return $result; }