Closed (won't fix)
Project:
Drupal core
Version:
8.0.x-dev
Component:
migration system
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
13 Jul 2015 at 22:35 UTC
Updated:
15 Sep 2015 at 00:35 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
phenaproximaI wouldn't say this is Migrate critical but it is a major bug with a quick fix.
Comment #2
benjy commented$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.
Comment #3
quietone commentedYes, that was quick.
Comment #5
phenaproximaIs 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?
IIRC, <front> does NOT take a leading slash. Everything else yes, but not <front>.
Comment #6
hass commentedAh... 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.
Comment #7
tim.plunkettFrom \Drupal\Core\Path\PathMatcher::matchPath():
'/(\r\n?|\n)/'Comment #8
hass commentedand do not touch PHP code snippets...
Comment #9
quietone commentedYep, completely forgot that this needs to handle multiple lines. The attached should be an improvement.
Comment #10
phenaproximaIt'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:
Other than that, looks good.
Comment #13
hass commentedCNW: These patches do not cover the PHP snippet upgrades.
Comment #14
quietone commentedFixed issues from #10.
Comment #15
quietone commented@hass, it seems to me the php code snippets is outside the scope of this issue. Maybe make a new issue for that?
Comment #16
hass commentedWhy? 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.
Comment #17
phenaproxima@hass, @quietone has been working diligently on this. Please be patient -- or by all means feel free to submit your own patch.
@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?
Comment #18
tim.plunkettSkipProcessException sounds right, since D8 does not support PHP snippets any more.
Comment #19
hass commentedNo, 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.
Comment #20
phenaproxima@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:
Comment #21
quietone commentedTo 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?
Comment #22
phenaproximaTo 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.
For now, don't worry about it. To me, it seems outside the scope of this issue.
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.
Comment #23
quietone commentedEven with suggestions from mikeryan1 and webchick on IRC I can't implement this.
Comment #24
tim.plunkettThis 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.
Comment #25
tim.plunkettWrote a unit test. This only covers the 'pages' part.
Comment #26
quietone commentedAdded 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.
Comment #28
catchI 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?
Comment #29
hass commentedWhy are these PHP snippets not having a closing tag?
Comment #30
tim.plunkett@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.
Comment #31
quietone commentedDid 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 ....
Comment #32
hass commentedComment #34
quietone commentedMaybe this is right for the unit test.
Comment #36
quietone commentedComment #37
quietone commentedSo, 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.
Comment #38
mikeryan#2559571: Handle MigrateException consistently during import is in, unblocking.
Comment #39
quietone commentedRight. How's this?
Comment #40
tim.plunkettWhich } was outdented wrong? Can't tell even when squinting.
End with a .
Block::load
instanceof is all lowercase
Comment #42
quietone commented1-4 Fixed. #1 was caused by an extra space.
And changed the Unit test to test for the correct exception, MigrateException, not MigrateSkipRowException.
Comment #46
quietone commentedComment #47
tim.plunkettI can't speak to the simpletest changes, but everything else looks good for me. Just some nits.
RTBC from my perspective.
Comment #48
phenaproximaSo 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.
Comment #51
phenaproximaI'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.