I get 4 messages at each node page view (see below).
This is what I did:
- add settings to Nodereference field of content type A, referring content type B; save.
- edit/save settings of content type B.
Then I showed a node of type B, and got the following messages:
(I did not do 'Rebuild permissions' yet)
I do not get the warnings on other content types.
Notice: Undefined index: referenced in nodeaccess_nodereference_node_access_records() (line 489 of nodeaccess_nodereference.module).
Warning: array_keys() [function.array-keys]: The first argument should be an array in nodeaccess_nodereference_node_access_records() (line 489 of nodeaccess_nodereference.module).
Warning: Invalid argument supplied for foreach() in nodeaccess_nodereference_node_access_records() (line 489 of nodeaccess_nodereference.module).
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | NANR_1619636_19_update_variable.patch | 1.07 KB | johnv |
| #14 | cumulative-settings-improvement-patch-1.diff | 7.18 KB | danielb |
| #9 | cumulative-settings-improvement-patch.diff | 5.58 KB | danielb |
| #2 | nodeaccess_nodereference_1619636_2_messages.patch | 3.66 KB | johnv |
| #1 | nodeaccess_nodereference_1619636_1_messages.patch | 2.78 KB | johnv |
Comments
Comment #1
johnvPlease check attached patch. It contains the following:
@@ -465,7 +465,7 @@ function nodeaccess_nodereference_node_access_records($node)
- returns always an array, which gives easier logic, and is in accordance with hook documentation;
- has a small improvement, due to NANR_field_settings() now returning only array's.
@@ -564,15 +561,20 @@ function nodeaccess_nodereference_field_settings()
- logic is now clearer IMO;
- returns always an array, which is easier for parsing the resulting data, as in .._access-records() ;
- has some hints for #1630658: Less memory-usage in nodeaccess_nodereference_field_settings()
@@ -603,7 +608,7 @@ function nodeaccess_nodereference_check_cross_access()
- has a small modification to remove the message. Please check if the logic is not broken.
Comment #2
johnva better patch.
Comment #3
danielb commentedAny reason to remove
if (!empty($field_data)) {? Seems like a quick way to avoid the loop if the data isn't there? Especially if you propose we don't store anything at all for content types without the settings enabled?Will have to make sure there is nowhere else that !empty() should be used as a result of your proposal.
Comment #4
danielb commentedI also think the TODO you have there should be handled by code that calls this function (by calling it an additional time to check the data first), probably not within the function.
Comment #5
danielb commentedFor comparing old settings, can we get away with comparing arrays like
(serialize($array1) == serialize($array2))?I really don't want to hardcode all the things it should look for, or recurse through the array.
Comment #6
johnv@#3, indeed, we do not need
if (!empty($field_data)) {if the function ALWAYS returns an array, perhaps an empty one. I did not have the overview to remove it on other places.@#4, I thought that this get/set function was a nice place to centralize the data. If done outside, you must make sure it is called on all set-statements.
@#5, I tried something like
But I couldn't easily get a nice set of default_data in the fist place..
In some other module, we had $default_settings (but it was a simple array - this is more complex). You can mimic the submit data, and you can use it to set the field_settings, too
Comment #7
danielb commentedI might create a function that reduces the settings arrays to their bare minimums, will be necessary for the other issue too.
Comment #8
danielb commentedThere's only one place that call this function to set it, I think I will do the reductions and tests there.
Comment #9
danielb commentedI got started and all of this is kinda related so it all blended together in my hand.
I'm marking the following as duplicates since there is a bit of crossover.
#1630658: Less memory-usage in nodeaccess_nodereference_field_settings()
#1630684: node_access_needs_rebuild(TRUE) is set too often.
I've attached a patch which hopes to address these issues. I've tested the new functions, but not quite sure how the whole thing comes together.
Comment #10
danielb commentedI'm not quite happy with it yet, I think there are some typical cases where it won't reduce the way it should because of the tree structure of the array. But it will reduce nicely when the settings aren't used at all.
Comment #11
danielb commentedWell I solved that somewhat by adding
before
return $variablein nodeaccess_nodereference_reduce_variable().However this loses the 'published' setting if it was changed - despite the related settings not being in use. Maybe it's not a good idea.
The other issue is that technically the keys 'author_published', 'author', 'all_published', and 'all' don't get used when the 'referenced' grants aren't set.
But again, do we really want to reset those, as they will be lost in the settings form too?
Comment #12
danielb commentedActually...
the settings form could be changed to rely on the settings as they are stored in $instance, which don't get reset.
Comment #13
danielb commentedThe updates also allow simplification of nodeaccess_nodereference_field_delete_instance()
Comment #14
danielb commentednew patch
Comment #15
danielb commentedIf this works out a similar issue should be created for http://drupal.org/project/nodeaccess_userreference
Comment #16
danielb commentedthis bit can probably be deleted, it's redundant with what happens later anyway
Comment #17
johnvNice, such a feuilleton.. :-)
I won't be able to test until next tuesday, so I'll await more episodes...
Comment #18
danielb commentedI will commit it, "Move fast and break things" right? works for facebook...
also brings in more testers, whether they know it or not
Comment #19
johnvI think this works fine. Thanks.
Addition 1: I couldn't resist creating an update function. It removes superfluous data in your variable.
The data will be deleted when you save a Node type, but who knows when that happens..
See attached patch (sorry, no git)
2 more suggestions for better readibility of the code:
- move the function nodeaccess_nodereference_field_delete_instance($instance) underneath the ..._update_instance()
- rename internal functions to _nodeaccess_nodereference_...() . This way it is easier to make the difference between hooks and own/internal functions.
Comment #20
johnvSuppose a node type with node reference, but without NANR settings.
The code below invalidates the cache, which should not be necessary for a 'normal' node type.
Comment #21
johnvWe need these lines :
Comment #22
danielb commented@#20 - because we don't know whether the grants have changed. NANR settings could have been enabled previously? If the node is saved or content access permissions are rebuilt, then that code will run.
Comment #23
danielb commentedHmm maybe invalidating when the content type settings change is enough?
I dunno, it feels risky
Comment #24
danielb commentedYes it is risky, because someone could hit a node between the content type being changed and the node being rebuilt, and the cache would be wrong after the rebuild.
Comment #25
danielb commentedadded code in #21
Comment #26
johnvI still get the following, using code of this morning:
Notice: Undefined index: unused in nodeaccess_nodereference_node_access_records() (line 507Comment #27
johnvand this:
Warning: Invalid argument supplied for foreach() in nodeaccess_nodereference_reduce_variable() (line 624 of
Comment #28
danielb commentedWhat is being passed into nodeaccess_nodereference_reduce_variable() to cause that foreach error? As far as I can see it should always be an array? Plus it goes through nodeaccess_nodereference_recursive_filter() earlier which also does a foreach?
Comment #29
danielb commentedrelated #1650422: Problems with array indexes in node_access_records
Comment #30
johnvrecap:
#19: the attached patch for an update function is necessary, to clean up existing saved data and avoid messages.
#20:
variable_set('nodeaccess_nodereference_cache_needs_clear', TRUE);is OK, according to #22-24, but I'm not convinced, yet.#21: is solved with #25
#26:
Notice: Undefined index: unuseddoes not occur after activating the updated function, or resaving the field-data#27-#28:
Warning: Invalid argument supplied for foreach()idem#29:
if ($data['unused'] && isset($data['referenced']))idemComment #31
johnvI now see that my update function 7104 is too complicated, and may adopt the style of 7103.
Comment #32
danielb commentedwhat is idem?
Comment #33
danielb commentedsomething like this?
Comment #34
johnvit's Latin, 'the same as', 'dito'
Comment #35
johnvSeems OK, do you need me to test it?
1 typo: "Reduce
dsettings to essentials."Comment #36
johnvDaniel, will you copy the changes to node access user reference?
Comment #37
danielb commentedthat's not a typo, and yes I have created an issue in NAUR
Comment #38
danielb commentedalright added that in
Comment #39
johnvBoth in NANR and NAUR we need this :
An error occurs when you add a new XXXreference field and save without settings, or when you remove all settings from an existing field.
Comment #40
danielb commentedmade updates similar to this to both modules, cheers
Comment #41
johnvDaniel, thanx for the coöperation.
PS. You might want to synchronise the .info files, too.
Node access node reference 7.x-1.21+5-dev Provides per node access control with Node reference fields.
Node access user reference 7.x-3.8+3-dev Provides node access through user reference fields.
Comment #42
danielb commentedI've updated the descriptions. Please don't reopen a fixed issue to add unrelated comments as I was unable to properly deal with this change here.