Use case:

1. Install a clean Drupal 6 with CCK and ImageCache Modules.
2. Create a single node in the site.
3. Try to migrate to Drupal 8 beta 15 using "drush migrate-upgrade"

Result:

Error from ConvertTokens.php who get's a NULL parameter and throws a MigrateException.

Desired:

NULL is handled correctly.

Fix:

Convert any NULLs to empty strings, which then can be used by str_replace.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

johnstorey created an issue. See original summary.

johnstorey’s picture

benjy’s picture

Issue tags: +needs test

Thanks for the patch, good find. We'll need to add some tests for this, ideally a unit test may already exist otherwise we can try add one.

Also, checkout the Drupal coding standards, we always put brackets for if statements like that.

phenaproxima’s picture

+++ b/core/modules/user/src/Plugin/migrate/process/ConvertTokens.php
@@ -40,6 +40,11 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
+    if ($value == NULL) $value = '';

When using ==, an empty string ('') will resolve to NULL. This should use is_null() or ===.

Agreed with @benjy that this needs a test (I believe there is a unit test of ConvertTokens, so all you'd need is an additional assert in there) and brackets for the if statement. Otherwise, looks fine and dandy to me.

johnstorey’s picture

I cannot seem to locate where the current ConvertTokens test exist. Can anyone give me a pointer? I'd like to wrap this up before the end of the Barcelona sprint day. Thanks!

johnstorey’s picture

Per IRC conversation, existing tests do not exist to extend to cover this use case. My suggestion is to open a new issue to cover that.

Meanwhile, here is my re-rolled patch.

phenaproxima’s picture

Status: Needs review » Needs work

Per IRC conversation, existing tests do not exist to extend to cover this use case. My suggestion is to open a new issue to cover that.

We need to fix the tests in this issue -- the reason being that committers generally don't like to commit a bug fix that is unaccompanied by test coverage. I believe ConvertTokens already has a test, so it should be reasonably simple to add an assertion or two.

svendecabooter’s picture

Assigned: Unassigned » svendecabooter
svendecabooter’s picture

Assigned: svendecabooter » Unassigned
Status: Needs work » Needs review
FileSize
2.11 KB

There is no ConvertTokens test yet...
Attached is a patch that adds this test, and tests for normal token conversion, as well as conversion with a NULL value.

Status: Needs review » Needs work

The last submitted patch, 9: drupal-handle-NULL-in-ConvertToken-2573895-9-8.0.patch, failed testing.

The last submitted patch, 9: drupal-handle-NULL-in-ConvertToken-2573895-9-8.0.patch, failed testing.

phenaproxima’s picture

Status: Needs work » Needs review
Issue tags: -needs test
FileSize
2.27 KB

This oughta help :)

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

Since 95% of the patch is by @svendecabooter and @johnstorey, I feel OK RTBCing this. Full speed ahead!

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Nit-pick, fixed on commit:

+    // value, sometimes that filters down to here. str_replace cannot
+    // handle NULLs as he subject, so we reset to an empty string.

str_replace()
"the" subject

Committed and pushed to 8.0.x. Thanks!

  • webchick committed eb93c68 on 8.0.x
    Issue #2573895 by johnstorey, phenaproxima, svendecabooter, benjy:...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.