You are here

public static function FieldHelper::purgeInstanceData in Helper 7

Purge all data from a field instance.

Parameters

array $instance: The field instance definition. This may be deleted or inactive.

1 call to FieldHelper::purgeInstanceData()
FieldHelper::deleteInstance in lib/FieldHelper.php
Delete a field instance.

File

lib/FieldHelper.php, line 244

Class

FieldHelper

Code

public static function purgeInstanceData(array $instance) {
  $field = static::readFieldByID($instance['field_id']);
  $data_table = _field_sql_storage_tablename($field);

  // Ensure the entity caches are cleared for the changed entities.
  if ($ids = db_query("SELECT entity_id FROM {$data_table} WHERE entity_type = :type AND bundle = :bundle", array(
    ':type' => $instance['entity_type'],
    ':bundle' => $instance['bundle'],
  ))
    ->fetchCol()) {
    entity_get_controller($instance['entity_type'])
      ->resetCache($ids);
    db_delete($data_table)
      ->condition('entity_type', $instance['entity_type'])
      ->condition('bundle', $instance['bundle'])
      ->execute();
  }
  $revision_table = _field_sql_storage_revision_tablename($field);
  if (db_table_exists($revision_table)) {
    db_delete($revision_table)
      ->condition('entity_type', $instance['entity_type'])
      ->condition('bundle', $instance['bundle'])
      ->execute();
  }
  watchdog('helper', "Purged data for field instance ID {$instance['id']}.");
}