diff --git a/protected/controllers/MigrateController.php b/protected/controllers/MigrateController.php index 9d3a133..ac43471 100644 --- a/protected/controllers/MigrateController.php +++ b/protected/controllers/MigrateController.php @@ -128,7 +128,7 @@ public function actionStep1() if (isset($connection) AND $connection){ mysqli_close($connection); } - + if ($validate){ //save to config file $configTemplate = Yii::app()->basePath .DIRECTORY_SEPARATOR. "config".DIRECTORY_SEPARATOR."config.template"; @@ -171,10 +171,9 @@ public function actionStep1() } } else { if ($step->status == MigrateSteps::STATUS_NOT_DONE) { - //load database 1 settings in magento 1 website config app/etc/local.xml + //auto load database 1 settings if exists $configFilePath = Yii::app()->basePath ."/../../app/etc/local.xml"; if (file_exists($configFilePath)){ - $configData = simplexml_load_file($configFilePath); $settings = (object)json_decode($step->migrated_data); $settings->mg1_host = $configData->global->resources->default_setup->connection->host; @@ -196,6 +195,17 @@ public function actionStep1() $settings->mg1_version = 'mage19x'; } } + //auto load database 2 settings if exists + $configFilePath = Yii::app()->basePath ."/../../../app/etc/env.php"; + if (file_exists($configFilePath)){ + $configData = require $configFilePath; + $settings = (object)json_decode($step->migrated_data); + $settings->mg2_host = $configData['db']['connection']['default']['host']; + $settings->mg2_db_user = $configData['db']['connection']['default']['username']; + $settings->mg2_db_pass = $configData['db']['connection']['default']['password']; + $settings->mg2_db_name = $configData['db']['connection']['default']['dbname']; + $settings->mg2_db_prefix = $configData['db']['table_prefix']; + } } } @@ -1781,6 +1791,7 @@ public function actionStep6() $customer_groups = Mage1CustomerGroup::model()->findAll(); //variables to log + $errors = array(); $migrated_customer_group_ids = array(); $migrated_customer_ids = array(); @@ -1827,10 +1838,19 @@ public function actionStep6() $needed_update_attr = array( 'created_in', 'firstname', + 'middlename', 'lastname', 'password_hash', 'rp_token', - 'rp_token_created_at' + 'rp_token_created_at', + 'prefix', + 'suffix', + 'dob', + 'default_billing', + 'default_shipping', + 'taxvat', + 'confirmation', + 'gender' ); $customers = Mage1CustomerEntity::model()->findAll("group_id = {$group_id}"); @@ -1872,6 +1892,8 @@ public function actionStep6() $customer2->update(); } } + } else { + $errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors()); } } } @@ -1890,7 +1912,18 @@ public function actionStep6() } } $model2->attribute_id = $attribute_id2; - $model2->save(); + if ($model2->save()){ + //this only for Magento 2 from version 0.74.0 - beta 12 + $attribute_code1 = MigrateSteps::getMage1AttributeCode($model->attribute_id); + if (in_array($attribute_code1, $needed_update_attr)){ + if ($customer2->hasAttribute($attribute_code1)){ + $customer2->$attribute_code1 = $model->value; + $customer2->update(); + } + } + } else { + $errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors()); + } } } } @@ -1909,7 +1942,18 @@ public function actionStep6() } } $model2->attribute_id = $attribute_id2; - $model2->save(); + if ($model2->save()){ + //this only for Magento 2 from version 0.74.0 - beta 12 + $attribute_code1 = MigrateSteps::getMage1AttributeCode($model->attribute_id); + if (in_array($attribute_code1, $needed_update_attr)){ + if ($customer2->hasAttribute($attribute_code1)){ + $customer2->$attribute_code1 = $model->value; + $customer2->update(); + } + } + } else { + $errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors()); + } } } } @@ -1927,7 +1971,18 @@ public function actionStep6() } } $model2->attribute_id = $attribute_id2; - $model2->save(); + if ($model2->save()){ + //this only for Magento 2 from version 0.74.0 - beta 12 + $attribute_code1 = MigrateSteps::getMage1AttributeCode($model->attribute_id); + if (in_array($attribute_code1, $needed_update_attr)){ + if ($customer2->hasAttribute($attribute_code1)){ + $customer2->$attribute_code1 = $model->value; + $customer2->update(); + } + } + } else { + $errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors()); + } } } } @@ -1958,12 +2013,39 @@ public function actionStep6() $customer2->update(); } } + } else { + $errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors()); } } } } //customer_address_entity + //Some attributes was move from children tables to main table + //So we need to do this + //needed_update_attr. + $needed_update_attr2 = array( + 'country_id', + 'firstname', + 'lastname', + 'middlename', + 'street', + 'telephone', + 'city', + 'fax', + 'company', + 'country_id', + 'postcode', + 'prefix', + 'region', + 'region_id', + 'suffix', + 'vat_id', + 'vat_is_valid', + 'vat_request_date', + 'vat_request_id', + 'vat_request_success' + ); $address_entities = Mage1CustomerAddressEntity::model()->findAll("parent_id = {$customer->entity_id}"); if ($address_entities){ foreach($address_entities as $address_entity){ @@ -1973,6 +2055,15 @@ public function actionStep6() $address_entity2->$key = $address_entity->$key; } } + //some fields is new in Magento2 and required at this table, so we need to do this + //and we will update correct value for them later + $address_entity2->country_id = '0'; + $address_entity2->firstname = 'unknown'; + $address_entity2->lastname = 'unknown'; + $address_entity2->street = 'unknown'; + $address_entity2->telephone = 'unknown'; + $address_entity2->city = 'unknown'; + if ($address_entity2->save()){ //customer_address_entity_datetime $models = Mage1CustomerAddressEntityDatetime::model()->findAll("entity_id = $address_entity2->entity_id"); @@ -1988,7 +2079,18 @@ public function actionStep6() } } $model2->attribute_id = $attribute_id2; - $model2->save(); + if ($model2->save()){ + //some attributes was move to main table, so we need to do this + $attribute_code1 = MigrateSteps::getMage1AttributeCode($model->attribute_id); + if (in_array($attribute_code1, $needed_update_attr2)){ + if ($address_entity2->hasAttribute($attribute_code1)){ + $address_entity2->$attribute_code1 = $model->value; + $address_entity2->update(); + } + } + } else { + $errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors()); + } } } } @@ -2007,7 +2109,18 @@ public function actionStep6() } } $model2->attribute_id = $attribute_id2; - $model2->save(); + if ($model2->save()){ + //some attributes was move to main table, so we need to do this + $attribute_code1 = MigrateSteps::getMage1AttributeCode($model->attribute_id); + if (in_array($attribute_code1, $needed_update_attr2)){ + if ($address_entity2->hasAttribute($attribute_code1)){ + $address_entity2->$attribute_code1 = $model->value; + $address_entity2->update(); + } + } + } else { + $errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors()); + } } } } @@ -2026,7 +2139,18 @@ public function actionStep6() } } $model2->attribute_id = $attribute_id2; - $model2->save(); + if ($model2->save()){ + //some attributes was move to main table, so we need to do this + $attribute_code1 = MigrateSteps::getMage1AttributeCode($model->attribute_id); + if (in_array($attribute_code1, $needed_update_attr2)){ + if ($address_entity2->hasAttribute($attribute_code1)){ + $address_entity2->$attribute_code1 = $model->value; + $address_entity2->update(); + } + } + } else { + $errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors()); + } } } } @@ -2044,7 +2168,18 @@ public function actionStep6() } } $model2->attribute_id = $attribute_id2; - $model2->save(); + if ($model2->save()){ + //some attributes was move to main table, so we need to do this + $attribute_code1 = MigrateSteps::getMage1AttributeCode($model->attribute_id); + if (in_array($attribute_code1, $needed_update_attr2)){ + if ($address_entity2->hasAttribute($attribute_code1)){ + $address_entity2->$attribute_code1 = $model->value; + $address_entity2->update(); + } + } + } else { + $errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors()); + } } } } @@ -2062,13 +2197,28 @@ public function actionStep6() } } $model2->attribute_id = $attribute_id2; - $model2->save(); + if ($model2->save()){ + //some attributes was move to main table, so we need to do this + $attribute_code1 = MigrateSteps::getMage1AttributeCode($model->attribute_id); + if (in_array($attribute_code1, $needed_update_attr2)){ + if ($address_entity2->hasAttribute($attribute_code1)){ + $address_entity2->$attribute_code1 = $model->value; + $address_entity2->update(); + } + } + } else { + $errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors()); + } } } } + } else { + $errors[] = get_class($address_entity2).": ".MigrateSteps::getStringErrors($address_entity2->getErrors()); } } }//end a customer entity address + } else { + $errors[] = get_class($customer2).": ".MigrateSteps::getStringErrors($customer2->getErrors()); } //and save a customer entity } } @@ -2104,6 +2254,12 @@ public function actionStep6() Yii::app()->user->setFlash('success', $message); } } + + //alert errors if exists + if ($errors){ + $strErrors = implode('
', $errors); + Yii::app()->user->setFlash('error', $strErrors); + } }//end post request else{ if ($step->status == MigrateSteps::STATUS_DONE){ @@ -2723,7 +2879,7 @@ public function actionStep7() $model2->updated_at = null; $model2->customer_name = $model->shipping_name; if (!$model2->save()){ - $errors[] = MigrateSteps::getStringErrors($model2->getErrors()); + $errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors()); } } } @@ -2738,7 +2894,7 @@ public function actionStep7() } } if (!$model2->save()){ - $errors[] = MigrateSteps::getStringErrors($model2->getErrors()); + $errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors()); } } } @@ -2753,7 +2909,7 @@ public function actionStep7() } } if (!$model2->save()){ - $errors[] = MigrateSteps::getStringErrors($model2->getErrors()); + $errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors()); } } } @@ -2768,7 +2924,7 @@ public function actionStep7() } } if (!$model2->save()){ - $errors[] = MigrateSteps::getStringErrors($model2->getErrors()); + $errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors()); } } } @@ -2788,7 +2944,7 @@ public function actionStep7() } $model2->store_id = MigrateSteps::getMage2StoreId($model->store_id); if (!$model2->save()){ - $errors[] = MigrateSteps::getStringErrors($model2->getErrors()); + $errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors()); } } } @@ -2805,7 +2961,7 @@ public function actionStep7() } $model2->store_id = MigrateSteps::getMage2StoreId($model->store_id); if (!$model2->save()){ - $errors[] = MigrateSteps::getStringErrors($model2->getErrors()); + $errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors()); } } } @@ -2851,7 +3007,7 @@ public function actionStep7() $model2->updated_at = null; $model2->customer_name = $model->billing_name; if (!$model2->save()){ - $errors[] = MigrateSteps::getStringErrors($model2->getErrors()); + $errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors()); } } } @@ -2876,7 +3032,7 @@ public function actionStep7() //this field was not exists in Magento1 $model2->tax_ratio = null; if (!$model2->save()){ - $errors[] = MigrateSteps::getStringErrors($model2->getErrors()); + $errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors()); } } } @@ -2891,7 +3047,7 @@ public function actionStep7() } } if (!$model2->save()){ - $errors[] = MigrateSteps::getStringErrors($model2->getErrors()); + $errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors()); } } }