content_update_1003

Versions
5
content_update_1003()

Rename data tables to avoid collision with core node_* tables

Code

contributions/cck/content.install, line 407

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

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

  $rename = array();

  $types = content_types();
  $fields = content_fields();

  // "per content type" tables
  foreach ($types as $type) {
    $old_name = _content_tablename($type['type'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE);
    $new_name = _content_tablename($type['type'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE, 1003);
    if (db_table_exists($old_name)) {
      if (!in_array($old_name, array('node_access',  'node_comments_statistics', 'node_counter', 'node_field', 'node_field_instance', 'node_group', 'node_group_fields', 'node_revisions', 'node_type'))) {
        $rename[$old_name] = $new_name;
      }
      else {
        // TODO : what ? create the table ?
      }
    }
  }

  // "per field" tables
  foreach ($fields as $field) {
    $old_name = _content_tablename($field['field_name'], CONTENT_DB_STORAGE_PER_FIELD);
    $new_name = _content_tablename($field['field_name'], CONTENT_DB_STORAGE_PER_FIELD, 1003);
    $old_name = 'node_data_'.$field['field_name'];
    $new_name = 'content_'. $field['field_name'];
    if (db_table_exists($old_name)) {
      $rename[$old_name] = $new_name;
    }
  }

  // rename
  foreach ($rename as $old_name => $new_name) {
    switch ($GLOBALS['db_type']) {
      case 'mysql':
      case 'mysqli':
        $ret[] = update_sql("RENAME TABLE {". $old_name ."} TO {". $new_name ."}");
        break;

      case 'pgsql':
        $ret[] = update_sql("ALTER TABLE {". $old_name ."} RENAME TO {". $new_name ."}");
        break;
    }
  }

  variable_set('content_schema_version', 1003);
  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.