From de791a3c0727d794ca7fecc2f72e2366321902ae Mon Sep 17 00:00:00 2001
From: Guillaume Heurtier <guillaume.heurtier@maarch.org>
Date: Tue, 14 Jan 2020 12:09:56 +0100
Subject: [PATCH] FEAT #10633 TIME 0:30 action reject visa back to redactor

---
 core/xml/actions_pages.xml                     |  4 ++--
 migration/19.12/1912.sql                       |  2 ++
 sql/data_fr.sql                                |  2 +-
 .../controllers/ActionMethodController.php     | 18 +++++++++++++++++-
 4 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/core/xml/actions_pages.xml b/core/xml/actions_pages.xml
index 695d06fa77a..ecd6709776f 100755
--- a/core/xml/actions_pages.xml
+++ b/core/xml/actions_pages.xml
@@ -281,7 +281,7 @@ An action page is described in a ACTIONPAGE tag :
         <LABEL>_REJECTION_WORKFLOW_REDACTOR</LABEL>
         <NAME>rejection_visa_redactor</NAME>
         <DESC>_REJECTION_WORKFLOW_REDACTOR_DESC</DESC>
-        <component>v1Action</component>
+        <component>rejectVisaBackToRedactorAction</component>
         <ORIGIN>module</ORIGIN>
         <MODULE>visa</MODULE>
         <FLAG_CREATE>false</FLAG_CREATE>
@@ -294,7 +294,7 @@ An action page is described in a ACTIONPAGE tag :
         <LABEL>_REJECTION_WORKFLOW_PREVIOUS</LABEL>
         <NAME>rejection_visa_previous</NAME>
         <DESC>_REJECTION_WORKFLOW_PREVIOUS_DESC</DESC>
-        <component>v1Action</component>
+        <component>rejectVisaBackToPreviousAction</component>
         <ORIGIN>module</ORIGIN>
         <MODULE>visa</MODULE>
         <FLAG_CREATE>false</FLAG_CREATE>
diff --git a/migration/19.12/1912.sql b/migration/19.12/1912.sql
index 973b39accf7..634bc5e96ec 100644
--- a/migration/19.12/1912.sql
+++ b/migration/19.12/1912.sql
@@ -88,6 +88,8 @@ DELETE FROM actions WHERE action_page = 'view' OR component = 'viewDoc';
 
 UPDATE actions SET component = 'rejectVisaBackToPrevious' WHERE action_page = 'rejection_visa_previous';
 UPDATE actions SET component = 'redirectInitiatorEntityAction' WHERE action_page = 'redirect_visa_entity';
+UPDATE actions SET component = 'rejectVisaBackToPreviousAction' WHERE action_page = 'rejection_visa_previous';
+UPDATE actions SET component = 'rejectVisaBackToRedactorAction' WHERE action_page = 'rejection_visa_redactor';
 
 
 /* FOLDERS */
diff --git a/sql/data_fr.sql b/sql/data_fr.sql
index f25df523f4a..9b5199372b3 100755
--- a/sql/data_fr.sql
+++ b/sql/data_fr.sql
@@ -996,7 +996,7 @@ INSERT INTO actions (id, keyword, label_action, id_status, is_system, action_pag
 INSERT INTO actions (id, keyword, label_action, id_status, is_system, action_page, history, component) VALUES (400, '', 'Envoyer un AR', '_NOSTATUS_', 'N', 'send_attachments_to_contact', 'Y', 'v1Action');
 INSERT INTO actions (id, keyword, label_action, id_status, is_system, action_page, history, component) VALUES (405, '', 'Viser le courrier', '_NOSTATUS_', 'N', 'confirm_status', 'Y', 'confirmAction');
 INSERT INTO actions (id, keyword, label_action, id_status, is_system, action_page, history, component) VALUES (407, '', 'Renvoyer pour traitement', 'COU', 'N', 'confirm_status', 'Y', 'confirmAction');
-INSERT INTO actions (id, keyword, label_action, id_status, is_system, action_page, history, component) VALUES (408, '', 'Refuser le visa et remonter le circuit', '_NOSTATUS_', 'N',  'rejection_visa_previous', 'N', 'rejectVisaBackToPrevious');
+INSERT INTO actions (id, keyword, label_action, id_status, is_system, action_page, history, component) VALUES (408, '', 'Refuser le visa et remonter le circuit', '_NOSTATUS_', 'N',  'rejection_visa_previous', 'N', 'rejectVisaBackToPreviousAction');
 INSERT INTO actions (id, keyword, label_action, id_status, is_system, action_page, history, component) VALUES (410, '', 'Transmettre la réponse signée', 'EENV', 'N', 'interrupt_visa', 'Y', 'v1Action');
 INSERT INTO actions (id, keyword, label_action, id_status, is_system, action_page, history, component) VALUES (414, '', 'Envoyer au parapheur', '_NOSTATUS_', 'N', 'send_to_visa', 'Y', 'v1Action');
 INSERT INTO actions (id, keyword, label_action, id_status, is_system, action_page, history, component) VALUES (416, '', 'Valider et poursuivre le circuit', '_NOSTATUS_', 'N', 'visa_workflow', 'Y', 'v1Action');
diff --git a/src/app/action/controllers/ActionMethodController.php b/src/app/action/controllers/ActionMethodController.php
index 3f314ad918f..e7ce9f2984b 100644
--- a/src/app/action/controllers/ActionMethodController.php
+++ b/src/app/action/controllers/ActionMethodController.php
@@ -54,6 +54,8 @@ class ActionMethodController
         'sendSignatureBookAction'               => 'sendSignatureBook',
         'rejectVisaBackToPrevious'              => 'rejectVisaBackToPrevious',
         'redirectInitiatorEntityAction'         => 'redirectInitiatorEntityAction',
+        'rejectVisaBackToPreviousAction'        => 'rejectVisaBackToPrevious',
+        'rejectVisaBackToRedactorAction'        => 'rejectVisaBackToRedactor',
         'noConfirmAction'                       => null
     ];
 
@@ -312,7 +314,7 @@ class ActionMethodController
                         'data' => [$listInstances[0]['listinstance_id']]
                     ]);
                     ResModel::update([
-                        'set'   => ['destination' => $resource['initiator']], 
+                        'set'   => ['destination' => $resource['initiator']],
                         'where' => ['res_id = ?'],
                         'data'  => [$args['resId']]
                     ]);
@@ -421,4 +423,18 @@ class ActionMethodController
 
         return true;
     }
+
+    public static function rejectVisaBackToRedactor(array $args)
+    {
+        ValidatorModel::notEmpty($args, ['resId']);
+        ValidatorModel::intVal($args, ['resId']);
+
+        ListInstanceModel::update([
+            'set'   => ['process_date' => null],
+            'where' => ['res_id = ?', 'difflist_type = ?'],
+            'data'  => [$args['resId'], 'VISA_CIRCUIT']
+        ]);
+
+        return true;
+    }
 }
-- 
GitLab