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.
node_submit will reset $node->uid to '0' when $node->name is not set, which is a common occurrence when creating node programmatically. The can be seen in a number of module issue queues and forums support requests.
This patch fixes this issue.
Comment | File | Size | Author |
---|---|---|---|
#47 | node_submit-398110-d6-47.patch | 706 bytes | Albert Volkman |
#34 | 398110_node_submit.goodbye.with-tests.patch | 4.26 KB | matt2000 |
#33 | 398110_node_submit.goodbye1.patch | 3.68 KB | matt2000 |
#27 | 398110_node_submit.goodbye.patch | 3.02 KB | matt2000 |
#21 | 398110_node_submit.driesified.patch | 1.8 KB | matt2000 |
Comments
Comment #1
matt2000 CreditAttribution: matt2000 commentedHere's a slightly better version of the patch that can potentially save us an unnecessary user_load().
One other difference from before: If we somehow get a node where the uid and the name disagree, then the uid now wins instead of the name.
Comment #3
matt2000 CreditAttribution: matt2000 commentedHere's a re-roll against HEAD. Advice was given on the dev list today about using node_submit() + node_save(), so this is still relevant.
Comment #4
sunPlease revert this.
Please add an inline comment right before the condition that does not repeat the condition, but explains the reasoning for the condition.
I'm on crack. Are you, too?
Comment #5
matt2000 CreditAttribution: matt2000 commentedNote #1:
But node_submit doesn't allow modules to make changes any more. That happens elsewhere. (node_save, etc) There's no more _invoke functions here. So the new doc describes what the function actually does, including the change introduced by this patch.
Note #2:
How about we bump up the comment that follows the line and append as
//Populate the "authored by" field with the User ID, when it is not already present.
Comment #6
sunyes, we want to move + extend that comment instead. A note about the actual condition/reasoning wouldn't hurt. I mean, this issue talks about a problem in programmatic creation of nodes, and the existing condition in the code presumes that there is some magic around "administer nodes" permission involved, and somewhere, I saw you talking about a special case when $node->name is defined... So just adding another condition will increase the WTF. Hence, we need a proper inline comment here that properly explains why & when this is happening. To the point, no novel required.
Regarding 1), ok, if that is the case, then yeah, good catch.
Comment #7
matt2000 CreditAttribution: matt2000 commentedOk, how's this?
Comment #8
sun"Prepare node for saving by populating author and creation date."
Trailing white-space introduced here.
The permission name should be in quotes.
This review is powered by Dreditor.
Comment #9
matt2000 CreditAttribution: matt2000 commentedDone.
Comment #10
matt2000 CreditAttribution: matt2000 commentedfixed whitespace alter.
Comment #11
sunThanks!
Comment #13
sunTests failed. :(
Comment #14
matt2000 CreditAttribution: matt2000 commentedoops... ~:-S
Try this, testbot.
Comment #15
moshe weitzman CreditAttribution: moshe weitzman commentedlooks good.
in another patch, i'd be up for a rename of node_submit(), or merge it into some other function. it is confusing with fapi submit handlers and all
Comment #16
webchickLet's get some tests for this. This definitely sounds like an edge case we're bound to break again someday.
And I don't think a rename of node_submit() at this stage makes sense. We've been confusing it with form submit handlers since D4.7, so another release won't kill us. Would be happy to discuss cleaning this entire node pseudo-hook mess up in D8 tho. :)
Comment #17
matt2000 CreditAttribution: matt2000 commentedIs it OK to modify an existing test? Or does each bug require it's own test function? See attached for proposed solution.
Comment #18
sunThis should have led to an exception, because variables cannot be passed by reference. Please remove the ampersand from $node.
1) (minor) Trailing white-space here; blank lines should be blank.
2) The inline comment should properly describe what is being verified here; without issue number.
3) You want to use assertEqual() here.
This review is powered by Dreditor.
Comment #19
matt2000 CreditAttribution: matt2000 commentedThanks. Here ya go.
Comment #20
Dries CreditAttribution: Dries commentedCan we consistently use the same term (e.g. user ID) instead of UID?
See above.
Comment #21
matt2000 CreditAttribution: matt2000 commentedSo say we all.
Comment #22
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks.
Comment #23
matt2000 CreditAttribution: matt2000 commentedThis needs to be fixed in D6 even more so, since more happens in node_submit() there. //TODO
Comment #24
clojel CreditAttribution: clojel commentedIn node_submit function (node.module,v 1.1179 2009/12/06 18:27:23)
The statement !isset($node->uid) would be false by default.
As a result, even with administer nodes access, user cannot assign alternative author from node form. Please review...
Comment #25
clojel CreditAttribution: clojel commentedComment #26
matt2000 CreditAttribution: matt2000 commentedHmm. How did that slip by?
it looks like there's quite a bit of redundancy between node_submit() and node_object_prepare(). As per #15 above, maybe it's time to retire node_submit altogether, and do the name conversion in node_form_submit() ?
Then the new recommended procedure for programmatically creating new nodes apart from drupal_execute() would be
Comment #27
matt2000 CreditAttribution: matt2000 commentedThe bug this patch introduced was reported as #659962: Nodes with a $node->uid assigned can not have author changed.
This patch removes node_submit entirely, and moves it's remaining functionality into node_form_submit_build_node, which is the only function that called it anyway, and which is clearly identified as being related to FORM submission, so as to avoid confusion about programmatically created nodes.
it removes the test created for the old patch, but doesn't provide any new tests... yet. So this is just for testbot to munch on, and to get community feedback on the concept.
Comment #29
Dave ReidMy bad.
Comment #33
matt2000 CreditAttribution: matt2000 commentedThis should fix the old test. A new test will come tomorrow.
Comment #34
matt2000 CreditAttribution: matt2000 commentedHere it is with 2 new tests to make sure we don't see this issue or #659962: Nodes with a $node->uid assigned can not have author changed again.
Comment #37
chx CreditAttribution: chx commentedOMG everyone's hated node_submit dies. Quick commit soon before it resurrects.
Comment #38
sunActually, I'm not very happy of this move... this is the god-forsaken #builder_function for nodes, and we all know what we don't know, but we all know that we want to eliminate those #builder_functions entirely, because literally no one on this earth really groks that Form API + Field API integration _entirely_.
For example, this builder function is also invoked for AJAX submits and elsewhere. Intended?
Trailing white-space here.
5 days to code freeze. Better review yourself.
Comment #39
matt2000 CreditAttribution: matt2000 commentedAll I did was take the code form node_submit and put it into the one and only function in core that still called node submit. The issue really has nothing to do with builder functions. It has everything to do with avoiding confusion with (form)_submit functions, which this solves.
Comment #40
sun.core CreditAttribution: sun.core commentedIt's too late for more. We need to fix #24 and be done with it.
Comment #41
David_Rothstein CreditAttribution: David_Rothstein commentedLooks like this was all fixed by the latest commit at #492186: Authoring information is never updated., although the bug report here was older.
Comment #43
matt2000 CreditAttribution: matt2000 commentedDid the original issue ever get fixed in 6.x?
Comment #44
langworthy CreditAttribution: langworthy commentedThe problem described in OP just bit me using Drupal 6.19
Comment #45
dpearcefl CreditAttribution: dpearcefl commentedHas this issue been fixed in the latest D6?
Comment #46
sunComment #47
Albert Volkman CreditAttribution: Albert Volkman commentedD6 backport.
Comment #48
rjbrown99 CreditAttribution: rjbrown99 commented#47 does this still suffer from the issue raised in #24? After that approach was rolled to D7 there was this issue that came up: #659962: Nodes with a $node->uid assigned can not have author changed. D7 seems to have been fixed here. For D6, perhaps this would be the simplest approach.
Comment #49
jcisio CreditAttribution: jcisio commented#47 does not work as we could see in D7. So I continue in #492186: Authoring information is never updated. with a backported patch similar to the D6 patch pointed out in #48, but we keep the code in sync with D7.