소스 검색

materiaux companies ok

+ sql improvement

Signed-off-by: bachy <git@g-u-i.net>
bachy 13 년 전
부모
커밋
760047e9fc
5개의 변경된 파일177개의 추가작업 그리고 40개의 파일을 삭제
  1. 1 0
      migrate_materio.account.inc
  2. 4 1
      migrate_materio.admin.inc
  3. 4 1
      migrate_materio.contact.inc
  4. 167 38
      migrate_materio.materiau.inc
  5. 1 0
      migrate_materio.sample.inc

+ 1 - 0
migrate_materio.account.inc

@@ -22,6 +22,7 @@ class MaterioIndustrialAccountUserMigration extends MaterioBasicMigration {
 			->fields('iid', array('id_industrial', 'date_creation', 'date_modif'))
 			->fields('ind_ac', array('login', 'password'))
 			->fields('iinf', array('company', 'email_general'))
+			->condition('email_general', '', '<>')
 			->orderBy('iid.id_industrial', 'DESC');
 			
 		$query->groupBy('iid.id_industrial');

+ 4 - 1
migrate_materio.admin.inc

@@ -21,6 +21,7 @@ class MaterioIndustrialAdminUserMigration extends MaterioBasicMigration {
 		$query
 			->fields('iid', array('id_industrial', 'date_creation', 'date_modif'))
 			->fields('iinf', array('company', 'email_admin'))
+			->condition('email_admin', '', '<>')
 			->orderBy('iid.id_industrial', 'DESC');
 		
 		$query->groupBy('iid.id_industrial');
@@ -122,7 +123,9 @@ class MaterioIndustrialAdminProfile2Migration extends MaterioBasicMigration {
 		$query->addField('ilfr', 'admin_quality', 'admin_quality_fr');
 		$query->addField('ilen', 'admin_quality', 'admin_quality_en');
 
-		$query->groupBy('iid.id_industrial')
+		$query
+			->condition('email_admin', '', '<>')
+			->groupBy('iid.id_industrial')
 			->orderBy('iid.id_industrial', 'DESC');
 		
 		

+ 4 - 1
migrate_materio.contact.inc

@@ -21,6 +21,7 @@ class MaterioIndustrialContactUserMigration extends MaterioBasicMigration {
 		$query
 			->fields('iid', array('id_industrial', 'date_creation', 'date_modif'))
 			->fields('iinf', array('company', 'email_contact'))
+			->condition('email_contact', '', '<>')
 			->orderBy('iid.id_industrial', 'DESC');
 		
 		$query->groupBy('iid.id_industrial');
@@ -125,7 +126,9 @@ class MaterioIndustrialContactProfile2Migration extends MaterioBasicMigration {
 
 		$query->addField('ilen', 'contact_quality', 'contact_quality_en');
 
-		$query->groupBy('iid.id_industrial')
+		$query
+			->condition('email_contact', '', '<>')
+			->groupBy('iid.id_industrial')
 			->orderBy('iid.id_industrial', 'DESC');
 		
 		

+ 167 - 38
migrate_materio.materiau.inc

@@ -11,61 +11,190 @@ class MaterioMateriauNodeMigration extends MaterioBasicMigration {
 		// provide better description for source fields
 		// and add new field source not from sql
     $source_fields = array(
-      'id_product' => t('Materiau id from source')
+      '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', '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 = 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');
+		
 
-	$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('prod_id.id_product', 'DESC');
+		// 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');
 	
-	$query->groupBy('prod_id.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->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->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('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);
 
-	$this->addFieldMapping('title', 'name');
-	$this->addFieldMapping('field_memo', 'memo');
-	
-	/*
-		TODO translate node
-	*/
-	//$this->addFieldMapping('language');
-	//$this->addFieldMapping('field_nature_titre', 'nature');
 
 	}
 	
 	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();
 		
-		$cr->company = trim($cr->company);
+		$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));
+		
+  }
 	
 	
 	

+ 1 - 0
migrate_materio.sample.inc

@@ -21,6 +21,7 @@ class MaterioIndustrialSampleUserMigration extends MaterioBasicMigration {
 		$query
 			->fields('iid', array('id_industrial', 'date_creation', 'date_modif'))
 			->fields('iinf', array('company', 'email_sample'))
+			->condition('email_sample', '', '<>')
 			->orderBy('iid.id_industrial', 'DESC')
 			->groupBy('iid.id_industrial');