Skip to content

Commit 0fe471d

Browse files
authored
Merge pull request #7761 from ProcessMaker/FOUR-20266
FOUR-20266 Improve modifying exception messages in RunServiceTask
2 parents 10da31a + 389b1c3 commit 0fe471d

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

‎ProcessMaker/Jobs/RunServiceTask.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace ProcessMaker\Jobs;
44

5+
use Exception;
56
use Illuminate\Contracts\Queue\ShouldQueue;
67
use Illuminate\Support\Facades\Log;
78
use ProcessMaker\Exception\ConfigurationException;
@@ -127,8 +128,11 @@ public function action(ProcessRequestToken $token = null, ServiceTaskInterface $
127128
$error->setName($message);
128129

129130
$token->setProperty('error', $error);
130-
$exceptionClass = get_class($exception);
131-
$modifiedException = new $exceptionClass($message);
131+
if ($message !== $exception->getMessage()) {
132+
$modifiedException = new Exception($message, $exception->getCode(), $exception);
133+
} else {
134+
$modifiedException = $exception;
135+
}
132136
$token->logError($modifiedException, $element);
133137

134138
Log::error('Service task failed: ' . $implementation . ' - ' . $message);

‎tests/TestCase.php‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@
33
namespace Tests;
44

55
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
6-
use Illuminate\Database\DatabaseManager;
76
use Illuminate\Foundation\Testing\DatabaseTransactions;
87
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
98
use Illuminate\Support\Facades\Artisan;
109
use Illuminate\Support\Facades\Bus;
1110
use PDOException;
11+
use ProcessMaker\ImportExport\Importer;
12+
use ProcessMaker\ImportExport\Options;
1213
use ProcessMaker\Jobs\RefreshArtisanCaches;
1314
use ProcessMaker\Models\Process;
14-
use ProcessMaker\Models\ProcessRequest;
15-
use ProcessMaker\Models\ProcessRequestLock;
16-
use ProcessMaker\Models\SecurityLog;
17-
use ProcessMaker\Models\Setting;
1815

1916
abstract class TestCase extends BaseTestCase
2017
{
@@ -127,6 +124,30 @@ protected function createProcessFromBPMN(string $bpmnFile, array $attributes = [
127124
return Process::factory()->create(array_merge($data, $attributes));
128125
}
129126

127+
/**
128+
* Creates a Process instance from a JSON file.
129+
*
130+
* This method reads the specified JSON file, merges the provided attributes,
131+
* and creates a new Process instance.
132+
*
133+
* @param string $jsonFile The path to the JSON file containing the process definition.
134+
* @param array $attributes Additional attributes to merge into the process definition.
135+
* @return Process The created Process instance.
136+
*/
137+
protected function createProcessFromJSON(string $jsonFile, array $attributes = []): Process
138+
{
139+
$payload = json_decode(file_get_contents($jsonFile), true);
140+
$options = new Options([]);
141+
$importer = new Importer($payload, $options);
142+
$importer->previewImport();
143+
$manifest = $importer->doImport();
144+
$processId = $manifest[$payload['root']]->log['newId'];
145+
$process = Process::find($processId);
146+
$process->update($attributes);
147+
148+
return $process;
149+
}
150+
130151
/**
131152
* Connections transacts
132153
*

0 commit comments

Comments
 (0)