How to create own cron-job in extension

Discussion in 'General discussions' started by test, May 15, 2019.

  1. test

    test New Member

    Joined:
    Nov 28, 2018
    Messages:
    2
    Likes Received:
    0
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    How to override send-campaign command with ourself command. Maybe there are some possibility to kill core command and make own, and then when the cron job is running, it will work with own Class in extension not from the core.
     
  2. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,048
    Likes Received:
    2,344
    @test - That is totally possible!

    I advise you to extend the send-campaigns command instead of replacing it entirely.

    Easiest way to do this is:
    1. Create a file called MySendCampaignsCommand.php in apps/console/commands/ folder.
    2. The file should have this content at least:
    PHP:
    <?php defined('MW_PATH') || exit('No direct script access allowed');

    if ( ! 
    class_exists'SendCampaignsCommand'false ) ) {
        require_once 
    __DIR__ '/SendCampaignsCommand.php';
    }

    class 
    MySendCampaignsCommand extends SendCampaignsCommand
    {
       
    }
    And inside the class you can override any functionality inherited from the original SendCampaignsCommand file.

    Now, in order to make use of this code in your cron job, instead of calling send-campaigns call mysendcampaigns.
    That's it.
     

Share This Page