/** * Save chosen third-party category */ public function actionIntCatSave() { $service = Yii::app()->getRequest()->getQuery('service'); $strSelected = Yii::app()->getRequest()->getQuery('selected'); $arrSelected = explode("|", $strSelected); if (count($arrSelected) > 1) { $objCategory = Category::model()->findByPk($arrSelected[0]); if ($objCategory instanceof Category) { $strTable = "Category" . ucfirst($service); $objIntCategory = $strTable::model()->findByPk($arrSelected[1]); if ($objIntCategory instanceof $strTable) { if (!$objIntCategory->isUsable) { echo json_encode(ucfirst($service) . " does not allow you to pick this category without choosing a further subcategory."); return; } CategoryIntegration::model()->deleteAllByAttributes(array('category_id' => $objCategory->id, 'module' => $service)); $objCI = new CategoryIntegration(); $objCI->category_id = $objCategory->id; $objCI->module = $service; $objCI->foreign_id = $objIntCategory->id; switch (count($arrSelected)) { case 4: $objCI->extra = $arrSelected[2] . "," . $arrSelected[3]; break; case 3: $objCI->extra = $arrSelected[2]; break; case 2: $objCI->extra = null; break; } if (!$objCI->save()) { echo json_encode(_xls_convert_errors($objCI->getErrors())); } else { echo json_encode("success|" . $objIntCategory->name0); } } else { echo json_encode(ucfirst($service) . " category not found"); } } else { echo json_encode("Web Store category not found"); } } else { echo json_encode("Array error"); } }
/** * 9-13 load amazon, Convert our web keywords into new tags table */ protected function actionConvertGoogle() { $ct = 0; //Load google categories _dbx('SET FOREIGN_KEY_CHECKS=0'); if ($this->online == 9) { Yii::app()->db->createCommand()->truncateTable(CategoryGoogle::model()->tableName()); } $file = fopen(YiiBase::getPathOfAlias('ext.wsgoogle.assets') . "/googlecategories.txt", "r"); if ($file) { while (!feof($file)) { $strLine = fgets($file); $ct++; if ($ct >= 1 && $ct <= 1000 && $this->online == 9 || $ct >= 1001 && $ct <= 2000 && $this->online == 10 || $ct >= 2001 && $ct <= 3000 && $this->online == 11 || $ct >= 3001 && $ct <= 4000 && $this->online == 12 || $ct >= 4001 && $ct <= 5000 && $this->online == 13) { $objGC = new CategoryGoogle(); $objGC->name0 = trim($strLine); $arrItems = array_filter(explode(" > ", $strLine)); if (isset($arrItems[0])) { $objGC->name1 = trim($arrItems[0]); } if (isset($arrItems[1])) { $objGC->name2 = trim($arrItems[1]); } if (isset($arrItems[2])) { $objGC->name3 = trim($arrItems[2]); } if (isset($arrItems[3])) { $objGC->name4 = trim($arrItems[3]); } if (isset($arrItems[4])) { $objGC->name5 = trim($arrItems[4]); } if (isset($arrItems[5])) { $objGC->name6 = trim($arrItems[5]); } if (isset($arrItems[6])) { $objGC->name7 = trim($arrItems[6]); } if (isset($arrItems[7])) { $objGC->name8 = trim($arrItems[7]); } if (isset($arrItems[8])) { $objGC->name9 = trim($arrItems[8]); } $objGC->save(); } } } fclose($file); if ($this->online == 13) { for ($x = 1; $x <= 9; $x++) { _dbx("update xlsws_category_google set `name" . $x . "`=null where `name" . $x . "`=''"); } CategoryGoogle::model()->deleteAllByAttributes(array('name1' => null)); //Import old google categories to new try { $dbC = Yii::app()->db->createCommand(); $dbC->setFetchMode(PDO::FETCH_OBJ); //fetch each row as Object $dbC->select()->from('xlsws_category')->where('google_id IS NOT NULL')->order('id'); foreach ($dbC->queryAll() as $row) { _dbx("delete from xlsws_category_integration where module='google' AND foreign_id=" . $row->google_id . " and category_id=" . $row->id); $obj = new CategoryIntegration(); $obj->category_id = $row->id; $obj->module = "google"; $obj->foreign_id = $row->google_id; $obj->extra = $row->google_extra; $obj->save(); } _dbx("alter table xlsws_category drop google_id"); _dbx("alter table xlsws_category drop google_extra"); } catch (Exception $e) { } } _dbx('SET FOREIGN_KEY_CHECKS=1'); return array('result' => "success", 'makeline' => $this->online + 1, 'tag' => 'Installing Google categories (group ' . ($this->online - 7) . " of 6)", 'total' => 50); }