function webform_update_13 in Webform 5.2
Same name and namespace in other branches
- 6.2 webform.install \webform_update_13()
Update to the 2.x version of webform.
File
- ./
webform.install, line 452
Code
function webform_update_13() {
$ret = array();
// Set the webform weight to -1. This is needed to have webform's hook_menu()
// take precedence over node_menu().
$ret[] = update_sql("UPDATE {system} SET weight = -1 WHERE type = 'module' and name = 'webform'");
// Ensure crufty submission data that was not removed when webform nodes
// were deleted is cleared out before doing key changes.
$ret[] = update_sql("DELETE FROM {webform} WHERE nid NOT IN (SELECT nid FROM {node} WHERE type = 'webform')");
$ret[] = update_sql("DELETE FROM {webform_component} WHERE nid NOT IN (SELECT nid FROM {node} WHERE type = 'webform')");
$ret[] = update_sql("DELETE FROM {webform_submissions} WHERE nid NOT IN (SELECT nid FROM {node} WHERE type = 'webform')");
$ret[] = update_sql("DELETE FROM {webform_submitted_data} WHERE nid NOT IN (SELECT nid FROM {node} WHERE type = 'webform')");
// Convert timestamp-based cids to small integers starting at 1 for each node.
$result = db_query("SELECT nid, cid FROM {webform_component} ORDER BY nid ASC, cid ASC");
$nid = 0;
while ($component = db_fetch_array($result)) {
if ($component['nid'] != $nid) {
$nid = $component['nid'];
$cid = 1;
}
$ret[] = update_sql("UPDATE {webform_component} SET cid = " . $cid . " WHERE nid = " . $nid . " AND cid = " . $component['cid']);
$ret[] = update_sql("UPDATE {webform_component} SET pid = " . $cid . " WHERE nid = " . $nid . " AND pid = " . $component['cid']);
$ret[] = update_sql("UPDATE {webform_submitted_data} SET cid = " . $cid . " WHERE nid = " . $nid . " AND cid = " . $component['cid']);
$cid++;
}
// Convert the cid and pid columns to smallints for efficiency.
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
$ret[] = update_sql("ALTER TABLE {webform_component} CHANGE cid cid smallint unsigned NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE {webform_component} CHANGE pid pid smallint unsigned NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE {webform_submitted_data} CHANGE cid cid smallint unsigned NOT NULL default '0'");
break;
case 'pgsql':
db_change_column($ret, 'webform_component', 'cid', 'cid', 'smallint', array(
'not null' => TRUE,
'default' => '0',
));
db_change_column($ret, 'webform_component', 'pid', 'pid', 'smallint', array(
'not null' => TRUE,
'default' => '0',
));
db_change_column($ret, 'webform_submitted_data', 'cid', 'cid', 'smallint', array(
'not null' => TRUE,
'default' => '0',
));
break;
}
return $ret;
}