You are here

function data_schema_alter in Data 6

Same name and namespace in other branches
  1. 8 data.install \data_schema_alter()
  2. 7 data.install \data_schema_alter()

Implementation of hook_schema_alter().

This is a central piece of data module: Here we tack schema information that has been defined through the API in data_tables or by hook_data_default onto the $schema array.

We do not use hook_schema() for exposing schema information as this would cause a race condition: ctools/exports looks for data module's data_tables at the same time when we are actually rebuilding it - follow path through data_get_all_tables() ... _data_load_table() ... ctools_export_load_object().

File

./data.module, line 29
Hooks and API functions for data module.

Code

function data_schema_alter(&$schema) {
  $tables = data_get_all_tables(TRUE);
  foreach ($tables as $table) {

    // Only add table if not yet present or the table at hand is defined in DB.
    // This allows other modules to "own" data managed tables which in turn makes Drupal
    // track schema versions - the prerequisit for using hook_update_N() on data tables.
    if (!isset($schema[$table
      ->get('name')]) || EXPORT_IN_DATABASE & $table
      ->get('export_type')) {
      $schema[$table
        ->get('name')] = $table
        ->get('table_schema');
    }
  }
}