Install Cronjobs on 5.2 programmatically

Hi guys

I can’t find documentation regarding how to install cronjobs using the new 5.2 Plugin System. Before, we had on Bootstrap the createCronJob(…) method available, but this is not available on \Shopware\Components\Plugin. What is the best way to do that using the new 5.2 PSystem?

Thanks.

 

Best

 In Your Plugin Class : 

$this->container->get('dbal_connection')->insert(
    's_crontab',
    [
        'name' => 'XXXX',
        'action' => 'Shopware_CronJob_XXXXXXXXXX', 
        'next' => new \DateTime(),
        'start' => null,
        '`interval`' => 60 * 5,
        'active' => true,
        'end' => new \DateTime(),
        'pluginID' => $context->getPlugin()->getId(),
    ],
    [
        'next' => 'datetime',
        'end' => 'datetime',
    ]
);

In your cronjob class

/**
* @return array
*/
public static function getSubscribedEvents()
{
    return [
        'Shopware_CronJob_XXXXXXXXXX' => 'execute'
    ];
}

 

1 „Gefällt mir“