A common task in upgrading from Drupal 7 to 8 will be to move variables into the configuration management system. The patch creates a generalised function to do this by readings the keys from the config xml file. It assumes that the new config keys have the same name as the old variables.
Comments
Comment #1
acrollet commentedThis code passed review by heyrocker in another issue, so I think it's ok to set rtbc (pending test results).
Comment #2
pcambraI think it's a great function, I've changed it a little so if there are no var values, the deletion doesn't happen
Comment #3
marcingy commentedOne issue with this is that in certain cases we are amending the name of the variable I think we need some way to rename the variable and if if only a one name is supplied then the it should be used in both the from to operation.
Comment #4
marcingy commentedah misread but we still have issue in that the code assumes that we are not renaming anything. I am thinking we really need tests for this function - so taging as such
Comment #5
gddI think for situations where the variables are getting renamed, then you just need to write a manual update function. This is a helper for the simple (and most common) use case.
However I agree it needs tests.
Comment #6
acrollet commentedClarifying issue status.
Comment #7
marcingy commentedNew version with the ability to map fields.
Comment #9
pcambraLittle coding fix, submitting again to the testbot.
Comment #10
alexpottUpdated patch with tests and better documentation.
Comment #11
alexpottImproved documentation.
Comment #13
alexpottAdd in missing config xml file
Comment #15
alexpottFixed patch
Comment #16
lars toomre commentedDrupal's coding standards require the first line of docblock to start with an active verb, be a single line and have no more than 80 characters in total. The current text could be kept as an explanation with a blank line in between.
Comment #17
alexpottFix function documentation as outlined in #16 and remove variable_set from test so that when this function is removed from drupal 8 the test will continue to function.
Comment #18
lars toomre commentedThanks Alex this is looking good. Two thoughts while reviewing this patch:
1) Both @param directives in docblock could use type hinting.
2) The intent in time is to have the variables table go away. Won't this function then fail and as a consequence cause a site upgrade to fail? This function needs to remain around for quite sometime to help straggling sites upgrade to D8 or even D9.
To prevent such a failure possibility, I think we should check if the table exists before starting the db_select(). We might also want to add a test to make sure that this function runs correctly after dropping the variables table. With that, I think this can remain forever to help D7 upgrades to new content management subsystem.
Comment #19
alexpott1) Not sure that type hinting is in the standards - see http://drupal.org/node/1354 but I've improved the comments anyway.
2) Good point - implemented so that the test drops the table if it exists and always creates it. This way once Drupal 8 no longer has the variable table this test will continue to work... don't think extra tests needed.
Comment #20
gddDrupal 8 will always have the variable table, we need to keep it around so that contrib modules have an upgrade path. It won't go away until Drupal 9. So the extra functionality introduced in #19 won't be necessary. If we can revert that but keep the new comments then I think we are good to go here.
Comment #21
lars toomre commentedAh thanks for the update @heyrocker. I thought the intent was for variables table to go away for D8.
@alexpott - My understanding is that @param type hinting is being introduced with D8 as a nice to have, but not yet required. Your expanded comments there look great.
Comment #22
marcingy commentedPatch removing the extra test that was added above.
Comment #23
Anonymous (not verified) commentedthis doesn't look right to me. we should catch this exception, and log it so the site admin knows what blew up.
other than that though, this looks ready to go.
Comment #24
alexpottAdded try around config set and variable delete to catch and log errors to watchdog.
Comment #25
gddFixing tag
Comment #26
gddShip it. Thanks everyone.
Comment #27
gddcatch pointed out that this really shouldn't live in the config module's main config directory, It's going to get installed with all the real config and clutter up things. A better option would be to make a module just for testing in core/modules/simpletests. There are several there already.
Also while talking to catch in IRC, I noticed incorrect comment this which I assume is a copy/paste error from another test.
Powered by Dreditor.
Comment #28
alexpottHere's a new patch that fixes the cut & paste comment error and moves the config.xml into simpletest/tests/config_upgrade. I created the config_upgrade directory so the test config is not installed with any other test module in the simpletest/tests directory.
Comment #29
gddAwesome, going back to RTBC. Thanks for your patience on this.
Comment #30
marcingy commentedI think we might still be lacking something in that the new configuration files are not loaded in the active store for modules already enabled (this would brought up in chat with Zlender today) a call to config_install_default_config only exists when performing the initial install and when modules are being enabled which will not be the case when an update happens.
I am thinking in update_variables_to_config we need to check if $config = config($config_name); returns a valid config object and if it doesn't we then config_install_default_config and again check if config can be retrieved. I may of course be missing something.
Comment #31
gddFor modules already enabled, they will have to manage this themselves in their upgrade path. I don't want to add a call to config_install_default_config() in this function, as it feels like we would be making too many assumptions and doing too much in this function. I think it should be up to the modules themselves to deal with that part as they wish, and then just call this function for the conversion.
Comment #32
marcingy commentedOk so in effect all core modules are going to have to load config as part of the upgrade process which seems like a lot of duplication one way round that could be
That way the caller has control over the upgrade process.
Comment #33
Rok Žlender commentedSo for instance for core system module config update hook would look something like
or if we leave it up to modules
I prefer the 2nd option though
Comment #34
marcingy commentedSeeing the 2 options laid out above I agree the 2nd option looks cleaner, so no issues with what we have here at the moment from me as that was the only concern which later dawn on me.
Comment #35
catchLooks good now. Committed/pushed to 8.x.
This will need a change notice explaining how to use the new function.
Comment #36
aspilicious commentedAnd this will need a followup afterwards to remove those trailing whitespaces...
Comment #37
alexpottAdded change notice: http://drupal.org/node/1511542
Patch attached fixes whitespace issues and improves code code comments as http://api.drupal.org/api/drupal/core%21includes%21update.inc/function/u... doesn't look so good.
Comment #38
lars toomre commentedStill no type hinting ...
Comment #39
pcambraWith type hinting for the array.
Comment #40
aspilicious commentedRTBC for the doc changes and the change notice is probbaly OK to.
Comment #41
catchChange notice looks fine, and I've committed the follow-up. Marking fixed, thanks all!
Comment #42
Tor Arne Thune commented