You are here

function _serial_rename_tables in Serial Field 7

Same name and namespace in other branches
  1. 6 serial.inc \_serial_rename_tables()

Renames serial table(s) when a entity bundle us renamed.

Parameters

string $entity_type: Type of entity.

string $bundle_old: An old entity bundle machine name.

string $bundle_new: A new entity bundle machine name.

1 call to _serial_rename_tables()
serial_field_attach_rename_bundle in ./serial.module
Implements hook_field_attach_rename_bundle().

File

./serial.inc, line 53
Internal functions for the Serial module.

Code

function _serial_rename_tables($entity_type, $bundle_old, $bundle_new) {

  // Build the query to find all affected tables.
  $query = db_select('field_config', 'f')
    ->fields('f', array(
    'field_name',
  ));
  $query
    ->join('field_config_instance', 'i', '(f.field_name = i.field_name)');
  $query
    ->condition('f.type', SERIAL_FIELD_TYPE);
  $query
    ->condition('i.entity_type', $entity_type);
  $query
    ->condition('i.bundle', $bundle_new);

  // Rename each affected table.
  foreach ($query
    ->addTag('node_access')
    ->execute() as $record) {
    db_rename_table(_serial_get_table_name($entity_type, $bundle_old, $record->field_name), _serial_get_table_name($entity_type, $bundle_new, $record->field_name));
  }
}