settings.php can't be written by the webserver as it would be insecure. Yet, we want certain pieces of configuration to be accessible before the database and it'd be so nice if this could be done from the UI. So this patch introduces a JSON-encoded settings file that can be written by the webserver and so it's treated as if the user would be able to tamper it and so there is a HMAC to ensure it's secure. That's the settings part. Could use serialize (the main reason to use JSON was security but the HMAC makes sure it's not tampered anyways) but this opens the door to a human readable (and writeable!) settings file down the road. You can't do that with serialize, no. Could go into its own patch but it'd be pointless IMO without something that uses it.
Based on that, I introduce a stupid simple plugins system which is approximately a copy-paste of _cache_get_object just it uses settings_get instead of variable_get and cache is not hardwired. Queue uses it too as a demo (need to add reliable queues back). There are a few more queue calls to be converted, too.
The settings system is also pluggable, of course :) but this one can only be overwritten in settings.php. Chicken-egg problem, see. One could use SQLite or whatever people dream up.
I know others want more sophisticated plugins. Sure. This is a 15 LoC plugin system.
| Comment | File | Size | Author |
|---|---|---|---|
| plugin_settings.patch | 14.23 KB | chx |
Comments
Comment #1
chx commentedA code comment hints at the next step in functionality (aside from tests and doxygen of course): variable_get() uses plugin_get() -- it'd be a trivial thing to make variable storage pluggable at this point.
My ultimate goal is that every subsystem that queries a (configuration) table with a SQL string for speed reasons should be moved to a plugin. Then we can write mock plugins to speed up testing -- these mock plugins could persist data in a PHP array and we can add a DBTNG driver that also works with just that. Testing sites are small and this way we would not need to create a separate database. Massive, massive speedup in testing. The other reason is to make NoSQL integration better.
Comment #4
chx commentedNote that we could change variable_set to get a .. 'domain' argument which can be 'before bootstrap', 'after db', 'on demand' -- and the on demand parts are loaded only when there is an explicit get -- stuff like user mail are excellent 'on demand' candidates -- rarely needed and large.
Comment #5
catchI like the approach here - we get an editable/versionable file, it will be writeable from the UI for people who don't want to hand edit it, it has the potential to be more performant than the current system although we need to verify how that will look in practice.
@chx's #4, I already have a patch at #987768: [PP-1] Optimize variable caching which means that rarely used variables will not be loaded for the vast majority of requests, and which tries to lessen some of the impact of variable_set(). The scope of that patch is very limited because it's primarily intended as something that can be potentially backported to D7 and D6 Pressflow, but it comes out of seeing many, many problems from the current system on real sites both in terms of memory usage and contention on the variables themselves.
There are a few cases (which to a large extent are a mis-use of the variable system but we don't have anything better right now) where this is a real issue - both rarely used variables like user settings, and frequently updated variables like cache clears, css/js aggregates, or whichever contrib module this week decided calling variable_set() on every request was a good idea. Replacing the system needs to either deal with those issues, or happen alongside other initiatives to clear those up.
Comment #6
chx commentedTalked to Damien and the plan is to convert all variable_get calls in core to either settings_get (the new system) or variable_get which will be another new system, a proper key-value API with an interface resembling memcached (variable_inc, anyone?). For now, I will keep the patch small.
Comment #7
David_Rothstein commentedSubscribe.
Comment #8
dave reid.
Comment #9
sunComment #10
Anonymous (not verified) commentedi'm unconvinced so far. the only value add i can see is "write pre-database settings from the UI".
i like the idea of a standardised plugin loading system, but this patch seems to aim for more than that.
how about two patches, one that focuses on a standard plugin loading system, and one that allows for variable_get/set (or whatever else we change it to) to be pluggable?
EDIT: change "write settings" to "write pre-database settings"
Comment #11
Crell commentedI've not gone over this patch with a fully fine toothed comb, so these comments are preliminary and in no particular order.
- The plugin system here looks like very early versions of the handlers stuff I was working on, before it got renamed Butler. :-) I am tentatively in favor, with two concerns:
1) This only maps to class names directly using an array, which makes it out of reach for most pluggable use cases. It would only be useful for very low-level things, and only by people who edit PHP config files.
2) I am unclear how we'd extend this system to handle the 50 other things we want a unified plugin system to do. Mostly I don't see how configuration and context information could be injected, and without a clear path forward I'm worried about us coding into a dead-end. (That said, it is a step up from where Queue is right now.)
- I am overall very much in favor of configuration data moving predominantly to a human-editable file. My concern is that doing so in a way that is both secure and not a huge PITA for users to edit (due to file permission issues) is really really hard, and we'd have to solve that first to make it worthwhile. I don't know if what's listed here would solve that; I don't see how, but it is after midnight.
- I do not like that it looks like there's still a dependency between variable_X() and setting_X(). It seems like we'd want to make them fully independent and then gradually eliminate usage of variable_X() in favor of setting_X(), and then drop the old variable system entirely. Adding more inter-related systems solves nothing. Unless I'm completely missing the goal here, but it seems like a "variable system TNG" patch, which I support in the general sense. (See previous note about it being after midnight.) Edit: Looks like Damien was suggesting the same thing from chx's comments in #6.
- As chx and I have discussed before, I am fully in agreement with the goal of "all queries happen in pluggable classes" for largely the same reasons he mentions, but also for general code cleanliness as it helps us to separate business logic code from data management code, which should be separate things. I don't know if in practice we'd be able to achieve that goal, but I believe we should strive for it.
- We would definitely need to examine the performance implications here. If it's break-even or better, that is good enough for me.
It's now too late for me to think more about it. :-) For now, +0.7 subscribe.
Comment #12
catchchx is going to add a UI for this. The idea is you can either change settings from the UI and have them written to, or hand edit.
While it's good to separate data and business logic, most systems I've seen that swap in different data storage often want to change business logic as well to take advantage - for example memcache has major changes from the database cache.inc since it needs to account for very different feature sets. I think that's something which may have to happen within the pluggable subsystems themselves via convention, not necessarily at the level of what's pluggable. But there might be some in-between areas too.
Comment #13
chx commentedMe? UI? that's a possibility down the road. As for complexity -- the drop always moves. We can add more as we go and need. We can't code ourselves into a dead end.
Comment #14
gddSubscribey-scribe
Comment #15
Crell commented"The drop is always moving" doesn't mean that going down a too-limited path doesn't make life difficult later, especially given core's haphazard at best development schedule. That's no excuse for not planning ahead. That is a meta-discussion, though. :-)
catch: Like most concepts, business/data separation is a great theory that frequently has gray areas in practice. That doesn't mean we shouldn't still try to push in that direction as much as possible anyway; the benefits of doing so are well understood.
Comment #16
jhedstromsub
Comment #17
jcnventurasubmariniscribing
Comment #18
fgmFWIW, this is the issue discussed during the "configuration" core conversation at DC Chicago (IOW, "subscribing")
Comment #19
pwolanin commentedFrom core conversation, sounds like we need perhaps a way to figure out how to find cache/DB settings early in bootstrap, and maybe a larger file containing all the user settings.
Comment #20
pillarsdotnet commentedComment #21
eclipsegc commentedAfter reading through both the patch and this issue, I have a few points I'd like to make.
1.) The "plugin" system here seems rather limited in it's exposure to the community at large. Essentially this is insufficient for the "plugin" system we need, so naming as the plugin system lends it a sense of finality that I think is false, and misleading. We need to be considering what the proper abstraction for a plugin utility is going to look like and start there. There are dozens of other places in core where plugin tools have been proposed and would be useful, so it seems problematic to eat the namespace without actually solving the problem.
2.) Some of your solutions here are very similar to rather larger scope solutions David Strauss had discussed at Drupalcon. He had discussed a whole hog replacement for the existing variable system, and I think it's relevant to this discussion.
Bottom line: Looks compelling, we should probably focus on plugins in core early in the cycle so that we don't have half a dozen independent plugin utilities floating around when we get ready to release.
Eclipse
Comment #22
dixon_sub
Comment #23
sdboyer commentedAmen. We have some really quite concrete plans, per our last discussion on sprint day at dcchi, for "early-stage" stuff that would look like this. I would rather wait for those than put this system in then have to rip it out later, along with whatever other systems have come to rely on it.
Comment #24
mlncn commentedLooking for the concrete plans to become code quickly :-)
Comment #26
aaron commentedsubscribe
Comment #27
podaroksubscribe
Comment #28
chx commentedI do not know what to do or say. I am sitting here and staring at http://drupalcode.org/sandbox/Crell/1260830.git/blob/f98590d80d40122d8e3... . This not even yet plugins, mind you just stacking and locking.
Adding context plugins to the system outlined in this issue is, of course, trivial. Any kind of plugins, mind you. The settings storage is solved by CMI.
Crell is the initative owner, he is surrounded by like minded people, basically whatever comes out of that corner will be in Drupal 8 and I have no idea how to communicate through that I feel it's terribly overengineered and incomprehensible in such a way that people will actually stop and think. Mind you, I still didnt get a call chain in the HttpFoundation issue either.
Comment #29
chx commentedOnly care about the plugin_get from the original patch. The rest is going away in favor of CMI.
Comment #30
bojanz commentedMarking as duplicate of #1497366: Introduce Plugin System to Core.