Skip to content

Commit

Permalink
Merge pull request #1522 from bakaphp/feat-user-customfield-worklfow
Browse files Browse the repository at this point in the history
feat: new connector
  • Loading branch information
kaioken authored Jun 16, 2024
2 parents 704463d + 0dc639a commit 6e94a39
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 37 deletions.
75 changes: 38 additions & 37 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Kanvas\Connectors\Internal\Activities;

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

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

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

$customField = $params['customField'] ?? null;

if (! $customField) {
return ['No custom field configured to set for user'];
}

//set custom field to user
foreach ($customField as $key => $value) {
$value = $value['value'] ?? null;
$isPublic = $value['is_public'] ?? false;
$user->set($key, $value, $isPublic);
}

return [
'user_id' => $user->getId(),
'custom_field' => $customField,
];
}
}
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 Baka\Users\Contracts\UserInterface;
use Generator;
use Kanvas\Connectors\Internal\Activities\UserCustomFieldActivity;
use Workflow\ActivityStub;
use Workflow\Workflow;

class UserCustomFieldWorkflow extends Workflow
{
public function execute(AppInterface $app, UserInterface $user, array $params): Generator
{
$result = yield ActivityStub::make(UserCustomFieldActivity::class, $app, $user, $params);

return $result;
}
}

0 comments on commit 6e94a39

Please sign in to comment.