Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
file system
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
28 Sep 2012 at 04:04 UTC
Updated:
29 Jul 2014 at 21:13 UTC
Jump to comment: Most recent file
The file usage system currently has to use mysql storage if we convert it to a plugin we can remove another table dependency on an optional basis.
| Comment | File | Size | Author |
|---|---|---|---|
| #38 | 1797478_38.patch | 29.28 KB | chx |
| #32 | 1797478-32.patch | 29.22 KB | marcingy |
| #31 | 1797478-31.patch | 29.23 KB | marcingy |
| #30 | 1797478-30.patch | 29.18 KB | marcingy |
| #30 | interdiff.txt | 6.75 KB | marcingy |
Comments
Comment #1
marcingy commentedComment #2
chx commentedYes. Reviewing the API it is not a normal CRUD that can be converted to an Entity. It's not fieldable, translateable, adding fields sounds like madness, we do not want to get or set invidual properties, it's definitely not one.
Comment #3
quicksketchI agree that a plugin seems like the sanest route here. File usages are not entities as they have no individual properties, they're just a mapping between an entity and the file (which is also an entity, though not fieldable yet). The retrieval mechanisms in the file usage table typically simple.
Comment #4
marcingy commentedFirst stab at the conversion
Comment #5
marcingy commentedReroll get rid of variable_get and convert the class to config. Also fix typo that meant we instanciating the class multiple times.
Comment #6
chx commentedI think we should just register the service into DIC in CoreBundle and then use drupal_container()->get('file.usage') much like config() does. No need for a static or another way to plug things. Altering the DIC should be possible no matter what.
Comment #7
marcingy commentedMakes sense now I have finally got my head around how to alter classes registered in the DIC. Setting back to needs works while I deal with change.
Comment #8
chx commentedPerhaps add that here so if someone does a git blame they find it here. I know how to change the bootstrap DIC but not the proper one. I only mentioned it vaguely that it should be possible; if it already is then it's great.
Comment #9
marcingy commentedNew version using DIC and adds a tests to show default class can be overriden.
Comment #10
chx commentedThanks that's even so much better! And a DIC change demo, I love it.
Comment #11
lars toomre commentedAbout the naming of the class you might want to note #1798420: Document and consider renaming AbstractStorage and what @tim.plunkett wrote about no other classes starting ith Abstract. Other than that, this implemention is personally quite educational for me.
Comment #13
marcingy commentedRemove abstract from class name for consistency.
Comment #14
Crell commentedchx asked me to have a look here for Container pedantry...
Since this object is in the DIC, it should take the Database connection as a dependency in its constructor. Then db_merge() gets replaced with $this->connection->merge(), (and the same for the other db_* functions).
To do so, modify the register call to chain the following after the register method:
->addArgument(new Reference('database'));
And then add a constructor that takes a single parameter, a DB connection, and assign it to $this->connection. (Or $this->dbConnection, or whatever. The name doesn't matter except as a convention.)
All methods should define their public/protected state explicitly.
Method names should always be lowerCamel case. That is, listUsage().
Edit: The reason to make the DB connection injected is that it's probably possible to then convert the tests from WebTest to UnitTest (unless there's other file system dependencies I'm not recognizing), which should improve their accuracy and performance about 10000%. :-)
Comment #15
marcingy commentedMethod name converted, and database connection injected via the DIC. I am unclear what
* All methods should define their public/protected state explicitly
means as from a quick look through code I can find doing exactly what I am doing eg
public function listAll($prefix = '') { in DatabaseStorage.php
Patch with the all the other changes attached.
Comment #16
marcingy commentedComment #17
marcingy commentedSpoke to chx in irc he cleared up what needs to happen :)
New version with public for functions.
Comment #18
chx commentedCrell's concerns are addressed. interdiff between #13 and #17 is attached.
Comment #19
Crell commentedOops, left in the router docblock parameters. :-) I'd actually fix this by specifying the table name, too, and using that as a protected property like $connection, so that the docblock is accurate, rather than removing the @param. (Although the @param needs to be updated with what the actual default value is, since I assume it's not 'router'.)
Other than that, this looks done to me.
Comment #20
chx commentedThis not a plugin (and I doubt it needs to be one).
Comment #21
marcingy commentedFixes up _construct doxygen and allows for table to be passed in.
Comment #23
marcingy commentedRe-roll to keep up with head.
Comment #24
chx commentedOK, Crell's latest concerns are addressed :)
Comment #25
lars toomre commentedI see that this has already been RTBC'd. Thus, I am not going to change the status.
However, I would like to plead going forward that we add type hinting to all @param and @return directives in docblocks, particularly in any interface files that added or modified. It really helps make the docs API website much clearer when someone down the road goes to use this spiffy new feature.
Comment #26
lars toomre commentedI noticed that the patch in #23 needed a couple of other documentation fixes. Attached is an untested patch and interdiff that rewraps a couple of doc lines, adds a couple of default values to docs and makes a stab at adding type hinting to @param and @return directives.
I would appreciate a review to make sure the type hinting is correct.
Comment #27
Crell commentedThe "as" part here is redundant. I won't block the patch on it but just an FYI.
We're back to light green. Let's make it dark green, k? :-)
Comment #28
catchWhy are the classes added to
Corewhen the managed file API is owned entirely by file module now?Comment #29
chx commentedSounds like another round :/
Comment #30
marcingy commentedMove class and remove unneeded as File.
Comment #31
marcingy commentedComment #32
marcingy commentedMeh
Comment #33
chx commentedThat seems to address the sole concern anyone had with the patch.
Comment #34
chx commentedThat seems to address the sole concern anyone had with the patch.
Comment #35
dave reidThe only concern I see is registering the class name 'FileBundle' when bundle is an entity term, but it shouldn't hold this up. I just found it odd. Overall this looks good and makes a lot of sense.
Comment #36
Crell commentedFileBundle is a bundle class in the Symfony sense, vis, thing that registers services. Entity "bundles" are getting renamed to subtypes to avoid confusion: #1380720: Rename entity "bundle" to "subtype" in the UI text and help
Comment #37
webchickThis looks like sane clean-up to me, and looks like catch's feedback has been addressed. Also has sign-off from at least one of the people who deal with files a bunch in contrib.
However! It no longer applies. :( Can we get a quick re-roll?
Comment #38
chx commentedComment #39
chx commentedActually it's the same patch that was RTBC before, it applied with fuzz.
Comment #40
webchickCommitted and pushed to 8.x. Thanks!
We'll need a change notice for this.
Comment #41
chx commentedhttp://drupal.org/node/1812240