function field_sql_storage_field_attach_rename_bundle

7.x field_sql_storage.module field_sql_storage_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new)

Implements hook_field_attach_rename_bundle().

File

drupal/modules/field/modules/field_sql_storage/field_sql_storage.module, line 701
Default implementation of the field storage API.

Code

function field_sql_storage_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) {
  // We need to account for deleted or inactive fields and instances.
  $instances = field_read_instances(array('entity_type' => $entity_type, 'bundle' => $bundle_new), array('include_deleted' => TRUE, 'include_inactive' => TRUE));
  foreach ($instances as $instance) {
    $field = field_info_field_by_id($instance['field_id']);
    if ($field['storage']['type'] == 'field_sql_storage') {
      $table_name = _field_sql_storage_tablename($field);
      $revision_name = _field_sql_storage_revision_tablename($field);
      db_update($table_name)->fields(array('bundle' => $bundle_new))->condition('entity_type', $entity_type)->condition('bundle', $bundle_old)->execute();
      db_update($revision_name)->fields(array('bundle' => $bundle_new))->condition('entity_type', $entity_type)->condition('bundle', $bundle_old)->execute();
    }
  }
}