I've posted this as a support request, although I suspect it might be a drupal bug. Just thought I'd post it here first before making a dick of myself by posting my own mistakes as a drupal bug.
I just created a module and noticed that the behaviour for the blocks changed with block caching enabled. My module is designed to display ads for individual users on content that they created, so the ad (i.e. block) would change depending on page. I included the following code for each block:
<?php
// listing of blocks, such as on the admin/block page
if ($op == "list") {
$block = array();
foreach (ads_zone_array() as $zone_id => $zone_name) {
$block[$zone_id] = array(
'info' => t('Ads Module Block: '. $zone_name),
'status' => 1,
'region' => $zone_name,
'cache' => BLOCK_CACHE_PER_PAGE
);
}
return $block;
}
?>
With per page caching enabled the block content still varies; no ads are shown for normal users and guests, but are shown for admin users. Admin does not have any permissions that normal users do not (there is not even an admin settings menu). Disabling Block caching fixes this problem, but using BLOCK_NO_CACHE has no effect. I have tried removing the module (including all reference to it from the {system} table) and reinstalling, to no avail. To repeat this problem I have included the version of the ads module I am using here: http://drupal.org/files/ads.zip
You can repeat the issue by installing the module, adding an ad provider (with a non-admin login go to my account -> configure ads, add google adsense, activate the left sidebar with client ID pub-3265410399671521 and ad ID 9810729274), and then viewing the page as guest or with a user that does not have admin privileges.
I am running windows vista (german), Version 0.2.149.30 of Google Chrome and Internet Explorer 7.0.6001.18000 (error occurs on both). I am running mysql version 5.0.51a and php version 5.2.6. My version of drupal is 6.5 (although this problem occured with 6.4 as well).
I have asked the community with help on this problem in case it was a problem with my code, but no one has been able to suggest a problem from my end. I appologise if this is an error on my behalf, I simply can't think of anything else I've done wrong.
| Comment | File | Size | Author |
|---|---|---|---|
| ads.zip | 31.18 KB | armanschwarz |
Comments
Comment #1
armanschwarz commentedComment #2
skritek00 commentedThis also applies to BLOCK_NO_CACHE as well. My chages to this block are not picked up. Also the way in which the block updates doesn't seem consistent with the rest of the cache settings. Is there a good workaround for this? I've just set the block cache value to -1 in the DB and hoped for the best...
Comment #3
ainigma32 commentedI installed your module and fiddled around a bit. It looks like it works as it should if you just change:
'cache' => BLOCK_CACHE_PER_PAGEto
'cache' => BLOCK_NO_CACHEAfter changing that you install the module and go to /admin/build/block That action will add the blocks to the db with a cache value of -1.
I'm assuming that by admin users you mean uid 1 and the reason that user can always see the block is
(block.module line 29)
Could you try this suggestion or confirm that you are still seeing unexpected behavior using this code and (of course) the latest Drupal release?
- Arie
Comment #4
ainigma32 commentedLooks like armsch6 won't be posting any feedback so I'm setting this to fixed.
Feel free to reopen if you think that is wrong.
- Arie