Skip to content

Commit 4e47d30

Browse files
committed
RINGSTED-705 news migration
1 parent 552277b commit 4e47d30

File tree

5 files changed

+229
-103
lines changed

5 files changed

+229
-103
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
id: byradsportal_d7_node_news
2+
label: Ringsted Byradsportal D7 Node News
3+
migration_group: ringsted_d7
4+
migration_tags:
5+
- Drupal 7
6+
- Content
7+
deriver: Drupal\node\Plugin\migrate\D7NodeDeriver
8+
source:
9+
plugin: d7_node
10+
node_type: nyhed
11+
track_changes: true
12+
process:
13+
# If you are using this file to build a custom migration consider removing
14+
# the nid and vid fields to allow incremental migrations.
15+
# In D7, nodes always have a tnid, but it's zero for untranslated nodes.
16+
# We normalize it to equal the nid in that case.
17+
# @see \Drupal\node\Plugin\migrate\source\d7\Node::prepareRow().
18+
type:
19+
plugin: default_value
20+
default_value: os2web_news
21+
langcode:
22+
plugin: default_value
23+
source: language
24+
default_value: 'und'
25+
title: title
26+
field_os2web_news_heading: title
27+
status: status
28+
created: created
29+
changed: changed
30+
sticky: sticky
31+
field_os2web_news_article_author: field_author
32+
field_os2web_news_article_date:
33+
- plugin: skip_row_if_old_news
34+
index: 0
35+
source: field_publishdate
36+
- plugin: sub_process
37+
source: field_publishdate
38+
process:
39+
value:
40+
plugin: format_date
41+
from_format: 'Y-m-d H:i:s'
42+
to_format: 'Y-m-d\TH:i:s'
43+
from_timezone: 'Europe/Copenhagen'
44+
source: value
45+
field_os2web_news_description:
46+
- plugin: sub_process
47+
source: body
48+
process:
49+
value: value
50+
format:
51+
plugin: default_value
52+
default_value: 'wysiwyg_tekst'
53+
field_os2web_news_intro:
54+
-
55+
plugin: skip_on_empty
56+
method: process
57+
source: body/0/value
58+
-
59+
plugin: substr
60+
start: 0
61+
length: 199
62+
migrate_paragraph_files:
63+
plugin: migration_lookup
64+
migration: byradsportal_d7_node_news_paragraph_files
65+
source: nid
66+
no_stub: true
67+
field_os2web_news_paragraph_narr:
68+
plugin: sub_process
69+
source:
70+
- '@migrate_paragraph_files'
71+
process:
72+
target_id: '0'
73+
target_revision_id: '1'
74+
moderation_state:
75+
plugin: callback
76+
callable:
77+
- 'Drupal\byradsportal_d7_migration\Utility\MigrationHelper'
78+
- setModerationState
79+
source: status
80+
destination:
81+
plugin: entity:node
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
id: byradsportal_d7_node_news_paragraph_files
2+
label: Ringsted Byradsportal D7 OS2Web news files
3+
migration_tags:
4+
- 'Drupal 7'
5+
migration_group: faxe_d7
6+
deriver: Drupal\node\Plugin\migrate\D7NodeDeriver
7+
source:
8+
plugin: d7_node
9+
node_type:
10+
- nyhed
11+
track_changes: true
12+
process:
13+
field_os2web_news_article_date:
14+
- plugin: skip_row_if_old_news
15+
index: 0
16+
source: field_publishdate
17+
- plugin: sub_process
18+
source: field_publishdate
19+
process:
20+
value:
21+
plugin: format_date
22+
from_format: 'Y-m-d H:i:s'
23+
to_format: 'Y-m-d\TH:i:s'
24+
from_timezone: 'Europe/Copenhagen'
25+
source: value
26+
field_os2web_files_media:
27+
- plugin: skip_row_if_not_set
28+
index: 0
29+
source: field_file
30+
- plugin: sub_process
31+
source: field_file
32+
process:
33+
migrate_file_url_source:
34+
- plugin: callback
35+
source: fid
36+
callable:
37+
- 'Drupal\byradsportal_d7_migration\Utility\MigrationHelper'
38+
- getFileDownloadUrl
39+
migrate_file_url_destination:
40+
- plugin: callback
41+
source: fid
42+
callable:
43+
- 'Drupal\byradsportal_d7_migration\Utility\MigrationHelper'
44+
- generateFileDestinationPath
45+
migrate_file_fid:
46+
- plugin: skip_on_empty
47+
method: process
48+
source: '@migrate_file_url_source'
49+
message: 'Image is missing'
50+
- plugin: file_copy
51+
source:
52+
- '@migrate_file_url_source'
53+
- '@migrate_file_url_destination'
54+
- plugin: callback
55+
callable:
56+
- 'Drupal\byradsportal_d7_migration\Utility\MigrationHelper'
57+
- createFileManaged
58+
migrate_file_title:
59+
- plugin: callback
60+
source: fid
61+
callable:
62+
- 'Drupal\byradsportal_d7_migration\Utility\MigrationHelper'
63+
- getFileName
64+
migrate_media_entity:
65+
- plugin: skip_on_empty
66+
method: process
67+
source: '@migrate_file_url_source'
68+
message: 'File is missing'
69+
- plugin: callback
70+
unpack_source: true
71+
callable:
72+
- 'Drupal\byradsportal_d7_migration\Utility\MigrationHelper'
73+
- createMediaEntity
74+
source:
75+
- '@migrate_file_fid'
76+
- '@migrate_file_title'
77+
target_id: '@migrate_media_entity'
78+
destination:
79+
plugin: 'entity_reference_revisions:paragraph'
80+
default_bundle: os2web_files_paragraph

web/modules/custom/byradsportal_d7_migration/scripts/migrate.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,14 @@ drush migrate:reset byradsportal_d7_forum_comment
2121
drush migrate:import byradsportal_d7_forum_comment
2222
echo "Migration byradsportal_d7_forum_comment - END"
2323

24+
echo "Migration byradsportal_d7_node_news_paragraph_files - START"
25+
drush migrate:reset byradsportal_d7_node_news_paragraph_files
26+
drush migrate:import byradsportal_d7_node_news_paragraph_files
27+
echo "Migration byradsportal_d7_node_news_paragraph_files - END"
28+
29+
echo "Migration byradsportal_d7_node_news - START"
30+
drush migrate:reset byradsportal_d7_node_news
31+
drush migrate:import byradsportal_d7_node_news
32+
echo "Migration byradsportal_d7_node_news - END"
33+
2434
echo "Migration finished"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace Drupal\byradsportal_d7_migration\Plugin\migrate\process;
4+
5+
use Drupal\migrate\ProcessPluginBase;
6+
use Drupal\migrate\MigrateExecutableInterface;
7+
use Drupal\migrate\Row;
8+
use Drupal\migrate\MigrateSkipRowException;
9+
10+
/**
11+
* Skips processing the current row when a source value is not set.
12+
*
13+
* The skip_row_if_not_set process plugin checks whether a value is set. If the
14+
* value is set, it is returned. Otherwise, a MigrateSkipRowException
15+
* is thrown.
16+
*
17+
* Available configuration keys:
18+
* - index: The source property to check for.
19+
* - message: (optional) A message to be logged in the {migrate_message_*} table
20+
* for this row. If not set, nothing is logged in the message table.
21+
*
22+
* Example:
23+
*
24+
* @code
25+
* process:
26+
* settings:
27+
* # Check if the "contact" key exists in the "data" array.
28+
* plugin: skip_row_if_old_news
29+
* index: contact
30+
* source: data
31+
* message: "Missed the 'data' key"
32+
* @endcode
33+
*
34+
* This will return $data['contact'] if it exists. Otherwise, the row will be
35+
* skipped and the message "Missed the 'data' key" will be logged in the
36+
* message table.
37+
*
38+
* @see \Drupal\migrate\Plugin\MigrateProcessInterface
39+
*
40+
* @MigrateProcessPlugin(
41+
* id = "skip_row_if_old_news",
42+
* handle_multiples = TRUE
43+
* )
44+
*/
45+
class SkipRowIfOldNews extends ProcessPluginBase {
46+
47+
/**
48+
* {@inheritdoc}
49+
*/
50+
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
51+
if (strtotime($value[$this->configuration['index']]['value']) < strtotime('2022-01-01')) {
52+
$message = !empty($this->configuration['message']) ? $this->configuration['message'] : '';
53+
throw new MigrateSkipRowException($message);
54+
}
55+
return $value[$this->configuration['index']];
56+
}
57+
58+
}

web/modules/custom/ringsted_d7_migration/config/install/migrate_plus.migration.ringsted_d7_node_news.yml

Lines changed: 0 additions & 103 deletions
This file was deleted.

0 commit comments

Comments
 (0)