Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
This is a followup issue for #1535868: Convert all blocks into plugins.
Currently, Drupal 7 block configurations are not upgraded to the new Block architecture.
Proposed resolution
Per #26
- Modules that implement blocks are responsible for upgrading their own blocks wrt mapping, name changes, etc...
- Add _(block_)update_block_to_config
- Get/Make config entity using config() for the block name.
- Merge in changes like in _update_variables_to_config()?
- Get node type and role visibility settings for block id.
- Set properties necessary for block entities based on property map passed in?
Manual Testing
- See screenshots in comment #49
- Download Drupal 8 development version
- Apply latest patch
- Import Drupal 7.22 database from zip file (#49)
- This is a devel-module generated database, not a test-driven database dump.
- Create a settings file to point to the database with update access turned on.
- Go to update.php and try the upgrade
- Login as user 1 (use Drush 6 to generate a login link) and verify blocks
- Login as an authenticated user and verify blocks.
- Login as an anonymous user and verify blocks.
Remaining tasks
- Re-roll
- Adjust aggregator update per #1888702: Use configuration selection instead of derivatives for some blocks
- Change use of config() to \Drupal::config()
- Manual testing. See #49
API changes
- Adds an update helper function that core and contrib. can use to upgrade blocks.
Updated per comment #76
Comment | File | Size | Author |
---|---|---|---|
#78 | 1871700-block-upgrade-take-two-78.patch | 22.71 KB | mradcliffe |
#78 | interdiff-1.txt | 745 bytes | mradcliffe |
#78 | interdiff-2.txt | 1.08 KB | mradcliffe |
#78 | interdiff-3.txt | 3.3 KB | mradcliffe |
#71 | d7db.tar_.gz | 111.26 KB | benjy |
Comments
Comment #1
xjmActually, we can start work on this as soon as we finish the ConfigEntity conversion. At most I expect we will need to re-save exported block instances with a few additional plugin IDs, I think.
Comment #2
larowlanGiven where the code in #1871772: Convert custom blocks to content entities is going, we'll need to write to field_data_field_body|field_revision_field_body too as block.body moves to a field, plus initialize the {custom_block} and {custom_block_revision} tables
We can follow the 6-7 node body upgrade easily enough for the field stuff.
Comment #3
larowlanor rather field_data_body|field_revision_body
Comment #4
xjmIn #1875260: Make the block title required and allow it to be hidden we're looking to make the block title required. For the upgrade path, we'll need to replace titles that are an empty string or
<none>
with the block description ({block_custom}.info
for custom block instances and I suppose whatever the D8 plugin's default title is for other blocks).Did we keep the same block type IDs for all the core blocks when we converted them?
Comment #5
xjmRelated issue: #1887688: locale_update_8001() references unused block tables
Comment #6
xjmComment #7
webchickHow long are we planning on postponing this? AFAICS, all of the architectural issues are done now, yeah?
Comment #8
larowlanFWIW the custom_blocks (ie data from {block_custom}) are upgraded, this was fixed in #1871772: Convert custom blocks to content entities so that just leaves their configuration (ie data from the {block} table)
Updating issue summary
Comment #9
larowlanI'm with @webchick on this
Now that #1871696: Convert block instances to configuration entities to resolve architectural issues is in, this can be active imo
Comment #10
catchYeah even if it changes again there's no reason it can't be fixed now then updated later.
Comment #11
mradcliffeI was looking into what the upgrade path for blocks would be and stumbled upon this issue. After looking into code, it looks like the basic upgrade path would be to go through each block table row, create an config instance for the block, and then remove the block table at the end. The hard part of this would be to identify any changes from block.delta to the config entity id (as well as serialized data).
Comment #12
xjm@webchick, @catch, I've asked several times for this to be unpostponed, but @EclipseGc and others posit that it will be a huge duplication of effort before displays are done. (I'm not saying I agree it should remain postponed; just that is the response I've gotten when I ask about this issue every week or two.)
Comment #13
mradcliffeHere's an incomplete patch that borks the site after block upgrade test, but I might as well post my approach. There are two issues I ran into:
I am also having trouble finding docs on appropriate instantiation of configuration entities such as blocks. Maybe I'm missing something obvious..?
Comment #14
swentel CreditAttribution: swentel commentedWe don't drop tables in the upgrade path - see #1860986: Drop left-over tables from 8.x
Other than that, I had a quick look how to get this forward, and yes, we need some sort of mapping for the core blocks. Same would apply to contrib, so maybe we should create a helper upgrade function where core (and contrib) can pass on a list of old id's mapping to new id's ? A bit like how we handle the variables now as well.
Comment #15
mradcliffeAh, if the block tables still exist until 9.x, then contrib can take care of itself.
For core blocks, a block/plugin map. Then I'd just go back to creating the block entity with createInstance() instead of manually creating a Config object.
Comment #16
mradcliffeI tried switching back to entity_create(), but still ran into controller class issues so I switched back to config(). I quickly (read: sloppily) made a mapping function, which works mostly, and there are some issues still with system menu, menu, and locale blocks. Currently ignoring poll, profile, locale, language, and blog blocks.
Everything else either fits the consistent pattern or has a mapping, but needs a test (aggregator, etc...).
I modified the block upgrade test to temporarily just look at admin/structure/block and admin/structure/block/list/block_plugin_ui:seven. If anything bad happens it will break there.
Also still need to filter out contrib blocks per my last comment.
I started out making the block mapping function fairly verbose, but cut back. It may just be a good idea to make it a complete map with properties as well as plugin ids.
Needs work patch attached. No interdiff as I forgot to commit locally last time.
Comment #17
podaroktrailing whitespace http://drupal.org/coding-standards#indenting
Comment #18
mradcliffeI had some changes that I haven't posted yet and I am not sure when I'm going to get back to this issue so I'll post a new patch up.
I redid the mapping function so that it will be able to map other block properties instead of just id. Still trying to get menu and system menu blocks to upgrade properly. I think I need to stop relying on the block upgrade test so I can actually inspect config files that are being written and compare those to what they should be.
Comment #19
mradcliffeOkay, all core blocks except locale, profile, poll, and blog have configuration entities "written" with visibility settings although it is messy code.
However I still end up with corrupt block configuration for block instances that are disabled due to label settings. It's almost as if the configuration entity writes differently when it's created manually rather than via the block plugin container (which does not seem to be possible in the upgrade path).
Any ideas from anyone else?
Comment #20
xjmThat's probably exactly the case. Somehow the entity plugin manager is available for Views though (I think?) Maybe it becomes available later?
There's a lot of criticals in this problem space right now:
#1949724: Allow simpletest child sites to additionally load a test-specific settings.php to allow testing anonymous and configless updates
#1848998: Problems with update_module_enable()
#1856972: config() isn't safe to use during minor updates if there's a change to configuration storage
Comment #21
alexpottWell one thing is for sure - we can't use entity_* functions in updates... mad stuff happens!
This patch needs to update the block manifest file with the new entities created too.
Comment #22
alexpottAlso should the block module be upgrading blocks provided by other modules?
Comment #23
xjmThis is an interesting question. Since the data was originally in
{block}
, I think it should?Comment #24
alexpottBut the implementation of hook_block_info is the modules... eg. http://api.drupal.org/api/drupal/modules%21system%21system.module/functi...
Comment #25
mradcliffeThank you for the direction, xjm and alexpott.
Comment #26
mradcliffeOkay, new proposal after thinking about this on the plane.
Comment #27
jaredsmith CreditAttribution: jaredsmith commentedIssue summary should be updated to specify that it should no longer be postponed
Comment #27.0
jaredsmith CreditAttribution: jaredsmith commentedUpdated issue summary.
Comment #28
pameeela CreditAttribution: pameeela commentedUpdated issue summary based on the latest approach proposed in #26. This will need more updates around reviews, steps to test, API changes - but should be OK for now?
@mradcliffe are you happy to continue working on this, in which case I will stop hounding other people to do it? :)
Comment #29
mradcliffe@pameeela, I'm planning on at least working on it before Friday, and then when I am not working as a mentor on Friday in Portland.
Edit: I don't have any additional code at the moment.
Comment #30
mradcliffeOkay, I made some progress on an alternate way of doing this. I added a function to handle creating config entities in update.inc, and then each module will need to implement this. I added user and menu module as a test and to see what's going to fail.
I still need to do some more actual testing, but wanted to post a WIP patch for some review on this new approach.
Questions:
Comment #32
mradcliffeOkay, here's an added test and fixing the label issue. I think this is going to work.
Need to hammer out the rest of core.
Comment #34
pameeela CreditAttribution: pameeela commented@mradcliffe looks like you are getting close. Can you or anyone else across this issue post some steps to test for when we get to green?
Comment #35
mradcliffe@pameela. I think if we want full test coverage, then the upgrade database needs to be filled with content for all blocks, and then tests each block for specific content/configuration. I think the most important assert would be if the block is not corrupt (i.e. the code created config entities incorrectly via config()).
I have added book, comment, forum, node, search, system, and shortcut block upgrade paths in this next patch. I haven't had a chance to look at the one failure yet.
Note: the interdiff has two commits in it (didn't post patch #3).
Edit
Comment #36
geerlingguy CreditAttribution: geerlingguy commentedComment #39
mradcliffeOops. That patch was terrible. this won't solve the 1 fail, but that's next.
Comment #40
mradcliffeSure let's go for a test.
Comment #41
mradcliffeOkay, this patch will fix some bad plugin ids that I had in the previous patches in the new approach. Again, I haven't looked at the one failing test yet to do with block title length. I am not sure what changed that would cause this.
Todo:
Also screenshots added:
Comment #42
mradcliffeI am not saving the label correctly, which should account for the test failure.
Comment #43
oadaeh CreditAttribution: oadaeh commentedI was confused by the title and thought that it meant that blocks had not yet been upgraded in D8. Hopefully the new title still says what is intended while removing the confusion.
Comment #44
mradcliffeIgnore comment #42. The test fail comes from switching to standard_all instead of minimal. The test assumes that sidebar region will be available on admin pages, but that's not true for the standard_all database.
- Switched back to minimal database for now.
- Improved docs a bit (not complete) including fixing a typo in node.install.
Comment #46
mradcliffeThis patch is mainly cleanup with a fix for the exceptions in the last test run and incrementing the node update number.
Comment #48
mradcliffeOh, heh, block_navigation != book_navigation. I also fixed not using array union correctly.
Let's give this patch a whirl while the queue is low.
Comment #48.0
mradcliffeUpdated issue summary
Comment #49
mradcliffeNew patch:
Manual testing.
Comment #50
mradcliffeComment #50.0
mradcliffeRemoving myself from the author field so I can unfollow. --xjm
Comment #50.1
Gaelan CreditAttribution: Gaelan commentedUpdated issue summary.
Comment #51
mradcliffeRe-roll and remove the node/comment settings additions per #50.
Comment #51.0
mradcliffeWhoops. I failed. This should be better.
Comment #51.1
mradcliffeRemove completed task.
Comment #52
mradcliffeRe-roll, patch no longer applies and changed update numbers for node, system, and user.
Comment #53
Gábor HojtsyComment #54
mradcliffe#52: 1871700-block-upgrade-take-two-12.patch queued for re-testing.
Comment #56
mradcliffeAh, that's not my fault. There's a regression in core and that default local task no longer works. If the previous patch was in core already than tests would have caught the regression. :*(
Here's a patch that uses the working menu route for the block form controller.
Filed related issue #2052019: Fix block configuration default local task to use block_admin_edit route.
Comment #58
mradcliffeThat test is not failing locally for me so rebase and re-roll.
Comment #59
jibranAwesome work @mradcliffe. I have found some minor doc issues.
Typehint missing.
Can we make these multi lines?
Comment #60
mradcliffeThank you for the review, jibran.
Comment #61
benjy CreditAttribution: benjy commentedI tested this using the database dump provided and the latest codebase and I get the following error when hitting update.php. Can anyone comment on what I might have done wrong, or replicate the same error?
Comment #62
mradcliffeHi benjy,
Do you have a drupal 7 settings.php? You need to make that writable and place it in sites/default. I think most likely Drupal "detected" that 8 was installed and tried to bootstrap Drupal 8. You can see this if you find a Drupal 8 config_* directory or Drupal 8 tables created in the database (ugh). I found that I needed to go directly to core/update.php instead of being redirected from /update.php to core/update.php.
Unrelated to the above...
I was able to run the update with and without the patch on the database dump from a while ago, but I was left with a broken / bugged installation. Next step is to re-do the manual database dump.
Comment #62.0
mradcliffeAdded manual testing steps to issue summary.
Comment #63
benjy CreditAttribution: benjy commentedOK I can confirm I got this patch to work my main problem been that I was using a D8 settings file I think.
It was a little flakey though, like afterwards I was getting quite a lot of random errors around the place. I'm going to try upgrade a an out the box D7 site populated with devel content and a live site sometime this week and i'll post back with some more steps and results.
Comment #64
webchickRe-adding eaten tags.
Thanks SO much for working on this, folks!!
Comment #65
benjy CreditAttribution: benjy commentedanyone know what causes tags to sometimes get destroyed? It's a bit annoying!
Comment #66
webchickI blame gremlins.
Comment #67
klonos:D
Comment #68
mradcliffeThe database dump provided is blocked on #2049465: Upgrade of image styles and effects broken.
Comment #69
benjy CreditAttribution: benjy commentedOK I did some more testing and the results are below. I've also attached a new patch which increments the hook_update() number.
Troubleshooting
Issues
1. My custom blocks were no longer "Placed" in their regions.
2. After the update I ran drush uli and got this error when submitting the user/edit page with my a new password.
Comment #70
benjy CreditAttribution: benjy commentedUpdate for the bot
Comment #71
benjy CreditAttribution: benjy commentedDB dump attached, mentioned in #69
Comment #72
webchickTagging all critical D8 upgrade path issues as "beta blocker."
Comment #73
Wim LeersAFAICT this is because there is no test coverage for the upgrade path of custom blocks from D7 to D8. Neither #1871772: Convert custom blocks to content entities nor #1919910: Refactor custom_block upgrade path to create tables using hook_schema_0() instead of in block_update_N() added that.
Comment #74
jibranIs it NW or NR because of #73?
Comment #75
catchThis is going to need a re-roll due to #1888702: Use configuration selection instead of derivatives for some blocks which I'm about to commit.
Comment #76
BerdirTo clarify, that issue removes derivates for aggregator feeds and categories and instead puts the item count into the block instance configuration, where it already kinda is.
I haven't check what this issue is doing, but it simply needs to create a block instance for each (enabled, not sure if you care about others here?) aggregator block and put the feed/category id into the configuration. Then drop the block column.
Comment #76.0
BerdirRemove use of deprecated function.
Comment #77
mradcliffeYes, this is going to need work. Also adjusted status per remaining tasks section.
Comment #78
mradcliffeHopefully this gets things up to speed for any Prague core sprinters.
Comment #80
benjy CreditAttribution: benjy commentedThis issue is no longer relevant now we're brining migrate into core. I'll post back with the new issue when it's created.
There is a group for the migrate efforts here: https://groups.drupal.org/imp
Comment #81
mradcliffeI wanted to mention it for those at Badcamp tackling this issue, but the patch can still come in handy so you don't have to duplicate a lot of work.
Comment #82
David_Rothstein CreditAttribution: David_Rothstein commentedYeah, I don't think an issue should be closed when the code in it will still need to be added in some form or another.
Maybe at most this could be marked "postponed"?
Comment #83
mradcliffeIt depends on if the Migrate work should be split into a separate issue or not. I could not find any information on an existing tag for the Imp Initiative so I went ahead and added one as "Imp Initiative".
Comment #84
catchI'd commit this patch assuming it works + passes tests so there's a reference point to work from in core, however I don't want to encourage anyone to work on it when it's likely that a good chunk of the code will have to be done again for migrate. Assuming that doesn't happen 'postponed' feels like the right status - a lot of the code can likely be re-used or at worst shows what data needs to go to/from where.
Comment #84.0
catchUpdated issue summary per latest comments.
Comment #85
catchNo longer blocks release. But we need a way to track issues that block releasing a migration path at some point.
Comment #86
klonos...parent/related issues now have their own place as issue metadata. Also hiding past patches and interdiffs.
Comment #87
moshe weitzman CreditAttribution: moshe weitzman commentedWe have an IMP issue for #2120629: Write a source plugin + tests for 6.x Blocks. Metadata also needs migrating (enabled/disabled, region, etc.). That one is now #2149179: Write a source plugin + tests for 6.x Block Metadata (status, region, visibility, ...) and has Related Issue and Summary links back to this one.
Marking this as a duplicate.