Ejemplo n.º 1
0
 /**
  * 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);
 }