瀏覽代碼

Industrials OK

Company CT
account, contact, admin, sample USERS

Signed-off-by: bachy <git@g-u-i.net>
bachy 13 年之前
父節點
當前提交
94bf329b91

+ 84 - 0
migrate_materio.account.inc

@@ -0,0 +1,84 @@
+<?php
+/**
+ * MaterioIndustrialUserMigration
+ * 
+ */
+class MaterioIndustrialAccountUserMigration extends MaterioBasicMigration {
+  public function __construct() {
+    parent::__construct();
+    $this->description = t('Migrate Materio Industrials Account Users');
+
+		// provide better description for source fields
+		// and add new field source not from sql
+    $source_fields = array(
+      'id_industrial' => t('Industrial id from source'),
+			'memo' => t('memo'),
+    );
+
+	  $query = db_select(MIG_MAT_SRC_DB .'.industrial_id', 'iid');
+		$query->join(MIG_MAT_SRC_DB .'.industrial_account', 'ind_ac', 'iid.id_industrial = ind_ac.id_industrial');
+		$query->join(MIG_MAT_SRC_DB .'.industrial_info', 'iinf', 'iid.id_industrial = iinf.id_industrial');
+		$query
+			->fields('iid', array('id_industrial', 'date_creation', 'date_modif'))
+			->fields('ind_ac', array('login', 'password'))
+			->fields('iinf', array('company', 'email_general'))
+			->orderBy('iid.id_industrial', 'DESC');
+			
+		$query->groupBy('iid.id_industrial');
+		
+	  $this->source = new MigrateSourceSQL($query, $source_fields);
+    $this->destination = new MigrateDestinationUser();
+    $this->map = new MigrateSQLMap($this->machineName,
+      array(
+        'id_industrial' => array(
+          'type' => 'int',
+          'unsigned' => TRUE,
+          'not null' => TRUE,
+          'description' => 'OLD Unique industrial ID',
+          'alias' => 'iid',
+        )
+      ),
+      MigrateDestinationUser::getKeySchema()
+    );
+
+	  // Make the mappings
+	  $this->addFieldMapping('name', 'login');
+	  $this->addFieldMapping('pass', 'password');//->defaultValue(NULL);
+	  $this->addFieldMapping('mail', 'email_general');
+		# NOTE : maybe if we provide only init mail, we wiil be able to ask email confirmation for users
+	  $this->addFieldMapping('init', 'email_general');
+	  $this->addFieldMapping('language')->defaultValue('');
+	  $this->addFieldMapping('theme')->defaultValue('');
+	  $this->addFieldMapping('signature')->defaultValue('');
+	  $this->addFieldMapping('signature_format')->defaultValue('filtered_html');
+	 	$this->addFieldMapping('created', 'date_creation');
+	  $this->addFieldMapping('access', 'date_modif');
+	  $this->addFieldMapping('login')->defaultValue(0);
+	  $this->addFieldMapping('status')->defaultValue(0);
+	  $this->addFieldMapping('picture')->defaultValue(0);
+	  $this->addFieldMapping('timezone')->defaultValue(NULL);
+	  // $this->addFieldMapping('path')->issueGroup(t('DNM'));
+	  $this->addFieldMapping('pathauto')->defaultValue(1);
+		$this->addFieldMapping('roles')->defaultValue(array(5));
+		$this->addFieldMapping('is_new')->defaultValue(TRUE);
+	
+		$this->addFieldMapping('field_memo', 'memo');
+	
+		$this->addFieldMapping('field_company', 'company');
+	
+	}
+	
+	public function prepareRow($cr) {
+			if($cr->email_general == '')
+				return false;
+		
+			$cr->company = trim($cr->company);
+		
+			$cr->memo = $cr->login .' | '. $cr->password;
+		
+	    return TRUE;
+	    // return FALSE if you wish to skip a particular row
+	  }
+	
+}
+

+ 232 - 0
migrate_materio.admin.inc

@@ -0,0 +1,232 @@
+<?php
+/**
+ * MaterioIndustrialUserMigration
+ * 
+ */
+class MaterioIndustrialAdminUserMigration extends MaterioBasicMigration {
+  public function __construct() {
+    parent::__construct();
+    $this->description = t('Migrate Materio Industrials Admin Users');
+
+		// provide better description for source fields
+		// and add new field source not from sql
+    $source_fields = array(
+      'id_industrial' => t('Industrial id from source'),
+			'memo' => t('memo'),
+    );
+
+	  $query = db_select(MIG_MAT_SRC_DB .'.industrial_id', 'iid');
+		$query->join(MIG_MAT_SRC_DB .'.industrial_info', 'iinf', 'iid.id_industrial = iinf.id_industrial');
+		
+		$query
+			->fields('iid', array('id_industrial', 'date_creation', 'date_modif'))
+			->fields('iinf', array('company', 'email_admin'))
+			->orderBy('iid.id_industrial', 'DESC');
+		
+		$query->groupBy('iid.id_industrial');
+		
+	  $this->source = new MigrateSourceSQL($query, $source_fields);
+    $this->destination = new MigrateDestinationUser();
+	  
+    $this->map = new MigrateSQLMap($this->machineName,
+      array(
+        'id_industrial' => array(
+          'type' => 'int',
+          'unsigned' => TRUE,
+          'not null' => TRUE,
+          'description' => 'OLD Unique industrial ID',
+          'alias' => 'iid',
+        )
+      ),
+      MigrateDestinationUser::getKeySchema()
+    );
+
+	  // Make the mappings
+	  $this->addFieldMapping('name')->defaultValue('aname');
+	  $this->addFieldMapping('pass')->defaultValue(NULL);
+	  $this->addFieldMapping('mail', 'email_admin');
+		# NOTE : maybe if we provide only init mail, we wiil be able to ask email confirmation for users
+	  $this->addFieldMapping('init', 'email_admin');
+	  $this->addFieldMapping('language')->defaultValue('');
+	  $this->addFieldMapping('theme')->defaultValue('');
+	  $this->addFieldMapping('signature')->defaultValue('');
+	  $this->addFieldMapping('signature_format')->defaultValue('filtered_html');
+	 	$this->addFieldMapping('created', 'date_creation');
+	  $this->addFieldMapping('access', 'date_modif');
+	  $this->addFieldMapping('login')->defaultValue(0);
+	  $this->addFieldMapping('status')->defaultValue(0);
+	  $this->addFieldMapping('picture')->defaultValue(0);
+	  $this->addFieldMapping('timezone')->defaultValue(NULL);
+	  // $this->addFieldMapping('path')->issueGroup(t('DNM'));
+	  $this->addFieldMapping('pathauto')->defaultValue(1);
+		$this->addFieldMapping('roles')->defaultValue(array(5));
+		$this->addFieldMapping('is_new')->defaultValue(TRUE);
+	
+		$this->addFieldMapping('field_memo', 'memo');
+	
+		$this->addFieldMapping('field_company', 'company');
+	
+	}
+	
+	public function prepareRow($cr) {
+			
+		if($cr->email_admin == "")
+			return false;
+		
+		$cr->company = trim($cr->company);
+		
+		$cr->memo = "#admin";
+							
+    return TRUE;
+    // return FALSE if you wish to skip a particular row
+  }
+	
+}
+
+
+/**
+ * MaterioIndustrialProfile2Migration
+ */
+class MaterioIndustrialAdminProfile2Migration extends MaterioBasicMigration {
+  public function __construct() {
+    parent::__construct();
+		global $user;
+    $this->description = t('Migrate Materio Industrials Admin Profiles2');
+
+		// provide better description for source fields
+		// and add new field source not from sql
+    $source_fields = array(
+      'id_industrial' => t('Industrial id from source'),
+			'admin_quality'=> t('en-fr admin quality implemented on prepare'),
+			'language'=> t('en-fr langauge description, used in prepare'),
+			'tels_admin' => '',
+			'ccodes_admin' => ''
+    );
+
+	  $query = db_select(MIG_MAT_SRC_DB .'.industrial_id', 'iid');
+		$query->join(MIG_MAT_SRC_DB .'.industrial_info', 'iinf', 'iid.id_industrial = iinf.id_industrial');
+		
+		$ilfr_select = db_select(MIG_MAT_SRC_DB .'.industrial_lang', 'ilfr_select')
+			->fields('ilfr_select')->condition('ilfr_select.id_locale',1)->orderBy('ilfr_select.id_industrial', 'DESC')->distinct();
+		$query->join($ilfr_select, 'ilfr', 'iid.id_industrial = ilfr.id_industrial');
+		
+		
+		$ilen_select = db_select(MIG_MAT_SRC_DB .'.industrial_lang', 'ilen_select')
+			->fields('ilen_select')->condition('ilen_select.id_locale',2)->orderBy('ilen_select.id_industrial', 'ASC')->distinct();
+		$query->join($ilen_select, 'ilen', 'iid.id_industrial = ilen.id_industrial'); 
+		
+		$query
+			->fields('iid', array('id_industrial', 'date_creation', 'date_modif'))
+			->fields('iinf', array('admin', 'admin_title', 'email_admin', 'tel1_admin', 'ccode1_admin', 'tel2_admin', 'ccode2_admin'));
+
+		$query->addField('ilfr', 'admin_quality', 'admin_quality_fr');
+		$query->addField('ilen', 'admin_quality', 'admin_quality_en');
+
+		$query->groupBy('iid.id_industrial')
+			->orderBy('iid.id_industrial', 'DESC');
+		
+		
+	  $this->source = new MigrateSourceSQL($query, $source_fields);
+		// $this->dependencies = array('MaterioIndustrialUser');
+    $this->destination = new MigrateDestinationProfile2('contact_operationnel');
+	  
+    $this->map = new MigrateSQLMap($this->machineName,
+      array(
+        'id_industrial' => array(
+          'type' => 'int',
+          'unsigned' => TRUE,
+          'not null' => TRUE,
+          'description' => 'OLD Unique industrial ID',
+          'alias' => 'iid',
+        )
+      ),
+      MigrateDestinationProfile2::getKeySchema()
+    );
+
+	  // Connecting the profile2 to the user:
+	  $this->addFieldMapping('uid', 'id_industrial')
+	    ->sourceMigration('MaterioIndustrialAdminUser')  // If your user migration class was named 'MyUserMigration', the string is 'MyUser'
+	    ->description(t('The assignment of profile2-items to the respective user'));
+
+		$this->addFieldMapping('revision_uid', 'id_industrial')
+			->sourceMigration('MaterioIndustrialAdminUser');
+	
+	  // Make the mappings
+		$this->addFieldMapping('language')->defaultValue('');
+	
+		$this->addFieldMapping('field_private_name', 'admin');
+		$this->addFieldMapping('field_private_name_title', 'admin_title');
+		
+		// see on prepareRow()
+		$this->addFieldMapping('field_private_quality', 'admin_quality');		
+		$this->addFieldMapping('field_private_quality:language', 'language');		
+		$this->addFieldMapping(NULL, 'admin_quality_en');
+		$this->addFieldMapping(NULL, 'admin_quality_fr');
+		
+		
+		$this->addFieldMapping('field_private_email', 'email_admin'); // http://drupal.org/node/1232028
+		
+		$arguments = array(
+			'number' => array('source_field' => 'tel1_admin'),
+			// 'extension' => array('source_field' => 'ccode1_admin'),
+		);
+		$this->addFieldMapping('field_private_phone', 'ccode1_admin')
+			->arguments($arguments);
+			
+		$this->addFieldMapping(NULL, 'tel1_admin');
+		// $this->addFieldMapping(NULL, 'ccode1_admin');
+		$this->addFieldMapping(NULL, 'tel2_admin');
+		$this->addFieldMapping(NULL, 'ccode2_admin');
+
+		$this->addFieldMapping('field_memo', 'memo');
+			
+	}
+
+
+	public function prepareRow($cr) {
+		if($cr->email_admin == "")
+			return false;
+
+		$cr->admin_quality = array($cr->admin_quality_en, $cr->admin_quality_fr);
+		$cr->language = array('en', 'fr');
+		
+		$ccs = cck_phone_countrycodes();
+		$match = 0;
+		foreach ($ccs as $cc => $cc_values) {
+			if('+'.$cr->ccode1_admin == $cc_values['code']){
+				$cr->ccode1_admin = $cc;
+				$match++;
+			}
+			if('+'.$cr->ccode2_admin == $cc_values['code']){
+				$cr->ccode2_admin = $cc;
+				$match++;
+			}
+			if($match == 2) 
+				break;
+		}
+		
+		if($cr->tel2_admin != ''){
+			$cc = cck_phone_countrycodes($cr->ccode2_admin);
+			$cr->memo .= "\n".'tel2 admin : '. $cc['country'] . ' (' . $cc['code'] . ')' .' '. $cr->tel2_admin;
+		}
+
+		// dsm($cr, '- - - - $cr - - - -');
+		
+    return TRUE;
+    // return FALSE if you wish to skip a particular row
+	}
+
+
+	
+	public function prepare($node, stdClass $row) {
+		// dsm('-- prepare --');
+		// dsm($node, '$node');
+		// dsm($row, '$row');
+		
+		// $node->field_public_email = array('und'=>array($row->email_admin));
+		
+  }
+	
+  
+	
+}

+ 204 - 0
migrate_materio.company.inc

@@ -0,0 +1,204 @@
+<?php
+/**
+ * MaterioIndustrialUserMigration
+ * 
+ */
+class MaterioCompanyMigration extends MaterioBasicMigration {
+  public function __construct() {
+    parent::__construct();
+    $this->description = t('Migrate Materio Company Node');
+
+		// provide better description for source fields
+		// and add new field source not from sql
+    $source_fields = array(
+      'id_industrial' => t('Industrial id from source'),
+			'department'=> t('en-fr department implemented on prepare'),
+			'language'=> t('en-fr langauge description, used in prepare'),
+    );
+
+	  $query = db_select(MIG_MAT_SRC_DB .'.industrial_id', 'iid');
+		$query->join(MIG_MAT_SRC_DB .'.industrial_info', 'iinf', 'iid.id_industrial = iinf.id_industrial');
+		
+		$ilfr_select = db_select(MIG_MAT_SRC_DB .'.industrial_lang', 'ilfr_select')
+			->fields('ilfr_select')->condition('ilfr_select.id_locale',1)->orderBy('ilfr_select.id_industrial', 'DESC')->distinct();
+		$query->join($ilfr_select, 'ilfr', 'iid.id_industrial = ilfr.id_industrial');
+		
+		$ilen_select = db_select(MIG_MAT_SRC_DB .'.industrial_lang', 'ilen_select')
+			->fields('ilen_select')->condition('ilen_select.id_locale',2)->orderBy('ilen_select.id_industrial', 'ASC')->distinct();
+		$query->join($ilen_select, 'ilen', 'iid.id_industrial = ilen.id_industrial'); 
+		
+		$query
+			->fields('iid', array('id_industrial', 'date_creation', 'date_modif', 'memo'))
+			->fields('iinf', array('company', 'address', 'city', 'zip', 'web', 'ccode1', 'tel1', 'ccode2', 'tel2', 'ccode3', 'tel3'))
+			->orderBy('id_industrial', 'DESC');
+		
+		$query->addField('ilfr', 'department', 'department_fr');
+		$query->addField('ilfr', 'country', 'country_fr');
+
+		$query->addField('ilen', 'department', 'department_en');
+		$query->addField('ilen', 'country', 'country_en');
+
+		$query->groupBy('id_industrial')
+			->orderBy('id_industrial', 'DESC');
+		
+		
+	  $this->source = new MigrateSourceSQL($query, $source_fields);
+    $this->destination = new MigrateDestinationNode('company');
+	  
+    $this->map = new MigrateSQLMap($this->machineName,
+      array(
+        'id_industrial' => array(
+          'type' => 'int',
+          'unsigned' => TRUE,
+          'not null' => TRUE,
+          'description' => 'OLD Unique industrial ID',
+          'alias' => 'iid',
+        )
+      ),
+    	MigrateDestinationNode::getKeySchema()
+    );
+
+	  // Make the mappings
+		$this->addFieldMapping('language')->defaultValue('');
+		$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('field_tode_company', 'company')
+			->arguments(array('create_term' => TRUE));
+
+		// see on prepareRow()
+		$this->addFieldMapping('field_department', 'department');		
+		$this->addFieldMapping('field_department:language', 'language');		
+		$this->addFieldMapping(NULL, 'department_en');
+		$this->addFieldMapping(NULL, 'department_fr');
+
+		$arguments = array(
+      // 'name_line' => array('source_field' => 'name'),
+      'thoroughfare' => array('source_field' => 'address'),
+      'locality' => array('source_field' => 'city'),
+      'postal_code' => array('source_field' => 'zip'),
+    );
+		$this->addFieldMapping('field_public_address', 'country_en')
+			->arguments($arguments);
+			
+		$this->addFieldMapping(NULL, 'address');
+		$this->addFieldMapping(NULL, 'city');
+		$this->addFieldMapping(NULL, 'zip');
+		$this->addFieldMapping(NULL, 'country_fr');
+
+		$arguments = MigrateLinkFieldHandler::arguments(array('source_field' => 'web_title'));
+		$this->addFieldMapping('field_website', 'web')
+			->arguments($arguments);
+			
+		$this->addFieldMapping('body')->defaultValue('');
+		$this->addFieldMapping('field_infos_from_company')->defaultValue('');
+
+		
+		$arguments = array(
+			'number' => array('source_field' => 'tel1'),
+			// 'extension' => array('source_field' => 'ccode1_contact'),
+		);
+		$this->addFieldMapping('field_public_phone', 'ccode1')
+			->arguments($arguments);
+			
+		$this->addFieldMapping(NULL, 'tel1');
+		// $this->addFieldMapping(NULL, 'ccode1_contact');
+		$this->addFieldMapping(NULL, 'tel2');
+		$this->addFieldMapping(NULL, 'ccode2');
+		$this->addFieldMapping(NULL, 'tel3');
+		$this->addFieldMapping(NULL, 'ccode3');
+		/*
+			TODO 
+			multiple field phone number ?? tel2 ccode2 tel3 ccode3
+			for now added to memo
+		*/
+
+		
+		$this->addFieldMapping('field_note')->defaultValue(2);
+		$this->addFieldMapping('field_memo', 'memo');
+		
+		$this->addFieldMapping('pathauto')->defaultValue(1);
+		$this->addFieldMapping('comment')->defaultValue(0);
+		$this->addFieldMapping('revision')->defaultValue(0);
+			
+	}
+
+
+	public function prepareRow($cr) {
+			$cr->address = preg_replace('/\\n/', ', ', $cr->address);
+			$cr->city = preg_replace('/\\n/', ' ', $cr->city);
+			
+			$cr->department = array($cr->department_en, $cr->department_fr);
+			// $cr->contact_quality = array($cr->contact_quality_en, $cr->contact_quality_fr);
+			// $cr->admin_quality = array($cr->admin_quality_en, $cr->admin_quality_fr);
+			$cr->language = array('en', 'fr');
+			
+			$cr->web_title = str_replace('http://', '', $cr->web);
+			$cr->web = 'http://' . $cr->web_title;
+			
+			$cr->company = trim($cr->company);
+			
+			
+			// if($cr->email_general != "")
+			// 	$cr->email_sample .= ','.$cr->email_general;
+			
+			$ccs = cck_phone_countrycodes();
+			$match = 0;
+			foreach ($ccs as $cc => $cc_values) {
+				if('+'.$cr->ccode1 == $cc_values['code']){
+					$cr->ccode1 = $cc;
+					$match++;
+				}
+				if('+'.$cr->ccode2 == $cc_values['code']){
+					$cr->ccode2 = $cc;
+					$match++;
+				}
+				if('+'.$cr->ccode3 == $cc_values['code']){
+					$cr->ccode3 = $cc;
+					$match++;
+				}
+				
+				if($match == 4) 
+					break;
+			}
+			
+			// 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;
+			}
+			if($cr->tel3 != ''){
+				$cc = cck_phone_countrycodes($cr->ccode3);
+				$cr->memo .= "\n".'tel3 : '. $cc['country'] . ' (' . $cc['code'] . ')' .' '. $cr->tel3;
+			}
+
+
+		
+			// dsm($cr, '- - - - $cr - - - -');
+			
+	    return TRUE;
+	    // return FALSE if you wish to skip a particular row
+	}
+
+
+	
+	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));
+		
+  }
+	
+  
+	
+}

+ 103 - 223
migrate_materio.contact.inc

@@ -3,25 +3,25 @@
  * MaterioIndustrialUserMigration
  * 
  */
-class MaterioIndustrialUserMigration extends MaterioBasicMigration {
+class MaterioIndustrialContactUserMigration extends MaterioBasicMigration {
   public function __construct() {
     parent::__construct();
-    $this->description = t('Migrate Materio Industrials Users');
+    $this->description = t('Migrate Materio Industrials Contact Users');
 
 		// provide better description for source fields
 		// and add new field source not from sql
     $source_fields = array(
-      'id_industrial' => t('Industrial id from source')
+      'id_industrial' => t('Industrial id from source'),
+			'memo'=>t('memo'),
     );
 
 	  $query = db_select(MIG_MAT_SRC_DB .'.industrial_id', 'iid');
-		$query->join(MIG_MAT_SRC_DB .'.industrial_account', 'ind_ac', 'iid.id_industrial = ind_ac.id_industrial');
 		$query->join(MIG_MAT_SRC_DB .'.industrial_info', 'iinf', 'iid.id_industrial = iinf.id_industrial');
+		
 		$query
 			->fields('iid', array('id_industrial', 'date_creation', 'date_modif'))
-			->fields('ind_ac', array('login', 'password'))
-			->fields('iinf', array('email_general'))
-			->orderBy('id_industrial', 'DESC');
+			->fields('iinf', array('company', 'email_contact'))
+			->orderBy('iid.id_industrial', 'DESC');
 		
 		$query->groupBy('iid.id_industrial');
 		
@@ -41,36 +41,45 @@ class MaterioIndustrialUserMigration extends MaterioBasicMigration {
       MigrateDestinationUser::getKeySchema()
     );
 
-  // Make the mappings
-  $this->addFieldMapping('name', 'login');
-  $this->addFieldMapping('pass', 'password');
-  $this->addFieldMapping('mail', 'email_general');
-  $this->addFieldMapping('language')->defaultValue('');
-  $this->addFieldMapping('theme')->defaultValue('');
-  $this->addFieldMapping('signature')->defaultValue('');
-  $this->addFieldMapping('signature_format')->defaultValue('filtered_html');
- 	$this->addFieldMapping('created', 'date_creation');
-  $this->addFieldMapping('access', 'date_modif');
-  $this->addFieldMapping('login')->defaultValue(0);
-  $this->addFieldMapping('status')->defaultValue(1);
-  $this->addFieldMapping('picture')->defaultValue(0);
-  $this->addFieldMapping('init', 'email_general');
-  $this->addFieldMapping('timezone')->defaultValue(NULL);
-  // $this->addFieldMapping('path')->issueGroup(t('DNM'));
-  $this->addFieldMapping('pathauto')->defaultValue(1);
-	$this->addFieldMapping('roles')->defaultValue(array(5));
-	$this->addFieldMapping('is_new')->defaultValue(TRUE);
+	  // Make the mappings
+	  $this->addFieldMapping('name')->defaultValue('aname');
+	  $this->addFieldMapping('pass')->defaultValue(NULL);
+	  $this->addFieldMapping('mail', 'email_contact');
+		# NOTE : maybe if we provide only init mail, we wiil be able to ask email confirmation for users
+	  $this->addFieldMapping('init', 'email_contact');
+	  $this->addFieldMapping('language')->defaultValue('');
+	  $this->addFieldMapping('theme')->defaultValue('');
+	  $this->addFieldMapping('signature')->defaultValue('');
+	  $this->addFieldMapping('signature_format')->defaultValue('filtered_html');
+	 	$this->addFieldMapping('created', 'date_creation');
+	  $this->addFieldMapping('access', 'date_modif');
+	  $this->addFieldMapping('login')->defaultValue(0);
+	  $this->addFieldMapping('status')->defaultValue(0);
+	  $this->addFieldMapping('picture')->defaultValue(0);
+	  $this->addFieldMapping('timezone')->defaultValue(NULL);
+	  // $this->addFieldMapping('path')->issueGroup(t('DNM'));
+	  $this->addFieldMapping('pathauto')->defaultValue(1);
+		$this->addFieldMapping('roles')->defaultValue(array(5));
+		$this->addFieldMapping('is_new')->defaultValue(TRUE);
 	
-	// $this->addFieldMapping('contact', 'contact_list')
-	//      ->separator(',')
-	//      ->arguments(array('source_type' => 'tid'));
+		$this->addFieldMapping('field_memo', 'memo');
+			
+		$this->addFieldMapping('field_company', 'company');
 	
 	}
 	
-	// public function prepareRow($current_row) {
-	//     return TRUE;
-	//     // return FALSE if you wish to skip a particular row
-	//   }
+	public function prepareRow($cr) {
+
+		if($cr->email_contact == "")
+			return false;
+
+		$cr->company = trim($cr->company);			
+		
+		$cr->memo = "#contact";
+			
+    return TRUE;
+    // return FALSE if you wish to skip a particular row
+  }
 	
 }
 
@@ -78,56 +87,46 @@ class MaterioIndustrialUserMigration extends MaterioBasicMigration {
 /**
  * MaterioIndustrialProfile2Migration
  */
-class MaterioIndustrialProfile2Migration extends MaterioBasicMigration {
+class MaterioIndustrialContactProfile2Migration extends MaterioBasicMigration {
   public function __construct() {
     parent::__construct();
 		global $user;
-    $this->description = t('Migrate Materio Industrials Profiles2');
+    $this->description = t('Migrate Materio Industrials Contact Profiles2');
 
 		// provide better description for source fields
 		// and add new field source not from sql
     $source_fields = array(
       'id_industrial' => t('Industrial id from source'),
-			'department'=> t('en-fr department implemented on prepare'),
 			'contact_quality'=> t('en-fr contat quality implemented on prepare'),
-			'admin_quality'=> t('en-fr admin quality implemented on prepare'),
 			'language'=> t('en-fr langauge description, used in prepare'),
 			'tels_contact'=>'',
 			'ccodes_contact'=>'',
-			'tels_admin' => '',
-			'ccodes_admin' => ''
+			'memo' => ','
     );
-
+		
+		
 	  $query = db_select(MIG_MAT_SRC_DB .'.industrial_id', 'iid');
 		$query->join(MIG_MAT_SRC_DB .'.industrial_info', 'iinf', 'iid.id_industrial = iinf.id_industrial');
 		
 		$ilfr_select = db_select(MIG_MAT_SRC_DB .'.industrial_lang', 'ilfr_select')
 			->fields('ilfr_select')->condition('ilfr_select.id_locale',1)->orderBy('ilfr_select.id_industrial', 'DESC')->distinct();
-				
 		$query->join($ilfr_select, 'ilfr', 'iid.id_industrial = ilfr.id_industrial');
 		
-		
 		$ilen_select = db_select(MIG_MAT_SRC_DB .'.industrial_lang', 'ilen_select')
 			->fields('ilen_select')->condition('ilen_select.id_locale',2)->orderBy('ilen_select.id_industrial', 'ASC')->distinct();
-		
 		$query->join($ilen_select, 'ilen', 'iid.id_industrial = ilen.id_industrial'); 
 		
+		
 		$query
-			->fields('iid', array('id_industrial', 'memo'))
-			->fields('iinf', array('company', 'address', 'city', 'zip', 'web', 'email_general', 'contact', 'contact_title', 'email_contact', 'tel1_contact', 'ccode1_contact', 'tel2_contact', 'ccode2_contact', 'admin', 'admin_title', 'email_admin', 'tel1_admin', 'ccode1_admin', 'tel2_admin', 'ccode2_admin', 'email_sample'));
+			->fields('iid', array('id_industrial', 'date_creation', 'date_modif'))
+			->fields('iinf', array('contact', 'contact_title', 'email_contact', 'tel1_contact', 'ccode1_contact', 'tel2_contact', 'ccode2_contact'));
 
-		$query->addField('ilfr', 'department', 'department_fr');
-		$query->addField('ilfr', 'country', 'country_fr');
 		$query->addField('ilfr', 'contact_quality', 'contact_quality_fr');
-		$query->addField('ilfr', 'admin_quality', 'admin_quality_fr');
 
-		$query->addField('ilen', 'department', 'department_en');
-		$query->addField('ilen', 'country', 'country_en');
 		$query->addField('ilen', 'contact_quality', 'contact_quality_en');
-		$query->addField('ilen', 'admin_quality', 'admin_quality_en');
 
-		$query->groupBy('id_industrial')
-			->orderBy('id_industrial', 'DESC');
+		$query->groupBy('iid.id_industrial')
+			->orderBy('iid.id_industrial', 'DESC');
 		
 		
 	  $this->source = new MigrateSourceSQL($query, $source_fields);
@@ -149,208 +148,89 @@ class MaterioIndustrialProfile2Migration extends MaterioBasicMigration {
 
 	  // Connecting the profile2 to the user:
 	  $this->addFieldMapping('uid', 'id_industrial')
-	    ->sourceMigration('MaterioIndustrialUser')  // If your user migration class was named 'MyUserMigration', the string is 'MyUser'
-	    ->description(t('The assignment of profile2-items to the respective user'));
+	    ->sourceMigration('MaterioIndustrialContactUser')  // If your user migration class was named 'MyUserMigration', the string is 'MyUser'
+	    ->description(t('The assignment of profile2-items to the respective Contact user'));
 
 		$this->addFieldMapping('revision_uid', 'id_industrial')
-			->sourceMigration('MaterioIndustrialUser');
+			->sourceMigration('MaterioIndustrialContactUser');
 
 	  // Make the mappings
 		$this->addFieldMapping('language')->defaultValue('');
-
-		$this->addFieldMapping('field_company', 'company')
-			->arguments(array('create_term' => TRUE));
-
-		// see on prepareRow()
-		$this->addFieldMapping('field_department', 'department');		
-		$this->addFieldMapping('field_department:language', 'language');		
-		$this->addFieldMapping(NULL, 'department_en');
-		$this->addFieldMapping(NULL, 'department_fr');
-
-		$arguments = array(
-      // 'name_line' => array('source_field' => 'name'),
-      'thoroughfare' => array('source_field' => 'address'),
-      'locality' => array('source_field' => 'city'),
-      'postal_code' => array('source_field' => 'zip'),
-    );
-		$this->addFieldMapping('field_public_address', 'country_en')
-			->arguments($arguments);
-			
-		$this->addFieldMapping(NULL, 'address');
-		$this->addFieldMapping(NULL, 'city');
-		$this->addFieldMapping(NULL, 'zip');
-		$this->addFieldMapping(NULL, 'country_fr');
-
 	
-		// $this->addFieldMapping('field_website', 'web');
-			// ->arguments(array('url'=>array("source_field"=>'web')));
-		$arguments = MigrateLinkFieldHandler::arguments(array('source_field' => 'web_title'));
-		$this->addFieldMapping('field_website', 'web')
-			->arguments($arguments);
-			
-			
-		$this->addFieldMapping('field_presentation')->defaultValue('');
-		$this->addFieldMapping('field_public_name', 'contact');
-		$this->addFieldMapping('field_public_name_title', 'contact_title');
+		$this->addFieldMapping('field_private_name', 'contact');
+		$this->addFieldMapping('field_private_name_title', 'contact_title');
+		
+		// see on prepareRow()
+		$this->addFieldMapping('field_private_quality', 'contact_quality');		
+		$this->addFieldMapping('field_private_quality:language', 'language');		
+		$this->addFieldMapping(NULL, 'contact_quality_en');
+		$this->addFieldMapping(NULL, 'contact_quality_fr');
+		
 		
-		$this->addFieldMapping('field_public_email', 'email_contact'); // http://drupal.org/node/1232028
+		
+		$this->addFieldMapping('field_private_email', 'email_contact'); // http://drupal.org/node/1232028
 		
 		$arguments = array(
 			'number' => array('source_field' => 'tel1_contact'),
 			// 'extension' => array('source_field' => 'ccode1_contact'),
 		);
-		$this->addFieldMapping('field_public_phone', 'ccode1_contact')
+		$this->addFieldMapping('field_private_phone', 'ccode1_contact')
 			->arguments($arguments);
 			
 		$this->addFieldMapping(NULL, 'tel1_contact');
 		// $this->addFieldMapping(NULL, 'ccode1_contact');
 		$this->addFieldMapping(NULL, 'tel2_contact');
 		$this->addFieldMapping(NULL, 'ccode2_contact');
-		/*
-			TODO 
-			multiple field phone number ?? tel2_contact ccode2_contact
-		*/
-
-		// see on prepareRow()
-		$this->addFieldMapping('field_public_quality', 'contact_quality');		
-		$this->addFieldMapping('field_public_quality:language', 'language');		
-		$this->addFieldMapping(NULL, 'contact_quality_en');
-		$this->addFieldMapping(NULL, 'contact_quality_fr');	
-	
-		$this->addFieldMapping('field_private_name', 'admin');
-		$this->addFieldMapping('field_private_name_title', 'admin_title');
-		$this->addFieldMapping('field_private_email', 'email_admin');
 
-		// see on prepareRow()
-		$this->addFieldMapping('field_private_quality', 'admin_quality');		
-		$this->addFieldMapping('field_private_quality:language', 'language');
-		$this->addFieldMapping(NULL, 'admin_quality_en');
-		$this->addFieldMapping(NULL, 'admin_quality_fr');
-		
-
-		$arguments = array(
-			'number' => array('source_field' => 'tel1_admin'),
-			// 'extension' => array('source_field' => 'ccode1_admin'),
-		);
-		$this->addFieldMapping('field_private_phone', 'ccode1_admin')
-			->arguments($arguments);
-			
-		$this->addFieldMapping(NULL, 'tel1_admin');
-		// $this->addFieldMapping(NULL, 'ccode1_admin');
-		$this->addFieldMapping(NULL, 'tel2_admin');
-		$this->addFieldMapping(NULL, 'ccode2_admin');
-		/*
-		TODO 
-		multiple field phone number ?? tel2_admin ccode2_admin
-		*/
-
-	
-		$this->addFieldMapping('field_private_other_emails', 'email_sample')
-			->separator(',');
-		$this->addFieldMapping(NULL, 'email_general');
-		
-		
-		$this->addFieldMapping('field_note')->defaultValue(2);
 		$this->addFieldMapping('field_memo', 'memo');
 			
 	}
 
 
-	public function prepareRow($current_row) {
-			$current_row->address = preg_replace('/\\n/', ', ', $current_row->address);
-			$current_row->city = preg_replace('/\\n/', ' ', $current_row->city);
-			
-			$current_row->department = array($current_row->department_en, $current_row->department_fr);
-			$current_row->contact_quality = array($current_row->contact_quality_en, $current_row->contact_quality_fr);
-			$current_row->admin_quality = array($current_row->admin_quality_en, $current_row->admin_quality_fr);
-			$current_row->language = array('en', 'fr');
-			
-			$current_row->web_title = str_replace('http://', '', $current_row->web);
-			$current_row->web = 'http://' . $current_row->web_title;
-			
-			if($current_row->email_general != "")
-				$current_row->email_sample .= ','.$current_row->email_general;
-			
-			$ccs = cck_phone_countrycodes();
-			$match = 0;
-			foreach ($ccs as $cc => $cc_values) {
-				if('+'.$current_row->ccode1_contact == $cc_values['code']){
-					$current_row->ccode1_contact = $cc;
-					$match++;
-				}
-				if('+'.$current_row->ccode2_contact == $cc_values['code']){
-					$current_row->ccode2_contact = $cc;
-					$match++;
-				}
-					
-				if('+'.$current_row->ccode1_admin == $cc_values['code']){
-					$current_row->ccode1_admin = $cc;
-					$match++;
-				}
-				if('+'.$current_row->ccode2_admin == $cc_values['code']){
-					$current_row->ccode2_admin = $cc;
-					$match++;
-				}
-				
-				if($match == 4) 
-					break;
-			}
-			
-			if($current_row->tel2_contact != ''){
-				$cc = cck_phone_countrycodes($current_row->ccode2_contact);
-				$current_row->memo .= "\n".'tel2 contact : '. $cc['country'] . ' (' . $cc['code'] . ')' .' '. $current_row->tel2_contact;
-			}
+	public function prepareRow($cr) {
+		if($cr->email_contact == "")
+			return false;
 
-			if($current_row->tel2_admin != ''){
-				$cc = cck_phone_countrycodes($current_row->ccode2_admin);
-				$current_row->memo .= "\n".'tel2 admin : '. $cc['country'] . ' (' . $cc['code'] . ')' .' '. $current_row->tel2_admin;
-			}
 
+		$cr->contact_quality = array($cr->contact_quality_en, $cr->contact_quality_fr);
+		$cr->language = array('en', 'fr');
+		
+		$ccs = cck_phone_countrycodes();
+		$match = 0;
+		foreach ($ccs as $cc => $cc_values) {
+			if('+'.$cr->ccode1_contact == $cc_values['code']){
+				$cr->ccode1_contact = $cc;
+				$match++;
+			}
+			if('+'.$cr->ccode2_contact == $cc_values['code']){
+				$cr->ccode2_contact = $cc;
+				$match++;
+			}
+			if($match == 2) 
+				break;
+		}
+		
+		if($cr->tel2_contact != ''){
+			$cc = cck_phone_countrycodes($cr->ccode2_contact);
+			$cr->memo .= "\n".'tel2 contact : '. $cc['country'] . ' (' . $cc['code'] . ')' .' '. $cr->tel2_contact;
+		}
 
-			// $current_row->tels_contact = array();
-			// $current_row->ccodes_contact = array();
-			// if($current_row->tel1_contact != ''){
-			// 	// $current_row->tels_contact[] = $current_row->tel1_contact;
-			// 	// $current_row->ccodes_contact[] = $current_row->ccode1_contact;
-			// 	$current_row->tels_contact[] = drupal_json_encode(array('counry_code'=>$current_row->ccode1_contact, 'number'=>$current_row->tel1_contact));
-			// }
-			// if($current_row->tel2_contact != ''){
-			// 	// $current_row->tels_contact[] = $current_row->tel2_contact;
-			// 	// $current_row->ccodes_contact[] = $current_row->ccode2_contact;
-			// 	$current_row->tels_contact[] = drupal_json_encode(array('counry_code'=>$current_row->ccode2_contact, 'number'=>$current_row->tel2_contact));
-			// }
-				
-			// $current_row->tels_admin = array();
-			// $current_row->ccodes_admin = array();
-			// if($current_row->tel1_admin != ''){
-			// 	// $current_row->tels_admin[] = $current_row->tel1_admin;
-			// 	// $current_row->ccodes_admin[] = $current_row->ccode1_admin;
-			// 	$current_row->tels_admin[] = drupal_json_encode(array('counry_code'=>$current_row->ccode1_admin, 'number'=>$current_row->tel1_admin));
-			// }
-			// if($current_row->tel2_admin != ''){
-			// 	// $current_row->tels_admin[] = $current_row->tel2_admin;
-			// 	// $current_row->ccodes_admin[] = $current_row->ccode2_admin;
-			// 	$current_row->tels_admin[] = drupal_json_encode(array('counry_code'=>$current_row->ccode2_admin, 'number'=>$current_row->tel2_admin));
-			// }
-		  
-			
+		// dsm($cr, '- - - - $cr - - - -');
 		
-			dsm($current_row, '- - - - $current_row - - - -');
-			
-	    return TRUE;
-	    // return FALSE if you wish to skip a particular row
+    return TRUE;
+    // return FALSE if you wish to skip a particular row
 	}
 
 
 	
-	public function prepare($node, stdClass $row) {
-		// dsm('-- prepare --');
-		// dsm($node, '$node');
-		// dsm($row, '$row');
-		
-		// $node->field_public_email = array('und'=>array($row->email_contact));
-		
-  }
+	// public function prepare($node, stdClass $row) {
+	// 	// dsm('-- prepare --');
+	// 	// dsm($node, '$node');
+	// 	// dsm($row, '$row');
+	// 	
+	// 	// $node->field_private_email = array('und'=>array($row->email_contact));
+	// 	
+	//   }
 	
   
 	

+ 4 - 0
migrate_materio.info

@@ -13,7 +13,11 @@ core = 7.x
 ; Loadable code files
 	files[] = migrate_materio.module
 	files[] = migrate_materio.basic.inc
+	files[] = migrate_materio.company.inc
+	files[] = migrate_materio.account.inc
 	files[] = migrate_materio.contact.inc
+	files[] = migrate_materio.admin.inc
+	files[] = migrate_materio.sample.inc
 	files[] = migrate_materio.materiau.inc
 
 ; Module dependencies

+ 12 - 1
migrate_materio.materiau.inc

@@ -21,7 +21,7 @@ class MaterioMateriauNodeMigration extends MaterioBasicMigration {
 	$query
 		->fields('pod_id', array('id_product', 'id_materio', 'status', 'temp_flag', 'sample_status', 'memo', 'source', 'date_creation', 'date_modif'))
 		->fields('prod_info', array('name', 'nature', 'description', 'usage', 'technical', 'keywords'))
-		->orderBy('id_product', 'DESC');
+		->orderBy('prod_id.id_product', 'DESC');
 	
 	$query->groupBy('prod_id.id_product');
 	
@@ -59,4 +59,15 @@ class MaterioMateriauNodeMigration extends MaterioBasicMigration {
 	//$this->addFieldMapping('field_nature_titre', 'nature');
 
 	}
+	
+	public function prepareRow($cr){
+		
+		$cr->company = trim($cr->company);
+		
+	}
+	
+	
+	
+	
+	
 }

+ 84 - 0
migrate_materio.sample.inc

@@ -0,0 +1,84 @@
+<?php
+/**
+ * MaterioIndustrialUserMigration
+ * 
+ */
+class MaterioIndustrialSampleUserMigration extends MaterioBasicMigration {
+  public function __construct() {
+    parent::__construct();
+    $this->description = t('Migrate Materio Industrials Email Sample Users');
+
+		// provide better description for source fields
+		// and add new field source not from sql
+    $source_fields = array(
+      'id_industrial' => t('Industrial id from source'),
+			'memo' => t('memo'),
+    );
+
+	  $query = db_select(MIG_MAT_SRC_DB .'.industrial_id', 'iid');
+		$query->join(MIG_MAT_SRC_DB .'.industrial_info', 'iinf', 'iid.id_industrial = iinf.id_industrial');
+		
+		$query
+			->fields('iid', array('id_industrial', 'date_creation', 'date_modif'))
+			->fields('iinf', array('company', 'email_sample'))
+			->orderBy('iid.id_industrial', 'DESC')
+			->groupBy('iid.id_industrial');
+		
+	  $this->source = new MigrateSourceSQL($query, $source_fields);
+    $this->destination = new MigrateDestinationUser();
+	  
+    $this->map = new MigrateSQLMap($this->machineName,
+      array(
+        'id_industrial' => array(
+          'type' => 'int',
+          'unsigned' => TRUE,
+          'not null' => TRUE,
+          'description' => 'OLD Unique industrial ID',
+          'alias' => 'iid',
+        )
+      ),
+      MigrateDestinationUser::getKeySchema()
+    );
+
+	  // Make the mappings
+	  $this->addFieldMapping('name')->defaultValue('aname');
+	  $this->addFieldMapping('pass')->defaultValue(NULL);
+	  $this->addFieldMapping('mail', 'email_sample');
+		# NOTE : maybe if we provide only init mail, we wiil be able to ask email confirmation for users
+	  $this->addFieldMapping('init', 'email_sample');
+	  $this->addFieldMapping('language')->defaultValue('');
+	  $this->addFieldMapping('theme')->defaultValue('');
+	  $this->addFieldMapping('signature')->defaultValue('');
+	  $this->addFieldMapping('signature_format')->defaultValue('filtered_html');
+	 	$this->addFieldMapping('created', 'date_creation');
+	  $this->addFieldMapping('access', 'date_modif');
+	  $this->addFieldMapping('login')->defaultValue(0);
+	  $this->addFieldMapping('status')->defaultValue(0);
+	  $this->addFieldMapping('picture')->defaultValue(0);
+	  $this->addFieldMapping('timezone')->defaultValue(NULL);
+	  // $this->addFieldMapping('path')->issueGroup(t('DNM'));
+	  $this->addFieldMapping('pathauto')->defaultValue(1);
+		$this->addFieldMapping('roles')->defaultValue(array(5));
+		$this->addFieldMapping('is_new')->defaultValue(TRUE);
+	
+		$this->addFieldMapping('field_memo', 'memo');
+	
+		$this->addFieldMapping('field_company', 'company');
+	
+	
+	}
+	
+	public function prepareRow($cr) {
+		if($cr->email_sample == '')
+			return false;
+		
+		$cr->company = trim($cr->company);
+		
+		$cr->memo = "#sample";
+		
+    return TRUE;
+    // return FALSE if you wish to skip a particular row
+  }
+	
+}
+