Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
creecros committed Oct 18, 2022
1 parent 29e80a3 commit 4c2ec10
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 14 deletions.
37 changes: 23 additions & 14 deletions Action/EmailTaskHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

class EmailTaskHistory extends Base
Expand Down Expand Up @@ -37,13 +38,18 @@ public function getEventRequiredParameters()
{
return array(
'task',
'comment',
//these are event parameters and the task close event does not have a comment parameter
);
}


public function doAction(array $data)
{
//here is where we will pull all the comments from a task using the same method in the TaskViewController, note we would need to add the user metadata model up above in "use"
$commentSortingDirection = $this->userMetadataCacheDecorator->get(UserMetadataModel::KEY_COMMENT_SORTING_DIRECTION, 'ASC');
$comments = $this->commentModel->getAll($data['task']['id'], $commentSortingDirection);

//Noticing you have are using a lot of undefined variables below, example $task, $project, $comments. I defined $comments above, and will fix the others
$historySent = FALSE;
if ($this->getParam('check_box_include_title') == true ){
$subject = $this->getParam('subject') . ": " . $data['task']['title'] . "(#" . $data['task']['id'] . ")";
Expand All @@ -62,20 +68,22 @@ public function doAction(array $data)
$user['email'],
$user['name'] ?: $user['username'],
$subject,
<?= $this->template->render('task_comments/show', array(
'task' => $task,
$this->template->render('task_comments/show', array(
'task' => $data['task'],
'comments' => $comments,
'project' => $project,
'project' => $this->projectModel->getById($data['task']['project_id']),
'editable' => false,
))
);
// Add comment to task to show an email has been fired
$this->commentModel->create( array(
'comment' => t('Task history emailed to "%s" with subject "%s".', $values['email'], $values['subject']),
'user_id' => $user,
'task_id' => $task['id'],
'comment' => t('Task history emailed to '.$user['username'].' with subject '. $subject),
'user_id' => $user['id'],
'task_id' => $data['task']['id'],
));
$historySent = TRUE;
//an easy way to test code is to use error_log, assuming you know how to check your error logs
error_log("I worked",0);
}
}
if ($send_to == 'creator' || $send_to == 'both') {
Expand All @@ -87,20 +95,21 @@ public function doAction(array $data)
$user['email'],
$user['name'] ?: $user['username'],
$subject,
<?= $this->template->render('task_comments/show', array(
'task' => $this->getTask(),
'comments' => $this->commentModel->getAll($task['id'], $commentSortingDirection),
'project' => $this->projectModel->getById($task['project_id']),
$this->template->render('task_comments/show', array(
'task' => $data['task'],
'comments' => $comments,
'project' => $this->projectModel->getById($data['task']['project_id']),
'editable' => false,
))
);
// Add comment to task to show an email has been fired
$this->commentModel->create( array(
'comment' => t('Task history emailed to "%s" with subject "%s".', $values['email'], $values['subject']),
'user_id' => $user,
'task_id' => $task['id'],
'comment' => t('Task history emailed to '.$user['username'].' with subject '. $subject),
'user_id' => $user['id'],
'task_id' => $data['task']['id'],
));
$historySent = TRUE;
error_log("I worked",0);
}
}
return $historySent;
Expand Down
50 changes: 50 additions & 0 deletions Plugin.php
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
<?php

namespace Kanboard\Plugin\KanboardEmailHistory;

use Kanboard\Core\Plugin\Base;
use Kanboard\Plugin\KanboardEmailHistory\Action\EmailTaskHistory;
use Kanboard\Core\Translator;

class Plugin extends Base

{

public function initialize()

{

$this->actionManager->register(new EmailTaskHistory($this->container));

}

public function onStartup()
{
Translator::load($this->languageModel->getCurrentLanguage(), __DIR__.'/Locale');
}


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

public function getPluginAuthor()
{
return 'aljawaid';
}

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

public function getPluginDescription()
{
return 'Action to email a tasks history on close';
}

public function getPluginHomepage()
{
return 'https://github.com/aljawaid/KanboardEmailHistory';
}
}

0 comments on commit 4c2ec10

Please sign in to comment.