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

deleteCategory() public method

Delete a category and move all related content
public deleteCategory ( integer $categoryID, integer $moveChildrenTo ) : boolean
$categoryID integer
$moveChildrenTo integer
return boolean
    public function deleteCategory(int $categoryID, int $moveChildrenTo = 0) : bool
    {
        if ($moveChildrenTo <= 0) {
            $moveChildrenTo = null;
        }
        $this->db->beginTransaction();
        try {
            $this->db->update('hull_blog_posts', ['category' => $moveChildrenTo], ['category' => $categoryID]);
            $this->db->delete('hull_blog_categories', ['categoryid' => $categoryID]);
        } catch (DBException $ex) {
            $this->db->rollBack();
            return false;
        }
        \Airship\clear_cache();
        return $this->db->commit();
    }

Usage Example

Example #1
0
 /**
  * Delete a blog post category
  *
  * @param int $categoryId
  * @param array $post
  * @return bool
  */
 protected function processDeleteCategory(int $categoryId, array $post = []) : bool
 {
     if (!$this->isSuperUser()) {
         if (!$this->can('delete')) {
             return false;
         }
     }
     return $this->blog->deleteCategory($categoryId, (int) ($post['moveChildrenTo'] ?? 0));
 }