Closed (duplicate)
Project:
Drupal core
Version:
8.0.x-dev
Component:
configuration system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
29 Aug 2012 at 17:00 UTC
Updated:
29 Jul 2014 at 21:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
katbailey commentedThis patch removes the constructor from StorageInterface so that each implementation can decide for itself what it needs, and in the case of the DatabaseStorage class, it takes a db connection.
I've only tested the patch against the Configuration group of tests and I'm still getting 19 fails that I can't figure out, but before I spend more time on it I wanted to see what the CMI people think of this - I haven't been involved in this initiative at all and could be missing a very good reason why you need to have the constructor in the interface that takes an anonymous array of options (I realise there's the issue of configurability and being able to register the settings as a parameter to the DIC, but presumably each individual setting could be equally configurable as a DIC param).
Comment #3
Crell commentedWhy is the connection optional? If this backend won't work without it, just require it.
Once the connection is a property, we can just access it directly. No need to go through this method every time and spend the stack call.
Isn't that what a delete query does anyway? No need to set a return directive. Really, that's an internal property.
Isn't that what an update query does anyway? No need to set a return directive. Really, that's an internal property.
That said, I am +1 on using proper DI here and eliminating the hard dependency on the Database class.
Comment #4
katbailey commentedAnd
Yes indeed - and that is how I had done things first time around and things exploded much more spectacularly - basically it broke the installer. It all boils down to this comment in the read() method of the DatabaseStorage class:
Basically, this system relies on exceptions being thrown when there is no db in place. So perhaps that @todo should be taken care of in this patch as well.
Comment #5
gddTagging
Comment #6
sunHm. In general, this is different from #1730774: Untangle Cache\DatabaseBackend from procedural database.inc functions to make it available in early bootstrap, because that one is about Cache\DatabaseBackend, while this is touching Config\*Storage
Injecting dependent services explicitly is quite a change.
The problem with this approach is that some storage controllers require (or rather: allow for) additional options to be set.
For example:
- DatabaseStorage: connection/target, table
- FileStorage: directory
- CacheStorage: backend + backend-specific options
- CachedFileStorage: all the CacheStorage options + FileStorage options
The architectural goal really is to keep the config storage controllers as pluggable as possible. Essentially hinting at #1202336: Add a key/value store API to some extent already (a secondary goal is to rebase/wrap the config storage controllers onto the k/v API as soon as it's available).
Comment #7
Crell commentedRe #6, I think this is an issue that is going to hit most plugins, too. It's good practice to not put the constructor in the interface, for exactly this reason; a Database backend only works with a DB connection object and table name, but a Memcache backend wants neither of those but a memcache object instead, while a File backend wants nothing but a path, etc. The dependencies differ. On the other hand, we want to have a common factory point. I'm not entirely sure how to resolve that, but we do need to. (This is another reason why I don't think a universal k/v API is a good idea, but that's technically OT here.)
Making things pluggable (which is good) should not force anonymous array constructors (which are bad).
At bare minimum, though, even if we keep the array constructor we should be passing in an actual connection object, which we can then use internally rather than always calling to Database:: every time. That's the bug we're trying to eliminate here.
Comment #8
katbailey commentedOK then, as a compromise I'll roll a version of the patch that keeps the constructor in the interface with its anonymous options array and passes the db service from the DIC as the connection option for DatabaseStorage. Will try and get that done this evening.
Comment #9
katbailey commentedOn second thoughts, I think we should keep this issue for making the proper change, i.e. removing the constructor and using dependency injection, given the discussion that has already taken place here.
Once I get around to rolling the less ambitious version of the patch, i.e. where we don't change the interface but just pass the db connection as the 'connection' param in the options array, I'll create a separate issue for it.
Comment #10
chx commentedLet me see.
Edit: note that we will not inject a database connection in this patch, that's #1764474: Make Cache interface and backends use the DIC and diamond hard. I will just get rid of the options array.
Comment #11
chx commentedSo here is one just to make the tests pass. I hope they do. As we are about to rip the database storage out, it's not worth fretting over whether this is the correct architecture (it's not) -- this is just enough to rip that horrific config options array out and then in the next patch when database storage is thrown out and cachestorage is introdiuced we can properly inject a filestorage into it.
Comment #13
chx commentedBleh, installer.
Comment #14
chx commentedOh, that still contains the remnants of bumping the database service from corebundle to bootstrap. This is really becoming an absolute small patch.
Comment #15
sunLooks like this patch makes that situation even worse?
Comment #16
chx commentedSure. We can leave DatabaseStorage alone, it's not for long.
Comment #18
chx commentedHere."Import configuration 45 passes, 0 fails, and 0 exceptions"
Comment #19
chx commentedNote that the patch has been enrolled into #1702080: Introduce canonical FileStorage + (regular) cache so if that's accepted this can be closed as duplicate.
Comment #20
sunNot sure who had the idea to remove DatabaseStorage, but that's not on the table.
Marking this issue postponed, as it looks like we're going to perform this change in #1702080: Introduce canonical FileStorage + (regular) cache
Comment #21
mtiftLooks like this is quite a bit out-of-date, that we are already using dependency injection for FileStorage, and that we added the concept of collections in #2262861: Add concept of collections to config storages.
Feel free to re-open if I'm mis-understanding.