Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding event handlers to extension modules
#1
I was reading the vtlib docs and came accross this code:

Code:
<?xml version="1.0" encoding=”utf-8”?>
<module>
<type>extension</type>
<name>MODULENAME</name>
<label>MODULE LABEL</label>
<parent>Tools</parent>
<version>1.0</version>
<dependencies>
<vtiger_version>5.1.0</vtiger_version>
</dependencies>
<tables>
<table>
<name>TABLE-NAME</name>
<sql><![CDATA[CREATE_TABLE_SQL]]></sql>
</table>
</tables>
<events>
<event>
<eventname>EVENT_NAME</eventname>
<classname>EVENT_HANDLER_CLASS</classname>
<filename>EVENT_HANDLER_CLASS_FILE</filename>
<condition><![CDATA[modulename in ['MODULENAME']]]></condition>
</event>
</events>
</module>

Where I see you can add event handlers in the manifest file of an extension module. But we could just as easily do it in the vtlib_handler class method of the main file right? So in modules/MyModuleName/MyModuleName.php I would create:

PHP Code:
    function vtlib_handler($modulename$event_type) {
        if(
$event_type == 'module.postinstall') {
            
// TODO Handle post installation actions
        
} else if($event_type == 'module.disabled') {
            
// TODO Handle actions when this module is disabled.
        
} else if($event_type == 'module.enabled') {
            
// TODO Handle actions when this module is enabled.
        
} else if($event_type == 'module.preuninstall') {
            
// TODO Handle actions when this module is about to be deleted.
        
} else if($event_type == 'module.preupdate') {
            
// TODO Handle actions before this module is updated.
        
} else if($event_type == 'module.postupdate') {
            
// TODO Handle actions after this module is updated.
        
}
    } 

Where I would do the event handler creation in the postinstall?
Reply
#2
Creating the event handler in the manifest file is equivalent to creating it in the vtlib_handler postinstall section. The manifest file gets executed on install of the module/extension and then the vtlib_handler postinstall section is invoked. So they are basically the same. The big difference is that vtlib_handler you can execute any code you want.
Joe
TSolucio
Reply
#3
Great, thanks. That's what I thought but nice to know for sure.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)