function advpoll_update_3 in Advanced Poll 5
Same name and namespace in other branches
- 6 advpoll.install \advpoll_update_3()
- 6.2 advpoll.install \advpoll_update_3()
Switch date handling from a duration to an enddate.
File
- ./
advpoll.install, line 158
Code
function advpoll_update_3() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
// New default '0' instead of NULL for startdate
$ret[] = update_sql("ALTER TABLE {advpoll} CHANGE startdate startdate int NOT NULL default '0'");
$ret[] = update_sql("UPDATE {advpoll} SET startdate = 0 WHERE startdate IS NULL");
// Add the new column.
$ret[] = update_sql("ALTER TABLE {advpoll} ADD COLUMN enddate int NOT NULL default '0' AFTER startdate");
// Calculate the new value.
$ret[] = update_sql("UPDATE {advpoll} SET enddate = startdate + runtime WHERE runtime != 0");
// Drop the old column.
$ret[] = update_sql("ALTER TABLE {advpoll} DROP COLUMN runtime");
break;
case 'pgsql':
// New default '0' instead of NULL for startdate
db_change_column($ret, 'advpoll', 'startdate', 'startdate', 'integer', array(
'not null' => TRUE,
'default' => '0',
));
$ret[] = update_sql("UPDATE {advpoll} SET startdate = 0 WHERE startdate IS NULL");
// Add the new column.
db_add_column($ret, 'advpoll', 'enddate', 'integer', array(
'not null' => TRUE,
'default' => '0',
));
// Calculate the new value.
$ret[] = update_sql("UPDATE {advpoll} SET enddate = startdate + runtime WHERE runtime != 0");
// Drop the old column.
db_drop_column($ret, 'advpoll', 'runtime');
break;
}
return $ret;
}