From 778c9d82126560980d6473a708cd45c8ee0ba330 Mon Sep 17 00:00:00 2001
From: Frederic Guillot <fred@kanboard.net>
Date: Sun, 19 Feb 2017 12:00:35 -0500
Subject: Allow people to remove missing automatic actions

When an automatic action is installed from a plugin,
if the plugin is removed the automatic could stay
in the database if the user didn't remove manually
the automatic action.
---
 app/Controller/ActionCreationController.php |  5 +++--
 app/Core/Action/ActionManager.php           | 25 +++++++++++++++++--------
 app/Locale/bs_BA/translations.php           |  1 +
 app/Locale/cs_CZ/translations.php           |  1 +
 app/Locale/da_DK/translations.php           |  1 +
 app/Locale/de_DE/translations.php           |  1 +
 app/Locale/el_GR/translations.php           |  1 +
 app/Locale/es_ES/translations.php           |  1 +
 app/Locale/fi_FI/translations.php           |  1 +
 app/Locale/fr_FR/translations.php           |  1 +
 app/Locale/hu_HU/translations.php           |  1 +
 app/Locale/id_ID/translations.php           |  1 +
 app/Locale/it_IT/translations.php           |  1 +
 app/Locale/ja_JP/translations.php           |  1 +
 app/Locale/ko_KR/translations.php           |  1 +
 app/Locale/my_MY/translations.php           |  1 +
 app/Locale/nb_NO/translations.php           |  1 +
 app/Locale/nl_NL/translations.php           |  1 +
 app/Locale/pl_PL/translations.php           |  1 +
 app/Locale/pt_BR/translations.php           |  1 +
 app/Locale/pt_PT/translations.php           |  1 +
 app/Locale/ru_RU/translations.php           |  1 +
 app/Locale/sr_Latn_RS/translations.php      |  1 +
 app/Locale/sv_SE/translations.php           |  1 +
 app/Locale/th_TH/translations.php           |  1 +
 app/Locale/tr_TR/translations.php           |  1 +
 app/Locale/zh_CN/translations.php           |  1 +
 app/Template/action/index.php               | 10 +++++++++-
 28 files changed, 54 insertions(+), 11 deletions(-)

(limited to 'app')

diff --git a/app/Controller/ActionCreationController.php b/app/Controller/ActionCreationController.php
index 1629e68f..7fee58d1 100644
--- a/app/Controller/ActionCreationController.php
+++ b/app/Controller/ActionCreationController.php
@@ -59,7 +59,8 @@ class ActionCreationController extends BaseController
         $values = $this->request->getValues();
 
         if (empty($values['action_name']) || empty($values['project_id']) || empty($values['event_name'])) {
-            return $this->create();
+            $this->create();
+            return;
         }
 
         $action = $this->actionManager->getAction($values['action_name']);
@@ -72,7 +73,7 @@ class ActionCreationController extends BaseController
         $projects_list = $this->projectUserRoleModel->getActiveProjectsByUser($this->userSession->getId());
         unset($projects_list[$project['id']]);
 
-        return $this->response->html($this->template->render('action_creation/params', array(
+        $this->response->html($this->template->render('action_creation/params', array(
             'values' => $values,
             'action_params' => $action_params,
             'columns_list' => $this->columnModel->getList($project['id']),
diff --git a/app/Core/Action/ActionManager.php b/app/Core/Action/ActionManager.php
index aec9ef02..3a77084d 100644
--- a/app/Core/Action/ActionManager.php
+++ b/app/Core/Action/ActionManager.php
@@ -2,6 +2,7 @@
 
 namespace Kanboard\Core\Action;
 
+use Exception;
 use RuntimeException;
 use Kanboard\Core\Base;
 use Kanboard\Action\Base as ActionBase;
@@ -84,8 +85,12 @@ class ActionManager extends Base
         $params = array();
 
         foreach ($actions as $action) {
-            $currentAction = $this->getAction($action['action_name']);
-            $params[$currentAction->getName()] = $currentAction->getActionRequiredParameters();
+            try {
+                $currentAction = $this->getAction($action['action_name']);
+                $params[$currentAction->getName()] = $currentAction->getActionRequiredParameters();
+            } catch (Exception $e) {
+                $this->logger->error(__METHOD__.': '.$e->getMessage());
+            }
         }
 
         return $params;
@@ -127,14 +132,18 @@ class ActionManager extends Base
         }
 
         foreach ($actions as $action) {
-            $listener = clone $this->getAction($action['action_name']);
-            $listener->setProjectId($action['project_id']);
+            try {
+                $listener = clone $this->getAction($action['action_name']);
+                $listener->setProjectId($action['project_id']);
 
-            foreach ($action['params'] as $param_name => $param_value) {
-                $listener->setParam($param_name, $param_value);
-            }
+                foreach ($action['params'] as $param_name => $param_value) {
+                    $listener->setParam($param_name, $param_value);
+                }
 
-            $this->dispatcher->addListener($action['event_name'], array($listener, 'execute'));
+                $this->dispatcher->addListener($action['event_name'], array($listener, 'execute'));
+            } catch (Exception $e) {
+                $this->logger->error(__METHOD__.': '.$e->getMessage());
+            }
         }
 
         return $this;
diff --git a/app/Locale/bs_BA/translations.php b/app/Locale/bs_BA/translations.php
index 533dee1f..3da046d9 100644
--- a/app/Locale/bs_BA/translations.php
+++ b/app/Locale/bs_BA/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/cs_CZ/translations.php b/app/Locale/cs_CZ/translations.php
index cf941106..46427df9 100644
--- a/app/Locale/cs_CZ/translations.php
+++ b/app/Locale/cs_CZ/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/da_DK/translations.php b/app/Locale/da_DK/translations.php
index bcf6e43d..9d4d6a87 100644
--- a/app/Locale/da_DK/translations.php
+++ b/app/Locale/da_DK/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/de_DE/translations.php b/app/Locale/de_DE/translations.php
index 0ebc4a13..fda8b023 100644
--- a/app/Locale/de_DE/translations.php
+++ b/app/Locale/de_DE/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/el_GR/translations.php b/app/Locale/el_GR/translations.php
index 091c2675..d58d375e 100644
--- a/app/Locale/el_GR/translations.php
+++ b/app/Locale/el_GR/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/es_ES/translations.php b/app/Locale/es_ES/translations.php
index d400cd98..cd65f3be 100644
--- a/app/Locale/es_ES/translations.php
+++ b/app/Locale/es_ES/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/fi_FI/translations.php b/app/Locale/fi_FI/translations.php
index 6b77fd40..c8345a2d 100644
--- a/app/Locale/fi_FI/translations.php
+++ b/app/Locale/fi_FI/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/fr_FR/translations.php b/app/Locale/fr_FR/translations.php
index 5fc5e1cb..cf538fc9 100644
--- a/app/Locale/fr_FR/translations.php
+++ b/app/Locale/fr_FR/translations.php
@@ -1320,4 +1320,5 @@ return array(
     'Remove this user from group' => 'Enlever cet utilisateur du groupe',
     'Your project must have at least one active swimlane.' => 'Votre projet doit avoir au moins une swimlane active.',
     'Project: %s' => 'Projet : %s',
+    'Automatic action not found: "%s"' => 'Action automatique introuvable : « %s »',
 );
diff --git a/app/Locale/hu_HU/translations.php b/app/Locale/hu_HU/translations.php
index 76d04c15..a555c01e 100644
--- a/app/Locale/hu_HU/translations.php
+++ b/app/Locale/hu_HU/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/id_ID/translations.php b/app/Locale/id_ID/translations.php
index 0ab68d7b..84fda7ce 100644
--- a/app/Locale/id_ID/translations.php
+++ b/app/Locale/id_ID/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/it_IT/translations.php b/app/Locale/it_IT/translations.php
index e30f7696..f469748c 100644
--- a/app/Locale/it_IT/translations.php
+++ b/app/Locale/it_IT/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/ja_JP/translations.php b/app/Locale/ja_JP/translations.php
index 215c0838..7523986f 100644
--- a/app/Locale/ja_JP/translations.php
+++ b/app/Locale/ja_JP/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/ko_KR/translations.php b/app/Locale/ko_KR/translations.php
index ae2bcba1..8b37183c 100644
--- a/app/Locale/ko_KR/translations.php
+++ b/app/Locale/ko_KR/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/my_MY/translations.php b/app/Locale/my_MY/translations.php
index 9fb54c2f..5878ac18 100644
--- a/app/Locale/my_MY/translations.php
+++ b/app/Locale/my_MY/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/nb_NO/translations.php b/app/Locale/nb_NO/translations.php
index 7cc3b99b..dba51b02 100644
--- a/app/Locale/nb_NO/translations.php
+++ b/app/Locale/nb_NO/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/nl_NL/translations.php b/app/Locale/nl_NL/translations.php
index 795ad0bb..5fb19d35 100644
--- a/app/Locale/nl_NL/translations.php
+++ b/app/Locale/nl_NL/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/pl_PL/translations.php b/app/Locale/pl_PL/translations.php
index 704fb8cf..b3e02555 100644
--- a/app/Locale/pl_PL/translations.php
+++ b/app/Locale/pl_PL/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/pt_BR/translations.php b/app/Locale/pt_BR/translations.php
index 5694380e..b7a33138 100644
--- a/app/Locale/pt_BR/translations.php
+++ b/app/Locale/pt_BR/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/pt_PT/translations.php b/app/Locale/pt_PT/translations.php
index b211b2b4..a50c9204 100644
--- a/app/Locale/pt_PT/translations.php
+++ b/app/Locale/pt_PT/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/ru_RU/translations.php b/app/Locale/ru_RU/translations.php
index 1dcb8a43..bef9dbc3 100644
--- a/app/Locale/ru_RU/translations.php
+++ b/app/Locale/ru_RU/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/sr_Latn_RS/translations.php b/app/Locale/sr_Latn_RS/translations.php
index 6aa3cbf7..8b38e584 100644
--- a/app/Locale/sr_Latn_RS/translations.php
+++ b/app/Locale/sr_Latn_RS/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/sv_SE/translations.php b/app/Locale/sv_SE/translations.php
index 3e36175a..60af921c 100644
--- a/app/Locale/sv_SE/translations.php
+++ b/app/Locale/sv_SE/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/th_TH/translations.php b/app/Locale/th_TH/translations.php
index cf287ce5..e9647129 100644
--- a/app/Locale/th_TH/translations.php
+++ b/app/Locale/th_TH/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/tr_TR/translations.php b/app/Locale/tr_TR/translations.php
index 00ff0491..1b00621a 100644
--- a/app/Locale/tr_TR/translations.php
+++ b/app/Locale/tr_TR/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Locale/zh_CN/translations.php b/app/Locale/zh_CN/translations.php
index f84e5465..a513dccd 100644
--- a/app/Locale/zh_CN/translations.php
+++ b/app/Locale/zh_CN/translations.php
@@ -1320,4 +1320,5 @@ return array(
     // 'Remove this user from group' => '',
     // 'Your project must have at least one active swimlane.' => '',
     // 'Project: %s' => '',
+    // 'Automatic action not found: "%s"' => '',
 );
diff --git a/app/Template/action/index.php b/app/Template/action/index.php
index a889f588..a6fc70f9 100644
--- a/app/Template/action/index.php
+++ b/app/Template/action/index.php
@@ -26,11 +26,18 @@
                     </ul>
                 </div>
 
-                <?= $this->text->in($action['action_name'], $available_actions) ?>
+                <?php if (! isset($available_params[$action['action_name']])): ?>
+                    <?= $this->text->e($action['action_name']) ?>
+                <?php else: ?>
+                    <?= $this->text->in($action['action_name'], $available_actions) ?>
+                <?php endif ?>
             </th>
         </tr>
         <tr>
             <td>
+                <?php if (! isset($available_params[$action['action_name']])): ?>
+                    <p class="alert alert-error"><?= t('Automatic action not found: "%s"', $action['action_name']) ?></p>
+                <?php else: ?>
                 <ul>
                     <li>
                         <?= t('Event name') ?> =
@@ -61,6 +68,7 @@
                         </li>
                     <?php endforeach ?>
                 </ul>
+                <?php endif ?>
             </td>
         </tr>
         <?php endforeach ?>
-- 
cgit v1.2.3