-
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.
Merge pull request #1522 from bakaphp/feat-user-customfield-worklfow
feat: new connector
- Loading branch information
Showing
3 changed files
with
100 additions
and
37 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
src/Domains/Connectors/Internal/Activities/UserCustomFieldActivity.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,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, | ||
]; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Domains/Connectors/Internal/Workflows/UserCustomFieldWorkflow.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 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; | ||
} | ||
} |