Details
-
Type: Improvement
-
Status: Done/Fixed
-
Priority: Minor
-
Resolution: Fixed/Completed
-
Affects Version/s: 2.0, 2.2.7, 3.0
-
Component/s: CiviCRM API
-
Labels:None
Description
Currently, hook civicrm_custom is called when a row is added to a custom table, but no hook is called when a custom table is added to the database. It would be nice to have this feature for the following reason: the Drupal views module needs to know where to find data to be displayed in a view. If Drupal and CiviCRM use two separate databases (which seems to us like a good practice) it is necessary to give Drupal an array $db_prefix which specifies the database holding any table that is not in the default (Drupal) database. Thus if CiviCRM data is stored in a database named abc_civicrm, we must provide Drupal with a $db_prefix array listing all tables in abc_civicrm: $db_prefix = array( 'civicrm_acl' => 'abc_civicrm.', 'civicrm_acl_cache' => 'abc_civicrm.', ...)
It should be fairly obvious that this array can be generated automatically by listing all of the tables in abc_civicrm, then generating an array element for each table. This can be easily done at any time, but would be a time consuming operation to perform on every page load! Better to generate the list once then regenerate it when the tables in the database change. There are a limited number of situations where CiviCRM adds a new table to the database, the most obvious being when a custom field is added. These fields are also prime candidates to display in a Drupal view.
It would be great to have a hook, say civicrm_schema_change or so, that was called whenever the database schema changed. This should be relatively infrequently, and thus would be the most efficient time to regenerate the $db_prefix array.