2

In an extension, what is the best way to create a DB table that has a matching logging table? Do we just have to literally create a matching new table with triggers?

There must be a better way?

3 Answers 3

1

I happen to be doing this in an extension at the moment... I had the table created normally and stuck

  // Make sure the log table is created if required
  $schema = new CRM_Logging_Schema();
  $schema->fixSchemaDifferences();

at the end of the civicrm_enable hook. Unless I take care of this, if I install the extension with logging already enabled and try to create one of my new entity with drush right away, I get an error about the log table not existing.

3

Per Lobo's comment - the logging triggers & tables are automatically created. But, from experience sometimes you have to turn logging off & on to get the tables created. The triggers seem to create & cause lots of errors which stop when you turn logging off & on.

Obviously the function called by turning logging on is more thorough than the enable extension function

1

All tables that start with "civicrm_" are logged. tables with _temp and _cache in their names are skipped (and a few other tables).

You can check the code at CRM/Logging/Schema.php

Might be good to consider using hook(s) in multiple places so extensions can add to the list of tables to be logged and excluded

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.