Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
73 changes: 73 additions & 0 deletions ProcessMaker/Events/TemplatePublished.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace ProcessMaker\Events;

use Carbon\Carbon;
use Illuminate\Foundation\Events\Dispatchable;
use ProcessMaker\Contracts\SecurityLogEventInterface;
use ProcessMaker\Models\ProcessCategory;

class TemplatePublished implements SecurityLogEventInterface
{
use Dispatchable;

private array $newTemplate;

/**
* Create a new event instance.
*
* @return void
*/
public function __construct(array $newTemplate)
{
$this->newTemplate = $newTemplate;

if (isset($newTemplate['process_category_id'])) {
$this->newTemplate['process_category'] = ProcessCategory::getNamesByIds(
$newTemplate['process_category_id']
);
unset($newTemplate['process_category_id']);
}
}

/**
* Get specific data related to the event
*
* @return array
*/
public function getData(): array
{
return [
'name' => [
'label' => $this->newTemplate['name'],
'link' => route('processes.index') . '#nav-templates',
],
'description' => $this->newTemplate['description'] ?? '',
'save assets mode' => $this->newTemplate['saveAssetsMode'] ?? '',
'Template Categories' => $this->newTemplate['process_category'] ?? '',
'created_at' => $this->newTemplate['created_at'] ?? Carbon::now(),
];
}

/**
* Get specific changes without format related to the event
*
* @return array
*/
public function getChanges(): array
{
return [
'id' => $this->newTemplate['asset_id'] ?? '',
];
}

/**
* Get the Event name with the syntax ‘[Past-test Action] [Object]’
*
* @return string
*/
public function getEventName(): string
{
return 'TemplatePublished';
}
}
6 changes: 4 additions & 2 deletions ProcessMaker/Http/Controllers/Api/TemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Http\Request;
use ProcessMaker\Events\ProcessCreated;
use ProcessMaker\Events\TemplateDeleted;
use ProcessMaker\Events\TemplatePublished;
use ProcessMaker\Events\TemplateUpdated;
use ProcessMaker\Http\Controllers\Controller;
use ProcessMaker\Http\Resources\TemplateCollection;
Expand Down Expand Up @@ -67,8 +68,9 @@ public function store(string $type, Request $request)
], 409);
}
$request->validate(Template::rules($request->id, $this->types[$type][4]));

return $this->template->store($type, $request);
$storeTemplate = $this->template->store($type, $request);
TemplatePublished::dispatch($request->request->all());
return $storeTemplate;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions ProcessMaker/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use ProcessMaker\Events\SignalUpdated;
use ProcessMaker\Events\TemplateCreated;
use ProcessMaker\Events\TemplateDeleted;
use ProcessMaker\Events\TemplatePublished;
use ProcessMaker\Events\TemplateUpdated;
use ProcessMaker\Events\TokenCreated;
use ProcessMaker\Events\TokenDeleted;
Expand Down Expand Up @@ -141,6 +142,7 @@ public function boot()
$this->app['events']->listen(SignalUpdated::class, SecurityLogger::class);
$this->app['events']->listen(TemplateCreated::class, SecurityLogger::class);
$this->app['events']->listen(TemplateDeleted::class, SecurityLogger::class);
$this->app['events']->listen(TemplatePublished::class, SecurityLogger::class);
$this->app['events']->listen(TemplateUpdated::class, SecurityLogger::class);
$this->app['events']->listen(TokenCreated::class, SecurityLogger::class);
$this->app['events']->listen(TokenDeleted::class, SecurityLogger::class);
Expand Down