Child pages
  • Generic DB callbacks
Skip to end of metadata
Go to start of metadata

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 eventDescriptionExpected parameters
CREATE_BEFOREExecuted before an item is created.none
CREATE_FAILUREExecuted if item could not be created.none
CREATE_SUCCESSExecuted it item could be created successfully.ID of created item
STORE_BEFOREExecuted before store process is executed.Item instance
STORE_FAILUREExecuted if store process failed.
This is also likely to happen if query would not change anything in database! 
Item instance
STORE_SUCCESSExecuted if store process saved the values in the database.Item instance
DELETE_BEFOREExecuted before deleting an itemID of the item to delete
DELETE_FAILUREExecuted if deletion of an item failsID of the item to delete
DELETE_SUCCESSExecuted 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.

Examples
// 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');