Skip to content

Instantly share code, notes, and snippets.

@torbentschechne
Last active March 2, 2017 08:34
Show Gist options
  • Save torbentschechne/6d0be285cdd6fd16af7d1b45ac52c178 to your computer and use it in GitHub Desktop.
Save torbentschechne/6d0be285cdd6fd16af7d1b45ac52c178 to your computer and use it in GitHub Desktop.
Shopware 5.2 - register cron with plugin
/**
* Valid for SW 5.2 - 5.2.14
* Since 5.2.15 cronjob.xml can be used https://developers.shopware.com/developers-guide/plugin-system/#plugin-cronjob
*/
public static function getSubscribedEvents() {
return [
'Shopware_CronJob_ReminderMail' => 'onCronRun'
];
}
/**
* install method
* @param InstallContext $context
*/
public function install(InstallContext $context) {
parent::install($context);
$this->addCron();
}
/**
* uninstall method
* @param InstallContext $context
* @return boolean
*/
public function uninstall(UninstallContext $context) {
parent::uninstall($context);
$this->removeCron();
}
public function addCron()
{
$connection = $this->container->get('dbal_connection');
$connection->insert(
's_crontab',
[
'name' => 'ReminderMail',
'action' => 'ReminderMail',
'next' => new \DateTime(),
'start' => null,
'`interval`' => '900',
'active' => 1,
'end' => new \DateTime(),
'pluginID' => null
],
[
'next' => 'datetime',
'end' => 'datetime',
]
);
}
public function removeCron()
{
$this->container->get('dbal_connection')->executeQuery('DELETE FROM s_crontab WHERE `name` = ?', [
'ReminderMail'
]);
}
public function onCronRun(\Shopware_Components_Cron_CronJob $job) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment