123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?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');
- //
- // }
-
-
-
- }
|