Airship\Cabin\Bridge\Blueprint\Blog::deletePost PHP Method

deletePost() public method

Delete a blog post
public deletePost ( array $formData, array $blogPost = [] ) : boolean
$formData array
$blogPost array
return boolean
    public function deletePost(array $formData, array $blogPost = []) : bool
    {
        $this->db->beginTransaction();
        try {
            if (!empty($formData['create_redirect'])) {
                $blogUrl = \implode('/', ['blog', $blogPost['blogyear'], $blogPost['blogmonth'] > 9 ? $blogPost['blogmonth'] : '0' . $blogPost['blogmonth'], $blogPost['slug']]);
                try {
                    if (\preg_match('#^https?://#', $formData['redirect_url'])) {
                        $cabin = $this->getCabinNameFromURL($formData['redirect_url']);
                    } else {
                        $cabin = $this->cabin;
                    }
                    $this->db->insert('airship_custom_redirect', ['oldpath' => $blogUrl, 'newpath' => $formData['redirect_url'], 'cabin' => $cabin, 'same_cabin' => $cabin === $this->cabin]);
                } catch (CabinNotFound $ex) {
                    $this->db->insert('airship_custom_redirect', ['oldpath' => $blogUrl, 'newpath' => $formData['redirect_url'], 'cabin' => $this->cabin, 'same_cabin' => false]);
                }
            }
            $this->db->delete('hull_blog_post_versions', ['post' => $blogPost['postid']]);
            $this->db->delete('hull_blog_post_tags', ['postid' => $blogPost['postid']]);
            $this->db->delete('hull_blog_comments', ['blogpost' => $blogPost['postid']]);
            $this->db->delete('hull_blog_posts', ['postid' => $blogPost['postid']]);
        } catch (DBException $ex) {
            $this->db->rollBack();
            return false;
        }
        \Airship\clear_cache();
        return $this->db->commit();
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Delete a blog post
  *
  * @param array $post
  * @param array $authorsAllowed
  * @param array $oldPost
  * @return bool
  */
 protected function processDeletePost(array $post, array $authorsAllowed = [], array $oldPost = []) : bool
 {
     // Extra caution: check permissions again.
     if (!$this->isSuperUser()) {
         if (!$this->can('delete')) {
             // Does this author belong to you?
             if (!\in_array((int) $oldPost['author'], $authorsAllowed)) {
                 return false;
             }
         }
     }
     return $this->blog->deletePost($post, $oldPost);
 }