Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
FOUR-20673
  • Loading branch information
pmPaulis committed Jan 10, 2025
commit a51b103ceb49368f4bf7fd6f239e56036f3d43b8
1 change: 1 addition & 0 deletions ProcessMaker/Models/ProcessRequestToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class ProcessRequestToken extends ProcessMakerModel implements TokenInterface
'token_properties' => 'array',
'is_priority' => 'boolean',
'is_actionbyemail' => 'boolean',
'is_emailsent' => 'boolean',
];

/**
Expand Down
36 changes: 34 additions & 2 deletions ProcessMaker/Repositories/TokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function persistActivityActivated(ActivityInterface $activity, TokenInter
$dataManager = new DataManager();
$tokenData = $dataManager->getData($token);
$feel = new FeelExpressionEvaluator();
$evaluatedUsers = $selfServiceUsers ? $feel->render($selfServiceUsers, $tokenData) ?? null: [];
$evaluatedUsers = $selfServiceUsers ? $feel->render($selfServiceUsers, $tokenData) ?? null : [];
$evaluatedGroups = $selfServiceGroups ? $feel->render($selfServiceGroups, $tokenData) ?? null : [];

// If we have single values we put it inside an array
Expand Down Expand Up @@ -172,7 +172,10 @@ public function persistActivityActivated(ActivityInterface $activity, TokenInter
CaseUpdate::dispatchSync($request, $token);

if (!is_null($user)) {
// Review if the task has enable the action by email
$this->validateAndSendActionByEmail($activity, $token, $user->email);
// Review if the user has enable the email notification
$this->validateEmailUserNotification($token, $user);
}
$this->instanceRepository->persistInstanceUpdated($token->getInstance());
}
Expand All @@ -183,7 +186,6 @@ public function persistActivityActivated(ActivityInterface $activity, TokenInter
* @param ActivityInterface $activity
* @param TokenInterface $token
* @param string $to
* @param array $data
*
* @return void
*/
Expand Down Expand Up @@ -225,6 +227,36 @@ private function validateAndSendActionByEmail(ActivityInterface $activity, Token
}
}

/**
* Validate email configuration and send email
*
* @param User $user
*
* @return void
*/
private function validateEmailUserNotification(TokenInterface $token, User $user)
{
try {
Log::Info('User isEmailTaskEnable: ' . $user->email_task_notification);
// If the email task notification is checked in user profile
if ($user->email_task_notification && !empty($user->email)) {
$taskName = $token->element_name ?? '';
$data['some_data'] = '';
$configEmail['emailServer'] = 0; // Use the default email server
$configEmail['subject'] = $user->firstname . ' assigned you in ' . $taskName;
$configEmail['screenEmailRef'] = 0; // Define here the screen to use

// Send Email
return (new TaskActionByEmail())->sendAbeEmail($configEmail, $user->email, $data);
}
} catch (\Exception $e) {
// Catch and log the error
Log::error('Failed to validate and send action by email', [
'error' => $e->getMessage(),
]);
}
}

/**
* Get due Variable
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('process_request_tokens', function (Blueprint $table) {
$table->boolean('is_emailsent')->default(false);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('process_request_tokens', function (Blueprint $table) {
$table->dropColumn('is_emailsent');
});
}
};