Closed (fixed)
Project:
Scheduler
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
29 Jan 2011 at 18:20 UTC
Updated:
19 Feb 2011 at 17:10 UTC
Jump to comment: Most recent file
As mentioned in #1040022: Detailed comparison of Scheduler D6 to D7, the D6 scheduler's hook_nodeapi has been split out into the new D7 hook_node_'op' functions. I'd like to take each one in turn to verify that the conversion is correct. First up is hook_node_load. Attached is a grab from my comparison program, comparing the latest D6 dev (21 Jan) with D7 (28 Jan).
I think this one is OK, but there are some improvements:
If these are not critical then we can leave it for now, but it is worth recording anything here for our future reference.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | node->scheduler in D6.jpg | 89.81 KB | jonathan1055 |
| #3 | _scheduler.1044660_3.node_load.D7.patch | 941 bytes | eric-alexander schaefer |
| comparison of node load.jpg | 416.63 KB | jonathan1055 |
Comments
Comment #1
jonathan1055 commentedJust noticed another improvement:
Comment #2
eric-alexander schaefer commented(1) Could be worth it. To be sure we would need to measure it.
(2) Right now I would rather keep the code if it is working and make it D7ish later
(3) Right. This is not needed anymore.
(4) Definitely.
I will do 3 and 4 right now and we should do (1) and (2) after release 1.0.
Comment #3
eric-alexander schaefer commentedComment #4
jonathan1055 commentedYes I agree with leaving 1 and 2 for later.
In your patch, I would do it in one line, ie change
into
to save the overhead of creating the array $nids which is not used anywhere else. This is how it is done in the API docs example
Comment #5
eric-alexander schaefer commentedI don't think this adds overhead and I like the code to speak to me. If you inline $nids you have no idea what array_keys() is retrieving. If you assign the result to $nids you will know that it returns a list of node IDs. Also I like statements to be about one thing. The first line is all about getting a list of node IDs while the second line is all about the query. In the inlined version of the code the line is about two things at once. This might not seem to be such a big deal but it usually pays off later, because the code is easier to understand.
Comment #6
jonathan1055 commentedYes, that is very good reasoning. In addition, having it as two lines means you can insert a debug line between the two if necessary. I'll test the patch and report back.
Comment #7
jonathan1055 commentedYour patch is fine, but I think there was another error in the original translation to D7. When $row was created in D6 it was being saved to $node->scheduler which is correct because the D6 version can only load one node at a time. But in D7, multiple nodes can be loaded, and they are stored in $nodes keyed by the node id. So the line
should become
Otherwise the $row never gets saved and stored, which is half of the point of this function.
Also you could change the function header text to read 'Implements hook_node_load().' as this is the new standard. I know this is quite minor, but this header block is bound to be copied to the other new hook_node_{op} functions so we might as well save ourselves effort later on.
Comment #8
jonathan1055 commentedForgot to set status back to 'needs work'
Comment #9
eric-alexander schaefer commentedThe values from the scheduler table actually get stored in $nodes[$nid]->publish_on and $nodes[$nid]->unpublish_on ($node-> in D6 and D5). I have no idea why $row was stored that way anyway.
Comment #10
jonathan1055 commentedYes the actual values get stored in $nodes[$nid]->publish_on, that is fine. What I'm saying is that the formatted text (which used to be stored in $node->scheduler via $row in D6) is now not saved at all. To match D6 we need the line change I suggested in #7 above.
Comment #11
eric-alexander schaefer commentedYes I understand that. But why create and save it at all? Where is it accessed?
Comment #12
jonathan1055 commentedI've just looked back, and the array $node->scheduler actually has all four scheduler values in the D5 and D6 versions. See screen grab from D6. The ->scheduler array was introduced somewhere between 5.x-1.3 (March 2007) and 5.x-1.10 (Feb 2008). I don't know the background why publish_on and unpublish_on are duplicated directly in $node and in the $node->scheduler array but I don't think we should remove either of them in the D7 conversion (atleast not for 7.x-1.0). They are not accessed in any scheduler module code, just provided for others to use, I presume.
So in addition to the line change in #7 above, we also need
so that the stored array has all four values just like D6.
Comment #13
eric-alexander schaefer commentedYou are probably right. There might be modules or themes that rely on this data so we should keep it.
http://drupal.org/cvs?commit=495054