Skip to content

Commit

Permalink
Issue #9: Add item selectors for translation migrations to skip impor…
Browse files Browse the repository at this point in the history
…t if titles are empty.
  • Loading branch information
LOBsTerr committed May 3, 2023
1 parent 9d9536e commit 587df49
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ class NewsroomCountryLanguageDeriver extends BaseNewsroomLanguageDeriver {
protected function getDerivativeValues(array $base_plugin_definition, LanguageInterface $language, $language_code) {
$language_id = $language->getId();

$base_plugin_definition['source']['item_selector'] = '//channel/item[string-length(title[@lang="' . $language_code . '"]) > 0]';

// Name.
$base_plugin_definition['source']['fields'][] = [
'name' => 'name',
'label' => 'Name',
'selector' => 'title[@lang="' . $language_code . '"]/text()',
];

$base_plugin_definition['process']['name'] = [
'plugin' => 'skip_on_empty',
'source' => 'name',
'method' => 'row',
$base_plugin_definition['process']['name'][] = [
'plugin' => 'get',
'source' => "type_name_$language_id",
'language' => $language_id,
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ source:
name: documents_match_language
label: 'Documents match language'
selector: 'infsonewsroom:docMatchLanguage/text()'

process:

type:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Drupal\newsroom_connector\Plugin\migrate\BaseNewsroomLanguageDeriver;

/**
* Deriver for the newsroom item translations.
* Deriver for the newsroom item media translations.
*/
class NewsroomItemImageMediaLanguageDeriver extends BaseNewsroomLanguageDeriver {

Expand All @@ -15,6 +15,7 @@ class NewsroomItemImageMediaLanguageDeriver extends BaseNewsroomLanguageDeriver
*/
protected function getDerivativeValues(array $base_plugin_definition, LanguageInterface $language, $language_code) {
$language_id = $language->getId();
$base_plugin_definition['source']['item_selector'] = '//channel/item[string-length(infsonewsroom:PicTitle[@lang="' . $language_code . '"]) > 0 and enclosure[@lang="' . $language_code . '" and @nrdoctype="image" and string-length(@url) > 0]]';

$base_plugin_definition['process']['langcode'] = [
'plugin' => 'default_value',
Expand All @@ -28,12 +29,6 @@ protected function getDerivativeValues(array $base_plugin_definition, LanguageIn
'selector' => 'infsonewsroom:PicTitle[@lang="' . $language_code . '"]/text()',
];

$base_plugin_definition['process']['name'][] = [
'plugin' => 'skip_on_empty',
'method' => 'row',
'source' => 'image_name',
];

$base_plugin_definition['process']['name'][] = [
'plugin' => 'get',
'source' => 'image_name',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ class NewsroomNewsletterLanguageDeriver extends BaseNewsroomLanguageDeriver {
protected function getDerivativeValues(array $base_plugin_definition, LanguageInterface $language, $language_code) {
$language_id = $language->getId();

$base_plugin_definition['source']['item_selector'] = '//channel/item[string-length(title[@lang="' . $language_code . '"]) > 0]';

// Name.
$base_plugin_definition['source']['fields'][] = [
'name' => 'name',
'label' => 'Name',
'selector' => 'title[@lang="' . $language_code . '"]/text()',
];

$base_plugin_definition['process']['name'] = [
'plugin' => 'skip_on_empty',
'source' => 'name',
'method' => 'row',
$base_plugin_definition['process']['name'][] = [
'plugin' => 'get',
'source' => "type_name_$language_id",
'language' => $language_id,
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class NewsroomServiceLanguageDeriver extends BaseNewsroomLanguageDeriver {
protected function getDerivativeValues(array $base_plugin_definition, LanguageInterface $language, $language_code) {
$language_id = $language->getId();

$base_plugin_definition['source']['item_selector'] = '//channel/item[string-length(title[@lang="' . $language_code . '"]) > 0]';

$base_plugin_definition['process']['langcode'] = [
'plugin' => 'default_value',
'default_value' => $language_id,
Expand All @@ -28,12 +30,6 @@ protected function getDerivativeValues(array $base_plugin_definition, LanguageIn
'selector' => 'title[@lang="' . $language_code . '"]/text()',
];

$base_plugin_definition['process']['name'][] = [
'plugin' => 'skip_on_empty',
'source' => "service_name_$language_id",
'method' => 'row',
];

$base_plugin_definition['process']['name'][] = [
'plugin' => 'get',
'source' => "service_name_$language_id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ class NewsroomTeamResponsibleLanguageDeriver extends BaseNewsroomLanguageDeriver
protected function getDerivativeValues(array $base_plugin_definition, LanguageInterface $language, $language_code) {
$language_id = $language->getId();

$base_plugin_definition['source']['item_selector'] = '//channel/item[string-length(title[@lang="' . $language_code . '"]) > 0]';

// Name.
$base_plugin_definition['source']['fields'][] = [
'name' => "name",
'label' => "Name",
'selector' => 'title[@lang="' . $language_code . '"]/text()',
];

$base_plugin_definition['process']['name'] = [
'plugin' => 'skip_on_empty',
'source' => "name",
'method' => 'row',
$base_plugin_definition['process']['name'][] = [
'plugin' => 'get',
'source' => "topic_name_$language_id",
'language' => $language_id,
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,15 @@ class NewsroomTopicLanguageDeriver extends BaseNewsroomLanguageDeriver {
protected function getDerivativeValues(array $base_plugin_definition, LanguageInterface $language, $language_code) {
$language_id = $language->getId();

$base_plugin_definition['source']['item_selector'] = '//channel/item[string-length(title[@lang="' . $language_code . '"]) > 0]';

// Name.
$base_plugin_definition['source']['fields'][] = [
'name' => "topic_name_$language_id",
'label' => "Topic name - $language_id",
'selector' => 'title[@lang="' . $language_code . '"]/text()',
];

$base_plugin_definition['process']['name'][] = [
'plugin' => 'skip_on_empty',
'source' => "topic_name_$language_id",
'method' => 'row',
];

$base_plugin_definition['process']['name'][] = [
'plugin' => 'get',
'source' => "topic_name_$language_id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@ class NewsroomTypeLanguageDeriver extends BaseNewsroomLanguageDeriver {
protected function getDerivativeValues(array $base_plugin_definition, LanguageInterface $language, $language_code) {
$language_id = $language->getId();

$base_plugin_definition['source']['item_selector'] = '//channel/item[string-length(title[@lang="' . $language_code . '"]) > 0]';

$base_plugin_definition['source']['fields'][] = [
'name' => "type_name_$language_id",
'label' => "Type name - $language_id",
'selector' => 'title[@lang="' . $language_code . '"]/text()',
];

$base_plugin_definition['process']['name'][] = [
'plugin' => 'skip_on_empty',
'method' => 'row',
'source' => "type_name_$language_id",
];
$base_plugin_definition['process']['name'][] = [
'plugin' => 'get',
'source' => "type_name_$language_id",
Expand Down

0 comments on commit 587df49

Please sign in to comment.