Generic DB callbacks
With the various changes for the Generic DB introduced in version 4.9 there also came the generic execution of callbacks, which can be registered dynamically. They mostly behave like the Chain system by executing an individual callback.
Event types
There are 9 different event types which can be handled with the generic execution.Â
Name of event | Description | Expected parameters |
---|---|---|
CREATE_BEFORE | Executed before an item is created. | none |
CREATE_FAILURE | Executed if item could not be created. | none |
CREATE_SUCCESS | Executed it item could be created successfully. | ID of created item |
STORE_BEFORE | Executed before store process is executed. | Item instance |
STORE_FAILURE | Executed if store process failed. This is also likely to happen if query would not change anything in database! | Item instance |
STORE_SUCCESS | Executed if store process saved the values in the database. | Item instance |
DELETE_BEFORE | Executed before deleting an item | ID of the item to delete |
DELETE_FAILURE | Executed if deletion of an item fails | ID of the item to delete |
DELETE_SUCCESS | Executed if item was deleted successfully. | ID of the item to delete |
Usage
Callbacks can be registered by using the static method "register" of the "cGenericDb" class.Â
The first parameter is the event name, which is stored as class constant. The second parameter is a valid callback, which is executed. The third parameter is the class name of the Item class, for which the callback should be registered.
Callbacks can only be unregistered at all for a single event in a class. Unregistering only one of multiple callbacks of a classes callback event is not supported yet.
// callback function would be "itemCreateHandler" cGenericDb::register(cGenericDb::CREATE_SUCCESS, 'itemCreateHandler', 'cApiArticle');  // callback function would be "executeCreateHandle" in the class "cCallbackHandler" cGenericDb::register(cGenericDb::CREATE_SUCCESS, 'cCallbackHandler::executeCreateHandle', 'cApiArticle');  // unregisters all "CREATE_SUCCESS" events from specified class cGenericDb::unregister(cGenericDb::CREATE_SUCCESS, 'cApiArticle');