/** * Save/Add a category with ID. * Rowid and ParentId are RowID of the current category and parentIDs * Category is the category name * blbImage is base64encoded png * meta keywords and descriptions are for meta tags displayed for SEO improvement * Custom page is a page-key defined in Custom Pages in admin panel * Position defines the sorting position of category. Lower number comes first * * @param string $passkey * @param int $intRowId * @param int $intParentId * @param string $strCategory * @param string $strMetaKeywords * @param string $strMetaDescription * @param string $strCustomPage * @param int $intPosition * @param string $blbImage * @return string */ public function save_category_with_id($passkey, $intRowId, $intParentId, $strCategory, $strMetaKeywords, $strMetaDescription, $strCustomPage, $intPosition, $blbImage) { Yii::app()->db->createCommand('SET FOREIGN_KEY_CHECKS=0;')->execute(); if (!$this->check_passkey($passkey)) { return self::FAIL_AUTH; } // Prepare values $strCategory = trim($strCategory); $strCustomPage = trim($strCustomPage); if (!$strCategory) { Yii::log("Could not save empty category", 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); return self::UNKNOWN_ERROR; } $objCategoryAddl = false; // If provided a rowid, attempt to load it if ($intRowId) { $objCategoryAddl = CategoryAddl::model()->findByPk($intRowId); } else { if (!$objCategoryAddl && $intParentId) { $objCategoryAddl = CategoryAddl::LoadByNameParent($strCategory, $intParentId); } } // Failing that, create a new Category if (!$objCategoryAddl) { $objCategoryAddl = new CategoryAddl(); $objCategoryAddl->created = new CDbExpression('NOW()'); $objCategoryAddl->id = $intRowId; } $objCategoryAddl->label = $strCategory; if ($intParentId > 0) { $objCategoryAddl->parent = $intParentId; } $objCategoryAddl->menu_position = $intPosition; $objCategoryAddl->modified = new CDbExpression('NOW()'); $objCategoryAddl->save(); //Now that we've successfully saved in our cache table, update the regular Category table $objCategory = Category::model()->findByPk($intRowId); // Failing that, create a new Category if (!$objCategory) { $objCategory = new Category(); $objCategory->created = new CDbExpression('NOW()'); $objCategory->id = $objCategoryAddl->id; } if ($objCategory) { $objCategory->label = $objCategoryAddl->label; $objCategory->parent = $objCategoryAddl->parent; $objCategory->menu_position = $objCategoryAddl->menu_position; } if (!$objCategory->save()) { _xls_log("SOAP ERROR : Error saving category {$strCategory} " . print_r($objCategory->getErrors(), true)); return self::UNKNOWN_ERROR . " Error saving category {$strCategory} " . print_r($objCategory->getErrors(), true); } //After saving, update some key fields $objCategory->UpdateChildCount(); $objCategory->request_url = $objCategory->GetSEOPath(); if (!$objCategory->save()) { _xls_log("SOAP ERROR : Error saving category (after updating){$strCategory} " . print_r($objCategory->getErrors(), true)); return self::UNKNOWN_ERROR . " Error saving category (after updating){$strCategory} " . print_r($objCategory->getErrors(), true); } Yii::app()->db->createCommand('SET FOREIGN_KEY_CHECKS=1;')->execute(); return self::OK; }