popsu_migrate: D7NodeProgramme partenaire paragraphe ok

This commit is contained in:
Bachir Soussi Chiadmi 2021-04-16 21:42:02 +02:00
parent 85b5fcff6e
commit e8040aa7b9
2 changed files with 73 additions and 5 deletions

View File

@ -64,6 +64,8 @@ process:
field_sous_parties: sous_parties field_sous_parties: sous_parties
field_partenaires: partenaires
field_fichier: field_fichier:
plugin: sub_process plugin: sub_process
source: fichiers source: fichiers

View File

@ -42,12 +42,11 @@ class D7NodeProgramme extends D7Programme {
$nid = $row->getSourceProperty('nid'); $nid = $row->getSourceProperty('nid');
$vid = $row->getSourceProperty('vid'); $vid = $row->getSourceProperty('vid');
$type = $row->getSourceProperty('type'); $type = $row->getSourceProperty('type');
$title = $row->getSourceProperty('title');
Drush::output()->writeln('- - - - ' . $title . '- - - - ');
// Get Field API field values. // Get Field API field values.
foreach ($this->getFields('node', $type) as $field_name => $field) { foreach ($this->getFields('node', $type) as $field_name => $field) {
// Ensure we're using the right language if the entity and the field are
// translatable.
// $field_language = $entity_translatable && $field['translatable'] ? $language : NULL;
$row->setSourceProperty($field_name, $this->getFieldValues('node', $field_name, $nid, $vid, NULL)); $row->setSourceProperty($field_name, $this->getFieldValues('node', $field_name, $nid, $vid, NULL));
} }
@ -67,9 +66,9 @@ class D7NodeProgramme extends D7Programme {
// associateds // associateds
$associateds = $this->getAssociatedSpecial($field_popsu_special_popsu_tid); $associateds = $this->getAssociatedSpecial($field_popsu_special_popsu_tid);
Drush::output()->writeln(dump($associateds)); // Drush::output()->writeln(dump($associateds));
// texts (migration_lookup) // texts (paragraphe)
$text = $row->getSourceProperty('field_popsu_special_text'); $text = $row->getSourceProperty('field_popsu_special_text');
$text[0]['format'] = 'wysiwyg'; $text[0]['format'] = 'wysiwyg';
$p = Paragraph::create(['type' => 'textes']); $p = Paragraph::create(['type' => 'textes']);
@ -129,6 +128,73 @@ class D7NodeProgramme extends D7Programme {
$row->setSourceProperty('sous_parties', $sous_parties); $row->setSourceProperty('sous_parties', $sous_parties);
} }
// Partenaires
$ps = array();
// looping through nodes
foreach ($associateds['partenaires'] as $key => $special) {
$p = Paragraph::create(['type' => 'partenaires']);
$p->set('field_nom_partenaire', $special['title']);
// texts
if(!empty($special['field_popsu_special_body']) || !empty($special['field_popsu_special_text'])){
$text = array(
array(
'value' => '',
'summary' => '',
'format' => 'wysiwyg'
),
);
foreach (['field_popsu_special_body', 'field_popsu_special_text'] as $src_field) {
if (!empty($special[$src_field])) {
$text[0]['value'] .= $special[$src_field][0]['value'];
$text[0]['summary'] .= isset($special[$src_field][0]['summary']) ? $special[$src_field][0]['summary'] : '';
}
}
$p->set('field_presentation', $text);
}
// files
// 'field_fichiers' => ['field_popsu_special_insert_intro', 'field_popsu_special_insert'],
$files = array();
foreach (['field_popsu_special_insert_intro', 'field_popsu_special_insert'] as $field) {
if (!empty($special[$field])) {
// Drush::output()->writeln(dump($special[$field]));
foreach ($special[$field] as $file) {
// Drush::output()->writeln(dump($file));
// change file fid from migration lookup
$database = \Drupal::database();
$fidquery = $database->select('migrate_map_d7_allpublicfiles', 'm')
->condition('m.sourceid1', $file['fid'])
->fields('m', ['sourceid1', 'destid1']);
$result = $fidquery->execute();
foreach ($result as $record) {
if($record){
$dfid = $record->destid1;
break;
}
}
if ($dfid) {
$file['target_id'] = $dfid;
unset($file['fid']);
$files[] = $file;
}
}
}
}
if (!empty($files)) {
Drush::output()->writeln(dump($files));
$p->set('field_fichiers', $files);
}
$p->isNew();
$p->save();
$ps[] = array(
'target_id' => $p->id(),
'target_revision_id' => $p->getRevisionId(),
);
}
if (!empty($ps)) {
$row->setSourceProperty('partenaires', $ps);
}
// fichiers // fichiers
// files from current node // files from current node
$fichiers = array(); $fichiers = array();