Ejemplo n.º 1
0
        }
        ?>
                                <input type="checkbox" <?php 
        echo $checked ? "checked" : '';
        ?>
 id="object_<?php 
        echo $id;
        ?>
" name="selected_objects[]" value="<?php 
        echo $id;
        ?>
" />
                                <?php 
        $total = 0;
        if ($id == 'review') {
            $total = Mage1Review::model()->count();
        } elseif ($id == 'rating') {
            $total = Mage1RatingOptionVote::model()->count();
        }
        ?>
                                <span> <?php 
        echo $label . " (" . $total . ")";
        ?>
 </span>
                            </h4>
                        </li>
                    <?php 
    }
    ?>
                </ul>
                <?php 
 /**
  * Migrate Data from:
  * Sales Orders, Sales Quote, Sales Payments, Sales Invoices, Sales Shipments
  */
 public function actionStep8()
 {
     $step = MigrateSteps::model()->find("sorder = 8");
     $result = MigrateSteps::checkStep($step->sorder);
     if ($result['allowed']) {
         //declare objects to migrate
         $objects = array('review' => Yii::t('frontend', 'Reviews'), 'rating' => Yii::t('frontend', 'Ratings'));
         //variables to log
         $migrated_object_ids = array();
         $migrated_review_ids = $migrated_rating_ids = array();
         if (Yii::app()->request->isPostRequest && $step->status == MigrateSteps::STATUS_NOT_DONE) {
             //uncheck foreign key
             Yii::app()->mage2->createCommand("SET FOREIGN_KEY_CHECKS=0")->execute();
             $selected_objects = Yii::app()->request->getPost('selected_objects', array());
             if ($selected_objects) {
                 //get migrated data from first step in session
                 $migrated_store_ids = isset(Yii::app()->session['migrated_store_ids']) ? Yii::app()->session['migrated_store_ids'] : array();
                 $str_store_ids = implode(',', $migrated_store_ids);
                 $migrated_customer_ids = isset(Yii::app()->session['migrated_customer_ids']) ? Yii::app()->session['migrated_customer_ids'] : array();
                 $str_customer_ids = implode(',', $migrated_customer_ids);
                 //$migrated_product_ids = isset(Yii::app()->session['migrated_product_ids']) ? Yii::app()->session['migrated_product_ids'] : array();
                 //$str_product_ids = implode(',', $migrated_product_ids);
                 if (in_array('review', $selected_objects)) {
                     //review_status -> this table was not changed
                     //review_entity -> this table was not changed
                     //review_entity_summary
                     $condition = "store_id IN ({$str_store_ids}) OR store_id IS NULL";
                     $models = Mage1ReviewEntitySummary::model()->findAll($condition);
                     if ($models) {
                         foreach ($models as $model) {
                             $model2 = new Mage2ReviewEntitySummary();
                             foreach ($model2->attributes as $key => $value) {
                                 if (isset($model->{$key})) {
                                     $model2->{$key} = $model->{$key};
                                 }
                             }
                             $model2->store_id = MigrateSteps::getMage2StoreId($model2->store_id);
                             $model2->save();
                         }
                     }
                     //review
                     $models = Mage1Review::model()->findAll();
                     if ($models) {
                         foreach ($models as $model) {
                             $model2 = new Mage2Review();
                             foreach ($model2->attributes as $key => $value) {
                                 if (isset($model->{$key})) {
                                     $model2->{$key} = $model->{$key};
                                 }
                             }
                             if ($model2->save()) {
                                 $migrated_review_ids[] = $model2->review_id;
                             }
                         }
                     }
                     //review_detail
                     $condition = "(store_id IN ({$str_store_ids}) OR store_id IS NULL)";
                     if ($str_customer_ids) {
                         $condition .= " AND (customer_id IN ({$str_customer_ids}) OR customer_id IS NULL)";
                     }
                     $models = Mage1ReviewDetail::model()->findAll($condition);
                     if ($models) {
                         foreach ($models as $model) {
                             $model2 = new Mage2ReviewDetail();
                             foreach ($model2->attributes as $key => $value) {
                                 if (isset($model->{$key})) {
                                     $model2->{$key} = $model->{$key};
                                 }
                             }
                             $model2->store_id = MigrateSteps::getMage2StoreId($model->store_id);
                             $model2->save();
                         }
                     }
                     //review_store
                     $condition = "store_id IN ({$str_store_ids}) OR store_id IS NULL";
                     $models = Mage1ReviewStore::model()->findAll($condition);
                     if ($models) {
                         foreach ($models as $model) {
                             $model2 = new Mage2ReviewStore();
                             foreach ($model2->attributes as $key => $value) {
                                 if (isset($model->{$key})) {
                                     $model2->{$key} = $model->{$key};
                                 }
                             }
                             $model2->store_id = MigrateSteps::getMage2StoreId($model->store_id);
                             $model2->save();
                         }
                     }
                     $migrated_object_ids[] = 'review';
                 }
                 //end migrate reviews
                 if (in_array('rating', $selected_objects)) {
                     //rating_entity (not changed)
                     //rating_option (not changed)
                     //rating  (not changed)
                     //rating_option_vote
                     $models = Mage1RatingOptionVote::model()->findAll();
                     if ($models) {
                         foreach ($models as $model) {
                             $model2 = new Mage2RatingOptionVote();
                             foreach ($model2->attributes as $key => $value) {
                                 if (isset($model->{$key})) {
                                     $model2->{$key} = $model->{$key};
                                 }
                             }
                             if ($model2->save()) {
                                 $migrated_rating_ids[] = $model2->vote_id;
                             }
                         }
                     }
                     //rating_option_vote_aggregated
                     $condition = "store_id IN ({$str_store_ids}) OR store_id IS NULL";
                     $models = Mage1RatingOptionVoteAggregated::model()->findAll($condition);
                     if ($models) {
                         foreach ($models as $model) {
                             $model2 = new Mage2RatingOptionVoteAggregated();
                             foreach ($model2->attributes as $key => $value) {
                                 if (isset($model->{$key})) {
                                     $model2->{$key} = $model->{$key};
                                 }
                             }
                             $model2->store_id = MigrateSteps::getMage2StoreId($model->store_id);
                             $model2->save();
                         }
                     }
                     //rating_store
                     $condition = "store_id IN ({$str_store_ids}) OR store_id IS NULL";
                     $models = Mage1RatingStore::model()->findAll($condition);
                     if ($models) {
                         foreach ($models as $model) {
                             $model2 = new Mage2RatingStore();
                             foreach ($model2->attributes as $key => $value) {
                                 if (isset($model->{$key})) {
                                     $model2->{$key} = $model->{$key};
                                 }
                             }
                             $model2->store_id = MigrateSteps::getMage2StoreId($model->store_id);
                             $model2->save();
                         }
                     }
                     //rating_title
                     $condition = "store_id IN ({$str_store_ids}) OR store_id IS NULL";
                     $models = Mage1RatingTitle::model()->findAll($condition);
                     if ($models) {
                         foreach ($models as $model) {
                             $model2 = new Mage2RatingTitle();
                             foreach ($model2->attributes as $key => $value) {
                                 if (isset($model->{$key})) {
                                     $model2->{$key} = $model->{$key};
                                 }
                             }
                             $model2->store_id = MigrateSteps::getMage2StoreId($model->store_id);
                             $model2->save();
                         }
                     }
                     $migrated_object_ids[] = 'rating';
                 }
                 //end migrate ratings
             } else {
                 Yii::app()->user->setFlash('note', Yii::t('frontend', 'You have not selected any Object.'));
             }
             //Update step status
             if ($migrated_object_ids) {
                 $step->status = MigrateSteps::STATUS_DONE;
                 $step->migrated_data = json_encode(array('object_ids' => $migrated_object_ids, 'review_ids' => $migrated_review_ids, 'rating_ids' => $migrated_rating_ids));
                 if ($step->update()) {
                     //check foreign key
                     Yii::app()->mage2->createCommand("SET FOREIGN_KEY_CHECKS=1")->execute();
                     //update session
                     Yii::app()->session['migrated_object_ids'] = $migrated_object_ids;
                     Yii::app()->session['migrated_review_ids'] = $migrated_review_ids;
                     Yii::app()->session['migrated_rating_ids'] = $migrated_rating_ids;
                     $message = Yii::t('frontend', 'Migrated successfully.');
                     $message .= "<br/>" . Yii::t('frontend', "Total Reviews migrated: %s1.", array('%s1' => sizeof($migrated_review_ids)));
                     $message .= "<br/>" . Yii::t('frontend', "Total Ratings migrated: %s2.", array('%s2' => sizeof($migrated_rating_ids)));
                     Yii::app()->user->setFlash('success', $message);
                 }
             }
         } else {
             if ($step->status == MigrateSteps::STATUS_DONE) {
                 Yii::app()->user->setFlash('note', Yii::t('frontend', "This step was finished. If you want to update data of this step, the first you have to click to 'Reset' button."));
             }
         }
         $this->render("step{$step->sorder}", array('step' => $step, 'objects' => $objects));
     } else {
         Yii::app()->user->setFlash('note', Yii::t('frontend', "The first you need to finish the %s.", array("%s" => ucfirst($result['back_step']))));
         $this->redirect(array($result['back_step']));
     }
 }