Drupal Most Recent Poll Block Not Caching
I searched for a bit, but no results and I was wondering if it were my fault that the poll was being cached. But eventually I came upon a Drupal forum post http://drupal.org/node/523676 which gave a patch which is transcribed below:
diff -urp –strip-trailing-cr ../drupal-6.x-dev/modules/poll/poll.install ./modules/poll/poll.install
— ../drupal-6.x-dev/modules/poll/poll.install 2009-01-06 16:46:37.000000000 +0100
+++ ./modules/poll/poll.install 2009-07-18 22:29:37.000000000 +0200
@@ -130,3 +130,21 @@ function poll_schema() {
return $schema;
}+/**
+ * @defgroup updates-6.x-extra Extra poll updates for 6.x
+ * @{
+ */
+
+/**
+ * Fix cache mode for “Most recent poll” block.
+ */
+function poll_update_6000() {
+ $ret = array();
+ $ret[] = update_sql(“UPDATE {blocks} SET cache = 2 WHERE module = ‘poll’ AND delta = ‘0′”);
+ return $ret;
+}
+
+/**
+ * @} End of “defgroup updates-6.x-extra”
+ * The next series of updates should start at 7000.
+ */
diff -urp –strip-trailing-cr ../drupal-6.x-dev/modules/poll/poll.module ./modules/poll/poll.module
— ../drupal-6.x-dev/modules/poll/poll.module 2008-12-18 16:46:20.000000000 +0100
+++ ./modules/poll/poll.module 2009-07-18 21:45:53.000000000 +0200
@@ -131,6 +131,7 @@ function poll_block($op = ‘list’, $delta
if (user_access(‘access content’)) {
if ($op == ‘list’) {
$blocks[0]['info'] = t(‘Most recent poll’);
+ $blocks[0]['cache'] = BLOCK_CACHE_PER_USER;
return $blocks;
}
else if ($op == ‘view’) {
@@ -776,6 +777,8 @@ function poll_cancel($form, &$form_state// Subtract from the votes.
db_query(“UPDATE {poll_choices} SET chvotes = chvotes – 1 WHERE nid = %d AND chorder = %d”, $node->nid, $node->vote);
+
+ cache_clear_all();
}/**
If this code looks strange to you you are not alone. I was confused too. I have patched files in linux before, but my webhost, Ixwebhosting, does not have access to ssh or the terminal in general so I was stuck. This was an obvious bug and I could not fix it. All I could find were links to how to convert a patch file to an exe on Windows, but first I have a linux server and also how would I have executed that anyway? So I decided to do it the manual way, open the files and manually edit it. Make sure you back up all original files before editing!
- First open ./modules/poll/poll.install and go to line 130
Findfunction poll_schema() { return $schema; }and add after it
function poll_update_6000() { $ret = array(); $ret[] = update_sql("UPDATE {blocks} SET cache = 2 WHERE module = 'poll' AND delta = '0'"); return $ret; } - Save and exit. Next open ./modules/poll/poll.module and go to line 131
Find:if (user_access('access content')) { if ($op == 'list') { $blocks[0]['info'] = t('Most recent poll'); return $blocks; } else if ($op == 'view') {and replace with:
if (user_access('access content')) { if ($op == 'list') { $blocks[0]['info'] = t('Most recent poll'); $blocks[0]['cache'] = BLOCK_CACHE_PER_USER; return $blocks; } else if ($op == 'view') { - In the same file go to line 777
Find:function poll_cancel($form, &$form_state) {$node = node_load($form['#nid']); global $user; if ($user->uid) {db_query('DELETE FROM {poll_votes} WHERE nid = %d and uid = %d', $node->nid, $user->uid); }else {db_query("DELETE FROM {poll_votes} WHERE nid = %d and hostname = '%s'", $node->nid, ip_address());} // Subtract from the votes.
db_query("UPDATE {poll_choices} SET chvotes = chvotes - 1 WHERE nid = %d AND chorder = %d", $node->nid, $node->vote);}
and replace with:
function poll_cancel($form, &$form_state // Subtract from the votes. db_query("UPDATE {poll_choices} SET chvotes = chvotes - 1 WHERE nid = %d AND chorder = %d", $node->nid, $node->vote); cache_clear_all(); } - Save this file and upload. Now the Poll block should work well.