You are here

function webform_update_1 in Webform 5

Same name and namespace in other branches
  1. 5.2 webform.install \webform_update_1()
  2. 6.2 webform.install \webform_update_1()

File

./webform.install, line 131

Code

function webform_update_1() {
  $ret = array();

  // Update pre-4.7 tables to the 463 build schema.
  $installed_version = variable_get("webform_version", 0);
  $current_version = array(
    'text' => '4.6.3',
    'build' => '463',
  );
  if ($installed_version > 0) {
    $ret = _webform_legacy_update($installed_version, $current_version);
  }

  // Start the normal update.
  $ret[] = update_sql("CREATE TABLE {webform_tmp} ( " . "  nid int(10) unsigned NOT NULL default '0', " . "  sid int(10) unsigned NOT NULL default '0', " . "  cid int(10) unsigned NOT NULL default '0', " . "  no int(10) unsigned NOT NULL default '0', " . "  data longtext, " . " PRIMARY KEY  (nid,sid,cid,no) " . " ) ");
  $result = db_query("SELECT ws.nid, ws.sid, wc.cid, ws.name, ws.data " . " FROM {webform_submitted_data} ws, {webform_component} wc " . " WHERE ws.nid = wc.nid " . " AND ws.name = wc.name ");
  while ($row = db_fetch_object($result)) {
    $data = unserialize($row->data);
    if (is_array($data)) {
      foreach ($data as $k => $v) {
        db_query("INSERT INTO {webform_tmp} (nid, sid, cid, no, data) VALUES (%d, %d, %d, %d, '%s')", $row->nid, $row->sid, $row->cid, $k, $v);
      }
    }
    else {
      db_query("INSERT INTO {webform_tmp} (nid, sid, cid, no, data) VALUES (%d, %d, %d, %d, '%s')", $row->nid, $row->sid, $row->cid, 0, $row->data);
    }
  }
  $ret[] = update_sql("DROP TABLE {webform_submitted_data}");
  $ret[] = update_sql("ALTER TABLE {webform_tmp} RENAME TO {webform_submitted_data}");
  $ret[] = update_sql("CREATE TABLE {webform_submissions} ( " . " nid int(10) unsigned NOT NULL default '0', " . " sid int(10) unsigned NOT NULL default '0', " . " submitted int(11)  NOT NULL default '0', " . " PRIMARY KEY  (nid, sid) " . ")");
  return $ret;
}