Upload.module uses the following syntax for system variables that indicate whether or not attachments are enabled for a certain node type: 'upload_' . $node->type. 'upload_' is also the prefix for the module's own settings, like the maximum resolution; this variable is 'upload_max_resolution'. This might conflict with a node type that's called 'max_resolution'. It is unlikely that this will happen, but nevertheless a minor bug that's easily fixed by changing the 'upload_' . $node->type syntax to 'upload_type_' . $node->type.
| Comment | File | Size | Author |
|---|---|---|---|
| #22 | upload_270302.patch | 8.84 KB | drewish |
| #17 | upload_variable_conflict_00.patch | 9.58 KB | xano |
| #13 | 270302_13_upload_type_namespace_conflict_D7.patch | 9.28 KB | xano |
| #11 | 270302_11_upload_type_namespace_conflict_D7.patch | 9.22 KB | xano |
| #8 | 270302_8_upload_type_namespace_conflict_D7.patch | 7.8 KB | mr.baileys |
Comments
Comment #1
ztyx commentedThere is no patch here. Did you forget to attach one?
Comment #2
xanoI think I did. Moving to 7.x.
Comment #3
mr.baileysSetting priority to normal as the risk of name collisions is real. Patch for D7 attached.
I also included an additional test in upload.test to verify that no 'File Attachments'-fieldset is included on node/x/add when attachments are disabled for type x.
Updated the documentation in
system.api.phptoo, since it used$form['workflow']['upload_' . $form['type']['#value']]as example inhook_form_alter.Refactored the user creation in upload.test: there were at least 4 different locations where admin/web users were created. By creating these users during setup, we don't have to keep creating them (saving time, improving test performance).
Comment #4
damien tournoud commentedWe need a small update function to migrate old variables to their new names.
Comment #5
mr.baileysI knew I missed something, thanks for pointing this out...
Attached is a patch that takes care of renaming the existing variables on update.
Comment #6
mr.baileys...and back to CNR.
Comment #8
mr.baileysadmin test user was missing "Administer content types"-permission.
Comment #9
xanoComment #10
mr.baileysargh. Thanks :)
Comment #11
xanoNew patch. This migration path is now sturdier. CONCAT() is not available for all SQL servers Drupal supports. Also, I changed the variable name to
'upload_node_type_' . $node_type, which makes more sense and is more future proof (what if we decide to make attachments available to other content than nodes?).Next time, please don't add extra tests and stuff in patches that have nothing to do with them. It only annoys other people because you make those patches harder to read.
Comment #13
xanoComment #14
mr.baileysI thought Drupal handled this through database wrapper functions. I had verified this against MySQL (concat supported natively) and sqlite (supported through a registered function, sqlFunctionConcat). Not sure about Postgres though, so you are probably right.
One thing that the changed update path no longer does is clean up the old variables. Shouldn't these be removed after copying the value to the new variables?
At the time of writing this patch, I felt the extra tests and stuff were relevant and related to this change. In hindsight (and having been exposed to the Drupal way of doing things a bit longer) I can see how I got carried away and went too far with the changes to the tests. I'm truly sorry if this annoyed you or anyone else, that was not my intention. Please feel free to remove the test changes from your patch, and I'll submit another issue to get the commited.
As for the documentation change to system.api.php, I feel this one is relevant, since if we're using a real-world example in document, and when the real-world example changes, so should the docs...
Comment #15
xanoNot for this kind of stuff, unfortunately. I verified that.
You're right. I did put a variable_del() there, but somehow it got removed again in the process.
Good thinking!
Comment #16
xanoComment #17
xanoThe attached patch adds a variable_del() to delete the old variables. This requires one extra query for each variable, resulting in 2+2N queries with N being the amount of variables. The alternative is to use the query below, which would result in 2+N queries, but in more and less maintainable code.
Comment #18
damien tournoud commentedIt does! If it doesn't, please open an issue.
Comment #19
xanoThese are expressions and the DBTNG docs expressively state that those should be used with caution, because not all of them are cross-database platform. Therefore an issue about this is not necessary. I checked MySQL, PostgreSQL and SQLite and CONCAT() and || are being used, but there is no common way of doing this.
Comment #20
xanoComment #22
drewish commentedre-rolled. the changes look good to me.
Comment #23
dries commentedWaw, I really think this is a non-issue -- the risk of getting a collision is pretty much zero. It has grown in a big patch. I personally prefer to keep the code slightly more readable than fixing this collision.
Comment #24
berdirThe patch is big because it adds tests and updates the example, the actual changes aren't so big.
AFAIK, it is adviced to prefix all variables with the name of the module. upload.module imho doesn't really follow that convention, because it has only the prefix. This is afaik the only place in core where we have something like this, so I think it should be changed.
About the patch:
Is there a reason you access the database directly in the update function, instead of using node_get_types('names')? Why isn't it possible to do something like:
Comment #25
drewish commentedI'm really not buying the size argument either. The weighty bits are the update function and unit tests.
Comment #27
emmajane commentedNothing here has been committed, so nothing to document yet. Please update the tags when the patch has been committed. Thanks! :)
Comment #28
webchickUpload module has been removed from Drupal 7. Dries's response sounds like "won't fix," so won't fixing.
Comment #29
xano