Backend\Modules\Blog\Actions\ImportWordpress::handleCategory PHP Method

handleCategory() private method

We'll check if the category exists in the fork blog module, and create it if it doesn't.
private handleCategory ( string $category = '' ) : integer
$category string The post category
return integer
    private function handleCategory($category = '')
    {
        // Does a category with this name exist?
        /* @var \SpoonDatabase $db */
        $db = BackendModel::getContainer()->get('database');
        $id = (int) $db->getVar('SELECT id FROM blog_categories WHERE title=? AND language=?', array($category, BL::getWorkingLanguage()));
        // We found an id!
        if ($id > 0) {
            return $id;
        }
        // Return default if we got an empty string
        if (trim($category) == '') {
            return 2;
        }
        // We should create a new category
        $cat = array();
        $cat['language'] = BL::getWorkingLanguage();
        $cat['title'] = $category;
        $meta = array();
        $meta['keywords'] = $category;
        $meta['description'] = $category;
        $meta['title'] = $category;
        $meta['url'] = $category;
        return Model::insertCategory($cat, $meta);
    }