text_update_4

Versions
5
text_update_4()

Data is now stored in per-field tables.

Code

contributions/cck/text.install, line 84

<?php
function text_update_4() {
  $ret = array();

  include_once('./'. drupal_get_path('module', 'content') .'/content.module');
  include_once('./'. drupal_get_path('module', 'content') .'/content_admin.inc');

  content_clear_type_cache();
  $fields = content_fields();

  foreach ($fields as $field) {
    switch ($field['type']) {
      case 'text_shorttext':
        $columns = array(
          'value' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => "''"),
          'format' => array('type' => 'int', 'length' => 10, 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
        );
        if ($field['text_processing'] == 0) {
          unset($columns['format']);
        }
        // the following line will trigger (negligible) warnings if content_update_5 was run before
        // (column already exists)
        @content_alter_db_field(array(), array(), $field, $columns);
        $db_info = content_database_info($field);
        $table = $db_info['table'];
        if ($field['multiple']) {
          if ($field['text_processing']) {
            $ret[] = update_sql('INSERT INTO {'. $table .'} (vid, delta, nid, '. $field['field_name'] .'_value, '. $field['field_name'] ."_format) SELECT vid, delta, nid, field_shorttext, format FROM {node_field_shorttext_data} WHERE field_name = '". $field['field_name'] ."'");
          }
          else {
            $ret[] = update_sql('INSERT INTO {'. $table .'} (vid, delta, nid, '. $field['field_name'] ."_value) SELECT vid, delta, nid, field_shorttext FROM {node_field_shorttext_data} WHERE field_name = '". $field['field_name'] ."'");
          }
        }
        else {
          if ($field['text_processing']) {
            $ret[] = update_sql('INSERT INTO {'. $table .'} (vid, nid, '. $field['field_name'] .'_value, '. $field['field_name'] ."_format) SELECT vid, nid, field_shorttext, format FROM {node_field_shorttext_data} WHERE field_name = '". $field['field_name'] ."'");
          }
          else {
            $ret[] = update_sql('INSERT INTO {'. $table .'} (vid, nid, '. $field['field_name'] ."_value) SELECT vid, nid, field_shorttext FROM {node_field_shorttext_data} WHERE field_name = '". $field['field_name'] ."'");
          }
        }
        break;
      case 'text_longtext':
        $columns = array(
          'value' => array('type' => 'mediumtext', 'not null' => TRUE, 'default' => "''"),
          'format' => array('type' => 'int', 'length' => 10, 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
        );
        if ($field['text_processing'] == 0) {
          unset($columns['format']);
        }
        // the following line will trigger (negligible) warnings if content_update_5 was run before
        // (column already exists)
        @content_alter_db_field(array(), array(), $field, $columns);
        $db_info = content_database_info($field);
        $table = $db_info['table'];
        if ($field['multiple']) {
          if ($field['text_processing']) {
            $ret[] = update_sql('INSERT INTO {'. $table .'} (vid, delta, nid, '. $field['field_name'] .'_value, '. $field['field_name'] ."_format) SELECT vid, delta, nid, field_longtext, format FROM {node_field_longtext_data} WHERE field_name = '". $field['field_name'] ."'");
          }
          else {
            $ret[] = update_sql('INSERT INTO {'. $table .'} (vid, delta, nid, '. $field['field_name'] ."_value) SELECT vid, delta, nid, field_longtext FROM {node_field_longtext_data} WHERE field_name = '". $field['field_name'] ."'");
          }
        }
        else {
          if ($field['text_processing']) {
            $ret[] = update_sql('INSERT INTO {'. $table .'} (vid, nid, '. $field['field_name'] .'_value, '. $field['field_name'] ."_format) SELECT vid, nid, field_longtext, format FROM {node_field_longtext_data} WHERE field_name = '". $field['field_name'] ."'");
          }
          else {
            $ret[] = update_sql('INSERT INTO {'. $table .'} (vid, nid, '. $field['field_name'] ."_value) SELECT vid, nid, field_longtext FROM {node_field_longtext_data} WHERE field_name = '". $field['field_name'] ."'");
          }
        }
        break;
    }
  }

  $ret[] = update_sql('DROP TABLE {node_field_shorttext_data}');
  $ret[] = update_sql('DROP TABLE {node_field_longtext_data}');

  db_query('DELETE FROM {cache}');
  return $ret;
}
?>

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.