From 66ea43f0c75050613764312dd7eb0839d60d2e37 Mon Sep 17 00:00:00 2001 From: arfenis Date: Thu, 17 Oct 2024 22:43:09 -0400 Subject: [PATCH 1/6] Add flag to disable workflow on receiver --- .../Shopify/Jobs/ProcessShopifyProductWebhookJob.php | 4 +++- .../Inventory/Importer/Actions/ProductImporterAction.php | 5 +++-- src/Domains/Inventory/Importer/Jobs/ProductImporterJob.php | 6 ++++-- .../Inventory/Products/Actions/CreateProductAction.php | 3 ++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Domains/Connectors/Shopify/Jobs/ProcessShopifyProductWebhookJob.php b/src/Domains/Connectors/Shopify/Jobs/ProcessShopifyProductWebhookJob.php index 7dfaba3d1..0ec846884 100644 --- a/src/Domains/Connectors/Shopify/Jobs/ProcessShopifyProductWebhookJob.php +++ b/src/Domains/Connectors/Shopify/Jobs/ProcessShopifyProductWebhookJob.php @@ -43,7 +43,9 @@ public function execute(): array $integrationCompany->company->branch, $this->receiver->user, $integrationCompany->region, - $this->receiver->app + $this->receiver->app, + null, + true ); return [ diff --git a/src/Domains/Inventory/Importer/Actions/ProductImporterAction.php b/src/Domains/Inventory/Importer/Actions/ProductImporterAction.php index 67d3cff39..1cef69ee9 100644 --- a/src/Domains/Inventory/Importer/Actions/ProductImporterAction.php +++ b/src/Domains/Inventory/Importer/Actions/ProductImporterAction.php @@ -52,7 +52,8 @@ public function __construct( public Companies $company, public UserInterface $user, public Regions $region, - public ?AppInterface $app = null + public ?AppInterface $app = null, + public bool $disableWorkflow = false ) { $this->app = $this->app ?? app(Apps::class); } @@ -81,7 +82,7 @@ public function execute(): ProductsModel 'is_published' => $this->importedProduct->isPublished, 'attributes' => $this->importedProduct->attributes, ]); - $this->product = (new CreateProductAction($productDto, $this->user))->execute(); + $this->product = (new CreateProductAction($productDto, $this->user, $this->disableWorkflow))->execute(); if (isset($this->importedProduct->customFields) && ! empty($this->importedProduct->customFields)) { $this->product->setAllCustomFields($this->importedProduct->customFields); diff --git a/src/Domains/Inventory/Importer/Jobs/ProductImporterJob.php b/src/Domains/Inventory/Importer/Jobs/ProductImporterJob.php index 3feec79b3..87acaefa5 100644 --- a/src/Domains/Inventory/Importer/Jobs/ProductImporterJob.php +++ b/src/Domains/Inventory/Importer/Jobs/ProductImporterJob.php @@ -52,7 +52,8 @@ public function __construct( public UserInterface $user, public Regions $region, public AppInterface $app, - public ?FilesystemImports $filesystemImport = null + public ?FilesystemImports $filesystemImport = null, + public bool $disableWorkflow = false ) { $minuteDelay = (int)($app->get('delay_minute_job') ?? 0); $queue = $this->onQueue('imports'); @@ -129,7 +130,8 @@ public function handle() $company, $this->user, $this->region, - $this->app + $this->app, + $this->disableWorkflow ))->execute(); if ($product->wasRecentlyCreated) { $created++; diff --git a/src/Domains/Inventory/Products/Actions/CreateProductAction.php b/src/Domains/Inventory/Products/Actions/CreateProductAction.php index 2f48930e7..0756f4d7e 100644 --- a/src/Domains/Inventory/Products/Actions/CreateProductAction.php +++ b/src/Domains/Inventory/Products/Actions/CreateProductAction.php @@ -33,6 +33,7 @@ class CreateProductAction public function __construct( protected ProductDto $productDto, protected UserInterface $user, + public bool $disableWorkflow = false ) { } @@ -124,7 +125,7 @@ public function execute(): Products throw $e; } - if ($this->runWorkflow) { + if (!$this->disableWorkflow && $this->runWorkflow) { $products->fireWorkflow( WorkflowEnum::CREATED->value, true From 1a51bdeeabff41263a014d4662ad7476eee13d14 Mon Sep 17 00:00:00 2001 From: arfenis Date: Thu, 17 Oct 2024 22:44:37 -0400 Subject: [PATCH 2/6] stylo --- src/Domains/Inventory/Products/Actions/CreateProductAction.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Domains/Inventory/Products/Actions/CreateProductAction.php b/src/Domains/Inventory/Products/Actions/CreateProductAction.php index 0756f4d7e..3b18beded 100644 --- a/src/Domains/Inventory/Products/Actions/CreateProductAction.php +++ b/src/Domains/Inventory/Products/Actions/CreateProductAction.php @@ -125,7 +125,7 @@ public function execute(): Products throw $e; } - if (!$this->disableWorkflow && $this->runWorkflow) { + if (! $this->disableWorkflow && $this->runWorkflow) { $products->fireWorkflow( WorkflowEnum::CREATED->value, true From 43da59889118f41530922da43c5fe9dca94226de Mon Sep 17 00:00:00 2001 From: arfenis Date: Thu, 17 Oct 2024 23:07:50 -0400 Subject: [PATCH 3/6] name params on job --- .../Jobs/ProcessShopifyProductWebhookJob.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Domains/Connectors/Shopify/Jobs/ProcessShopifyProductWebhookJob.php b/src/Domains/Connectors/Shopify/Jobs/ProcessShopifyProductWebhookJob.php index 0ec846884..650e44e0f 100644 --- a/src/Domains/Connectors/Shopify/Jobs/ProcessShopifyProductWebhookJob.php +++ b/src/Domains/Connectors/Shopify/Jobs/ProcessShopifyProductWebhookJob.php @@ -38,14 +38,13 @@ public function execute(): array $jobUuid = Str::uuid()->toString(); ProductImporterJob::dispatch( - $jobUuid, - [$mappedProduct], - $integrationCompany->company->branch, - $this->receiver->user, - $integrationCompany->region, - $this->receiver->app, - null, - true + jobUuid: $jobUuid, + importer: [$mappedProduct], + branch: $integrationCompany->company->branch, + user: $this->receiver->user, + region: $integrationCompany->region, + app: $this->receiver->app, + runWorkflow: false ); return [ From fad7a081e7781032f39df6c3a2d958b201924144 Mon Sep 17 00:00:00 2001 From: arfenis Date: Thu, 17 Oct 2024 23:08:17 -0400 Subject: [PATCH 4/6] rename variable --- src/Domains/Inventory/Importer/Jobs/ProductImporterJob.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Domains/Inventory/Importer/Jobs/ProductImporterJob.php b/src/Domains/Inventory/Importer/Jobs/ProductImporterJob.php index 87acaefa5..1db3fcdf7 100644 --- a/src/Domains/Inventory/Importer/Jobs/ProductImporterJob.php +++ b/src/Domains/Inventory/Importer/Jobs/ProductImporterJob.php @@ -53,7 +53,7 @@ public function __construct( public Regions $region, public AppInterface $app, public ?FilesystemImports $filesystemImport = null, - public bool $disableWorkflow = false + public bool $runWorkflow = true ) { $minuteDelay = (int)($app->get('delay_minute_job') ?? 0); $queue = $this->onQueue('imports'); @@ -131,7 +131,7 @@ public function handle() $this->user, $this->region, $this->app, - $this->disableWorkflow + $this->runWorkflow ))->execute(); if ($product->wasRecentlyCreated) { $created++; From df4a9499b0b735758700dc879f92758473e156cf Mon Sep 17 00:00:00 2001 From: arfenis Date: Thu, 17 Oct 2024 23:08:40 -0400 Subject: [PATCH 5/6] setRunWorkflow method --- .../Inventory/Products/Actions/CreateProductAction.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Domains/Inventory/Products/Actions/CreateProductAction.php b/src/Domains/Inventory/Products/Actions/CreateProductAction.php index 3b18beded..48c3f773c 100644 --- a/src/Domains/Inventory/Products/Actions/CreateProductAction.php +++ b/src/Domains/Inventory/Products/Actions/CreateProductAction.php @@ -33,7 +33,6 @@ class CreateProductAction public function __construct( protected ProductDto $productDto, protected UserInterface $user, - public bool $disableWorkflow = false ) { } @@ -125,7 +124,7 @@ public function execute(): Products throw $e; } - if (! $this->disableWorkflow && $this->runWorkflow) { + if ($this->runWorkflow) { $products->fireWorkflow( WorkflowEnum::CREATED->value, true @@ -134,4 +133,10 @@ public function execute(): Products return $products; } + + public function setRunWorkflow(bool $runWorkflow): self + { + $this->runWorkflow = $runWorkflow; + return $this; + } } From 05985c58d6fac206299fd9d28082a75a4b3bb322 Mon Sep 17 00:00:00 2001 From: arfenis Date: Thu, 17 Oct 2024 23:09:05 -0400 Subject: [PATCH 6/6] Set workflow run conditional --- .../Inventory/Importer/Actions/ProductImporterAction.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Domains/Inventory/Importer/Actions/ProductImporterAction.php b/src/Domains/Inventory/Importer/Actions/ProductImporterAction.php index 1cef69ee9..1a860e95b 100644 --- a/src/Domains/Inventory/Importer/Actions/ProductImporterAction.php +++ b/src/Domains/Inventory/Importer/Actions/ProductImporterAction.php @@ -53,7 +53,7 @@ public function __construct( public UserInterface $user, public Regions $region, public ?AppInterface $app = null, - public bool $disableWorkflow = false + public bool $runWorkflow = true ) { $this->app = $this->app ?? app(Apps::class); } @@ -82,7 +82,9 @@ public function execute(): ProductsModel 'is_published' => $this->importedProduct->isPublished, 'attributes' => $this->importedProduct->attributes, ]); - $this->product = (new CreateProductAction($productDto, $this->user, $this->disableWorkflow))->execute(); + $createAction = new CreateProductAction($productDto, $this->user); + $createAction->setRunWorkflow($this->runWorkflow); + $this->product = $createAction->execute(); if (isset($this->importedProduct->customFields) && ! empty($this->importedProduct->customFields)) { $this->product->setAllCustomFields($this->importedProduct->customFields);