debug
- company : dispatch address filed in premise and sub_premise if more than 255 char - company : avoid and record on memo tel1 if number is more than 15 char - materiau : move product_info query in prepareRow() Signed-off-by: bachy <git@g-u-i.net>
This commit is contained in:
parent
760047e9fc
commit
93b7db54fe
@ -14,6 +14,8 @@ class MaterioCompanyMigration extends MaterioBasicMigration {
|
||||
'id_industrial' => t('Industrial id from source'),
|
||||
'department'=> t('en-fr department implemented on prepare'),
|
||||
'language'=> t('en-fr langauge description, used in prepare'),
|
||||
'premise'=>t('premise'),
|
||||
'sub_premise'=>t('sub_premise'),
|
||||
);
|
||||
|
||||
$query = db_select(MIG_MAT_SRC_DB .'.industrial_id', 'iid');
|
||||
@ -79,6 +81,8 @@ class MaterioCompanyMigration extends MaterioBasicMigration {
|
||||
$arguments = array(
|
||||
// 'name_line' => array('source_field' => 'name'),
|
||||
'thoroughfare' => array('source_field' => 'address'),
|
||||
'premise' => array('source_field' => 'premise'),
|
||||
'sub_premise' => array('source_field' => 'sub_premise'),
|
||||
'locality' => array('source_field' => 'city'),
|
||||
'postal_code' => array('source_field' => 'zip'),
|
||||
);
|
||||
@ -86,6 +90,8 @@ class MaterioCompanyMigration extends MaterioBasicMigration {
|
||||
->arguments($arguments);
|
||||
|
||||
$this->addFieldMapping(NULL, 'address');
|
||||
$this->addFieldMapping(NULL, 'premise');
|
||||
$this->addFieldMapping(NULL, 'sub_premise');
|
||||
$this->addFieldMapping(NULL, 'city');
|
||||
$this->addFieldMapping(NULL, 'zip');
|
||||
$this->addFieldMapping(NULL, 'country_fr');
|
||||
@ -130,6 +136,14 @@ class MaterioCompanyMigration extends MaterioBasicMigration {
|
||||
|
||||
public function prepareRow($cr) {
|
||||
$cr->address = preg_replace('/\\n/', ', ', $cr->address);
|
||||
if(strlen($cr->address) > 255){
|
||||
$adress = $cr->address;
|
||||
$cr->address = substr($adress, 0, 250);
|
||||
$cr->premise = substr($adress, 250, 500);
|
||||
$sub = substr($adress, 500, 750);
|
||||
$cr->sub_premise = $sub ? $sub : '';
|
||||
}
|
||||
|
||||
$cr->city = preg_replace('/\\n/', ' ', $cr->city);
|
||||
|
||||
$cr->department = array($cr->department_en, $cr->department_fr);
|
||||
@ -148,32 +162,43 @@ class MaterioCompanyMigration extends MaterioBasicMigration {
|
||||
|
||||
$ccs = cck_phone_countrycodes();
|
||||
$match = 0;
|
||||
$ccode1 = '';
|
||||
foreach ($ccs as $cc => $cc_values) {
|
||||
if('+'.$cr->ccode1 == $cc_values['code']){
|
||||
$cr->ccode1 = $cc;
|
||||
$ccode1 = $ccs[$cc];
|
||||
$match++;
|
||||
}
|
||||
if('+'.$cr->ccode2 == $cc_values['code']){
|
||||
$cr->ccode2 = $cc;
|
||||
$cr->ccode2 = $ccs[$cc];
|
||||
$match++;
|
||||
}
|
||||
if('+'.$cr->ccode3 == $cc_values['code']){
|
||||
$cr->ccode3 = $cc;
|
||||
$cr->ccode3 = $ccs[$cc];
|
||||
$match++;
|
||||
}
|
||||
|
||||
if($match == 4)
|
||||
if($match == 3)
|
||||
break;
|
||||
}
|
||||
|
||||
$cr->ccode1 = strlen($cr->ccode1) == 2 ? $cr->ccode1 : false;
|
||||
|
||||
if(($cr->tel1 != '' && !$cr->ccode1) || strlen($cr->tel1) > 15){
|
||||
$cr->tel1 = '';
|
||||
|
||||
$cc = is_array($ccode1) ? $ccode1['country'] . ' (' . $ccode1['code'] . ')' : '';
|
||||
$cr->memo .= "\n".'tel1 : '. $cc .' '. $cr->tel1;
|
||||
}
|
||||
|
||||
// do this because i don't know how to insert multiple phone fields
|
||||
// do this because i don't know how to insert multiple phone fields
|
||||
if($cr->tel2 != ''){
|
||||
$cc = cck_phone_countrycodes($cr->ccode2);
|
||||
$cr->memo .= "\n".'tel2 : '. $cc['country'] . ' (' . $cc['code'] . ')' .' '. $cr->tel2;
|
||||
$cc = is_array($cr->ccode2) ? $cr->ccode2['country'] . ' (' . $cr->ccode2['code'] . ')' : '';
|
||||
$cr->memo .= "\n".'tel2 : '. $cc .' '. $cr->tel2;
|
||||
}
|
||||
if($cr->tel3 != ''){
|
||||
$cc = cck_phone_countrycodes($cr->ccode3);
|
||||
$cr->memo .= "\n".'tel3 : '. $cc['country'] . ' (' . $cc['code'] . ')' .' '. $cr->tel3;
|
||||
$cc = is_array($cr->ccode3) ? $cr->ccode3['country'] . ' (' . $cr->ccode3['code'] . ')' : '';
|
||||
$cr->memo .= "\n".'tel3 : '. $cc .' '. $cr->tel3;
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,38 +14,20 @@ class MaterioMateriauNodeMigration extends MaterioBasicMigration {
|
||||
'id_product' => t('Materiau id from source'),
|
||||
'company_fab'=>t('company_fab'),
|
||||
'company_distrib'=>t('company_distrib'),
|
||||
// 'name'=> t('en-fr name implemented on prepare'),
|
||||
// 'description'=> t('en-fr description implemented on prepare'),
|
||||
// 'nature'=> t('en-fr nature implemented on prepare'),
|
||||
// 'language'=> t('en-fr langauge description, used in prepare'),
|
||||
'title'=>t('title'),
|
||||
'name'=> t('en-fr name implemented on prepare'),
|
||||
'description'=> t('en-fr description implemented on prepare'),
|
||||
'nature'=> t('en-fr nature implemented on prepare'),
|
||||
'language'=> t('en-fr langauge description, used in prepare'),
|
||||
);
|
||||
|
||||
$query = db_select(MIG_MAT_SRC_DB .'.product_id', 'pid');
|
||||
|
||||
$query->join(MIG_MAT_SRC_DB .'.product_industrial', 'pind', 'pind.id_product = pid.id_product');
|
||||
|
||||
// $industrial_query = db_select(MIG_MAT_SRC_DB .'.industrial_info', 'iif_select')
|
||||
// ->fields('iif_select', array('id_industrial', 'company'))->distinct();
|
||||
// $query->join($industrial_query, 'iif', 'iif.id_industrial = pind.id_industrial');
|
||||
|
||||
|
||||
// WARNING ! product_info is double langauge + duplicate -> 4 rows each product
|
||||
// $pif_fr_query = db_select(MIG_MAT_SRC_DB .'.product_info', 'pif_fr_select')
|
||||
// //->fields('pif_fr_select')// , array('id_product') //, 'name', 'nature', 'description', 'usage', 'technical', 'keywords',
|
||||
// ->condition('pif_fr_select.id_locale', 2)->distinct();
|
||||
// $pif_fr_query->addField('pif_fr_select', 'id_product', 'id_product');
|
||||
// $query->join($pif_fr_query, 'pif_fr', 'pif_fr.id_product = pid.id_product');
|
||||
|
||||
// $pif_en_query = db_select(MIG_MAT_SRC_DB .'.product_info', 'pif_en_select')
|
||||
// ->fields('pif_en_select')//, array('id_product') //, 'name', 'nature', 'description', 'usage', 'technical', 'keywords',
|
||||
// ->condition('pif_en_select.id_locale', 1)->distinct();
|
||||
// // $pif_en_query->addField('pif_en_select', 'name', 'name_en');
|
||||
// $query->join($pif_en_query, 'pif_en', 'pif_en.id_product = pid.id_product');
|
||||
|
||||
$query
|
||||
->fields('pid', array('id_product', 'id_materio', 'status', 'memo', 'source', 'date_creation', 'date_modif'))
|
||||
->fields('pind', array('id_industrial', 'quarity'));
|
||||
// ->fields('iff', array('company'))
|
||||
|
||||
$query->addExpression('GROUP_CONCAT(DISTINCT pind.id_industrial)','list_industrial');
|
||||
$query->addExpression('GROUP_CONCAT(pind.quarity)','list_quarity');
|
||||
@ -54,21 +36,6 @@ class MaterioMateriauNodeMigration extends MaterioBasicMigration {
|
||||
->orderBy('pid.id_product', 'DESC')
|
||||
->groupBy('pid.id_product');
|
||||
|
||||
//'name', 'nature', 'description', 'usage', 'technical', 'keywords'
|
||||
// $query->addField('pif_fr', 'name', 'name_fr');
|
||||
// $query->addField('pif_fr', 'nature', 'nature_fr');
|
||||
// $query->addField('pif_fr', 'description', 'description_fr');
|
||||
// $query->addField('pif_fr', 'usage', 'usage_fr');
|
||||
// $query->addField('pif_fr', 'technical', 'technical_fr');
|
||||
// $query->addField('pif_fr', 'keywords', 'keywords_fr');
|
||||
//
|
||||
// $query->addField('pif_en', 'name', 'name_en');
|
||||
// $query->addField('pif_en', 'nature', 'nature_en');
|
||||
// $query->addField('pif_en', 'description', 'description_en');
|
||||
// $query->addField('pif_en', 'usage', 'usage_en');
|
||||
// $query->addField('pif_en', 'technical', 'technical_en');
|
||||
// $query->addField('pif_en', 'keywords', 'keywords_en');
|
||||
|
||||
$this->source = new MigrateSourceSQL($query, $source_fields);
|
||||
$this->destination = new MigrateDestinationNode('materiau');
|
||||
|
||||
@ -91,29 +58,25 @@ class MaterioMateriauNodeMigration extends MaterioBasicMigration {
|
||||
$this->addFieldMapping('status')->defaultValue(1);
|
||||
$this->addFieldMapping('promote')->defaultValue(0);
|
||||
$this->addFieldMapping('sticky')->defaultValue(0);
|
||||
$this->addFieldMapping('language')->defaultValue('fr');
|
||||
|
||||
// $this->addFieldMapping('title', 'name_fr');
|
||||
$this->addFieldMapping('title', 'title');
|
||||
$this->addFieldMapping('field_memo', 'memo');
|
||||
|
||||
// $this->addFieldMapping('title_field', 'name');
|
||||
// $this->addFieldMapping('title_field:language', 'language');
|
||||
// $this->addFieldMapping(NULL, 'name_en');
|
||||
// $this->addFieldMapping(NULL, 'name_fr');
|
||||
$this->addFieldMapping('title_field', 'name');
|
||||
$this->addFieldMapping('title_field:language', 'language');
|
||||
|
||||
// see on prepareRow()
|
||||
// $this->addFieldMapping('field_description', 'description');
|
||||
// $this->addFieldMapping('field_description:language', 'language');
|
||||
// $this->addFieldMapping(NULL, 'description_en');
|
||||
// $this->addFieldMapping(NULL, 'description_fr');
|
||||
$this->addFieldMapping('field_description', 'description');
|
||||
$this->addFieldMapping('field_description:language', 'language');
|
||||
$this->addFieldMapping('field_description:format')->defaultValue('filtred_html');
|
||||
|
||||
// $this->addFieldMapping('field_nature_titre', 'nature');
|
||||
// $this->addFieldMapping('field_nature_titre:language', 'language');
|
||||
// $this->addFieldMapping(NULL, 'nature_en');
|
||||
// $this->addFieldMapping(NULL, 'nature_fr');
|
||||
$this->addFieldMapping('field_nature_titre', 'nature');
|
||||
$this->addFieldMapping('field_nature_titre:language', 'language');
|
||||
|
||||
$this->addFieldMapping('field_company_fab', 'company_fab');
|
||||
$this->addFieldMapping('field_company_fab:create_term')->defaultValue(false);
|
||||
$this->addFieldMapping('field_company_distrib', 'company_distrib');
|
||||
$this->addFieldMapping('field_company_distrib:create_term')->defaultValue(false);
|
||||
|
||||
$this->addFieldMapping('pathauto')->defaultValue(1);
|
||||
$this->addFieldMapping('comment')->defaultValue(0);
|
||||
@ -130,26 +93,43 @@ class MaterioMateriauNodeMigration extends MaterioBasicMigration {
|
||||
public function prepareRow($cr){
|
||||
// dsm($cr);
|
||||
|
||||
// $result = db_select(MIG_MAT_SRC_DB .'.product_info', 'pif_fr_select')
|
||||
// ->fields('pif_fr_select' , array('name', 'nature', 'description'))// , 'usage', 'technical', 'keywords',
|
||||
// ->condition('pif_fr_select.id_locale', 2)
|
||||
// ->condition('pif_fr_select.id_product', $cr->id_product)
|
||||
// ->distinct();//->exectute();
|
||||
|
||||
// $prod_infos_fr = $result->fetchAll();
|
||||
|
||||
// dsm($result->__toString(), '$query to string');
|
||||
# parse product infos
|
||||
$infos_fr = db_select(MIG_MAT_SRC_DB .'.product_info', 'pif_fr')
|
||||
->condition('pif_fr.id_locale', 2)
|
||||
->condition('pif_fr.id_product', $cr->id_product)
|
||||
->fields('pif_fr' , array('name', 'nature', 'description', 'technical', 'keywords'))//, 'usage'
|
||||
->distinct()->execute();
|
||||
|
||||
foreach ($infos_fr as $record)
|
||||
$infos['fr'] = $record;
|
||||
|
||||
$infos['fr']->description .= "<br />technical : ".$infos['fr']->technical; // . "<br />usage".$infos['fr']->usage
|
||||
|
||||
$infos_en = db_select(MIG_MAT_SRC_DB .'.product_info', 'pif_en')
|
||||
->condition('pif_en.id_locale', 1)
|
||||
->condition('pif_en.id_product', $cr->id_product)
|
||||
->fields('pif_en' , array('name', 'nature', 'description', 'technical', 'keywords'))//, 'usage' , 'keywords'
|
||||
->distinct()->execute();
|
||||
|
||||
foreach ($infos_en as $record)
|
||||
$infos['en'] = $record;
|
||||
|
||||
$infos['en']->description .= "<br />technical : ".$infos['en']->technical; // . "<br />usage".$infos['en']->usage
|
||||
|
||||
$cr->title = $infos['fr']->name;
|
||||
$cr->name = array($infos['en']->name, $infos['fr']->name);
|
||||
$cr->description = array($infos['en']->description, $infos['fr']->description);
|
||||
$cr->nature = array($infos['en']->nature, $infos['fr']->nature);
|
||||
$cr->language = array('en', 'fr');
|
||||
|
||||
#record keywords on memo
|
||||
$cr->memo .= ($cr->memo != '' ? "\n\n" : '') . $infos['fr']->keywords;
|
||||
|
||||
|
||||
//
|
||||
// $cr->name = array($cr->name_en, $cr->name_fr);
|
||||
// $cr->description = array($cr->description_en, $cr->description_fr);
|
||||
// $cr->nature = array($cr->nature_en, $cr->nature_fr);
|
||||
// $cr->language = array('en', 'fr');
|
||||
|
||||
# parse companies
|
||||
dsm($cr->list_industrial, '-- $cr->list_industrial');
|
||||
dsm($cr->list_quarity, '$cr->list_quarity');
|
||||
// dsm($cr->list_industrial, '-- $cr->list_industrial');
|
||||
// dsm($cr->list_quarity, '$cr->list_quarity');
|
||||
$industrials = explode(',', $cr->list_industrial);
|
||||
$quarities = explode(',', $cr->list_quarity);
|
||||
|
||||
@ -164,7 +144,7 @@ class MaterioMateriauNodeMigration extends MaterioBasicMigration {
|
||||
->distinct()->execute();
|
||||
|
||||
foreach ($result as $record) {
|
||||
dsm($record);
|
||||
// dsm($record);
|
||||
$company = trim($record->company);
|
||||
|
||||
if($quarities[$i] == 'M'){
|
||||
@ -185,6 +165,10 @@ class MaterioMateriauNodeMigration extends MaterioBasicMigration {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function prepare($node, stdClass $row) {
|
||||
// dsm('-- prepare --');
|
||||
// dsm($node, '$node');
|
||||
|
Loading…
x
Reference in New Issue
Block a user