diff --git a/src/Actions/ProductModel/SaveProductModel.php b/src/Actions/ProductModel/SaveProductModel.php index efda575..a1f8140 100644 --- a/src/Actions/ProductModel/SaveProductModel.php +++ b/src/Actions/ProductModel/SaveProductModel.php @@ -33,6 +33,7 @@ public function save(ProductModelData $productModelData): void $productModel->update = $productModel->isDirty(['checksum']); } + $productModel->resetFailures(); $productModel->save(); } diff --git a/src/Actions/ProductModel/UpdateProductModel.php b/src/Actions/ProductModel/UpdateProductModel.php index f37c6b4..95e83b6 100644 --- a/src/Actions/ProductModel/UpdateProductModel.php +++ b/src/Actions/ProductModel/UpdateProductModel.php @@ -22,8 +22,7 @@ public function update(ProductModel $productModel): void $productModel->modified_at = now(); $productModel->update = false; - $productModel->fail_count = 0; - $productModel->failed_at = null; + $productModel->resetFailures(); $productModel->save(); } diff --git a/src/Jobs/Product/SaveProductJob.php b/src/Jobs/Product/SaveProductJob.php index 477c8f7..0327bc8 100644 --- a/src/Jobs/Product/SaveProductJob.php +++ b/src/Jobs/Product/SaveProductJob.php @@ -55,9 +55,8 @@ public function failed(Throwable $throwable): void }) ->useLog('error') ->withProperties([ - 'message' => $throwable->getMessage(), 'data' => $this->productData->toArray(), ]) - ->log('Failed to save the product data'); + ->log('Failed to save the product data: '.$throwable->getMessage()); } } diff --git a/src/Jobs/Product/UpdateProductJob.php b/src/Jobs/Product/UpdateProductJob.php index decce06..99685be 100644 --- a/src/Jobs/Product/UpdateProductJob.php +++ b/src/Jobs/Product/UpdateProductJob.php @@ -52,6 +52,6 @@ public function failed(Throwable $throwable): void ->withProperties([ 'code' => $throwable->getCode(), ]) - ->log('Failed to update product in Akeneo: ' . $throwable->getMessage()); + ->log('Failed to update product in Akeneo: '.$throwable->getMessage()); } } diff --git a/src/Jobs/ProductModel/SaveProductModelJob.php b/src/Jobs/ProductModel/SaveProductModelJob.php index 941ad45..43fd373 100644 --- a/src/Jobs/ProductModel/SaveProductModelJob.php +++ b/src/Jobs/ProductModel/SaveProductModelJob.php @@ -10,7 +10,6 @@ use JustBetter\AkeneoProducts\Contracts\ProductModel\SavesProductModel; use JustBetter\AkeneoProducts\Data\ProductModelData; use JustBetter\AkeneoProducts\Models\ProductModel; -use JustBetter\MagentoPrices\Models\Price; use Spatie\Activitylog\ActivityLogger; use Throwable; diff --git a/src/Models/Product.php b/src/Models/Product.php index afa4081..6d16b7b 100644 --- a/src/Models/Product.php +++ b/src/Models/Product.php @@ -28,8 +28,8 @@ */ class Product extends Model { - use SoftDeletes; use LogsActivity; + use SoftDeletes; protected $table = 'akeneo_products'; diff --git a/src/Models/ProductModel.php b/src/Models/ProductModel.php index 92f394a..551563c 100644 --- a/src/Models/ProductModel.php +++ b/src/Models/ProductModel.php @@ -28,8 +28,8 @@ */ class ProductModel extends Model { - use SoftDeletes; use LogsActivity; + use SoftDeletes; protected $table = 'akeneo_product_models'; @@ -73,6 +73,13 @@ public function failed(): void $this->save(); } + public function resetFailures(): void + { + $this->synchronize = true; + $this->fail_count = 0; + $this->failed_at = null; + } + public function getActivitylogOptions(): LogOptions { return LogOptions::defaults() diff --git a/tests/Jobs/Product/SaveProductJobTest.php b/tests/Jobs/Product/SaveProductJobTest.php index 1cef69d..545b5f3 100644 --- a/tests/Jobs/Product/SaveProductJobTest.php +++ b/tests/Jobs/Product/SaveProductJobTest.php @@ -6,7 +6,6 @@ use JustBetter\AkeneoProducts\Contracts\Product\SavesProduct; use JustBetter\AkeneoProducts\Data\ProductData; use JustBetter\AkeneoProducts\Jobs\Product\SaveProductJob; -use JustBetter\AkeneoProducts\Jobs\Product\UpdateProductJob; use JustBetter\AkeneoProducts\Models\Product; use JustBetter\AkeneoProducts\Tests\TestCase; use Mockery\MockInterface; diff --git a/tests/Jobs/ProductModel/RetrieveProductModelJobTest.php b/tests/Jobs/ProductModel/RetrieveProductModelJobTest.php index 75963f0..8f9cdab 100644 --- a/tests/Jobs/ProductModel/RetrieveProductModelJobTest.php +++ b/tests/Jobs/ProductModel/RetrieveProductModelJobTest.php @@ -38,8 +38,8 @@ public function it_has_correct_tags_and_unique_id(): void #[Test] public function it_can_fail(): void { - /** @var ProductModel $product */ - $product = ProductModel::query()->create([ + /** @var ProductModel $productModel */ + $productModel = ProductModel::query()->create([ 'code' => 'code', 'data' => [], ]); @@ -47,9 +47,9 @@ public function it_can_fail(): void $job = new RetrieveProductModelJob('code'); $job->failed(new Exception); - $product->refresh(); + $productModel->refresh(); - $this->assertNotNull($product->failed_at); + $this->assertNotNull($productModel->failed_at); } #[Test]