Skip to content

Commit

Permalink
feat : message workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
kaioken committed Jul 21, 2024
1 parent 1b28988 commit 6816d07
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Kanvas\Connectors\Internal\Activities;

use Baka\Contracts\AppInterface;
use Baka\Support\Str;
use Baka\Traits\KanvasJobsTrait;
use Illuminate\Database\Eloquent\Model;
use Kanvas\Workflow\Contracts\WorkflowActivityInterface;
use Workflow\Activity;

class GenerateMessageSlugActivity extends Activity implements WorkflowActivityInterface
{
use KanvasJobsTrait;
public $tries = 10;

public function execute(Model $message, AppInterface $app, array $params): array
{
$this->overwriteAppService($app);

$slugField = $params['field'] ?? null;

if ($slugField === null) {
return ['No field configured to generate slug'];
}

$fieldToSlug = $message->message[$slugField] ?? null;

if ($fieldToSlug === null) {
return ['No slug field {' . $slugField . ' found in message ' . $message->id];
}

$message->slug = Str::simpleSlug($fieldToSlug);
$message->saveOrFail();

return [
'message' => $message->id,
'slug' => $message->slug,
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Kanvas\Connectors\Internal\Workflows;

use Baka\Contracts\AppInterface;
use Generator;
use Kanvas\Connectors\Internal\Activities\GenerateMessageSlugActivity;
use Kanvas\Social\Messages\Models\Message;
use Workflow\ActivityStub;
use Workflow\Workflow;

class GenerateMessageSlugWorkflow extends Workflow
{
public function execute(AppInterface $app, Message $message, array $params): Generator
{
$result = yield ActivityStub::make(GenerateMessageSlugActivity::class, $app, $message, $params);

return $result;
}
}

0 comments on commit 6816d07

Please sign in to comment.