Drupal Most Recent Poll Block Not Caching

July 21st, 2009 260 comments

I was working on my new Drupal site, Shop the Internet, yesterday and I tried to insert a poll into a sidebar block that would ask the users which online shopping site did they prefer: Amazon, Bestbuy, Newegg, Target, or Walmart.  To test the poll I click Amazon and viola, it posted my vote.  Success!  Or so I thought…I was logged in to my admin panel in Firefox so I tried it in Internet Explorer.  When I refreshed the page, it said it was voted on and was showing the results.  So obviously the poll must have been more advanced than I thought, using IP address over cookies.  So again I tried it on Google Chrome and same thing.  Okay everything is fine.  So I go back to work with my site.  However after half an hour when my cache data was set to reset I decided to retest it and so I opened Internet Explorer and went to Shop the Internet…but now the poll was available to be voted on.  Of course I instantly realized this was because the caching of the poll was wrong, it was caching the poll and saving it as the cached version so that anyone who viewed it after I had voted on it would see the results only for another half an hour.  So I started my research on Google of course.

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!

  1. First open  ./modules/poll/poll.install and go to line 130
    Find

    function 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;
    }
  2. 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') {
  3. 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();
     }
  4. Save this file and upload.  Now the Poll block should work well.
ibed below:
Your Ad Here

Configuring a Router

June 4th, 2009 211 comments

Considering I just got a new router yesterday that has Wireless N I thought I would post something about how to configure one since the first time I tried with a router a year ago it took me two hours to figure out how and just happened to because I randomly saw an IP Address among the many pages of an instruction PDF.

First, the CD almost never works for anything…I’ve tried multiple CDs for router configuration and DSL configuration alike, but none have worked and I have always had to turn to manual configuration which I find very useful to know.

1.  Connect the router like the instructions that came with the router say.  Assuming you have a DSL modem or other modem that does not have wireless means, this means you connect the telephone cable or other internet cable from the wall to the modem.  Then take an ethernet cable and connect the output on the modem to the input on the router.  Now for initial configuration attach an ethernet cable to the router and connect it to your computer (I’m assuming its a portable one since why else would you really need wifi).

2. Open up an internet browser and enter one of the following ip addresses, depending on your router brand, into the address bar.  You may need to try several different ones:

Router IP Address Username Password

3Com

http://192.168.1.1

admin

admin

D-Link

http://192.168.0.1

admin

*

Linksys

http://192.168.1.1

admin

admin

Microsoft Broadband

http://192.168.2.1

admin

admin

Netgear

http://192.168.0.1

admin

password

Trendnet

http://192.168.1.1

admin

admin

3. Enter the username and password from above into the respective fields, submit, and you should find yourself in the control panel.  If these passwords don’t work for your router you may need to try the different ones for you router at http://www.routerpasswords.com/

4. Often times there will be a wizard that you can follow that will guide you through the process of connecting to the internet/setting up wifi.  Now usually though if you have done what I said you will not be able to access the internet if you load a page because the internet is not set up correctly.  Depending on your router you need to go to internet or WAN admin panel.  On my Trendnet, the WAN option if under the first menu, but on my D-Link there is a separate internet menu.  Either way find a form that has a drop down menu that has options such as DHCP, PPPoE etc.  Once you have found this menu you need to play around with the different options if you have not chosen the wizard to figure this out for you.  This is a tedious part as depending on your ISP (Internet Service Provider) you may have any of these.  At college, Virginia Tech, I must use DHCP option with obtain IP address automatically, but at home with Juno DSL, I must use PPPoE and enter my username and password for the DSL.  That is the part that took me a good hour the first time I set up a router.  It is probably a better option to use the wizard, but manual may be neccessary.  If all went well, you should now be able to load a website.

5. Now for wireless.  Again depending on your router you may have to search around for the Wireless configuration page, but you will know you found it if one of the fields asks for Wireless Network Name/SSID and another asks for a security type of WPA/WEP.  Once you have found this, you can create a name for your wireless network.  As for security type, I highly suggest WPA, and WPA2 if possible.  You will then be asked to enter a passphrase for the network.  I suggest something very random so that neighbors will not be able to leech from you wireless network.  Save your settings and test if you can connect to the network.

Categories: Technology Tags:
Your Ad Here

VirtualBox

June 4th, 2009 205 comments

A few months ago I got into using virtualization software, which as it suggests, allows you to virtualize operating systems. First I started with a program known as VMware, which proved decent, but was lacking in one thing that annoyed me, it could not virtualize graphics card drivers so trying to use Ubuntu through VMware was pointless if I could not have my lovely Compiz effects which I adore in Ubuntu. This being a tragedy, I could not continue much with VMware. However to my joy, a few weeks laterI discovered that the newst version of VirtualBox, made by Sun Microsystems (the same as who own Java), allowed using up to 128 Megabytes of Video Memory for virtualization, which means I can now happily use UBuntu with the amazing Compiz effects.  If you want more on compiz fusion effects please visit http://lifehacker.com/software/pretty-and-productive/power-up-your-linux-desktop-with-compiz-fusion-291002.php for a sampling.  VirtualBox can virtualize most Operating Systems except unfortunately Mac OSX (though since I don’t prefer Mac anyway it is okay).  For a list of Operating Systems that can be run through VirtualBOx please visit http://www.virtualbox.org/wiki/Guest_OSes.

Categories: Technology Tags:
Your Ad Here

Fun in Computer Science….

April 13th, 2009 208 comments

I’m taking a Problem Solving in Computer Science class this semester and one of the problems was:

How could a (normal, human) baby (accidently!) fall out of a twenty-story building onto the ground and live?

One of our solutions?  Drop the baby onto wet cement >_> What?!  It will survive (at least for a short time).  Fine what other suggestions do you have?


Categories: Programming Tags:
Your Ad Here

Integral of Position

March 19th, 2009 241 comments

Months ago when I started Mechanics in college, my friend and I were discussing kinematics obvioussly and a thought poppped into my head.  What is the intergral of position?  I thought about it all day.  Obviously the units had to be meter*seconds, but what was the meaning?  So I turned to google and discovered that at least one other mind has pondered this question, but as with me, the comprehension just doesn’t make sense.  Read the article here. What do you think?

Categories: Physics Tags: