Install
public function install(int $id) : void
Fires while creating a new cron job.
Description
If you need to perform a routine upon cron installation, you should attach the Installable interface to the cron job class. This technique exposes 2 new methods to handle the installation and the uninstallation. This is useful when you need to track something whenever the cron job is executed. The Installable interface is part of the E4J\VikRestaurants\Cron namespace.
It is possible to use the $id argument to make the tracking system unique, as the same type of cron job can be created multiple times.
For example, if you need to check whether a reservation has been tracked or not, you might consider adding a new column (e.g. mycron_exec_tracked) to the table. However, if you create another instance of the same cron job, this would lead to a conflict because the column would already exist.
For this reason, it is recommended to always append the $id to the end of the column name.
Parameters
- $id
-
(int) The cron job unique ID (primary key).
Return Value
None.
Example
/**
* @inheritDoc
*
* @see Installable
*/
public function install(int $id)
{
$db = \JFactory::getDbo();
// install a new column to track all the fetched reservation
$db->setQuery("ALTER TABLE `#__vikrestaurants_reservation` ADD COLUMN `cron_exec_tracked_{$id}` tinyint(1) DEFAULT 0");
$db->execute();
}