While the nodereference count fields will be updated when the node is saved or when the referencing node is saved, that isn't much help for pre-existing nodereferences to nodes created prior to the addition of a nodereference count field. It is probably best handled by a batch process that would update counts for all nodereference count fields. I think it makes the most sense to put this in a companion module in this project as it will generally only be useful to run once, immediately after adding nodereference count field(s) to an existing site.
I can build this as time allows. Patches are also always welcome.
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | event-number-groups-registered.png | 41.65 KB | geerlingguy |
| #13 | event-number-individuals-registered.png | 42.37 KB | geerlingguy |
| #13 | group-group-reference.png | 40.47 KB | geerlingguy |
Comments
Comment #1
geerlingguy commentedSubscribe
Comment #2
Flying Drupalist commentedsubscribe
Comment #3
gmak commentedYou could use VBO to update all of the nodes. Create a bulk view which lists all the nodes of the type you wish to update, add an operation (Publish) to apply. Run the view, click the 'select all' option and then apply the 'Publish' operation. This should re-save all of the nodes selected.
Comment #4
gilgabar commented@gmak, that sounds like a good idea when the number of nodes to update is relatively small. I'm concerned that a site with a large number of exisiting nodereferences would timeout if you did something like that. Using the batch api should allow any arbitrary number of node counts to be updated without worry of timeouts. Unless VBO already implements the batch api or does something similar, do you know if that is the case?
Comment #5
Flying Drupalist commentedIt definitely does use batch api, so you're alright there.
Actually if just resaving the content via VBO is a valid solution then this is as well as fixed for me. :)
Comment #6
gilgabar commentedOk, sounds like VBO is a good solution to this issue then. Thanks gmak and flying drupalist for your help. I've changed this to a documentation issue and I'll mark it fixed once I've updated the readme to include instructions for using VBO to update node counts.
Comment #7
geerlingguy commentedUsing VBO, I'm getting the following error on one of my update operations (repeated for each row):
The count updates worked for one content type, but not the second.
Running this update on another content type gives a similar error:
Comment #8
gilgabar commentedIt looks like the culprit is most likely a missing space. Notice the )AS. It should be ) AS. To confirm go to line 134 of nodereference_count.module and add a space in front of the AS. I think that should take care of it.
Comment #9
geerlingguy commentedStill getting this warning:
Could it be this line?
SELECT COUNT(*) FROM content_ WHERE = 13The first select statement works fine... but the second one doesn't seem to do anything.
Comment #10
gilgabar commentedOk, I see. It isn't selecting the right table. I'll have to look into that. If you have the devel module installed you can get some more info about what is going on by sticking a dsm() call in the foreach loop that is generating that SELECT. Probably dsm($db_info); would be most helpful. That variable is populated by a call to CCK, so for some reason it isn't getting the correct data.
Comment #11
geerlingguy commentedI'm getting this on the results that turn out correctly:
table (String, 36 characters ) content_type_individual_registrationAnd this on the results that turn out incorrect:
table (String, 8 characters ) content_I put in
dsm($db_info); on line 112...Could it possibly have to do with the fact that these group nodes are not only referencing another node type, but are also then referenced by a separate node type?
If I have more time later, I'll try to debug a little more.
Comment #12
gilgabar commentedMaybe it would be helpful if you map out the basics of the content types and the relationships you are using. It may be that I've made assumptions that aren't always true beyond my own basic requirements.
From the query it looks like you are trying to get an aggregate count from two separate nodereference fields. When you set up the nodereference count field what were the fields that you checked to have counted? It looks like one was 'field_event_reference'. What was the other?
Also does the error only occur with VBO or do you also see it when you save a node that is counted (or referencing)?
Comment #13
geerlingguy commentedI'm not trying to sum the counts of two separate nodereferences - rather I'm trying to have a count of all the "individual_registration" nodes that refer to an "event," and then separately (but in the same "event" content type) count all the "group" nodes that refer to the "event."
This error pops up both when I save an individual registration node from the Edit page and when I do a VBO on one node (or many).
Please see the three attached PNG files for reference - those are the three fields' Global Settings (the two event- fields are in the Event content type, and the group- field is in the Group content type.
Comment #14
gilgabar commentedThanks. That's super helpful. I'll see if I can replicate the issue.
Comment #15
gilgabar commentedOk, I think I have a fix. It looks like it's just a stupid oversight on my part. I was pretty sure I had tested that case, but apparently not. I'll have it committed shortly, but if you want to test immediately, just nest the contents of the foreach loop at line 110 inside an "if ($referencing_field) {}". Basically the field array returns all the fields available, but the ones that should not be counted have a value of zero. It was including those and passing zero to the content_fields() function which returned some garbage and generated errors. It should just skip those now.
Comment #16
gilgabar commentedThe latest dev release has the fix now.
Comment #17
geerlingguy commentedI'll update and let you know how it goes - thanks for your work on this!
Comment #18
geerlingguy commentedWorks swimmingly! I simply set up a views bulk operation, checked all the nodes to update, then did a 'publish node' operation on all of them...
A warning, though - it could take quite a while - I would use the Batch API feature of bulk operations, as you'll probably get a timeout if you have more than a few hundred nodes to update.
Comment #19
gilgabar commentedHere is a proposed addition to the README with some VBO info. It could use some double checking by someone else to make sure I'm not forgetting something or missing something important by using a really simple test case.
Comment #20
geerlingguy commentedLooks good to me!
Comment #21
gilgabar commentedGreat. The change is committed. I think we can consider this issue fixed. If there aren't any other problems found in the next week or two I think it should be safe to make a 1.0 release.