function workflow_update_1 in Workflow 5
Same name and namespace in other branches
- 5.2 workflow.install \workflow_update_1()
- 6.2 workflow.install \workflow_update_1()
- 6 workflow.install \workflow_update_1()
File
- ./
workflow.install, line 259
Code
function workflow_update_1() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
// Create new workflow_node_history table
$ret[] = update_sql("CREATE TABLE {workflow_node_history} (\n nid int(10) unsigned NOT NULL default '0',\n sid int(10) unsigned NOT NULL default '0',\n uid int(10) unsigned NOT NULL default '0',\n stamp int(10) unsigned NOT NULL default '0',\n KEY nid (nid,sid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
// Copy data from the current workflow_node table
$ret[] = update_sql("INSERT INTO {workflow_node_history} SELECT * FROM {workflow_node}");
// Delete older entries
$result = db_query("SELECT w1.* FROM {workflow_node} w1 LEFT JOIN {workflow_node} AS w2 ON w1.nid = w2.nid AND w1.start < w2.start WHERE w2.start is NULL");
while ($record = db_fetch_array($result)) {
db_query("DELETE FROM {workflow_node} WHERE nid = %d", $record['nid']);
db_query("INSERT INTO {workflow_node} (nid, sid, uid) VALUES (%d, %d, %d)", $record['nid'], $record['sid'], $record['uid']);
}
$ret[] = update_sql("ALTER TABLE {workflow_node} DROP PRIMARY KEY");
$ret[] = update_sql("ALTER TABLE {workflow_node} DROP start");
// We can now use a unique primary key
$ret[] = update_sql("ALTER TABLE {workflow_node} ADD PRIMARY KEY (nid)");
break;
case 'pgsql':
// Create new workflow_node_history table
$ret[] = update_sql("CREATE TABLE {workflow_node_history} (\n nid integer NOT NULL default '0',\n sid integer NOT NULL default '0',\n uid integer NOT NULL default '0',\n stamp integer NOT NULL default '0'\n );");
$ret[] = update_sql("CREATE INDEX {workflow_node_history}_nid_sid_idx ON {workflow_node_history}(nid,sid);");
// Copy data from the current workflow_node table
$ret[] = update_sql("INSERT INTO {workflow_node_history} SELECT * FROM {workflow_node}");
// Delete older entries
$result = db_query("SELECT w1.* FROM {workflow_node} w1 LEFT JOIN {workflow_node} AS w2 ON w1.nid = w2.nid AND w1.start < w2.start WHERE w2.start is NULL");
while ($record = db_fetch_array($result)) {
db_query("DELETE FROM {workflow_node} WHERE nid = %d", $record['nid']);
db_query("INSERT INTO {workflow_node} (nid, sid, uid) VALUES (%d, %d, %d)", $record['nid'], $record['sid'], $record['uid']);
}
$ret[] = update_sql("ALTER TABLE {workflow_node} DROP CONSTRAINT {workflow_node}_pkey");
$ret[] = update_sql("ALTER TABLE {workflow_node} DROP start");
// We can now use a unique primary key
$ret[] = update_sql("ALTER TABLE {workflow_node} ADD PRIMARY KEY (nid)");
break;
}
return $ret;
}