-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/Domains/Connectors/Internal/Activities/GenerateMessageSlugActivity.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
]; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Domains/Connectors/Internal/Workflows/GenerateMessageSlugWorkflow.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |