TRUE, 'default' => 0)); break; case 'mysql': case 'mysqli': $ret[] = update_sql("ALTER TABLE {node_field_date_data} ADD COLUMN nid int(10) NOT NULL DEFAULT 0"); break; } return $ret; } function date_update_2() { // Multi-part update if (!isset($_SESSION['date_update_2'])) { $_SESSION['date_update_2'] = 0; $_SESSION['date_update_2_max'] = db_result(db_query("SELECT COUNT(*) FROM {node_field_date_data}"));; } $limit = 20; $result = db_query_range("SELECT nr.nid, nfdd.vid, nfdd.field_name, nfdd.delta FROM {node_field_date_data} nfdd LEFT JOIN {node_revisions} nr ON nr.vid = nfdd.vid", $_SESSION['date_update_2'], $limit); if (db_num_rows($result) == 0) { unset($_SESSION['date_update_2']); unset($_SESSION['date_update_2_max']); return array(); } while ($data = db_fetch_object($result)) { $_SESSION['date_update_2']++; db_query("UPDATE {node_field_date_data} SET nid = %d WHERE vid = %d AND field_name = '%s' AND delta = %d", $data->nid, $data->vid, $data->field_name, $data->delta); } return array('#finished' => $_SESSION['date_update_2'] / $_SESSION['date_update_2_max']); } /** * Data is now stored in per-field tables. */ function date_update_3() { $ret = array(); include_once(drupal_get_path('module', 'content') .'/content.module'); include_once(drupal_get_path('module', 'content') .'/content_admin.inc'); $fields = content_fields(); foreach ($fields as $field) { switch ($field['type']) { case 'date': $columns = array( 'value' => array('type' => 'varchar', 'length' => 17, 'not null' => TRUE, 'default' => "'00010101T00:00:00'"), ); content_alter_db_field(array(), array(), $field, $columns); if ($field['multiple']) { $ret[] = update_sql('INSERT INTO {node_data_'. $field['field_name'] .'} (vid, delta, nid, '. $field['field_name'] ."_value) SELECT vid, delta, nid, field_date FROM {node_field_date_data} WHERE field_name = '". $field['field_name'] ."'"); } else { $ret[] = update_sql('INSERT INTO {node_data_'. $field['field_name'] .'} (vid, nid, '. $field['field_name'] ."_value) SELECT vid, nid, field_date FROM {node_field_date_data} WHERE field_name = '". $field['field_name'] ."'"); } break; } } $ret[] = update_sql('DROP TABLE {node_field_date_data}'); db_query('DELETE FROM {cache}'); return $ret; } function date_update_4() { $ret = array(); include_once(drupal_get_path('module', 'content') .'/content.module'); include_once(drupal_get_path('module', 'content') .'/content_admin.inc'); $fields = content_fields(); foreach ($fields as $field) { $db_info = content_database_info($field); switch ($field['type']) { case 'date': $old_columns = array( 'value' => array('type' => 'varchar', 'length' => 17, 'not null' => TRUE, 'default' => "'00010101T00:00:00'"), ); $new_columns = array( 'value' => array('type' => 'varchar', 'length' => 20, 'not null' => TRUE, 'default' => "'0001-01-01T00:00:00'"), ); content_alter_db_field($field, $old_columns, $field, $new_columns); if ($field['multiple']) { $result = db_query('SELECT vid, delta, '. $db_info['columns']['value']['column'] .' AS value FROM {'. $db_info['table'] .'}'); while ($date = db_fetch_object($result)) { $new_date = substr($date->value, 0, 4) .'-'. substr($date->value, 4, 2) .'-'. substr($date->value, 6); $ret[] = update_sql('UPDATE {'. $db_info['table'] .'} SET '. $db_info['columns']['value']['column'] .' = "'. $new_date .'" WHERE vid = '. $date->vid .' AND delta = '. $date->delta); } } else { $result = db_query('SELECT vid, '. $db_info['columns']['value']['column'] .' AS value FROM {'. $db_info['table'] .'}'); while ($date = db_fetch_object($result)) { $new_date = substr($date->value, 0, 4) .'-'. substr($date->value, 4, 2) .'-'. substr($date->value, 6); $ret[] = update_sql('UPDATE {'. $db_info['table'] .'} SET '. $db_info['columns']['value']['column'] .' = "'. $new_date .'" WHERE vid = '. $date->vid); } } break; } } db_query('DELETE FROM {cache}'); return $ret; }