Skip to content

Commit c992cee

Browse files
author
Tyler King
authored
Fix to remove job class from arguments passed to job (gnikyt#623)
* Fix to remove job class from arguments passed to job, issues with serialization occurs * StyleCI fixes
1 parent 2a60b23 commit c992cee

File tree

5 files changed

+25
-60
lines changed

5 files changed

+25
-60
lines changed

src/ShopifyApp/Actions/DispatchScripts.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,18 @@ class DispatchScripts
2727
*/
2828
protected $jobClass;
2929

30-
/**
31-
* The action to handle the job.
32-
*
33-
* @var callable
34-
*/
35-
protected $actionClass;
36-
3730
/**
3831
* Setup.
3932
*
40-
* @param IShopQuery $shopQuery The querier for the shop.
41-
* @param string $jobClass The job to dispatch.
42-
* @param callable $actionClass The action to handle the job.
33+
* @param IShopQuery $shopQuery The querier for the shop.
34+
* @param string $jobClass The job to dispatch.
4335
*
4436
* @return void
4537
*/
46-
public function __construct(IShopQuery $shopQuery, string $jobClass, callable $actionClass)
38+
public function __construct(IShopQuery $shopQuery, string $jobClass)
4739
{
4840
$this->shopQuery = $shopQuery;
4941
$this->jobClass = $jobClass;
50-
$this->actionClass = $actionClass;
5142
}
5243

5344
/**
@@ -74,13 +65,11 @@ public function __invoke(ShopId $shopId, bool $inline = false): bool
7465
if ($inline) {
7566
($this->jobClass)::dispatchNow(
7667
$shop->getId(),
77-
$this->actionClass,
7868
$scripttags
7969
);
8070
} else {
8171
($this->jobClass)::dispatch(
8272
$shop->getId(),
83-
$this->actionClass,
8473
$scripttags
8574
)->onQueue($this->getConfig('job_queues')['scripttags']);
8675
}

src/ShopifyApp/Actions/DispatchWebhooks.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,18 @@ class DispatchWebhooks
2727
*/
2828
protected $jobClass;
2929

30-
/**
31-
* The action to handle the job.
32-
*
33-
* @var callable
34-
*/
35-
protected $actionClass;
36-
3730
/**
3831
* Setup.
3932
*
40-
* @param IShopQuery $shopQuery The querier for the shop.
41-
* @param string $jobClass The job to dispatch.
42-
* @param callable $actionClass The action to handle the job.
33+
* @param IShopQuery $shopQuery The querier for the shop.
34+
* @param string $jobClass The job to dispatch.
4335
*
4436
* @return void
4537
*/
46-
public function __construct(IShopQuery $shopQuery, string $jobClass, callable $actionClass)
38+
public function __construct(IShopQuery $shopQuery, string $jobClass)
4739
{
4840
$this->shopQuery = $shopQuery;
4941
$this->jobClass = $jobClass;
50-
$this->actionClass = $actionClass;
5142
}
5243

5344
/**
@@ -74,13 +65,11 @@ public function __invoke(ShopId $shopId, bool $inline = false): bool
7465
if ($inline) {
7566
($this->jobClass)::dispatchNow(
7667
$shop->getId(),
77-
$this->actionClass,
7868
$webhooks
7969
);
8070
} else {
8171
($this->jobClass)::dispatch(
8272
$shop->getId(),
83-
$this->actionClass,
8473
$webhooks
8574
)->onQueue($this->getConfig('job_queues')['webhooks']);
8675
}

src/ShopifyApp/Messaging/Jobs/ScripttagInstaller.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Foundation\Bus\Dispatchable;
88
use Illuminate\Queue\InteractsWithQueue;
99
use Illuminate\Queue\SerializesModels;
10+
use Osiset\ShopifyApp\Actions\CreateScripts as CreateScriptsAction;
1011
use Osiset\ShopifyApp\Objects\Values\ShopId;
1112

1213
/**
@@ -26,13 +27,6 @@ class ScripttagInstaller implements ShouldQueue
2627
*/
2728
protected $shopId;
2829

29-
/**
30-
* Action for creating scripttags.
31-
*
32-
* @var string
33-
*/
34-
protected $createScriptsAction;
35-
3630
/**
3731
* The scripts to add.
3832
*
@@ -43,28 +37,28 @@ class ScripttagInstaller implements ShouldQueue
4337
/**
4438
* Create a new job instance.
4539
*
46-
* @param ShopId $shopId The shop ID.
47-
* @param string $createScriptsAction Action for creating scripttags.
48-
* @param array $configScripts The scripts to add.
40+
* @param ShopId $shopId The shop ID.
41+
* @param array $configScripts The scripts to add.
4942
*
5043
* @return void
5144
*/
52-
public function __construct(ShopId $shopId, callable $createScriptsAction, array $configScripts)
45+
public function __construct(ShopId $shopId, array $configScripts)
5346
{
5447
$this->shopId = $shopId;
55-
$this->createScriptsAction = $createScriptsAction;
5648
$this->configScripts = $configScripts;
5749
}
5850

5951
/**
6052
* Execute the job.
6153
*
54+
* @param CreateScriptsAction $createScriptsAction The action for creating scripttags.
55+
*
6256
* @return array
6357
*/
64-
public function handle(): array
58+
public function handle(CreateScriptsAction $createScriptsAction): array
6559
{
6660
return call_user_func(
67-
$this->createScriptsAction,
61+
$createScriptsAction,
6862
$this->shopId,
6963
$this->configScripts
7064
);

src/ShopifyApp/Messaging/Jobs/WebhookInstaller.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Foundation\Bus\Dispatchable;
88
use Illuminate\Queue\InteractsWithQueue;
99
use Illuminate\Queue\SerializesModels;
10+
use Osiset\ShopifyApp\Actions\CreateWebhooks as CreateWebhooksAction;
1011
use Osiset\ShopifyApp\Objects\Values\ShopId;
1112

1213
/**
@@ -18,20 +19,14 @@ class WebhookInstaller implements ShouldQueue
1819
use InteractsWithQueue;
1920
use Queueable;
2021
use SerializesModels;
22+
2123
/**
2224
* The shop's ID.
2325
*
2426
* @var int
2527
*/
2628
protected $shopId;
2729

28-
/**
29-
* Action for creating webhooks.
30-
*
31-
* @var callable
32-
*/
33-
protected $createWebhooksAction;
34-
3530
/**
3631
* The webhooks to add.
3732
*
@@ -42,28 +37,28 @@ class WebhookInstaller implements ShouldQueue
4237
/**
4338
* Create a new job instance.
4439
*
45-
* @param ShopId $shopId The shop ID.
46-
* @param string $createWebhooksAction Action for creating webhooks.
47-
* @param array $configWebhooks The webhooks to add.
40+
* @param ShopId $shopId The shop ID.
41+
* @param array $configWebhooks The webhooks to add.
4842
*
4943
* @return void
5044
*/
51-
public function __construct(ShopId $shopId, callable $createWebhooksAction, array $configWebhooks)
45+
public function __construct(ShopId $shopId, array $configWebhooks)
5246
{
5347
$this->shopId = $shopId;
54-
$this->createWebhooksAction = $createWebhooksAction;
5548
$this->configWebhooks = $configWebhooks;
5649
}
5750

5851
/**
5952
* Execute the job.
6053
*
54+
* @param CreateWebhooksAction $createWebhooksAction The action for creating webhooks.
55+
*
6156
* @return array
6257
*/
63-
public function handle(): array
58+
public function handle(CreateWebhooksAction $createWebhooksAction): array
6459
{
6560
return call_user_func(
66-
$this->createWebhooksAction,
61+
$createWebhooksAction,
6762
$this->shopId,
6863
$this->configWebhooks
6964
);

src/ShopifyApp/ShopifyAppProvider.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,13 @@ public function register()
163163
DispatchWebhooksAction::class => [self::CBIND, function ($app) {
164164
return new DispatchWebhooksAction(
165165
$app->make(IShopQuery::class),
166-
WebhookInstaller::class,
167-
$app->make(CreateWebhooksAction::class)
166+
WebhookInstaller::class
168167
);
169168
}],
170169
DispatchScriptsAction::class => [self::CBIND, function ($app) {
171170
return new DispatchScriptsAction(
172171
$app->make(IShopQuery::class),
173-
ScripttagInstaller::class,
174-
$app->make(CreateScriptsAction::class)
172+
ScripttagInstaller::class
175173
);
176174
}],
177175
AfterAuthorizeAction::class => [self::CBIND, function ($app) {

0 commit comments

Comments
 (0)