Cron Hook

Available Since: v1.1 (September 2009)

The hook_cron method opens a module class to interact with activities which are Schedule-able. The method has no parameters: CClass::hook_cron() (by comparison to implementations in some of the classes).

At the time of this writing, this is only used to modify update keys in the Contacts module, other modules - including Add Ons - could implement it also. One suggested area for use is the Event Queue and email reminders which are still implemented the old ways.

To enable this (and older Event Queue) within your system, set up a “cronjob” (on Linux, Unix, or OS X) or “Scheduled Task” (in Windows) to perform the following:

wget -O - -q http://{web2project installation}/queuescanner.php

Example

One such example of programmatically calling each of the active hooks within the system can be found in ./queuescanner.php (the code below is based on r420):

$AppUI = new CAppUI;
$AppUI->setUserLocale();
$moduleList = $AppUI->getLoadableModuleList();
foreach ($moduleList as $module) {
    include_once ($AppUI->getModuleClass($module['mod_directory']));
    $object = new $module['mod_main_class']();
    if (method_exists($object, 'hook_cron')) {
        $object->hook_cron();
    }
}

As of web2project v3.0, the Hook System is even easier. Here is the same example from the queuescanner.php:

$hooks = new w2p_Core_HookHandler($AppUI);
$hooks->process('cron');

To be specific, this code gets a list of all active modules in the system and loops over them. During the loop, this attempts to instantiate an object of that class and checks the object for the ‘hook_cron’ method. If the method exists, the system calls it. In this particular example, the results of calling the hook are not processed in any way. For sanity’s sake, a hook should return FALSE if an error occurred and TRUE or the result if the method executed successfully.

The primary benefit of this implementation is that as additional modules (Core or Add On) are added to the system and activated, there’s no further registration or configuration process. If the class implements the requested hook, it’s automatically added for process. If the class does not implement the hook, it is skipped as expected.

While there may be other drawbacks, the primary is the memory footprint required. If the underlying classes or methods are large or complex, it’s possible that PHP’s memory footprint could become quite large.


Step by step example of setting a Task scheduler job in WINDOWS environment:

After that, you should start receiving e-mails for the tasks which have the due/overdue date equal with the date you setup on step “g” - the 3rd interface of setting up a scheduled Task;

Note: in order for the reminders to properly work, there are also some settings to be performed;

On System Admin / System Configuration, settings are:

Tasks Section (last one) / Send Task Reminders: check box ON

/ Number of days warning for due tasks: must be set to at least 1

/ Maximum number of reminders to send: 100 (just an example);

Note: please take note as this last setting may conflict at your server with your maximum number of emails allowed to be sent daily from one account; if you have many users/notifications you may want to check this with your server administrator)

On System Admin / Default User Preferences, settings are:

/ Task Notification Method: Do not include task/event owner

/ Email Assignees: check box ON

Note: if you decide to include task/event owner on the notification you will receive the same Reminder twice, as you will be the task owner but also (by default) the assignee of the task; this option may work if you are only used to set tasks for other users without being an assignee on that tasks;

Note: Of course, the reminders and all messages are working if you previously set a proper e-mail account on your e-mail server; proper settings must be filled on System Admin / System Configuration / Email Settings section;


Available Hooks

Hooks are how we provide access to specific features and functionality in a standardized way. While no hooks are required in your custom module, they’re generally useful.

Available Since v3.0 (September 2013)

  • Workflow Hooks (pre-create, post-create, pre-delete, post-delete, pre-load, post-load, pre-store, post-store, pre-update, post-update)

Available Since v1.1 (September 2009)

  • Calendar Hook
  • Cron Hook
  • Search Hook