Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentBean committed Nov 13, 2024
1 parent 5434d53 commit 2936506
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/Actions/ProductModel/SaveProductModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function save(ProductModelData $productModelData): void
$productModel->update = $productModel->isDirty(['checksum']);
}

$productModel->resetFailures();
$productModel->save();
}

Expand Down
3 changes: 1 addition & 2 deletions src/Actions/ProductModel/UpdateProductModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
3 changes: 1 addition & 2 deletions src/Jobs/Product/SaveProductJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion src/Jobs/Product/UpdateProductJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
1 change: 0 additions & 1 deletion src/Jobs/ProductModel/SaveProductModelJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
*/
class Product extends Model
{
use SoftDeletes;
use LogsActivity;
use SoftDeletes;

protected $table = 'akeneo_products';

Expand Down
9 changes: 8 additions & 1 deletion src/Models/ProductModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
*/
class ProductModel extends Model
{
use SoftDeletes;
use LogsActivity;
use SoftDeletes;

protected $table = 'akeneo_product_models';

Expand Down Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion tests/Jobs/Product/SaveProductJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions tests/Jobs/ProductModel/RetrieveProductModelJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ 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' => [],
]);

$job = new RetrieveProductModelJob('code');
$job->failed(new Exception);

$product->refresh();
$productModel->refresh();

$this->assertNotNull($product->failed_at);
$this->assertNotNull($productModel->failed_at);
}

#[Test]
Expand Down

0 comments on commit 2936506

Please sign in to comment.