Selaa lähdekoodia

breves migration starting point

Signed-off-by: bachy <git@g-u-i.net>
bachy 12 vuotta sitten
vanhempi
commit
0370c6233d
3 muutettua tiedostoa jossa 169 lisäystä ja 1 poistoa
  1. 159 0
      migrate_materio.breves.inc
  2. 1 0
      migrate_materio.info
  3. 9 1
      migrate_materio.module

+ 159 - 0
migrate_materio.breves.inc

@@ -0,0 +1,159 @@
+<?php
+/**
+ * MaterioMateriauNodeMigration
+ * 
+ */
+class MaterioBrevesNodeMigration 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(
+   //    'nid' => t('Materiau id from source'),
+			// 'status'=>t('status'),
+			// 'promote'=>t('promote'),
+			// 'sticky'=>t('sticky'),
+			// 'summary'=>t('summary'),
+			// 'created'=>t('created'),
+			// 'changed'=>t('changed'),
+			'languages'=> t('languages'),
+			// 'tnid'=> t('tnid'),
+			// 'title'=> t('title'),
+			// 'body'=> t('body'),
+			// 'teaser' => t('teaser'),
+			// 'format' => t('format'),
+			'memo' => t('memo'),
+    );
+		
+    // $query = db_select(MIG_MAT_SRC_DB_D6 .'.fr_node', 'n');
+
+    // $query
+    // 	->condition('n.type',"actu")
+    // 	->condition('n.tnid',"0", "<>")
+    // 	->condition('n.language',"en");
+
+
+		/* translated */
+		$query_translated = db_select(MIG_MAT_SRC_DB_D6 .'.fr_i18n_node', 'i');
+		
+		$query_translated->join(MIG_MAT_SRC_DB_D6 .'.fr_node', 'n', 'n.nid = i.nid');
+		$query_translated->join(MIG_MAT_SRC_DB_D6 .'.fr_node_revisions', 'nr', 'nr.nid = n.nid');
+		
+ 		$query_translated->leftjoin(MIG_MAT_SRC_DB_D6 .'.fr_node', 'tn', 'tn.nid = i.trid');
+		$query_translated->leftjoin(MIG_MAT_SRC_DB_D6 .'.fr_node_revisions', 'tnr', 'tnr.nid = tn.nid');
+
+		$query_translated
+				->condition('n.type',"actu")				
+				// ->condition('i.trid', "0", "<>")
+				->fields('i', array('nid', 'trid'))
+				->fields('n', array('nid', 'status', 'promote', 'sticky', 'created', 'changed', 'language', 'tnid'))
+				->fields('nr', array('title', 'body', 'teaser', 'format'))
+				->fields('tn', array('nid', 'status', 'promote', 'sticky', 'created', 'changed', 'language'))
+				->fields('tnr', array('title', 'body', 'teaser', 'format'));
+				// ->orderBy('n.created', 'ASC');
+		
+
+		/* untranslated translated */
+		// $query_untranslated = db_select(MIG_MAT_SRC_DB_D6 .'.fr_i18n_node', 'un_i');
+
+		// $query_untranslated->join(MIG_MAT_SRC_DB_D6 .'.fr_node', 'un_n', 'un_n.nid = un_i.nid');
+		// $query_untranslated->join(MIG_MAT_SRC_DB_D6 .'.fr_node_revisions', 'un_nr', 'un_nr.nid = un_n.nid');
+
+		// $query_untranslated
+		// 		->condition('un_n.type',"actu")				
+		// 		->condition('un_i.trid', "0", "=")
+		// 		->fields('un_i', array('nid', 'trid'))
+		// 		->fields('un_n', array('nid', 'status', 'promote', 'sticky', 'created', 'changed', 'language', 'tnid'))
+		// 		->fields('un_nr', array('title', 'body', 'teaser', 'format'));
+
+
+		// $query_translated->union($query_untranslated, 'ALL');
+
+		// $query = db_select($query_translated, 'x');
+
+		// print  "\n\n- - - - - - \n\n";
+		// print_r($query_translated->__toString());
+		// print  "\n\n- - - - - - \n\n";
+
+
+		$this->source = new MigrateSourceSQL($query_translated, $source_fields);
+	  $this->destination = new MigrateDestinationNode('breve');
+  
+	  $this->map = new MigrateSQLMap($this->machineName,
+	    array(
+	      'nid' => array(
+	        'type' => 'int',
+	        'unsigned' => TRUE,
+	        'not null' => TRUE,
+	        'description' => 'OLD Unique Materiau NID',
+	        'alias' => 'i',
+	      )
+	    ),
+	    MigrateDestinationNode::getKeySchema()
+	  );
+
+		$this->addFieldMapping('is_new')->defaultValue(TRUE);
+		
+		$this->addSimpleMappings(array('created', 'changed', 'status', 'promote', 'sticky', 'language'));
+
+		$this->addFieldMapping('title', 'title');
+		$this->addFieldMapping('field_memo', 'memo');
+	
+		$this->addFieldMapping('title_field', 'title');
+		$this->addFieldMapping('title_field:language', 'languages');
+	
+		$this->addFieldMapping('body', 'body');
+		// $this->addFieldMapping('body:summary', 'teaser');		
+		$this->addFieldMapping('body:language', 'languages');
+		$this->addFieldMapping('body:format')->defaultValue('filtred_html');
+
+
+		$this->addUnmigratedDestinations(array('revision', 'revision_uid', 'log', 'tnid', 'comment', 'uid', 'path', 'pathauto',
+			'title_field:format',
+			'field_memo:format', 'field_memo:language',
+			'field_onthologie', 'field_onthologie:source_type', 'field_onthologie:create_term',
+		));
+	}
+	
+	public function prepareRow($cr){
+		// dsm($cr);
+		print "\n- - - - - - - - \n";
+		if($cr->trid){
+			print "\n" . $cr->title . "\n";
+			print "\n" . $cr->tnr_title . "\n";
+			$cr->title = array($cr->title, $cr->tnr_title);
+
+			$cr->body = array($cr->body, $cr->tnr_body);
+			// $cr->teaser = array($cr->teaser, $cr->tnr_teaser);
+
+			$cr->languages = array($cr->language, $cr->tn_language);
+		}else{
+			$cr->languages = $cr->language;
+		}
+		
+		return TRUE;
+	}
+	
+	
+	public function prepare($node, stdClass $row) {
+		// dsm('-- prepare --');
+		// dsm($node, '$node');
+		// dsm($row, '$row');
+		
+	  $node->workflow = 4;
+		
+  }
+	
+	// public function complete($node, $row) {
+	// 	// dsm('-- complete --');
+	// 	//     // Do what you need to do to 
+	// 	// dsm($row, '$row');
+	// 	// dsm($node, '$node');
+	// 
+	//   }
+	
+	
+	
+}

+ 1 - 0
migrate_materio.info

@@ -19,6 +19,7 @@ core = 7.x
 	files[] = migrate_materio.admin.inc
 	files[] = migrate_materio.sample.inc
 	files[] = migrate_materio.materiau.inc
+	files[] = migrate_materio.breves.inc
 
 ; Module dependencies
 	dependencies[] = migrate

+ 9 - 1
migrate_materio.module

@@ -8,7 +8,7 @@
  * that the file can be displayed nicely in default-sized consoles.
  */
 define('MIG_MAT_SRC_DB', variable_get('migrate_materio_database', ''));
-
+define('MIG_MAT_SRC_DB_D6', variable_get('migrate_materio_database_drupal6', ''));
 
 /**
  * You must implement hook_migrate_api(), setting the API level to 2, for
@@ -51,6 +51,14 @@ function migrate_materio_settings($form, &$form_state) {
     '#required' => TRUE,
   );
   
+  $form['migrate_materio_database_drupal6'] = array(
+    '#type' => 'textfield',
+    '#title' => 'Drupal 6 Database name',
+    '#default_value' => variable_get('migrate_materio_database_drupal6', ''),
+    '#description' => t('Please enter the name of the drupal 6 database.  Note that the database must be accessible by current website db user and must reside on the same db server.'),
+    '#required' => TRUE,
+  );
+  
   // $form['redcat_migration_file_path'] = array(
   //   '#type' => 'textfield',
   //   '#title' => 'Migrated Files Path',