[SOLVED] Plugin as CRON ... is it possible and if so: HOW?

Hi there again,
I would like to know, if it is possible to make a plugin, that is intended to act as a CRON-job.

So that it would be able to add new “modes” to the CLI-interface, thus enabling the plugin to be called via CLI to do something.

Is this possible, and if so, can anyone point out what exaclty would need to “declared” in Plugin.php

EDIT: Ooopps … looks like the answer is here.

Will give that a try … and maybe come back later if I’m stuck :slight_smile:

Looking forward to your answers,
Manfred

OK … looks like it is not as trivial as I hoped :frowning:

I started off with a very basic attempt, which (as expected) failed because it was apparently looking for a class MyCronAction

<?php

namespace Kanboard\Plugin\Cron_MyCronActions;

use Kanboard\Core\Plugin\Base;
use Kanboard\Plugin\Cron_MyCronActions\Console\MyCronAction;

class Plugin extends Base
{
    public function initialize()
    {
        // create new CLI-command
        $this->cli->add(new MyCronAction());
    }

    public function getPluginName()
    {
        return 'Cron_MyCronActions';
    }

    public function getPluginDescription()
    {
        return t('Add new cron-actions via plugin');
    }

    public function getPluginAuthor()
    {
        return 'Manfred Hoffmann';
    }

    public function getPluginVersion()
    {
        return '0.0.1';
    }

    public function getPluginHomepage()
    {
        return 'https://github.com/manne65-hd/Kanboard-Cron_MyCronActions';
    }
}
?>

Then I added that class in a new folder Console and made Plugin.php “aware” of it by adding a USE-statement …

<?php

namespace Kanboard\Plugin\Cron_MyCronActions\Console;

use Kanboard\Console\BaseCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * Class MyCronAction
 *
 */
class MyCronAction extends BaseCommand
{
    protected function configure()
    {
        $this
            ->setName('mycronaction')
            ->setDescription('Display "My Cron Action" on the console')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('My Cron Action');
    }
}

But now I get this ERROR:

Fatal error: Uncaught ArgumentCountError: Too few arguments to function Kanboard\Console\BaseCommand::__construct(), 0 passed in …

My skeleton is available here …

I’d be more than glad if anyone can help me, to get this basic attempt to work :slight_smile:

OK … I made some progress.

As you can see in the current version of my skeleton-plugin, I instantiated a new (empty ?) pimple-container and passed that as an argument to the cli-add-method.
Although it (partly) works now, I am still unaware, whether this is the way it’s meant to be done.

The other problem is, that I cannot use Kanboard’s core classes and methods, in my new “CLI-classes” because they are apparently a pimple-container that doesn’t seem to “know” anything about Kanboard’s classes and related methods.

Cann anyone shed some light on how I need to setup that pimple-container (or whatever else I need to do) in order to have access to Kanboard’s classes inside my custom “CLI-classes”

Please forgive me, if my terminology is completely wrong, but the level of abstraction that seems to be involved here, is still way ahead of my current understandings in OOP-programming.

Any help is much appreciated … thank in advance,
Manfred.

Here’s the initialize-function of my Plugin.php:

public function initialize()
{
    // create a new instance of pimple-container
    $container = new Container();

    // create new CLI-commands
    $this->cli->add(new MyCronAction($container));
    $this->cli->add(new MyOtherCronAction($container));
    $this->cli->add(new CreateTask($container));
}

So it looks like I actually figured it all out :smiley:

I have provided three “skeleton-plugins” to show how to generate a plugin that can act as a CLI-command (a.k.a CRON)

I would still be happy, to get any feedback on this :sunglasses: