Migration failed with source plugin exception: Serialization of SimpleXMLElement is not allowed

Created on 19 December 2016, over 7 years ago
Updated 14 September 2023, 10 months ago

The XML::fetchNextRow() method currently returns a SimpleXMLElement when the current selector doesn't render to a string and has children. This seems to be in conflict with core's MigrateExecutable::import() which starts by calling $source->rewind(). This will result in an exception being thrown ("Migration failed with source plugin exception: Serialization of SimpleXMLElement is not allowed"), and the migration is interrupted.

Quickly googling for this problem indicates that SimpleXMLElement can't really be serialized, so returning that as an object is simply not possible. I'm proposing that instead of returning the object, the code should be altered to return the element's XML, which can easily be converted back to the object with simplexml_load_string().

Since might be relevant, in this migration I've got a set of XML files in an import directory (crawled by the hook_install hack), and one of my processors needs to use the XML element, as the specific child being imported depends on a Drupal variable (the XML element contains different translations of a string, and which one gets imported depends on the current site's language).

πŸ› Bug report
Status

Needs work

Version

3.0

Component

Plugins

Created by

πŸ‡΅πŸ‡ΉPortugal jcnventura

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡Έ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.

Production build 0.69.0 2024