You are here

function webform_update_1 in Webform 5.2

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

Schema changes include component id's (cid) keys in the webform_component and webform_submitted_data tables.

File

./webform.install, line 189

Code

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

  // 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;
}