function availability_calendars_update_6103 in Availability Calendars 6
Same name and namespace in other branches
- 6.2 availability_calendars.install \availability_calendars_update_6103()
Change statuses to now use class strings instead of integers and alter defaultstatus setting if set.
File
- ./
availability_calendars.install, line 174 - Install, update and uninstall functions for the Availability Calendars module.
Code
function availability_calendars_update_6103(&$sandbox) {
$ret = array();
if (!isset($sandbox['progress'])) {
// changing statuses
$ret[] = update_sql("ALTER TABLE {availability_calendars_day} CHANGE status status MEDIUMTEXT NULL DEFAULT NULL");
$ret[] = update_sql("UPDATE {availability_calendars_day} SET status = 'calavailable' WHERE status = '0';");
$ret[] = update_sql("UPDATE {availability_calendars_day} SET status = 'calnotavailable' WHERE status = '1';");
$ret[] = update_sql("UPDATE {availability_calendars_day} SET status = 'calnotavailableprov' WHERE status = '2';");
$ret[] = update_sql("UPDATE {variable} SET value = 's:12:\"calavailable\";' WHERE name = 'availability_calendars_settings_system_defaultstatus' AND value = 'i:0;'");
$ret[] = update_sql("UPDATE {variable} SET value = 's:12:\"calavailable\";' WHERE name = 'availability_calendars_settings_system_defaultstatus' AND value = 's:1:\"0\";'");
$ret[] = update_sql("UPDATE {variable} SET value = 's:15:\"calnotavailable\";' WHERE name = 'availability_calendars_settings_system_defaultstatus' AND value = 'i:1;'");
$ret[] = update_sql("UPDATE {variable} SET value = 's:15:\"calnotavailable\";' WHERE name = 'availability_calendars_settings_system_defaultstatus' AND value = 's:1:\"1\";'");
$ret[] = update_sql("UPDATE {variable} SET value = 's:19:\"calnotavailableprov\";' WHERE name = 'availability_calendars_settings_system_defaultstatus' AND value = 'i:2;'");
$ret[] = update_sql("UPDATE {variable} SET value = 's:19:\"calnotavailableprov\";' WHERE name = 'availability_calendars_settings_system_defaultstatus' AND value = 's:1:\"2\";'");
// content type settings
$types = node_get_types();
$update_types = array();
foreach ($types as $id => $val) {
if (variable_get('availability_calendars_settings_system-type_' . $val->type, '0') == '1' || variable_get('availability_calendars_' . $val->type, '0') == '1') {
$update_types[] = "'{$val->type}'";
}
}
$sandbox['progress'] = 0;
$sandbox['current_nid'] = 0;
$sandbox['update_types'] = implode(', ', $update_types);
$sandbox['max'] = db_result(db_query('SELECT COUNT(DISTINCT nid) FROM {node} WHERE type IN (' . $sandbox['update_types'] . ')'));
}
// node specific updates: do not rewrite (i18n might restrict to a certain language)
$nodes = db_query_range('SELECT nid FROM {node} WHERE nid > ' . $sandbox['current_nid'] . ' AND type IN (' . $sandbox['update_types'] . ') ORDER BY nid ASC', 0, 1);
while ($node = db_fetch_object($nodes)) {
$nid = $node->nid;
$sql = '';
$sql = "WHEN (name = 'availability_calendars_settings_node_" . $nid . "_defaultstatus' AND value = 'i:0;') THEN 's:12:\"calavailable\";'";
$sql = "WHEN (name = 'availability_calendars_settings_node_" . $nid . "_defaultstatus' AND value = 's:1:\"0\";') THEN 's:12:\"calavailable\";'";
$sql .= " WHEN (name = 'availability_calendars_settings_node_" . $nid . "_defaultstatus' AND value = 'i:1;') THEN 's:15:\"calnotavailable\";'";
$sql .= " WHEN (name = 'availability_calendars_settings_node_" . $nid . "_defaultstatus' AND value = 's:1:\"1\";') THEN 's:15:\"calnotavailable\";'";
$sql .= " WHEN (name = 'availability_calendars_settings_node_" . $nid . "_defaultstatus' AND value = 'i:2;') THEN 's:19:\"calnotavailableprov\";'";
$sql .= " WHEN (name = 'availability_calendars_settings_node_" . $nid . "_defaultstatus' AND value = 's:1:\"1\";') THEN 's:19:\"calnotavailableprov\";'";
$ret[] = update_sql("UPDATE {variable} SET value = CASE {$sql} ELSE value END;");
$sandbox['progress']++;
$sandbox['current_nid'] = $nid;
}
$ret['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
$ret[] = array(
'success' => TRUE,
'query' => 'Fixed variables for ' . $sandbox['max'] . ' availability calendar variable settings.',
);
return $ret;
}