poll_update

Versions
4.6 – 7
poll_update($node)

Implementation of hook_update().

Code

modules/poll.module, line 483

<?php
function poll_update($node) {
  db_query('UPDATE {poll} SET runtime = %d, active = %d WHERE nid = %d', $node->runtime, $node->active, $node->nid);

  db_query('DELETE FROM {poll_choices} WHERE nid = %d', $node->nid);
  $total_votes = 0;
  foreach ($node->choice as $choice) {
    $chvotes = (int)$choice['chvotes'];
    $chtext = $choice['chtext'];
    $total_votes += $chvotes;

    if ($chtext != '') {
      db_query("INSERT INTO {poll_choices} (nid, chtext, chvotes, chorder) VALUES (%d, '%s', %d, %d)", $node->nid, $chtext, $chvotes, $i++);
    }
  }
  if (!$total_votes) {
    db_query('DELETE FROM {poll_votes} WHERE nid = %d', $node->nid);
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.