function data_schema_alter in Data 8
Same name and namespace in other branches
- 6 data.module \data_schema_alter()
- 7 data.install \data_schema_alter()
Implements 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().
TODO: This is still rather hairy, and needs more work. In the meantime, it's probably best to enable CTools first, and then Data rather than both together.
File
- ./
data.install, line 73 - Install hooks for Data module.
Code
function data_schema_alter(&$schema) {
// Sidestep this during installation, as otherwise this is circular:
// data_get_all_tables() calls ctools stuff, which calls the schema, and
// gets us right back here.
if (drupal_get_installed_schema_version('data') != SCHEMA_UNINSTALLED) {
$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')) {
$table_schema = $table
->get('table_schema');
// @todo: figure out why we need this check here and why for WTF
// reasons, we sometimes get here and get nada for $table_schema.
if (isset($table_schema)) {
$table_schema += array(
'module' => 'data',
);
$schema[$table
->get('name')] = $table_schema;
}
}
}
}
}