Custom source plugin + sourceid not found
Issue #2944765 on drupal.org by kumkum29.
Hello,
i have created a custom source plugin to create nodes (content type 2) from other nodes (content type 1).
I have defined a simple yml file to test this migration. But, I get errors with this migration:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'map.sourceid1' in 'field list': SELECT n.title AS title, map.sourceid1 AS migrate_map_sourceid1, map.sourceid2 AS migrate_map_sourceid2, map.source_row_status AS migrate_map_source_row_status FROM @node_field_data n LEFT OUTER JOIN mydb.migrate_map_datas_google_analytics map ON date_now = map.sourceid1 AND n.title = map.sourceid2 WHERE (map.sourceid1 IS NULL) OR (map.source_row_status = :db_condition_placeholder_0); Array ( [:db_condition_placeholder_0] => 1 )
Here is the configuration migration file :
# Source settings
source:
# Define the custom source
plugin: custom_source
# Choose the database (default database)
key: default
# Enable "track changes" feature.
track_changes: true
# Destination
destination:
plugin: entity:node
# Mapping
process:
# Entity type
type:
plugin: default_value
default_value: content_type_2
# Targets
title: title
And my CustomSource plugin file:
use Drupal\migrate\Plugin\migrate\source\SqlBase;
use Drupal\migrate\Row;
/**
*
@MigrateSource(
id = "source_custom"
)
*/
class SourceCustom extends SqlBase {
/**
{@inheritdoc}
*/
public function query() {
// Source data is queried from 'node_field_data' table.
$query = $this->select('node_field_data', 'n')
->condition('n.type', 'company')
->fields('n', [
'type',
'nid',
'title',
]);
//dpm($query);
return $query;
}
/**
{@inheritdoc}
*/
public function fields() {
$fields = [
'type' => $this->t('Type'),
'nid' => $this->t('Node ID'),
'title' => $this->t('Title'),
];
return $fields;
}
/**
{@inheritdoc}
*/
public function getIds() {
// Define the current date
$ids['date_now'] = date('Ymd');
// Return a composed key
return [
'date_now' => [
'type' => 'integer',
],
'title' => [
'type' => 'string',
'alias' => 'n',
],
];
}
/**
{@inheritdoc}
*/
public function prepareRow(Row $row) {
// Define the current date
$date_now = date('Ymd');
// Set the title
$title = $date_now .' - '. $row->getSourceProperty('title');
$row->setSourceProperty('title', $title);
return parent::prepareRow($row);
}
}
I have tested many things without success. I don't see how to resolve my problem.
In the table migrate_map_... I don't see sourceid columns. Why these columns aren't created when I launch the migration?
Thanks for your precious help.