Details
Description
- Add a new optional feature for modules to support an automation method that may be called at a given interval by Blesta cron
- Allow Input errors to be set? And if they are, include them in the cron log? Or simply assume the module will write errors to monolog?
- Add a new core cron task to call the automation method on all installed modules
Things to consider:
- Modules are much similar to plugins now, and differentiating them while merging similar features may require refactoring (something to do in a major release)
- Modules need database access. Loading the Record component may not suffice, and an instance of it may need to be provided instead
- Logging mechanisms may need to be provided to the module and its automation task
- Backward compatibility must be maintained
- Modules may need more flexibility with automation tasks, such as better support for running multiple tasks, or knowledge of the last time a particular task was last run (like a normal cron task). It would not have this information unless it creates database tables and maintains it itself.
- It may need to integrate similar install/upgrade/uninstall functionality as plugins
TODO:
- Update Modules to support a new method, cron($key), similar to plugins. Default to do nothing
- Refactor CronTasks and the `plugin_dir` column to support modules
- Add a `type` column, ENUM(system, plugin, module), default system, after `key`
- Rename the `plugin_dir` column to `dir`.
- Update the unique index for (`key`, `plugin_dir`) to (`key`, `type`, `dir`)
- Update for backward compatibility
- Update all returned objects to contain a 'plugin_dir' column. If `type` is 'plugin' then set 'plugin_dir' to the value of 'dir', otherwise null. TEST
- Update existing CronTasks methods and queries that use 'plugin_dir' to continue to work as before. TEST
- Add any new methods necessary to implement the same functionality on the new structure. Deprecate existing methods accordingly. TEST
- Update all core system calls to CronTasks to use the new methods. TEST
- (Create new tasks for each core plugin that uses cron tasks to update them accordingly)
- Add a new task when the cron runs for running module tasks, similar to plugin cron tasks. TEST
Consider allowing modules to create their own automation tasks. Such automation tasks could call methods within the module that registers the automation task to perform some action.
Or, maybe this could be abstracted such that there is a built in module automation task that calls such methods within each module on a regular basis so the module can perform such actions if it desires.
Requires some discussion
Why? Couldn't it call the module only? The module would be responsible for doing anything to services that need to be done. Maybe the module needs to perform some action and doesn't care about its services.
Whatever we do we need to maintain backwards compatibility. Allowing the module to register an automation task would be most flexible as Blesta would handle the scheduling automatically and the frequency or time the tasks run would be configurable in the standard place.
If database access cannot be granted without introducing a backwards incompatible change, perhaps a method in the core could be provided that allows the module to search/select/update related services. Maybe we don't want services to be able to perform any query under the sun, which could prove dangerous.