Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
42be508
Template sync proof of concept WIP
ryancooley May 15, 2023
aa40452
Prevent updating user editied default templates
sanjacornelius May 15, 2023
3d60da0
remove processTemplatesSeeder
sanjacornelius May 15, 2023
cb00548
create default template
sanjacornelius May 15, 2023
337b79a
Enable specifying specific variable/category for configuring settings.
sanjacornelius May 15, 2023
a0f7230
Remove default template fixtures
sanjacornelius May 16, 2023
a4ecfe5
Fix issue where process category was improperly set
sanjacornelius May 16, 2023
e1c5ba5
implement 'all' category option
sanjacornelius May 16, 2023
f84181f
Create migration to remove seeded templates
sanjacornelius May 16, 2023
c26afac
Create migration to remove seeded templates
sanjacornelius May 16, 2023
7d14478
Implement unitTest for TemplateSync
estebangallego May 17, 2023
9f13832
Add a daily scheduled command to sync default templates for ProcessMa…
sanjacornelius May 17, 2023
2d5b92d
Merge branch 'template-sync' of https://github.com/ProcessMaker/proce…
sanjacornelius May 17, 2023
c2eec76
Code Clean Up
sanjacornelius May 17, 2023
043d92d
Move unitTest to it's own PR
estebangallego May 17, 2023
2a5a93c
Add default template variables to phpUnit
estebangallego May 17, 2023
edb3cb4
Compare GitHub ProcessCount with Default templates
estebangallego May 17, 2023
0260add
Remove settings model
estebangallego May 17, 2023
d82c79e
Remove phpUnit env's for templates
estebangallego May 19, 2023
58d9224
Test only new added templates from the templates repo
estebangallego May 19, 2023
76b7536
Refactored testTemplateSync
estebangallego May 19, 2023
6016e52
Update phpunit.xml
estebangallego May 19, 2023
8791fa2
Update phpunit.xml
estebangallego May 19, 2023
1efb18b
Change function name
estebangallego May 19, 2023
dd582c5
Update ProcessTemplateTest.php
estebangallego May 22, 2023
f6c3e0c
Create processes from all templates test
estebangallego May 23, 2023
daf0dd3
Check all templates for all branches
estebangallego May 23, 2023
9afa2d4
Include DataSourceCategory factory to the test
estebangallego May 23, 2023
80cd6f1
Merge branch 'develop' into task/FOUR-8392
estebangallego May 24, 2023
6a066de
Refactor test
estebangallego May 24, 2023
3d5e7c4
fix typo
estebangallego May 24, 2023
445d866
Update conditional when checking for env variable
estebangallego May 25, 2023
ee4c46f
Remove .env conditional
estebangallego May 25, 2023
cc1591c
Merge branch 'develop' into template-sync
sanjacornelius May 26, 2023
c8394a2
Merge pull request #4794 from ProcessMaker/task/FOUR-8392
sanjacornelius May 31, 2023
d018d60
Merge branch 'develop' into template-sync
sanjacornelius Jun 9, 2023
04f4751
Merge branch 'develop' into template-sync
ryancooley Jun 13, 2023
ee15873
Merge branch 'develop' into template-sync
ryancooley Jun 13, 2023
3bbbe88
Merge branch 'develop' into template-sync
ryancooley Jun 15, 2023
31b95a1
Remove asset_type reference
sanjacornelius Jul 10, 2023
cefd404
Fix create process error
sanjacornelius Jul 10, 2023
e253c8c
Build
sanjacornelius Jul 10, 2023
1b3d702
Merge branch 'develop' into template-sync
sanjacornelius Jul 13, 2023
ce04f9a
cs fixer formatting
sanjacornelius Jul 13, 2023
3a374ad
Merge branch 'develop' into template-sync
sanjacornelius Jul 21, 2023
e921ed7
php cs fixer formatting
sanjacornelius Jul 21, 2023
8c9c0e7
sonar security compliance; Generate random delay
sanjacornelius Jul 21, 2023
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
51 changes: 51 additions & 0 deletions ProcessMaker/Console/Commands/SyncDefaultTemplates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace ProcessMaker\Console\Commands;

use Illuminate\Console\Command;
use ProcessMaker\Jobs\SyncDefaultTemplates as Job;

class SyncDefaultTemplates extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'processmaker:sync-default-templates
{--queue : Queue this command to run asynchronously}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Synchronize default templates from a central repository';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
if ($this->option('queue')) {
$randomDelay = random_int(10, 120);
Job::dispatch()->delay(now()->addMinutes($randomDelay));
} else {
Job::dispatchNow();
}

return 0;
}
}
4 changes: 4 additions & 0 deletions ProcessMaker/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\Artisan;
use ProcessMaker\Jobs\SyncDefaultTemplates;

class Kernel extends ConsoleKernel
{
Expand All @@ -30,6 +32,8 @@ protected function schedule(Schedule $schedule)

$schedule->command('package-data-sources:delete-logs')
->weekly();

$schedule->command('processmaker:sync-default-templates --queue')->daily();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion ProcessMaker/Events/AuthClientCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getData(): array
public function getChanges(): array
{
return [
'id' => $this->data['id']
'id' => $this->data['id'],
];
}

Expand Down
3 changes: 3 additions & 0 deletions ProcessMaker/Events/AuthClientUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ class AuthClientUpdated implements SecurityLogEventInterface
use FormatSecurityLogChanges;

private array $original;

private array $changes;

private string $clientId;

private string $clientName;

/**
Expand Down
6 changes: 3 additions & 3 deletions ProcessMaker/Events/CustomizeUiUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public function buildData()
if (isset($this->changes['variables'])) {
$varChanges = [];
$varOriginal = [];
foreach ((array)json_decode($this->changes['variables'], true) as $variable) {
foreach ((array) json_decode($this->changes['variables'], true) as $variable) {
$varChanges[$variable['title']] = $variable['value'];
}
foreach ((array)json_decode($this->original['variables'], true) as $variable) {
foreach ((array) json_decode($this->original['variables'], true) as $variable) {
$varOriginal[$variable['title']] = $variable['value'];
}
$varChanges = array_diff($varChanges, $varOriginal);
Expand All @@ -60,7 +60,7 @@ public function buildData()
'label' => 'Customize Ui',
'link' => route('customize-ui.edit'),
],
'last_modified' => Carbon::now()
'last_modified' => Carbon::now(),
],
$this->formatChanges($this->changes, $this->original)
);
Expand Down
2 changes: 1 addition & 1 deletion ProcessMaker/Events/PermissionUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function getData(): array
'label' => $userData->getAttribute('username'),
'link' => route('users.edit', $this->userId) . '#nav-profile',
],
'last_modified' => $userData->getAttribute('updated_at')
'last_modified' => $userData->getAttribute('updated_at'),
], $this->arrayPermissions);
}
}
Expand Down
2 changes: 1 addition & 1 deletion ProcessMaker/Events/ScreenUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ScreenUpdated implements SecurityLogEventInterface

public const REMOVE_KEYS = [
'screen_category_id',
'tmp_screen_category_id'
'tmp_screen_category_id',
];

/**
Expand Down
1 change: 1 addition & 0 deletions ProcessMaker/Events/ScriptCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ScriptCreated implements SecurityLogEventInterface
use FormatSecurityLogChanges;

private array $changes;

private string $categoryName = '';

private Script $script;
Expand Down
2 changes: 2 additions & 0 deletions ProcessMaker/Events/ScriptExecutorUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class ScriptExecutorUpdated implements SecurityLogEventInterface
use FormatSecurityLogChanges;

private array $changes;

private array $original;

private int $scriptId;

/**
Expand Down
2 changes: 1 addition & 1 deletion ProcessMaker/Events/ScriptUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ScriptUpdated implements SecurityLogEventInterface

public const REMOVE_KEYS = [
'script_category_id',
'tmp_script_category_id'
'tmp_script_category_id',
];

/**
Expand Down
3 changes: 2 additions & 1 deletion ProcessMaker/Events/SignalUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SignalUpdated implements SecurityLogEventInterface
use FormatSecurityLogChanges;

private array $changes;

private array $original;

/**
Expand All @@ -37,7 +38,7 @@ public function getData(): array
'label' => $this->changes['name'],
'link' => route('signals.edit', ['signalId' => $this->changes['id']]),
],
'last_modified' => Carbon::now()
'last_modified' => Carbon::now(),
], ArrayHelper::getArrayDifferencesWithFormat($this->changes, $this->original));
}

Expand Down
2 changes: 2 additions & 0 deletions ProcessMaker/Events/TemplateUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class TemplateUpdated implements SecurityLogEventInterface
use FormatSecurityLogChanges;

private array $changes;

private array $original;

private bool $processType;

/**
Expand Down
1 change: 1 addition & 0 deletions ProcessMaker/Events/TokenDeleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class TokenDeleted implements SecurityLogEventInterface
use Dispatchable;

private array $data;

private array $changes;

/**
Expand Down
2 changes: 1 addition & 1 deletion ProcessMaker/Events/UserUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getData(): array
'link' => route('users.edit', $this->user->getAttribute('id')) . '#nav-home',
],
'user_name' => $this->user->getAttribute('username'),
'last_modified' => $this->user->getAttribute('updated_at')
'last_modified' => $this->user->getAttribute('updated_at'),
], ArrayHelper::getArrayDifferencesWithFormat($this->changes, $this->original));
}

Expand Down
2 changes: 1 addition & 1 deletion ProcessMaker/Facades/MessageBrokerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* @see \ProcessMaker\Nayra\MessageBrokers\ServiceKafka
* @see \ProcessMaker\Nayra\MessageBrokers\ServiceRabbitMq
*
*
* @method static void connect()
* @method static void disconnect()
* @method static void sendMessage(string $subject, string $collaborationId, mixed $body)
Expand Down
4 changes: 3 additions & 1 deletion ProcessMaker/Helpers/ArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ public static function getArrayDifferencesWithFormat(array $changedArray, array
* @param string $newKey
* @return array
*/
public static function replaceKeyInArray(array $array, string $oldKey, string $newKey) {
public static function replaceKeyInArray(array $array, string $oldKey, string $newKey)
{
if (array_key_exists($oldKey, $array)) {
$array[$newKey] = $array[$oldKey];
unset($array[$oldKey]);
}

return $array;
}
}
4 changes: 2 additions & 2 deletions ProcessMaker/Http/Controllers/Api/SignalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public function store(Request $request)
SignalCreated::dispatch([
'id' => $newSignal->getId(),
'name' => $newSignal->getName(),
'detail' => $request->input('detail', '')
'detail' => $request->input('detail', ''),
]);

return response(['id' => $newSignal->getId(), 'name' => $newSignal->getName()], 200);
Expand Down Expand Up @@ -355,7 +355,7 @@ function ($carry, $process) {
// Register the Event
SignalDeleted::dispatch([
'id' => $signal->getId(),
'name' => $signal->getName()
'name' => $signal->getName(),
]);
}

Expand Down
1 change: 1 addition & 0 deletions ProcessMaker/Http/Controllers/Api/TemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function store(string $type, Request $request)
$request->validate(Template::rules($request->id, $this->types[$type][4]));
$storeTemplate = $this->template->store($type, $request);
TemplatePublished::dispatch($request->request->all());

return $storeTemplate;
}

Expand Down
2 changes: 1 addition & 1 deletion ProcessMaker/Jobs/RunNayraServiceTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RunNayraServiceTask implements ShouldQueue
public $tokenId;

public $attemptNum = 1;

/**
* Create a new job instance.
*
Expand Down
102 changes: 102 additions & 0 deletions ProcessMaker/Jobs/SyncDefaultTemplates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

namespace ProcessMaker\Jobs;

use Exception;
use Facades\ProcessMaker\JsonColumnIndex;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Http;
use ProcessMaker\ImportExport\Importer;
use ProcessMaker\ImportExport\Options;
use ProcessMaker\Models\ProcessCategory;
use ProcessMaker\Models\ProcessTemplates;

class SyncDefaultTemplates implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Execute the job.
* Function to handle the execution of this job when it is run.
* Here the function fetches default templates list from Github and saves them to the database.
* @return void
*/
public function handle()
{
$config = config('services.github');
$url = $config['base_url'] . $config['template_repo'] . '/' . $config['template_branch'] . '/index.json';

// If there are multiple categories of templates defined in the .env then separate them into an array.
$categories = (strpos($config['template_categories'], ',') !== false) ? explode(',', $config['template_categories']) : [$config['template_categories']];

$processCategoryId = ProcessCategory::firstOrCreate(
['name' => 'Default Templates'],
[
'name' => 'Default Templates',
'status' => 'ACTIVE',
'is_system' => 0,
]
)->getKey();

// Get the default template list from Github.
$response = Http::get($url);

if (!$response->successful()) {
throw new Exception('Unable to fetch default template list.');
}

// Extract the json data from the response and iterate over the categories and templates to retrieve them.
$data = $response->json();
foreach ($data as $templateCategory => $templates) {
if (!in_array($templateCategory, $categories) && !in_array('all', $categories)) {
continue;
}
foreach ($templates as $template) {
$existingTemplate = ProcessTemplates::where('uuid', $template['uuid'])->first();
// If the template already exists in the database with a user then skip it, since we don't want to overwrite their changes.
if (!is_null($existingTemplate) && !is_null($existingTemplate->user_id)) {
continue;
}

$url = $config['base_url'] . $config['template_repo'] . '/' . $config['template_branch'] . '/' . $template['relative_path'];
$response = Http::get($url);
if (!$response->successful()) {
throw new Exception("Unable to fetch default template {$template['name']}.");
}
$payload = $response->json();
data_set($payload, 'export.' . $payload['root'] . '.attributes.process_category_id', $processCategoryId);
$options = new Options([
'mode' => 'update',
'isTemplate' => true,
'saveAssetsMode' => 'saveAllAssets',
]);
$importer = new Importer($payload, $options);
$manifest = $importer->doImport();

$template = ProcessTemplates::where('uuid', $template['uuid'])->first();
$template->setRawAttributes([
'key' => 'default_templates',
'process_id' => null,
'user_id' => null,
'process_category_id' => $processCategoryId,
]);
$template->save();
}
}
}
}
1 change: 1 addition & 0 deletions ProcessMaker/Models/EnvironmentVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function getValueAttribute()
"\n" . $e->getMessage() .
"\n" . $e->getTraceAsString()
);

return null;
}
}
Expand Down
4 changes: 1 addition & 3 deletions ProcessMaker/Nayra/Managers/WorkflowManagerRabbitMq.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,7 @@ public function handleServiceTask(ProcessRequestToken $token, RunNayraServiceTas
'output' => $exception->getMessageForData($token),
];
$this->dispatchActionForServiceTask($version, $token, $response, $state, $userId);

} catch (Throwable $exception) {

$thisWasFinalAttempt = true;
if (isset($errorHandling)) {
$thisWasFinalAttempt = ($errorHandling->retryAttempts() === 0) || ($job->attemptNum >= $errorHandling->retryAttempts());
Expand All @@ -366,7 +364,7 @@ public function handleServiceTask(ProcessRequestToken $token, RunNayraServiceTas
Log::error($exception->getTraceAsString());

if ($thisWasFinalAttempt) {
// When the last
// When the last
$this->taskFailed($instance, $token, $exception->getMessage());
}
}
Expand Down
Loading