field_sql_storage_field_attach_rename_bundle

Versions
7
field_sql_storage_field_attach_rename_bundle($obj_type, $bundle_old, $bundle_new)

Implements hook_field_attach_rename_bundle().

Code

modules/field/modules/field_sql_storage/field_sql_storage.module, line 643

<?php
function field_sql_storage_field_attach_rename_bundle($obj_type, $bundle_old, $bundle_new) {
  $etid = _field_sql_storage_etid($obj_type);
  // We need to account for deleted or inactive fields and instances.
  $instances = field_read_instances(array('object_type' => $obj_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('etid', $etid)
        ->condition('bundle', $bundle_old)
        ->execute();
      db_update($revision_name)
        ->fields(array('bundle' => $bundle_new))
        ->condition('etid', $etid)
        ->condition('bundle', $bundle_old)
        ->execute();
    }
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.