我有一个迁移,这很简单。我有一个员工编号和服务年限的CSV文件。我已将两个字段添加到系统中的用户,并在添加用户后填充它们。我现在有一个年度文件来更新服务年限。我创建了以下迁移以导入/更新资历:
id: seniority_import
label: Seniority CSV file import
description: Seniority CSV file import
migration_group: timeoff
migration_tags:
- seniority_timeoff
langcode: en
status: true
dependencies:
enforced:
module:
- timeoff_seniority
source:
plugin: csv
track_changes: true
path: "/Users/rfulcher/Downloads/Seniority2017-2.csv"
keys:
- EMPNO
column_names:
0:
EMPNO: "Employee Number"
1:
SENIORITY: "Employee Seniority"
process:
uid:
-
plugin: user_lookup
source: EMPNO
value_key: field_employee_id
entity_type: user
bundle: 1
bundle_key: status
ignore_case: true
-
plugin: skip_on_empty
method: row
source: uid
message: 'no empno found'
field_employee_id: {}
field_seniority: SENIORITY
destination:
plugin: entity:user
overwrite_properties:
- field_seniority
我还创建了自定义流程插件,以使用员工编号查找用户的uid
class UserLookup extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$user_uid = $this->getUserByEmpNo($value);
if ($user_uid == FALSE){
drush_print('usernotfound for ' . $value . ' returning 0');
return 0;
} else {
drush_print('userfound:'.$user_uid.': for ' . $value);
return $user_uid;
}
}
protected function getUserByEmpNo($employeenumber) {
$id = \Drupal::entityQuery('user')
->condition('field_employee_id', $employeenumber)
->execute();
$users = \Drupal\user\Entity\User::loadMultiple($id);
if (!empty($users)) {
foreach ($users as $user) {
$update_id = $user->id();
return $update_id;
}
} else {
return FALSE;
}
}
public function prepareRow($row) {
}
}
运行导入,我找到uid并返回值,但是就像迁移忽略它并跳过该行一样。
我错过了什么吗?我已经以这种方式进行了太长时间的工作,这应该很简单,但是我一定不能理解它应该如何工作或什么。我完全茫然。
简单的csv文件,只有两个字段empno,资历。没有什么花哨。非常感谢。
谢谢