Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
At least one bug I found a fix for ealier (link when I can find it) was due to sloppy use of the node type 'module' addribute.
The problem: for a type created by the node module, the 'module' attribute is set to 'node'. However this causes name-space conflict when invoking hook_node, etc, so in many places it is coerced as follows:
if ($module == 'node') {
$module = 'node_content'; // Avoid function name collisions.
}
Why not simply store it as 'node_content' in the database? This would avoid having to special-case these and would make the code less prone to bugs in the future. Attached patch implements this and supplies an update function.
Comment | File | Size | Author |
---|---|---|---|
#43 | node-schema-206138-43.patch | 734 bytes | pwolanin |
#38 | node-type-namespace-206138-38.patch | 17.85 KB | pwolanin |
#37 | node-type-namespace-206138-37.patch | 17.8 KB | pwolanin |
#34 | node-type-namespace-206138-34.patch | 23.94 KB | pwolanin |
#32 | node-type-namespace-206138-32a.patch | 17.47 KB | pwolanin |
Comments
Comment #1
cwgordon7 CreditAttribution: cwgordon7 commented"Atributes" is not spelled "Atributes", but rather "Attributes". So, cnw.
Comment #2
pwolanin CreditAttribution: pwolanin commentedfixed typo
Comment #3
pwolanin CreditAttribution: pwolanin commentedbetter- I missed the profile
Comment #4
pwolanin CreditAttribution: pwolanin commentedComment #5
pwolanin CreditAttribution: pwolanin commentedComment #6
pwolanin CreditAttribution: pwolanin commentedbump
Comment #7
pwolanin CreditAttribution: pwolanin commentedfails on HEAD (7.x)
Comment #8
pwolanin CreditAttribution: pwolanin commentedRe-rolled for 7.x. Ran some of the node module tests as well as a quick manual test.
Also maybe we should consider fixing the mis-named "module" attribute of a node type back to "base" or to "hook" or something else less confusing.
Comment #9
pwolanin CreditAttribution: pwolanin commentedpatch still applies (with offset)
Comment #10
pwolanin CreditAttribution: pwolanin commentedAll tests pass with the patch (5765 passes, 0 fails, 0 exceptions)
Comment #11
webchickSo I agree that the code that's working around this is utter cruft and should be done away with. However, I don't think
'module' => 'node_content'
is a good fix, because there is no module called node_content, so this is going to be terribly confusing from a DX perspective.Since 'module' is a misnomer and is actually not meant to represent a module at all, but rather intended to be "the prefix applied to all node hook function names," a better solution is to rename that to something more descriptive while we're fixing this bug, and fix two problems at once. An informal poll of #drupal said sun's suggestion of 'hook_prefix' was best, and that seems the most intuitive to me.
Comment #12
sunsubscribing for later review
Comment #13
pwolanin CreditAttribution: pwolanin commentedThe D6 schema description is wrong and misleading, so here's a patch we can come back to for that.
Comment #14
pwolanin CreditAttribution: pwolanin commentedchanged as per webchick above. All tests still pass (5765 passes, 0 fails, 0 exceptions)
Comment #15
pwolanin CreditAttribution: pwolanin commentedafter chx argued strongly against 'hook_prefix', I find his argument persuasive that these are not even hooks we are calling (hook meaning a per-module callback), I have re-rolled with just 'prefix' as a replacement for 'module'.
Also, updated the 2 affected node.module queries to use DBTNG.
Ran all tests - all pass.
Comment #16
catch'prefix' is fine with me. Ran all tests with the patch applied and they pass fine.
Comment #17
sunSorry, really minor, but wrong indentation here:
Set back to RTBC afterwards.
Comment #18
pwolanin CreditAttribution: pwolanin commentedfixed indentation. Slight tweak to hook_schema wording.
Comment #19
webchickHm. I am getting a bunch of these:
notice: Undefined property: stdClass::$prefix in /Applications/MAMP/htdocs/core/modules/node/node.module on line 626.
on admin/build/testing. Can anyone else confirm?
Comment #20
webchickWell, certainly helps when I run update.php. ;)
However, at the last step of update.php I get:
( ! ) PDOException: UPDATE {node_type} SET type=:db_update_placeholder_0, name=:db_update_placeholder_1, prefix=:db_update_placeholder_2, has_title=:db_update_placeholder_3, title_label=:db_update_placeholder_4, has_body=:db_update_placeholder_5, body_label=:db_update_placeholder_6, description=:db_update_placeholder_7, help=:db_update_placeholder_8, min_word_count=:db_update_placeholder_9, custom=:db_update_placeholder_10, modified=:db_update_placeholder_11, locked=:db_update_placeholder_12 WHERE (type = :db_condition_placeholder_501) - Array ( [:db_update_placeholder_0] => blog [:db_update_placeholder_1] => Blog entry [:db_update_placeholder_2] => blog [:db_update_placeholder_3] => 1 [:db_update_placeholder_4] => Title [:db_update_placeholder_5] => 1 [:db_update_placeholder_6] => Body [:db_update_placeholder_7] => A blog entry is a single post to an online journal, or blog. [:db_update_placeholder_8] => [:db_update_placeholder_9] => 0 [:db_update_placeholder_10] => 0 [:db_update_placeholder_11] => [:db_update_placeholder_12] => 1 [:db_condition_placeholder_501] => blog ) SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'modified' at row 1 in /Applications/MAMP/htdocs/core/includes/database/database.inc on line 365
Looks like this still needs work.
Comment #21
pwolanin CreditAttribution: pwolanin commentedfor me, all tests pass ran all again) and the update runs fine when I apply the patch to a clean install.
Comment #22
webchickThe problem came from having blog module installed, and node_type_save() which happens at the end of update.php when the cache is cleared. modified deafaults to a NULL value which is getting cast to 0. Peter is working on a fix.
Comment #23
pwolanin CreditAttribution: pwolanin commentedah, the bug exhibits when blog module is enabled, not just default profile.
$info->modified
does not have a default value, so apparently DBTNG chokes trying to cast NULL to int. This adds a simple check along the lines of what's there for other values:Comment #24
Crell CreditAttribution: Crell commentedThe ginormous insert and update queries in node_type_save() are a textbook case where you want to use a merge query instead, methinks. At minimum you want to build $fields in advance and just pass it in to each query, so you only have to maintain that array once, but I'm pretty sure that a merge query is the correct solution here.
Comment #25
pwolanin CreditAttribution: pwolanin commented@Crell - do merge queries work? Are they documented? Why are you expanding the scope of the patch? A DBTNG conversion of those queries is really scope creep anyhow, so we should make it work, but refinement can come later. Also, we do not necessarily want to update all the fields - i.e. orig_type - when the type is edited. So, new patch this re-uses a fields array, but otherwise keeps the 2 separate queries.
Also, I think this fixes a bug with the insert query - we should insert $info->type for the orig_type field.
That aspect probably needs a D6 backport.
Comment #26
Crell CreditAttribution: Crell commentedMerge queries absolutely work according to the unit tests. Documentation is in progress. You also don't have to update all fields if you don't want to. (Or if you do, that's a bug.)
Whether or not merging those queries into one merge statement is scope creep or not I will defer to webchick.
Comment #27
pwolanin CreditAttribution: pwolanin commentedper IRC w/ webchick. prefix -> base. All tests pass, 1 exception unrelated to this patch (5801 passes, 0 fails, 1 exception)
Comment #28
catchBase works just as well, and slightly less of a loaded term in core. So this should be ready to go. Already ran tests with prefix, ran some again with base, no issues (and I can confirm the exception is unrelated to this patch).
Documentation for merge queries is still a stub - so let's defer that to a later issue.
Comment #29
webchickHm. Dang it!
( ! ) PDOException: INSERT INTO {node_type} (type, name, base, has_title, title_label, has_body, body_label, description, help, min_word_count, custom, modified, locked, orig_type) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13) - Array ( [:db_insert_placeholder_0] => poll [:db_insert_placeholder_1] => Poll [:db_insert_placeholder_2] => poll [:db_insert_placeholder_3] => 1 [:db_insert_placeholder_4] => Question [:db_insert_placeholder_5] => [:db_insert_placeholder_6] => [:db_insert_placeholder_7] => A poll is a question with a set of possible responses. A poll, once created, automatically provides a simple running count of the number of votes received for each response. [:db_insert_placeholder_8] => [:db_insert_placeholder_9] => 0 [:db_insert_placeholder_10] => 0 [:db_insert_placeholder_11] => 0 [:db_insert_placeholder_12] => 1 [:db_insert_placeholder_13] => poll ) SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'has_body' at row 1 in /Applications/MAMP/htdocs/core/includes/database/database.inc on line 365
Trying without the patch...
Comment #30
webchickHm. Does not happen without this patch. Sorry, Peter. :(
I get this error when going to admin/build/modules and enabling all modules.
Without this patch I still get notices related to the registry, but nothing like this.
Comment #31
pwolanin CreditAttribution: pwolanin commented@webchick - hey, no problem. This looks like a variant of the bug before - somebody is calling this function without setting 'has body' on the type.
Comment #32
pwolanin CreditAttribution: pwolanin commentedper IRC w/ webchick and Crell. DBTNG does not cast (e.g. bool to int) so for mysql it tends to choke and die if you pass a non-int to an int column. Also, we should make sure everything is set, so we don't pass a NULL where int is expected.
Comment #33
catchWith this patch I get "Call to undefined function function _node_type_set_defaults()" when I enable book module.
Comment #34
pwolanin CreditAttribution: pwolanin commentedyep, missed that one. Sorry.
diff to prior patch is just in book.install
Ran all tests with this patch: 5803 passes, 0 fails, 0 exceptions
Comment #35
catchI can't run all tests at the moment due to Fatal error: Class 'DatabaseLog' not found in /home/catch/www/7.x/includes/database/database.inc on line 769
Which fails in HEAD too.
however all the tests up to that one passed, and enabling every module on admin/build/modules worked fine. Since I incorrectly marked this rtbc last time, leaving open for one more double check.
Comment #36
pwolanin CreditAttribution: pwolanin commentedpatch still applies cleanly, all tests pass (5804 passes, 0 fails, 0 exceptions)
Comment #37
pwolanin CreditAttribution: pwolanin commentedomitting whitespace changes
Comment #38
pwolanin CreditAttribution: pwolanin commentedre-roll to eliminate extra function.
Comment #39
webchickOk, this addresses all of my concerns. :)
Comment #40
Crell CreditAttribution: Crell commentedDocs needed for this momentous occasion! http://drupal.org/node/224333
Comment #41
webchickD'oh! Thanks Crell! I'm slackin'! :D
Comment #42
pwolanin CreditAttribution: pwolanin commenteddraft doc done: http://drupal.org/node/224333#node_type_base
The correction to the schema description should be backported to 6.x
Comment #43
pwolanin CreditAttribution: pwolanin commentedbackport of just the string change.
Comment #44
sunComment #45
Gábor HojtsyThanks for the docs fix in D6. Committed.