almost every needed thing for corpus is ready, remains that all files are not migrated because of filepath :(

This commit is contained in:
Bachir Soussi Chiadmi
2017-11-26 12:45:11 +01:00
parent d3830fbad9
commit 6a9608f0c7
4 changed files with 328 additions and 87 deletions
@@ -6,13 +6,13 @@ migration_tags:
- Drupal 6
migration_group: d6_edlp
source:
plugin: d6_file
plugin: d6_edlp_file
constants:
# The tool configuring this migration must set source_base_path. It
# represents the fully qualified path relative to which URIs in the files
# table are specified, and must end with a /. See source_full_path
# configuration in this migration's process pipeline as an example.
source_base_path: '../drupal6/'
source_base_path: '../drupal6'
process:
# If you are using both this migration and d6_user_picture_file in a custom
@@ -40,109 +40,132 @@ process:
plugin: default_value
default_value: 1
status: status
# status: status
created: created
changed: changed
promote: promote
sticky: sticky
# 'body/format':
# plugin: migration_lookup
# migration: d6_filter_format
# source: format
# ARTICLE (body)
# node ref -> text
# 'body/value': here we have to get the body value of article
# 'body/summary': teaser
revision_uid: revision_uid
revision_log: log
revision_timestamp: timestamp
#
# custom fields
# workflow
'field_description/value': body
'field_description/format':
plugin: default_value
default_value: wysiwyg
# ARTICLE (body)
# node ref -> text
'body/value': article
'body/format':
plugin: default_value
default_value: wysiwyg
# taxo term -> entity ref terms
# use this one for fetchCol in plugin
field_entrees:
plugin: migration_lookup
migration: d6_edlp_entrees
source: entrees
# use this one for fetchAll in plugin
# field_entrees:
# -
# plugin: iterator
# source: entrees
# process:
# id: tid
# -
# plugin: flatten
# -
# plugin: migration_lookup
# migration: d6_edlp_entrees
# no_stub: true
# field_entrees:
# plugin: iterator
# source: entrees
# process:
# plugin: migration_lookup
# migration: d6_edlp_entrees
# field_genre -> field_genres
field_genres:
plugin: migration_lookup
migration: d6_edlp_genres
source: genres
# field_genres:
# -
# plugin: iterator
# source: field_genre
# process:
# id: value
# -
# plugin: flatten
# -
# plugin: migration_lookup
# migration: d6_edlp_genres
# taxo term -> entity ref terms
field_langues:
plugin: migration_lookup
migration: d6_edlp_langues
source: langues
# field_artiste: field_locuteurs
# text -> entity ref terms
# field_artiste: field_locuteur_s
# field_locuteurs_s:
# instead of entity_generate, i create the term in prepareRow from plugin
field_locuteurs: locuteurs
# field_locuteurs:
# plugin: entity_generate
# entity_type: taxonomy_term
# bundle_key: vid
# bundle: locuteurs
# source: field_artiste
# value_key: field_artiste_value
# source: locuteurs
# # value_key: field_artiste_value
# field_compositeur: field_collectionneurs
# text -> entity ref terms
# field_compositeur: field_collectionneur_s
# field_collectionneur_s:
# plugin: entity_generate
# entity_type: taxonomy_term
# bundle_key: vid
# bundle: collectionneurs
# source: field_compositeur
# value_key: field_compositeur_value
# instead of entity_generate, i create the term in prepareRow from plugin
field_collectionneurs: collectionneurs
# taxo term -> entity ref terms
# field_entree_s:
# plugin: iterator
# source:
# plugin: migration_lookup
# migration: d6_edlp_entrees
# source: name
# field_genre: field_genre_s
field_genre_s:
-
plugin: iterator
source: field_genre
process:
tid: value
-
plugin: flatten
# -
# plugin: migration_lookup
# migration: d6_edlp_genres
# plugin: migration
# migration: d6_edlp_genres
# source: field_genre
# plugin: iterator
# source: field_genre
# process:
# target_id:
# plugin: migration_lookup
# migration: d6_edlp_genres
# source: value
# taxo term -> entity ref terms
# field_langue: field_langue_s
# file
# field_mp3: field_fichier_son
field_fichier_son:
# # file
# # field_mp3 -> field_son
field_son:
plugin: migration_lookup
migration: d6_edlp_allfiles
source: fid
# plugin: iterator
# source: field_mp3
# process:
# target_id:
# plugin: migration_lookup
# migration: d6_edlp_allfiles
# source: fid
field_notes: body
source: sons_fid
# field_son:
# # plugin: migration_lookup
# # migration: d6_edlp_allfiles
# # source: fid
# plugin: iterator
# source: field_mp3
# process:
# target_id:
# plugin: migration_lookup
# migration: d6_edlp_allfiles
# source: fid
# unmapped d6 fields.
# tnid
# translate
# moderate
# comment
# workflow
status:
plugin: static_map
source: workflow
map:
1: 0
2: 0
3: 1
4: 1
destination:
plugin: entity:node
@@ -95,6 +95,11 @@ class D6EdlpCorpus extends D6Node {
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
drush_print(' ');
drush_print('- - - - - - - - - - - - - - - - - - - - - - - -');
drush_print($row->getSourceProperty('title'));
// format = 0 can happen when the body field is hidden. Set the format to 1
// to avoid migration map issues (since the body field isn't used anyway).
if ($row->getSourceProperty('format') === '0') {
@@ -104,17 +109,119 @@ class D6EdlpCorpus extends D6Node {
if ($this->moduleExists('content') && $this->getModuleSchemaVersion('content') >= 6001) {
foreach ($this->getFieldValues($row) as $field => $values) {
$row->setSourceProperty($field, $values);
// \Drupal::logger('edlp_migrate')->debug(print_r($values));
// print_r($field);
// print_r("\n");
// print_r($values);
}
}
$row_nid = $row->getSourceProperty('nid');
// Make sure we always have a translation set.
if ($row->getSourceProperty('tnid') == 0) {
$row->setSourceProperty('tnid', $row->getSourceProperty('nid'));
$row->setSourceProperty('tnid', $row_nid);
}
// get the article content
// drush_print_r($row->getSourceProperty('field_article'));
$article_nid = $row->getSourceProperty('field_article')[0]['nid'];
if($article_nid){
drush_print($article_nid);
$query = $this->select('content_type_episode', 'ctp');
// // $query->fields('cte', ['field_entree_value']);
$query->condition('ctp.nid', $article_nid);
$query->join('node_revisions', 'nr', 'nr.vid = ctp.vid');
$query->addField('nr', 'body');
$article = $query->execute()
->fetchField();
// drush_print_r($article);
$row->setSourceProperty('article', $article);
}
// get the entree values
$query = $this->select('term_node', 'tn');
// $query->fields('cte', ['field_entree_value']);
$query->condition('tn.nid', $row_nid);
$query->join('term_data', 'td', 'td.tid = tn.tid');
$query->condition('td.vid', 2); // vid of voc entrees
$query->addField('tn', 'tid');
$query->distinct();
$results = $query->execute()->fetchAll();
$entrees = [];
foreach ($results as $key => $value) {
$entrees[] = array($value['tid']);
}
$row->setSourceProperty('entrees', $entrees);
// Genres
$genres = [];
foreach ($row->getSourceProperty('field_genre') as $key => $value) {
$genres[] = array($value['value']);
}
$row->setSourceProperty('genres', $genres);
$langues = [];
foreach ($row->getSourceProperty('field_langue') as $key => $value) {
$langues[] = array($value['value']);
}
$row->setSourceProperty('langues', $langues);
// locuteurs
$locuteurs = [];
foreach ($row->getSourceProperty('field_artiste') as $key => $value) {
$term_name = $value['value'];
// check if term already exists in configured vocabulary
$term = array_shift(taxonomy_term_load_multiple_by_name($term_name, 'locuteurs'));
if(!$term){
// if not create the term and get the tid
$term = \Drupal\taxonomy\Entity\Term::create([
'vid' => 'locuteurs',
'name' => $term_name,
]);
$term->save();
}
// record the tid in array
$locuteurs[] = $term->get('tid')->value;
}
$row->setSourceProperty('locuteurs', $locuteurs);
// collectionneurs
$collectionneurs = [];
foreach ($row->getSourceProperty('field_compositeur') as $key => $value) {
$term_name = $value['value'];
// check if term already exists in configured vocabulary
$term = array_shift(taxonomy_term_load_multiple_by_name($term_name, 'collectionneurs'));
if(!$term){
// if not create the term and get the tid
$term = \Drupal\taxonomy\Entity\Term::create([
'vid' => 'collectionneurs',
'name' => $term_name,
]);
$term->save();
}
// record the tid in array
$collectionneurs[] = $term->get('tid')->value;
}
$row->setSourceProperty('collectionneurs', $collectionneurs);
// son
// drush_print('field_mp3 : ', 0, null, false);
// drush_print_r($row->getSourceProperty('field_mp3'));
$sons = [];
foreach ($row->getSourceProperty('field_mp3') as $key => $value) {
$sons[] = array($value['fid']);
}
$row->setSourceProperty('sons_fid', $sons);
// TODO: get the workflow status
// get the entree values
$query = $this->select('workflow_node', 'wn');
$query->fields('wn', ['sid']);
$query->condition('wn.nid', $row_nid);
$results = $query->execute()->fetchField();
drush_print('workflow query results : ', 0, null, false);
drush_print_r($results);
$row->setSourceProperty('workflow', $results);
$row = parent::prepareRow($row);
return $row;
@@ -0,0 +1,111 @@
<?php
namespace Drupal\edlp_migrate\Plugin\migrate\source;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 6 file source from database.
*
* @MigrateSource(
* id = "d6_edlp_file"
* )
*/
class D6EdlpFile extends DrupalSqlBase {
/**
* The file directory path.
*
* @var string
*/
protected $filePath;
/**
* The temporary file path.
*
* @var string
*/
protected $tempFilePath;
/**
* Flag for private or public file storage.
*
* @var bool
*/
protected $isPublic;
/**
* {@inheritdoc}
*/
public function query() {
return $this->select('files', 'f')
->fields('f')
->orderBy('timestamp')
// If two or more files have the same timestamp, they'll end up in a
// non-deterministic order. Ordering by fid (or any other unique field)
// will prevent this.
->orderBy('f.fid');
}
/**
* {@inheritdoc}
*/
protected function initializeIterator() {
$site_path = isset($this->configuration['site_path']) ? $this->configuration['site_path'] : 'sites/default';
// $filepath = $this->variableGet('file_directory_path', $site_path . '/files') . '/';
// $filepath = str_replace('//', '/', $filepath);
// drush_print('filepath : '.$filepath);
$this->filePath = $this->variableGet('file_directory_path', $site_path . '/files') . '/';
$this->tempFilePath = $this->variableGet('file_directory_temp', '/tmp') . '/';
// FILE_DOWNLOADS_PUBLIC == 1 and FILE_DOWNLOADS_PRIVATE == 2.
$this->isPublic = $this->variableGet('file_downloads', 1) == 1;
return parent::initializeIterator();
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
drush_print("D6EdlpFile");
// drush_print_r($row);
$filepath = $row->getSourceProperty('filepath');
$filepath = str_replace('//', '/', $filepath);
$filepath = preg_replace('/^\//', '', $filepath);
drush_print('filePath : '.$filepath);
$row->setSourceProperty('filepath', $filepath);
$row->setSourceProperty('file_directory_path', $this->filePath);
$row->setSourceProperty('temp_directory_path', $this->tempFilePath);
$row->setSourceProperty('is_public', $this->isPublic);
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'fid' => $this->t('File ID'),
'uid' => $this->t('The {users}.uid who added the file. If set to 0, this file was added by an anonymous user.'),
'filename' => $this->t('File name'),
'filepath' => $this->t('File path'),
'filemime' => $this->t('File MIME Type'),
'status' => $this->t('The published status of a file.'),
'timestamp' => $this->t('The time that the file was added.'),
'file_directory_path' => $this->t('The Drupal files path.'),
'is_public' => $this->t('TRUE if the files directory is public otherwise FALSE.'),
];
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['fid']['type'] = 'integer';
return $ids;
}
}