files, video, materiau ref
Signed-off-by: bachy <git@g-u-i.net>
This commit is contained in:
parent
40b0b8bae2
commit
3ca910cf34
@ -11,87 +11,37 @@ class MaterioBrevesNodeMigration extends MaterioBasicMigration {
|
||||
// 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'),
|
||||
'titlefield'=>t('title field'),
|
||||
'languages'=> t('languages'),
|
||||
// 'tnid'=> t('tnid'),
|
||||
// 'title'=> t('title'),
|
||||
// 'body'=> t('body'),
|
||||
// 'teaser' => t('teaser'),
|
||||
// 'format' => t('format'),
|
||||
'memo' => t('memo'),
|
||||
'images'=>t('images'),
|
||||
'images_titles'=>t('images titles'),
|
||||
'images_alts'=>t('images alts'),
|
||||
// 'source'=>t("source"),
|
||||
// 'materiau'=>t('materiau ref'),
|
||||
'video'=>t('video'),
|
||||
);
|
||||
|
||||
// $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 = 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->join(MIG_MAT_SRC_DB_D6 .'.fr_node', 'n', 'n.nid = i.nid');
|
||||
$query->join(MIG_MAT_SRC_DB_D6 .'.fr_node_revisions', 'nr', 'nr.nid = n.nid');
|
||||
// $query->join(MIG_MAT_SRC_DB_D6 .'.fr_content_field_imago', 'im', 'im.nid = n.nid');
|
||||
|
||||
// $query_translated->leftjoin(MIG_MAT_SRC_DB_D6 .'.fr_i18n_node', 'ti', 'ti.trid = i.trid');
|
||||
// $query_translated->leftjoin(MIG_MAT_SRC_DB_D6 .'.fr_node', 'tn', 'tn.nid = ti.nid');
|
||||
// $query_translated->leftjoin(MIG_MAT_SRC_DB_D6 .'.fr_node_revisions', 'tnr', 'tnr.nid = ti.nid');
|
||||
|
||||
$query_translated
|
||||
$query
|
||||
->condition('i.status', "0", "=")
|
||||
// ->condition('i.trid', "0", "<>")
|
||||
->condition('n.type',"actu")
|
||||
// ->condition('tn.type',"actu")
|
||||
// ->condition('ti.trid', "0", "<>")
|
||||
->fields('i', array('trid'))
|
||||
->fields('n', array('nid', 'status', 'promote', 'sticky', 'created', 'changed', 'language', 'tnid'))
|
||||
->fields('nr', array('title', 'body', 'teaser', 'format'));
|
||||
// ->fields('ti', array('nid'))
|
||||
// ->fields('tn', array('nid', 'status', 'promote', 'sticky', 'created', 'changed', 'language'))
|
||||
// ->fields('tnr', array('title', 'body', 'teaser', 'format'));
|
||||
// ->orderBy('n.created', 'ASC');
|
||||
// ->fields('im', array('title', 'body', 'teaser', 'format'));
|
||||
|
||||
|
||||
/* 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_translated->leftjoin(MIG_MAT_SRC_DB_D6 .'.fr_i18n_node', 'un_ti', 'un_ti.nid = un_i.nid');
|
||||
// $query_translated->leftjoin(MIG_MAT_SRC_DB_D6 .'.fr_node', 'un_tn', 'un_tn.nid = un_ti.nid');
|
||||
// $query_translated->leftjoin(MIG_MAT_SRC_DB_D6 .'.fr_node_revisions', 'un_tnr', 'un_tnr.nid = un_ti.nid');
|
||||
|
||||
|
||||
// $query_untranslated
|
||||
// ->condition('un_i.trid', "0", "=")
|
||||
// ->condition('un_n.type',"actu")
|
||||
// // ->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'));
|
||||
|
||||
// // ->fields('un_tn', array('nid', 'status', 'promote', 'sticky', 'created', 'changed', 'language'))
|
||||
// // ->fields('un_tnr', 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->__toString());
|
||||
// print "\n\n- - - - - - \n\n";
|
||||
|
||||
|
||||
$this->source = new MigrateSourceSQL($query_translated, $source_fields);
|
||||
$this->source = new MigrateSourceSQL($query, $source_fields);
|
||||
$this->destination = new MigrateDestinationNode('breve');
|
||||
|
||||
$this->map = new MigrateSQLMap($this->machineName,
|
||||
@ -109,30 +59,48 @@ class MaterioBrevesNodeMigration extends MaterioBasicMigration {
|
||||
|
||||
$this->addFieldMapping('is_new')->defaultValue(TRUE);
|
||||
|
||||
$this->addSimpleMappings(array('created', 'changed', 'status', 'promote', 'sticky', 'language'));
|
||||
$this->addSimpleMappings(array('created', 'changed', 'status', 'promote', 'sticky', 'language', 'title'));
|
||||
|
||||
$this->addFieldMapping('title', 'title');
|
||||
$this->addFieldMapping('field_memo', 'memo');
|
||||
|
||||
$this->addFieldMapping('title_field', 'title');
|
||||
$this->addFieldMapping('title_field', 'titlefield');
|
||||
$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->addFieldMapping('field_visuel', 'images');
|
||||
$this->addFieldMapping('field_visuel:source_dir')->defaultValue('public://SRC_imago');
|
||||
$this->addFieldMapping('field_visuel:title', 'images_titles');
|
||||
$this->addFieldMapping('field_visuel:alt', 'images_alts');
|
||||
|
||||
// $this->addFieldMapping('field_source', 'source');
|
||||
$this->addFieldMapping('field_video_filter', 'video');
|
||||
|
||||
$this->addUnmigratedDestinations(array('revision', 'revision_uid', 'log', 'tnid', 'comment', 'uid', 'path', 'pathauto',
|
||||
'title_field:format',
|
||||
'body:summary',
|
||||
'field_source',
|
||||
// 'field_video_filter',
|
||||
'field_materiau_ref',
|
||||
'field_memo:format', 'field_memo:language',
|
||||
'field_onthologie', 'field_onthologie:source_type', 'field_onthologie:create_term',
|
||||
'field_visuel:file_class','field_visuel:language','field_visuel:destination_dir','field_visuel:destination_file','field_visuel:file_replace','field_visuel:preserve_files',
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
public function prepareRow($cr){
|
||||
// dsm($cr);
|
||||
print "\n- - - - - - - - \n";
|
||||
// print $cr->nid . "\n";
|
||||
print $cr->title . "\n";
|
||||
|
||||
$body = $cr->body;
|
||||
|
||||
$cr->memo = '';
|
||||
|
||||
if($cr->trid){
|
||||
$query = db_select(MIG_MAT_SRC_DB_D6 .'.fr_i18n_node', 'i');
|
||||
@ -153,10 +121,10 @@ class MaterioBrevesNodeMigration extends MaterioBasicMigration {
|
||||
$tr = $record;
|
||||
}
|
||||
|
||||
print "\n" . $cr->title . "\n";
|
||||
print "\n" . $tr->title . "\n";
|
||||
// print $cr->title . "\n";
|
||||
// print $tr->title . "\n";
|
||||
|
||||
$cr->title = array($cr->title, $tr->title);
|
||||
$cr->titlefield = array($cr->title, $tr->title);
|
||||
|
||||
$cr->body = array($cr->body, $tr->body);
|
||||
// $cr->teaser = array($cr->teaser, $cr->tnr_teaser);
|
||||
@ -164,8 +132,57 @@ class MaterioBrevesNodeMigration extends MaterioBasicMigration {
|
||||
$cr->languages = array($cr->language, $tr->language);
|
||||
}else{
|
||||
$cr->languages = $cr->language;
|
||||
$cr->titlefield = $cr->title;
|
||||
// $cr->teaser = htmlspecialchars_decode($cr->teaser);
|
||||
}
|
||||
|
||||
/* IMAGES */
|
||||
$query = db_select(MIG_MAT_SRC_DB_D6.'.fr_content_field_imago', 'im');
|
||||
$query->join(MIG_MAT_SRC_DB_D6.'.fr_files', 'f', 'f.fid = im.field_imago_fid');
|
||||
$query
|
||||
->condition('im.nid', $cr->nid, "=")
|
||||
// ->condition('f.fid', $cr->nid, "=")
|
||||
->fields('im', array('field_imago_list', 'field_imago_data'))
|
||||
->fields('f', array('filename'));
|
||||
|
||||
$images = $query->execute();
|
||||
$cr->images = array();
|
||||
$cr->images_titles = array();
|
||||
$cr->images_alts = array();
|
||||
|
||||
foreach ($images as $image) {
|
||||
// print_r($image);
|
||||
$cr->images[] = $image->filename;
|
||||
$data = unserialize($image->field_imago_data);
|
||||
$cr->images_alts[] = $data['alt'];
|
||||
$cr->images_titles[] = $data['title'];
|
||||
}
|
||||
|
||||
|
||||
/* source */
|
||||
//Source : <a href="http://ucsdnews.ucsd.edu/pressreleases/researchers_create_living_neon_signs_composed_of_millions_of_glowing_bacter/" target="_blank">UCSanDiego</a>
|
||||
// preg_match('/Source\s:\s<a\shref="([^"]*)"[^>]*>([^<]*)<\/a>/', $body, $matches);
|
||||
// if(count($matches)){
|
||||
// print_r($matches);
|
||||
// $cr->source = str_replace('http://', '', $matches[1]);
|
||||
// }
|
||||
|
||||
/* materio */
|
||||
// (matériO P0059)
|
||||
preg_match('/\(matériO\s([^\)]*)\)/', $body, $matches);
|
||||
if(count($matches)){
|
||||
print_r($matches);
|
||||
$cr->memo .= "ref materio : ".$matches[1]."\n";
|
||||
}
|
||||
|
||||
/* video */
|
||||
//[video:http://www.youtube.com/watch?v=3Fzu2Av6BmE align:center autoplay:1]
|
||||
preg_match('/\[video:([^\s]*)[^\]]*]/', $body, $matches);
|
||||
if(count($matches)){
|
||||
print_r($matches);
|
||||
$cr->video = $matches[1];
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user