- πΊπΈUnited States jumpsuitgreen
@Michelle Thanks for posting. Your patch (#14) resolved our issue.
We have a D10 site with migrations using the URL source plugin to fetch XML file elements. Empty elements would trigger this error:
Migration failed with source plugin exception: Serialization of 'SimpleXMLElement' is not allowed in /var/www/web/core/modules/migrate/src/Row.php line 391
After applying patch #14, the migration runs smooth. - π¬π§United Kingdom joachim
@das-peter did you mean the patch from π Xml parser doesn't create array of values if value doesn't render to string Needs work should fix the issue here?
I tried the patch from π Xml parser doesn't create array of values if value doesn't render to string Needs work for my issue and it didn't fix it.
- π¬π§United Kingdom joachim
I also tried the patch from #14, and the values I get in my source row don't look right any more:
"mail" => "<property name="Email"/>"
- π¬π§United Kingdom joachim
I'm trying to understand the exact circumstances that produce this error, as some of my XML migrations are working fine.
Is it caused by the value-holding XML item having an attribute, for instance?
e.g.:
This works ok, because the xpath selector is 'property[@field="field-alpha"]' and the resulting item has no attributes, and so renders to a string:
<property name="field-alpha"> <value> value-to-be-migrated </value> </property>
But this doens't work:
<property name="field-alpha"> value-to-be-migrated </property>
- π¬π§United Kingdom joachim
I can see a partial fix: replace:
if ($value->children() && !trim((string) $value)) {
with:
if ($value->hasChildren() && !trim((string) $value)) {
MR coming.
It's a fix in that the use case I gave in #18 now works.
But it's not really a complete fix because this arm of the condition will still produce something that will crash Migrate:
if ($value->hasChildren() && !trim((string) $value)) { $this->currentItem[$field_name][] = $value; }
This code was added in π Allow XML elements to pass through as field values to process plugins (for SimpleXML processor) Fixed , but it's not clear how back when it was added it wasn't causing this crash!
- π¬π§United Kingdom joachim
I'm not sure about where to put a test, as the tests in tests/src/Kernel/Plugin/migrate_plus/data_parser are unit-ish tests -- they don't test the data parser plugins in the context of a migration. Where should tests that cover integration with the migration system go?
- Merge request !109#2837684: Fixed XML elements with attributes being handled as if they have children. β (Open) created by joachim