You are here

function sheetnode_update_6002 in Sheetnode 6

Implementation of hook_update_N().

File

./sheetnode.install, line 123

Code

function sheetnode_update_6002(&$sandbox) {
  drupal_load('module', 'sheetnode');
  require_once drupal_get_path('module', 'sheetnode') . '/socialcalc.inc';
  $ret = array();
  $sig = 'version:1.5';
  $siglen = strlen($sig);
  $result = db_query("SELECT * FROM {sheetnode}");
  while ($sheetnode = db_fetch_array($result)) {
    $value = unserialize($sheetnode['value']);
    if (strncmp($value, $sig, $siglen) === 0) {
      $sheet = socialcalc_parse_sheet($value);
      $sc = array(
        'sheet' => $sheet,
        'edit' => socialcalc_default_edit($sheet),
        'audit' => socialcalc_default_audit($sheet),
      );
      $sql = "UPDATE {sheetnode} SET value='%s' WHERE nid=%d";
      $ret[] = array(
        'success' => FALSE !== db_query($sql, serialize(socialcalc_save($sc)), $sheetnode['nid']),
        'query' => check_plain($sql),
      );
    }
  }
  $result = db_query("SELECT * FROM {sheetnode_template}");
  while ($template = db_fetch_array($result)) {
    $value = unserialize($template['value']);
    if (strncmp($value, $sig, $siglen) === 0) {
      $sheet = socialcalc_parse_sheet($value);
      $sc = array(
        'sheet' => $sheet,
        'edit' => socialcalc_default_edit($sheet),
        'audit' => socialcalc_default_audit($sheet),
      );
      $sql = "UPDATE {sheetnode_template} SET value='%s' WHERE tid=%d";
      $ret[] = array(
        'success' => FALSE !== db_query($sql, serialize(socialcalc_save($sc)), $template['tid']),
        'query' => check_plain($sql),
      );
    }
  }
  return $ret;
}