public function delete()
    {
        if (!userHasPermission('admin:blog:post:' . $this->blog->id . ':delete')) {

            unauthorised();
        }

        // --------------------------------------------------------------------------

        //  Fetch and check post
        $iPostId = (int) $this->uri->segment(6);
        $oPost   = $this->blog_post_model->getById($iPostId);

        if (!$oPost || $oPost->blog->id != $this->blog->id) {

            $this->session->set_flashdata('error', 'I could\'t find a post by that ID.');
            redirect('admin/blog/post/index/' . $this->blog->id);
        }

        // --------------------------------------------------------------------------

        if ($this->blog_post_model->delete($iPostId)) {

            $sStatus  = 'success';
            $sMessage = ucfirst($this->data['postName']) . ' was deleted successfully. ';
            if (userHasPermission('admin:blog:post:' . $this->blog->id . ':restore')) {
                $sMessage .= anchor('admin/blog/post/restore/' . $this->blog->id . '/' . $iPostId, 'Undo?');
            }

            //  Update admin changelog
            $this->oChangeLogModel->add('deleted', 'a', 'blog post', $iPostId, $oPost->title);

        } else {

            $sStatus  = 'error';
            $sMessage = 'I failed to delete that post. ' . $this->blog_post_model->lastError();
        }

        $this->session->set_flashdata($sStatus, $sMessage);

        redirect('admin/blog/post/index/' . $this->blog->id);
    }
public function delete()
    {
        if (!userHasPermission('admin:blog:post:' . $this->blog->id . ':delete')) {

            unauthorised();
        }

        // --------------------------------------------------------------------------

        //  Fetch and check post
        $iPostId = (int) $this->uri->segment(6);
        $oPost   = $this->blog_post_model->getById($iPostId);

        if (!$oPost || $oPost->blog->id != $this->blog->id) {

            $this->session->set_flashdata('error', 'I could\'t find a post by that ID.');
            redirect('admin/blog/post/index/' . $this->blog->id);
        }

        // --------------------------------------------------------------------------

        if ($this->blog_post_model->delete($iPostId)) {

            $sStatus  = 'success';
            $sMessage = ucfirst($this->data['postName']) . ' was deleted successfully. ';
            if (userHasPermission('admin:blog:post:' . $this->blog->id . ':restore')) {
                $sMessage .= anchor('admin/blog/post/restore/' . $this->blog->id . '/' . $iPostId, 'Undo?');
            }

            //  Update admin changelog
            $this->oChangeLogModel->add('deleted', 'a', 'blog post', $iPostId, $oPost->title);

        } else {

            $sStatus  = 'error';
            $sMessage = 'I failed to delete that post. ' . $this->blog_post_model->lastError();
        }

        $this->session->set_flashdata($sStatus, $sMessage);

        redirect('admin/blog/post/index/' . $this->blog->id);
    }
public function delete ( ) { if ( ! userHasPermission ( 'admin:blog:post:' . $ this -> blog -> id . ':delete' ) ) { unauthorised ( ) ; } // -------------------------------------------------------------------------- //  Fetch and check post $ iPostId = ( int ) $ this -> uri -> segment ( 6 ) ; $ oPost = $ this -> blog_post_model -> getById ( $ iPostId ) ; if ( ! $ oPost || $ oPost -> blog -> id != $ this -> blog -> id ) { $ this -> session -> set_flashdata ( 'error' , 'I could\'t find a post by that ID.' ) ; redirect ( 'admin/blog/post/index/' . $ this -> blog -> id ) ; } // -------------------------------------------------------------------------- if ( $ this -> blog_post_model -> delete ( $ iPostId ) ) { $ sStatus = 'success' ; $ sMessage = ucfirst ( $ this -> data [ 'postName' ] ) . ' was deleted successfully. ' ; if ( userHasPermission ( 'admin:blog:post:' . $ this -> blog -> id . ':restore' ) ) { $ sMessage .= anchor ( 'admin/blog/post/restore/' . $ this -> blog -> id . '/' . $ iPostId , 'Undo?' ) ; } //  Update admin changelog $ this -> oChangeLogModel -> add ( 'deleted' , 'a' , 'blog post' , $ iPostId , $ oPost -> title ) ; } else { $ sStatus = 'error' ; $ sMessage = 'I failed to delete that post. ' . $ this -> blog_post_model -> lastError ( ) ; } $ this -> session -> set_flashdata ( $ sStatus , $ sMessage ) ; redirect ( 'admin/blog/post/index/' . $ this -> blog -> id ) ; }
Delete a blog post
@return void
Delete a blog post