Преглед изворни кода

last commit of 0.x dev

Signed-off-by: bachy <git@g-u-i.net>
bachy пре 13 година
родитељ
комит
df91706e57
5 измењених фајлова са 485 додато и 14 уклоњено
  1. 11 0
      migrate_materio.basic.inc
  2. 357 0
      migrate_materio.contact.inc
  3. 15 6
      migrate_materio.info
  4. 62 0
      migrate_materio.materiau.inc
  5. 40 8
      migrate_materio.module

+ 11 - 0
migrate_materio.basic.inc

@@ -0,0 +1,11 @@
+<?php
+/**
+ * MaterioBasicMigration
+ * 
+ */
+abstract class MaterioBasicMigration extends Migration {
+	public function __construct(){
+		$this->description = t('Migrate Materio Basic Class');
+		parent::__construct(MigrateGroup::getInstance('MaterioMigrate'));
+	}
+}

+ 357 - 0
migrate_materio.contact.inc

@@ -0,0 +1,357 @@
+<?php
+/**
+ * MaterioIndustrialUserMigration
+ * 
+ */
+class MaterioIndustrialUserMigration extends MaterioBasicMigration {
+  public function __construct() {
+    parent::__construct();
+    $this->description = t('Migrate Materio Industrials 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')
+    );
+
+	  $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');
+		
+		$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');
+  $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);
+	
+	// $this->addFieldMapping('contact', 'contact_list')
+	//      ->separator(',')
+	//      ->arguments(array('source_type' => 'tid'));
+	
+	}
+	
+	// public function prepareRow($current_row) {
+	//     return TRUE;
+	//     // return FALSE if you wish to skip a particular row
+	//   }
+	
+}
+
+
+/**
+ * MaterioIndustrialProfile2Migration
+ */
+class MaterioIndustrialProfile2Migration extends MaterioBasicMigration {
+  public function __construct() {
+    parent::__construct();
+		global $user;
+    $this->description = t('Migrate Materio Industrials 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' => ''
+    );
+
+	  $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'));
+
+		$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');
+		
+		
+	  $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('MaterioIndustrialUser')  // 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('MaterioIndustrialUser');
+
+	  // 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_public_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')
+			->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;
+			}
+
+			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;
+			}
+
+
+			// $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($current_row, '- - - - $current_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));
+		
+  }
+	
+  
+	
+}

+ 15 - 6
migrate_materio.info

@@ -11,15 +11,24 @@ core = 7.x
 ; php = 5.2
 
 ; Loadable code files
-; files[] = migrate_materio.module
-; files[] = migrate_materio.admin.inc
-; files[] = migrate_materio.class.inc
+	files[] = migrate_materio.module
+	files[] = migrate_materio.basic.inc
+	files[] = migrate_materio.contact.inc
+	files[] = migrate_materio.materiau.inc
 
 ; Module dependencies
 	dependencies[] = migrate
-; dependencies[] = theirmodule (1.2)
-; dependencies[] = anothermodule (>=2.4)
-; dependencies[] = views (3.x)
+	dependencies[] = migrate_extras
+	dependencies[] = field
+; dependencies[] = file
+;	dependencies[] = image
+	dependencies[] = number
+	dependencies[] = text
+	dependencies[] = options
+	dependencies[] = taxonomy
+;	dependencies[] = date
+	dependencies[] = link
+;	dependencies[] = media
 
 ; Configuration page
 ; configure = admin/config/migrate_materio

+ 62 - 0
migrate_materio.materiau.inc

@@ -0,0 +1,62 @@
+<?php
+/**
+ * MaterioMateriauNodeMigration
+ * 
+ */
+class MaterioMateriauNodeMigration extends MaterioBasicMigration {
+  public function __construct() {
+    parent::__construct();
+    $this->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')
+    );
+		
+	$query = db_select(MIG_MAT_SRC_DB .'.product_id', 'prod_id');
+	// WARNING ! product_info is double langauge + duplicate -> 4 rows each product
+	$query->join(MIG_MAT_SRC_DB .'.product_info', 'prod_info', 'prod_id.id_product = prod_info.id_product');
+
+	$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');
+	
+	$query->groupBy('prod_id.id_product');
+	
+	$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' => 'prod_id',
+      )
+    ),
+    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');
+	$this->addFieldMapping('field_memo', 'memo');
+	
+	/*
+		TODO translate node
+	*/
+	//$this->addFieldMapping('language');
+	//$this->addFieldMapping('field_nature_titre', 'nature');
+
+	}
+}

+ 40 - 8
migrate_materio.module

@@ -7,6 +7,19 @@
  * file does exactly. Make sure to wrap your documentation in column 78 so
  * that the file can be displayed nicely in default-sized consoles.
  */
+define('MIG_MAT_SRC_DB', variable_get('migrate_materio_database', ''));
+
+
+/**
+ * You must implement hook_migrate_api(), setting the API level to 2, for
+ * your migration classes to be recognized by the Migrate module (for the 7.x-2.x branch).
+ */
+function migrate_materio_migrate_api() {
+  $api = array(
+    'api' => 2,
+  );
+  return $api;
+}
 
 /**
  * Implements hook_menu().
@@ -14,19 +27,38 @@
 function migrate_materio_menu() {
   $items = array();
 
-  // Type '$item ⇥' to create a new menu item.
+  $items['admin/config/development/migrate_materio'] = array(
+    'title' => 'Materio Migration Settings',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('migrate_materio_settings'),
+    'access callback' => 'user_access',
+    'access arguments' => array('administer site configuration'),
+  );
 
   return $items;
 }
 
 
 /**
- * You must implement hook_migrate_api(), setting the API level to 2, for
- * your migration classes to be recognized by the Migrate module (for the 7.x-2.x branch).
+ * Form to setting up the database name and migration file path for migration of data.
  */
-function migrate_materio_migrate_api() {
-  $api = array(
-    'api' => 2,
+function migrate_materio_settings($form, &$form_state) {
+  $form['migrate_materio_database'] = array(
+    '#type' => 'textfield',
+    '#title' => 'Database name',
+    '#default_value' => variable_get('migrate_materio_database', ''),
+    '#description' => t('Please enter the name of the database.  Note that the database must be accessible by current website db user and must reside on the same db server.'),
+    '#required' => TRUE,
   );
-  return $api;
-}
+  
+  // $form['redcat_migration_file_path'] = array(
+  //   '#type' => 'textfield',
+  //   '#title' => 'Migrated Files Path',
+  //   '#default_value' => variable_get('redcat_migration_file_path', '/Users/amodi/Sites/redcat.org/sites/redcat.org/files'),
+  //   '#description' => t('Please enter the full path to get to the home directory of the migrating site - the files will be found through the base'),
+  //   '#required' => TRUE,
+  // );
+  
+  return system_settings_form($form);
+}
+