123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- <?php
- namespace Drupal\edlp_migrate\Plugin\migrate\source;
- use Drupal\migrate\Row;
- use Drupal\node\Plugin\migrate\source\d6\Node as D6Node;
- /**
- * Source plugin for edlp corpus migration.
- *
- * @MigrateSource(
- * id = "d6_edlp_corpus"
- * )
- */
- class D6EdlpCorpus extends D6Node {
- /**
- * {@inheritdoc}
- */
- public function query() {
- $query = $this->select('node_revisions', 'nr');
- $query->innerJoin('node', 'n', static::JOIN);
- $this->handleTranslations($query);
- $query->fields('n', [
- 'nid',
- 'type',
- 'language',
- 'status',
- 'created',
- 'changed',
- 'comment',
- 'promote',
- 'moderate',
- 'sticky',
- 'tnid',
- 'translate',
- ])
- ->fields('nr', [
- 'title',
- 'body',
- 'teaser',
- 'log',
- 'timestamp',
- 'format',
- 'vid',
- ]);
- $query->addField('n', 'uid', 'node_uid');
- $query->addField('nr', 'uid', 'revision_uid');
- // If the content_translation module is enabled, get the source langcode
- // to fill the content_translation_source field.
- if ($this->moduleHandler->moduleExists('content_translation')) {
- $query->leftJoin('node', 'nt', 'n.tnid = nt.nid');
- $query->addField('nt', 'language', 'source_langcode');
- }
- if (isset($this->configuration['node_type'])) {
- $query->condition('n.type', $this->configuration['node_type']);
- }
- return $query;
- }
- /**
- * {@inheritdoc}
- */
- public function fields() {
- $fields = [
- 'nid' => $this->t('Node ID'),
- 'type' => $this->t('Type'),
- 'title' => $this->t('Title'),
- 'body' => $this->t('Body'),
- 'format' => $this->t('Format'),
- 'teaser' => $this->t('Teaser'),
- 'node_uid' => $this->t('Node authored by (uid)'),
- 'revision_uid' => $this->t('Revision authored by (uid)'),
- 'created' => $this->t('Created timestamp'),
- 'changed' => $this->t('Modified timestamp'),
- 'status' => $this->t('Published'),
- 'promote' => $this->t('Promoted to front page'),
- 'sticky' => $this->t('Sticky at top of lists'),
- 'revision' => $this->t('Create new revision'),
- 'language' => $this->t('Language (fr, en, ...)'),
- 'tnid' => $this->t('The translation set id for this node'),
- 'timestamp' => $this->t('The timestamp the latest revision of this node was created.'),
- ];
- return $fields;
- }
- /**
- * {@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') {
- $row->setSourceProperty('format', $this->filterDefaultFormat);
- }
- if ($this->moduleExists('content') && $this->getModuleSchemaVersion('content') >= 6001) {
- foreach ($this->getFieldValues($row) as $field => $values) {
- $row->setSourceProperty($field, $values);
- }
- }
- $row_nid = $row->getSourceProperty('nid');
- // Make sure we always have a translation set.
- if ($row->getSourceProperty('tnid') == 0) {
- $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);
- // get the workflow state (will be converted on status)
- $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;
- }
- }
|