[SOLVED] Help creating new automatic action

Hi everyone :slight_smile:

I’m looking for some help to create a new automatic action based on comment.create event.
I have no idea why my action / event is never triggered…
Expected : move a task on specific swimlane when comment is added.

(Of course, automatic action is created from UI in my settings project :P)

Plugin.php :

$this->actionManager->register(new MoveTaskSwimlaneOnComment($this->container));
$this->eventManager->register(CommentModel::EVENT_CREATE, "Création d'un commentaire");

Action/MoveTaskSwimlaneOnComment.php :

<?php

namespace Kanboard\Plugin\devTestsPlugin\Action;

use Kanboard\Action\Base;
use Kanboard\Model\CommentModel;

class MoveTaskSwimlaneOnComment extends Base
{
    public function getDescription()
    {
        return t('Déplacer la tâche dans une swimlane lorsqu\'un commentaire est laissé');
    }

    public function getCompatibleEvents()
    {
        return array(
            CommentModel::EVENT_CREATE,
        );
    }

    public function getActionRequiredParameters()
    {
        return array(
            'swimlane_id' => t('Swimlane'),
        );
    }

    public function getEventRequiredParameters()
    {
        return array(
            'task_id',
        );
    }

    public function doAction(array $data)
    {
        $values = array(
            'id' => $data['task_id'],
            'swimlane_id' => $this->getParam('swimlane_id'),
        );

        return $this->taskModificationModel->update($values);
    }

    public function hasRequiredCondition(array $data)
    {
        return true;
    }
}

Nothing in apache logs, nothing with DEBUG, comment is created without triggering anything :frowning:
If you have any idea it could be great !

Thanks :slight_smile:

check your stderr logs for php errors… I see you using a model but it’s not in the “use”.

try adding:

use Kanboard\Model\TaskModificationModel;

or maybe just add:

use Kanboard\Model\TaskModel;

I cant remeber…its been awhile for me since I’ve actually done this.

Hi :slight_smile:
I enable all levels for logging and nothing in stderr logs (apache / system / php logs) :frowning: No warning, no errors.
These “use” aren’t required (I don’t use it on my others custom Action), but I tried to add these and… nothing :sob: :sob: :sob:

I played with it, and figured out the error.

change your code to:

{
    public function getDescription()
    {
        return t('Déplacer la tâche dans une swimlane lorsqu\'un commentaire est laissé');
    }

    public function getCompatibleEvents()
    {
        return array(
            CommentModel::EVENT_CREATE,
        );
    }

    public function getActionRequiredParameters()
    {
        return array(
            'swimlane_id' => t('Swimlane'),
        );
    }

    public function getEventRequiredParameters()
    {
        return array(
            'task',
        );
    }

    public function doAction(array $data)
    {
        $values = array(
            'id' => $data['task']['id'],
            'swimlane_id' => $this->getParam('swimlane_id'),
        );
        return $this->taskModificationModel->update($values);
    }

    public function hasRequiredCondition(array $data)
    {
        return true;
    }
}

comment event does not have task_id, which stopped the action.

and you were correct, there were no error messages, it simply stopped after getEventRequiredParameters

what i do to problem solve those no message errors, is place error_log messages in key areas to figure out where things stop, and then i can diagnose why. you can also use it to make sure you are getting expected results/values.

in this particular case, i placed an error_log in doAction, and because it would not trigger, i added one to the previous function, getEventRequiredParameters, which did trigger. That left only one possible error, the Event Parameter. Now from here, you can dive in and figure out what does exist, or does not, but I simply guessed from here, and it makes complete sense that task_id would not be a parameter in the comment event, so i went with what i know from previous actions using the comment event, and just changed it to task and adjusted accordingly.

hope that helps, sorry for my bad typing, but i am currently minus a left hand.

1 Like

That’s perfect !!! Thanks a lot !

I put some die(“HEY”) and die(var_dump($var)) EVERYWHERE without thinking for a second to use error_reporting !! :sob: :sob: :sob: :sob:

Also I didn’t notice that events have their own parameters… my bad !

Thanks a LOT for your help <3 Now I just have to adjust my pre-update Task hook :slight_smile: