Comments

phenaproxima’s picture

Issue tags: +Quick fix

I wouldn't say this is Migrate critical but it is a major bug with a quick fix.

benjy’s picture

$this->assertIdentical('node/1', $visibility['request_path']['pages']);
urgh, yeah. Our tests weren't going to catch issues where core actually changes how it stores paths.

quietone’s picture

Status: Active » Needs review
StatusFileSize
new1.91 KB
new2.63 KB

Yes, that was quick.

The last submitted patch, 3: 2532550-3-fail.patch, failed testing.

phenaproxima’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/block/src/Plugin/migrate/process/d6/BlockVisibility.php
    @@ -60,7 +60,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
    -      $visibility['request_path']['pages'] = $pages;
    +      $visibility['request_path']['pages'] = '/' . $pages;
    

    Is this going to handle multiple pages (one per line)? I'd think this needs to explode()'ed first, with the leading slash inserted before each path in the list, no?

  2. +++ b/core/modules/block/src/Tests/Migrate/d6/MigrateBlockTest.php
    @@ -149,7 +149,7 @@ public function testBlockMigration() {
    -    $this->assertIdentical('<front>', $visibility['request_path']['pages']);
    +    $this->assertIdentical('/<front>', $visibility['request_path']['pages']);
    

    IIRC, <front> does NOT take a leading slash. Everything else yes, but not <front>.

hass’s picture

+++ b/core/modules/block/src/Plugin/migrate/process/d6/BlockVisibility.php
@@ -60,7 +60,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
-      $visibility['request_path']['pages'] = $pages;
+      $visibility['request_path']['pages'] = '/' . $pages;

Ah... no no no - not that easy.

Yes, that need to be splitted at "\r\n|\n" and than prefixed and than imploded again. There are some examples in core how this need to be splitted.

tim.plunkett’s picture

From \Drupal\Core\Path\PathMatcher::matchPath(): '/(\r\n?|\n)/'

hass’s picture

and do not touch PHP code snippets...

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new2.39 KB
new3.28 KB
new3.28 KB

Yep, completely forgot that this needs to handle multiple lines. The attached should be an improvement.

phenaproxima’s picture

Status: Needs review » Needs work
+++ b/core/modules/block/src/Plugin/migrate/process/d6/BlockVisibility.php
@@ -60,7 +60,13 @@
+      foreach ($paths as &$path) {

It's apparently not considered a best practice to reference the current variable with &. It's preferable to just do $k => $path and set $paths[$k] inside the loop. This will change the logic inside the loop and invalidate the use of strcmp(), but I'm OK with that -- strcmp() is a function with weird semantics and I think using simple == and != would be more readable.

One possibility:

foreach ($paths as $k => $path) {
  $paths[$k] = $path == '<front>' ? $path : "/$path";
}

Other than that, looks good.

The last submitted patch, 9: 2532550-9-fail.patch, failed testing.

The last submitted patch, 9: 2532550-9.patch, failed testing.

hass’s picture

CNW: These patches do not cover the PHP snippet upgrades.

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new3.39 KB
new1.08 KB

Fixed issues from #10.

quietone’s picture

@hass, it seems to me the php code snippets is outside the scope of this issue. Maybe make a new issue for that?

hass’s picture

Why? This case is about incorrect migration of paths value. The value may contains paths without slashes or php snippets.

Your code is now causing a WSOD and dead site if there has been a single php snippet. This will end with a critical followup as the site get's totally broken.

phenaproxima’s picture

Your code is now causing a WSOD and dead site if there has been a single php snippet. This will end with a critical followup as the site get's totally broken.

@hass, @quietone has been working diligently on this. Please be patient -- or by all means feel free to submit your own patch.

+++ b/core/modules/block/src/Plugin/migrate/process/d6/BlockVisibility.php
+++ b/core/modules/block/src/Plugin/migrate/process/d6/BlockVisibility.php
@@ -60,7 +60,11 @@ public function transform($value, MigrateExecutableInterface $migrate_executable

@@ -60,7 +60,11 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
     $visibility = array();
 
     if (!empty($pages)) {

@hass is correct that handling PHP code snippets is within the scope of this issue, since the D6/7 block system allows you to put PHP code into the 'pages' value.

It's a reasonably easy fix, but the question is what to do if $value is 2 (a.k.a. BLOCK_VISIBILITY_PHP). Return an empty value? Throw a SkipProcessException? Transform it somehow? For that matter, does Drupal 8 even support PHP-based block visibility?

tim.plunkett’s picture

SkipProcessException sounds right, since D8 does not support PHP snippets any more.

hass’s picture

It's a reasonably easy fix, but the question is what to do if $value is 2 (a.k.a. BLOCK_VISIBILITY_PHP). Return an empty value? Throw a SkipProcessException? Transform it somehow? For that matter, does Drupal 8 even support PHP-based block visibility?

No, just copy it 1:1. Do not skip it. Do not return an empty value, please.

We have the PHP module in contrib and if someone really need it he is able to install it again without loosing data/settings.

phenaproxima’s picture

@hass: If you have a better idea which will satisfy all use cases, please fix the patch and post your changes.

I suggest the following:

  1. If the visibility is 2 and the PHP module is installed, return $pages unaltered.
  2. If the visibility is 2 and the PHP module is NOT installed, throw MigrateSkipRowException.
  3. Otherwise, do what we're already doing.
quietone’s picture

To finish the suggestions in #20 I just need to know how to test if the module is installed. It seems the source plugins can use moduleExists but not process plugins?

I've and converted the tests to use assertEntity but now need to know more about the visibility array. Post import it contains $visibility['user_role']['negate']. How do I find out if that is correct? I can't seem to find anything useful.

Finally, why are only 10 of the 19 blocks in the source table imported?

phenaproxima’s picture

Issue tags: -Quick fix

To finish the suggestions in #20 I just need to know how to test if the module is installed. It seems the source plugins can use moduleExists but not process plugins?

To check if a module is installed on the destination DB, inject the module_handler service (using ContainerFactoryPluginInterface) and call its moduleExists() method. The moduleExists() method of source plugins (DrupalSqlSource plugins, specifically) tests if a module is enabled in the source database. In this case, we only care if the php module is present in the destination.

I've and converted the tests to use assertEntity but now need to know more about the visibility array. Post import it contains $visibility['user_role']['negate']. How do I find out if that is correct?

For now, don't worry about it. To me, it seems outside the scope of this issue.

Finally, why are only 10 of the 19 blocks in the source table imported?

Presumably some blocks were skipped, failed, or ignored. Details will be found in the message table for the migration, which will probably be named something like migrate_message_d6_block.

quietone’s picture

inject the module_handler service (using ContainerFactoryPluginInterface) and call its moduleExists() method.

Even with suggestions from mikeryan1 and webchick on IRC I can't implement this.

tim.plunkett’s picture

Issue tags: +Needs tests
StatusFileSize
new3.31 KB
new5.63 KB

This is just to get something working. We can debate what happens in the 3 cases identified in #20 later, but we first need to have the code follow those 3 paths.

Do any of these migrations have unit tests written for them? I could see one being rather useful here.

tim.plunkett’s picture

Issue tags: -Needs tests
StatusFileSize
new4.38 KB
new9.66 KB

Wrote a unit test. This only covers the 'pages' part.

quietone’s picture

StatusFileSize
new13.34 KB

Added the assertions as discussed but haven't had an opportunity to add unit tests for the roles part. I haven't really explored the unit tests yet but it should be easy since tim.plunkett has set it all up. thank you tim.plunkett.

The addition of simple php code to one of the blocks in dump file, Blocks.php will cause the MigrateSkipRowException to be thrown and the tests will fail. Not sure how to deal with that.

Status: Needs review » Needs work

The last submitted patch, 26: 2532550-migrate-26.patch, failed testing.

catch’s picture

I think this probably is migrate critical - or at least it'd be good to know exactly what the consequences are of a Drupal 6 site with PHP visibility getting migrated to 8.x - will it migrate the PHP snippet into path rules?

hass’s picture

+++ b/core/modules/block/src/Tests/Migrate/d6/MigrateBlockTest.php
@@ -82,101 +107,67 @@ public function testBlockMigration() {
+    $visibility['request_path']['pages'] = "<?php\nreturn TRUE;";

Why are these PHP snippets not having a closing tag?

tim.plunkett’s picture

@hass, those strings could be anything we want, they don't even have to be valid PHP, as we're not executing it. We're only checking the value of that radio button, that says its PHP code.

quietone’s picture

StatusFileSize
new17.36 KB

Did some cleanup and added data for testing the 'user_role' to the unit test. It was when I ran that test that I realized that it depends on another plugin. The learning continues ....

hass’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 31: 2532550-migrate-31.patch, failed testing.

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new17.49 KB
new1.14 KB

Maybe this is right for the unit test.

Status: Needs review » Needs work

The last submitted patch, 34: 2532550-migrate-34.patch, failed testing.

quietone’s picture

quietone’s picture

Status: Needs work » Postponed

So, I completely missed the obvious here with the tests. Thanks to phenaproxima for stating that. As well as pointing out that the process plugin should not be skipping rows, The Migration process plugin should not skip rows.

Changing the template to use SkipRow doesn't work in this case. SkipRow skips if the value is empty but an empty visibility array is valid. The test results confirmed that because blocks where $visibility=array() where not migrated. Using the other option, SkipProcess resulted in "'Plugin ID '0' was not found", although the test results looked correct, at least, doing a cursory look.

On IRC, mikeryan1 said to throw a MigrateException as process time, but that depends on Handle MigrateException consistently during import. I changed the code to use MigrateException and applied the current patch for that issue and all tests passed.

I got bold and marked it as postponed, not sure if that is the thing do here. I trust someone will update as needed.

mikeryan’s picture

Status: Postponed » Needs work
quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new18.01 KB
new2.61 KB

Right. How's this?

tim.plunkett’s picture

  1. +++ b/core/modules/block/src/Tests/Migrate/d6/MigrateBlockTest.php
    @@ -157,13 +157,12 @@
    -  }
    ...
    +   }
    

    Which } was outdented wrong? Can't tell even when squinting.

  2. +++ b/core/modules/block/src/Tests/Migrate/d6/MigrateBlockTest.php
    @@ -157,13 +157,12 @@
    +    // Custom block with php code is not migrated
    

    End with a .

  3. +++ b/core/modules/block/src/Tests/Migrate/d6/MigrateBlockTest.php
    @@ -157,13 +157,12 @@
    +    $block = block::load('block_3');
    

    Block::load

  4. +++ b/core/modules/block/src/Tests/Migrate/d6/MigrateBlockTest.php
    @@ -157,13 +157,12 @@
    +    $this->assertFalse($block Instanceof Block);
    

    instanceof is all lowercase

Status: Needs review » Needs work

The last submitted patch, 39: 2532550-migrate-39.patch, failed testing.

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new18 KB
new1.65 KB

1-4 Fixed. #1 was caused by an extra space.

And changed the Unit test to test for the correct exception, MigrateException, not MigrateSkipRowException.

The last submitted patch, 39: 2532550-migrate-39.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 42: 2532550-migrate-42.patch, failed testing.

quietone queued 42: 2532550-migrate-42.patch for re-testing.

quietone’s picture

Status: Needs work » Needs review
tim.plunkett’s picture

StatusFileSize
new17.98 KB
new1.68 KB

I can't speak to the simpletest changes, but everything else looks good for me. Just some nits.
RTBC from my perspective.

phenaproxima’s picture

StatusFileSize
new23.83 KB
new18.76 KB

So I'm sorry to do this, but after discussing on IRC with @mikeryan, we think it's probably overzealous for the block visibility plugin to throw MigrateException -- which will cause the entire row to be skipped -- when it can't resolve the PHP code.

This is a very tricky case because there are several reasonable courses of action that one could take when trying to migrate a block that uses PHP code for visibility. For example, you might want to drop PHP visibility configuration, but preserve role-based visibility.

The attached patch separates the two lines of logic. Role processing is handled separately from request path processing, which allows things to be cleaner and more granular while preserving as much data as possible. The migration is now configured to drop PHP visibility information if the PHP module is not enabled, but preserve role visibility in all cases.

Status: Needs review » Needs work

The last submitted patch, 48: 2532550-48.patch, failed testing.

The last submitted patch, 48: 2532550-48.patch, failed testing.

phenaproxima’s picture

Status: Needs work » Closed (won't fix)

I've decided to merge this patch into #2408165: Migration Files for Drupal 7 Blocks. Proper visibility migration is pretty much required for block migrations to complete successfully, and given that we're trying to get blocks done by DrupalCon Barcelona, it doesn't make a whole lot of sense to block that issue -- which, like this one, is also Migrate D7 critical -- on this one.