Closed (won't fix)
Project:
Drupal core
Version:
8.0.x-dev
Component:
configuration entity system
Priority:
Normal
Category:
Feature request
Assigned:
Issue tags:
Reporter:
Created:
31 Jan 2011 at 23:59 UTC
Updated:
29 Feb 2016 at 12:52 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
timhilliard commentedHi Dave, I think this is a really great idea. I am willing to write this piece of code however I'm wondering how this works as there is currently no 8.x-dev branch as far as I can see. Does this need to happen before we can start writing in new features?
Comment #2
timhilliard commentedHeres my attempt at variable_rename. I created a diff against HEAD of d7 so not sure how this gets rolled later on.
Cheers,
Tim
Comment #3
dave reidShould be @see variable_rename()
Bikeshedding, but for consistency let's name the parameters $name and $new_name.
I'm not sure yet about checking if (isset($conf[...])). We don't do this with variable_del() so I'm not sure why we'd want to add this here. Ahh I realize now since this would throw a warning on $conf[$new_name] = $conf[$current_name]. Hrm.
Powered by Dreditor.
Comment #4
timhilliard commentedYou're correct it does throw a warning but I think it's also good that it doesn't set the variable in $conf if it doesn't exist already. It also means the query doesn't needlessly need to run.
The reason it was variable_update in the comments was because thats what I originally called the function before I realised that it was the wrong name and changed it, I just forgot to update the comments as well.
I have now re-rolled patch with recommended changes.
Cheers,
Tim
Comment #5
catchPlease put this in common.inc rather than bootstrap.inc
Comment #6
timhilliard commentedRe-rolled per catch's direction. I assume this is so the function doesn't get loaded on bootstrap as it will only be needed at a later stage of loading?
Comment #7
dave reidRe-rolled patch with Git and updaed docs.
Comment #8
dave reidUsing format-patch.
Comment #9
timhilliard commentedLooks great Dave.
Comment #10
catchThis will break in the case a variable is set in settings.php but not in the database. It should probably do select, delete, insert instead of update. If a variable is renamed but was set in settings.php I'm not sure what the behaviour should be, maybe check conf as well as the return from the direct query. To be honest I'm not convinced of the usefulness of this, how often does variable renaming happen? Additionally the convention is now not to use api functions in update hooks, so adding an api function that will rarely be used outside of those goes against this.
Comment #11
dave reidDoesn't variable_set(), variable_del() etc also break in that way?
I cannot count the number of times I've renamed variables in my modules, so yes. Most of its usefulness is to contrib authors. And I found about 5 update hooks in D7 core that could have used this.
Comment #12
dave reidComment #13
catchThose two functions do not try to update a row that doesn't exist.
Comment #14
dave reidIf I have a $conf['my_variable'] in my settings.php, I cannot use variable_del() with it - it breaks and calls db_delete() on a row that does not exist.
Comment #15
catch$foo = variable_get('foo'); variable_set('bar', $foo); works though, the equivalent situation is broken in this patch.
Comment #16
catchAlso in your example deleting the variable won't remove it from $conf, but it does successfully delete it from the database, so the only cruft is a hopefully unused variable in settings.php. If the variable isn't in the db variable_del() doesn't care whether it's in conf or not in practice.
Comment #17
catchOK I'm back on computer now, shouldn't review patches from iphone....
The issue is that the current pattern for renaming a variable works:
That example works for both variables that are set in $conf, and variables that aren't.
The current patch would fail to set the old value to the new variable name, if the variable was only set in $conf.
Update hooks in D7 core should not be using API functions, arguably this includes variable_get()/variable_set()/variable_del() - so if they are we need to consider adding _update_variable_get_7000() equivalents to be consistent with the examples elsewhere.
Comment #18
timhilliard commentedCatch, when I created the function I used the exact pattern above as my guide and expanded the functions out and then re-factored it, so I believe that any problem that there is with the new function also exists with the pattern listed above.
I question whether you would want this function to rename a variable that is only set in $conf as that variable would be persistent even after attempting the rename. The only thing this function or pattern would do is unset the variable from $conf until the page was reloaded again.
As far as using API functions in update hooks that's not an argument that I'm going to weight into except only to say that I see variable_get()/variable_set()/variable_del() in update hooks all the time.
Comment #19
dawehner.
Comment #20
berdirI think we can close this. An 8.x solution would be completely different and I doubt this would be added to 7.x.