@@ -179,10 +179,6 @@ public function persistActivityActivated(ActivityInterface $activity, TokenInter
179179 if (!is_null ($ user )) {
180180 // Review if the task has enable the action by email
181181 $ this ->validateAndSendActionByEmail ($ activity , $ token , $ user ->email );
182- // Review if the user has enable the email notification
183- $ isEmailTaskValid = $ this ->validateEmailUserNotification ($ token , $ user );
184- // Define the flag if the email needs to sent
185- $ token ->is_emailsent = $ isEmailTaskValid ? 1 : 0 ;
186182 }
187183 $ this ->instanceRepository ->persistInstanceUpdated ($ token ->getInstance ());
188184 }
@@ -234,75 +230,6 @@ private function validateAndSendActionByEmail(ActivityInterface $activity, Token
234230 }
235231 }
236232
237- /**
238- * Validates the user's email notification settings and sends an email if enabled.
239- *
240- * @param TokenInterface $token The token containing task information.
241- * @param User $user The user to whom the email notification will be sent.
242- * @return mixed|null Returns the result of the email sending operation or null if not sent.
243- */
244- private function validateEmailUserNotification (TokenInterface $ token , User $ user )
245- {
246- try {
247- Log::Info ('User isEmailTaskEnable: ' . $ user ->email_task_notification );
248- // Return if email task notification is not enabled or email is empty
249- if ($ user ->email_task_notification === 0 || empty ($ user ->email )) {
250- return null ;
251- }
252- // Check if the required class exists
253- if (!class_exists ('ProcessMaker\Packages\Connectors\ActionsByEmail\EmailProvider ' )) {
254- return null ;
255- }
256- // Prepare data for the email
257- $ data = $ this ->prepareEmailData ($ token , $ user );
258-
259- // Send Email
260- return (new TaskActionByEmail ())->sendAbeEmail ($ data ['configEmail ' ], $ user ->email , $ data ['emailData ' ]);
261- } catch (\Exception $ e ) {
262- // Catch and log the error
263- Log::error ('Failed to validate and send email task notification ' , [
264- 'error ' => $ e ->getMessage (),
265- ]);
266- }
267- }
268-
269- /**
270- * Prepares the email data and configuration for sending an email notification.
271- *
272- * @param TokenInterface $token The token containing task information.
273- * @param User $user The user for whom the email data is being prepared.
274- * @return array An associative array containing 'emailData' and 'configEmail'.
275- */
276- private function prepareEmailData (TokenInterface $ token , User $ user )
277- {
278- // Get the case
279- $ caseTitle = ProcessRequest::where ('id ' , $ token ->process_request_id )->value ('case_title ' );
280- // Prepare the email data
281- $ taskName = $ token ->element_name ?? '' ;
282- $ emailData = [
283- 'firstname ' => $ user ->firstname ?? '' ,
284- 'assigned_by ' => Auth::user ()->fullname ?? __ ('System ' ),
285- 'element_name ' => $ taskName ,
286- 'case_title ' => $ caseTitle , // Populate this if needed
287- 'due_date ' => $ token ->due_at ?? '' ,
288- 'link_review_task ' => config ('app.url ' ) . '/ ' . 'tasks/ ' . $ token ->id . '/edit ' ,
289- 'imgHeader ' => config ('app.url ' ) . '/img/processmaker_login.png ' ,
290- ];
291- // Get the screen by key
292- $ screen = Screen::getScreenByKey ('default-email-task-notification ' );
293- // Prepare the email configuration
294- $ configEmail = [
295- 'emailServer ' => 0 , // Use the default email server
296- 'subject ' => "{$ user ->firstname } assigned you in ' {$ taskName }' " ,
297- 'screenEmailRef ' => $ screen ->id ?? 0 , // Define here the screen to use
298- ];
299-
300- return [
301- 'emailData ' => $ emailData ,
302- 'configEmail ' => $ configEmail ,
303- ];
304- }
305-
306233 /**
307234 * Get due Variable
308235 *
0 commit comments