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

updateCategorySlug() public method

public updateCategorySlug ( integer $id, array $post ) : boolean
$id integer
$post array
return boolean
    public function updateCategorySlug(int $id, array $post) : bool
    {
        $slug = $this->db->cell('SELECT slug FROM hull_blog_categories WHERE categoryid = ?', $id);
        if ($slug === $post['slug']) {
            // Don't update. It's the same.
            return false;
        }
        if ($this->db->exists('SELECT count(*) FROM hull_blog_categories WHERE slug = ?', $post['slug'])) {
            // Don't update.
            return false;
        }
        if (!empty($post['redirect_slug'])) {
            $oldUrl = \implode('/', ['blog', 'category', $slug]);
            $newUrl = \implode('/', ['blog', 'category', $post['slug']]);
            $this->db->insert('airship_custom_redirect', ['oldpath' => $oldUrl, 'newpath' => $newUrl, 'cabin' => $this->cabin, 'same_cabin' => true]);
        }
        // Allow updates to go through.
        return true;
    }