public function createCategories($cats) { $tables = array(); foreach ($cats as $key => $category) { //$this->out("Category Object --> " . print_r($category,true)); $k2_catid = $category->id; $table[$k2_catid] = JTableCategory::getInstance('category', 'JTable'); $nulldate = JFactory::getDbo()->getNullDate(); $params = json_decode($category->params); //$this->out(print_r($params,true)); $table[$k2_catid]->id = 0; if ($category->extraFieldsGroup == 1) { $table[$k2_catid]->extension = 'com_akrecipes'; $this->recipe_catids = $this->recipe_catids . ', ' . $category->id; } else { $table[$k2_catid]->extension = 'com_content'; $this->article_catids = $this->article_catids . ', ' . $category->id; } $table[$k2_catid]->title = $category->name; $table[$k2_catid]->alias = $category->alias; $table[$k2_catid]->description = $category->description; $table[$k2_catid]->published = $category->published; $table[$k2_catid]->language = $category->language; $table[$k2_catid]->version = 1; $table[$k2_catid]->params = '{"category_layout":"","image":""}'; $table[$k2_catid]->metadata = '{"author":"","robots":""}'; $table[$k2_catid]->metadesc = $params->catMetaDesc; $table[$k2_catid]->checked_out_time = $nulldate; $table[$k2_catid]->setLocation(1, 'last-child'); if (!$table[$k2_catid]->check()) { $this->out("Error in table" . $table[$k2_catid]->getError()); return false; } if (!$table[$k2_catid]->store()) { $this->out("Error in table" . $table[$k2_catid]->getError()); return false; } if (!$table[$k2_catid]->checkin()) { $this->out("Error in table" . $table[$k2_catid]->getError()); return false; } $primary_keys = $table[$k2_catid]->getPrimaryKey(); $this->out("Primary Key Object --> " . print_r($primary_keys, true)); $this->categories[$category->id] = $primary_keys['id']; if ($category->extraFieldsGroup == 1) { $this->recipe_category_map[$k2_catid] = $primary_keys['id']; } else { $this->article_category_map[$k2_catid] = $primary_keys['id']; } } foreach ($cats as $key => $category) { $k2_catid = $category->id; $k2_parentid = $category->parent; if (isset($k2_parentid) && $k2_parentid != 0) { $new_parentid = $this->categories[$k2_parentid]; $table[$k2_catid]->moveByReference($new_parentid, 'last-child'); } } }