I found one very strange bug when tried to include skinr to my existing website with new theme based on Fusion. Skinr controls simply haven't appear at any of the places they should. I was digging in this problems for 2 days and finally found the reason.
Initially I though that Skinr doesn't includes it's includes dues to some problem, but research shown that it does. However, even with included libs, it's hooks wasn't returned by module_invoke_all('skinr_data'), which was very-very strange. I dug deeper in this and found that module_invoke_all() runs module_implements(), which has static cache. So, if someone runs module_invoke_all('skinr_data') before skinr's includes were loaded, this static cache is getting full and further including doesn't help, as module_invoke_all('skinr_data') always return null.
This suppose to be handled by skinr_init(), right? Yes, in ideal world. I've set debug backtrace and have found few modules, who are implementing the same hook and run before Skinr. The problem is that they are running some theming functions, which eventually came up to skinr_preprocess() which runs skinr_fetch_data() with first module_invoke_all('skinr_data') which sets statick cache to NULL.
In my case the module who did the harm was Real Name (http://drupal.org/project/realname), which has pretty large number of users. Plus, who nows what module also can make the harm. So, I suggest to solve this once and for life by setting skinner weight to some very first value and ro prevent other modules run before it.
Attaching patches to fix this in both of 6.x branches. Thanks!
| Comment | File | Size | Author |
|---|---|---|---|
| #31 | skinr_796780-25.patch | 620 bytes | moonray |
| #29 | 796780.patch | 880 bytes | ericduran |
| #27 | 796780.patch | 894 bytes | ericduran |
| #17 | 796780.patch | 893 bytes | jacine |
| #13 | skinr_796780_13.patch | 606 bytes | moonray |
Comments
Comment #1
jacineComment #2
moonray commentedThis issue (if related to module_invoke_all('skinr_data') ) does not apply to the 2.x branch of skinr, only the 1.x branch.
Either way, I believe a better approach to this problem would be to check in skinr_init() was run at the top of the preprocess rather than changing the weight of skinr (through use of a static variable, perhaps). At least in the 7.x branch of skinr I've run into issues with the module weight, so better not to take any chances.
Comment #3
moonray commentedPlease review these patches.
Comment #4
neochief commentedWorks like a charm. Thanks!
Comment #5
moonray commentedCommitted to CVS.
Comment #7
moonray commentedNeed to port this to D7.
Comment #8
moonray commentedAnd here's the ported patch.
Comment #9
jacineShouldn't this be done with drupal_static()? If not, can you please explain why
&drupal_static()wouldn't be used here instead? Thanks :)Powered by Dreditor.
Comment #10
jacineComment #11
moonray commentedFrom api pages: All functions requiring a static variable to persist or cache data within a single page request are encouraged to use this function unless it is absolutely certain that the static variable will not need to be reset during the page request.
So this patch should be good.
Comment #12
sunHowever, a weight of -1000 looks a bit too extreme to me. -10 or -100 would be more than sufficient. Elsewhere, I used -1, due to a similar invocation order problem, which is sufficient, because I don't know of any other module that uses a negative module weight. So -10 should work.
Comment #13
moonray commentedHere's a stab at that patch for D7.
Comment #14
ChrisBryant commentedThanks @moonray. Could you also provide a little more info with the patches? A brief description or summary of how the patch addresses each of the points and would be very helpful.
Thanks again!
Comment #15
moonray commentedDescription for #13: Move that code from hook_init() into hook_module_implements_alter().
Comment #16
jacineShould be: "Implements hook_module_implements_alter()"
A comment should be added explaining why this is necessary.
Powered by Dreditor.
Comment #17
jacineHere's a patch that does that.
Comment #18
moonray commentedJust out of curiosity (not disputing): why is it Implements instead of Implementation?
Comment #19
jacineCoding standards: http://drupal.org/node/1354#hookimpl :)
Comment #20
jacineIf you approve of the patch, please mark it "Reviewed & tested by the community" and I will commit it.
Comment #21
ericduran commentedhmm, Couldn't we just move skinr to the beginning instead of looping thru it?
I didn't test this but just curious. It seems like a loop to manipulate the array is a bit overkill.
Comment #22
moonray commentedthe problem is that it's a keyed array, and it's passed by reference. I don't think array_unshift lets you add by key.
What you'd end up with your example is:
Comment #23
ericduran commentedhmm, @moonray: Yep, array_unshift sucks. lol
Ok this should work.
Comment #24
moonray commentedBecause implementations is passed by reference, does that work properly? Have you tested it?
Comment #25
moonray commentedAnd here's #23 in patch form. I've tested it, and it works as advertised.
Perhaps we can get a second opinion before RTBC?
Comment #26
jacineDid you forget to attach the patch?
Comment #27
ericduran commentedI need to get me a mac desktop. :-/ I always seem to leave my computer somewhere lol.
Here's a patch,. uhhm, I wrote the patch but it should applied :-/
Comment #28
ericduran commentednice, the bot will tell me if it applies correctly (sweet)
edit: @moonray, I also tested this. Works as expected it makes skinr run first in the hook_init.
Comment #29
ericduran commentedOops, wrong patch :-/, Sorry for spamming the issue queue.
Comment #31
moonray commentedOK, let's try and actually attach the patch. :)
Comment #32
jacineCommitted! Thanks :)
http://drupal.org/cvs?commit=443780
Comment #33
jacineNeeds to go to 6.x next.
Comment #34
moonray commentedThis code will not work for D6. There is alternative code in place that fixes this bug already. It's not ideal, but changing the weight of the module might cause other problems. I believe we should leave this as is.
Comment #35
moonray commented