description = t('Migrate Materio Materiau nodes'); // provide better description for source fields // and add new field source not from sql $source_fields = array( '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'), ); $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'); $query ->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'); $this->map = new MigrateSQLMap($this->machineName, array( 'id_product' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'OLD Unique Materiau ID', 'alias' => 'pid', ) ), MigrateDestinationNode::getKeySchema() ); $this->addFieldMapping('is_new')->defaultValue(TRUE); $this->addFieldMapping('created', 'date_creation'); $this->addFieldMapping('changed', 'date_modif'); $this->addFieldMapping('status')->defaultValue(1); $this->addFieldMapping('promote')->defaultValue(0); $this->addFieldMapping('sticky')->defaultValue(0); // $this->addFieldMapping('title', 'name_fr'); $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'); // 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_nature_titre', 'nature'); // $this->addFieldMapping('field_nature_titre:language', 'language'); // $this->addFieldMapping(NULL, 'nature_en'); // $this->addFieldMapping(NULL, 'nature_fr'); $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('pathauto')->defaultValue(1); $this->addFieldMapping('comment')->defaultValue(0); $this->addFieldMapping('revision')->defaultValue(0); $this->addFieldMapping(null, 'id_industrial'); $this->addFieldMapping(null, 'quarity'); $this->addFieldMapping('field_onthologie')->defaultValue(null); } 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'); // // $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'); $industrials = explode(',', $cr->list_industrial); $quarities = explode(',', $cr->list_quarity); $companies_fab = array(); $companies_distrib = array(); $l = count($industrials); for ($i=0; $i < $l; $i++) { $result = db_select(MIG_MAT_SRC_DB .'.industrial_info', 'iif') ->fields('iif', array('company')) ->condition('iif.id_industrial', $industrials[$i]) ->distinct()->execute(); foreach ($result as $record) { dsm($record); $company = trim($record->company); if($quarities[$i] == 'M'){ $companies_fab[] = $company; }else{ $companies_distrib[] = $company; } } } $cr->company_fab = implode(',', $companies_fab); $cr->company_distrib = implode(',', $companies_distrib); // // preg_match('/^(\w)([^-]+)-(\d+)$/', $cr->id_materio, $matches); // dsm($matches); // return TRUE; } public function prepare($node, stdClass $row) { // dsm('-- prepare --'); // dsm($node, '$node'); // dsm($row, '$row'); $node->workflow = 4; // $node->field_public_email = array('und'=>array($row->email_contact)); } }