| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* After the support for Product Variants, we need to reset the tracked products and re-sync them to MailerLite. |
| 5 |
* This job will reset the tracked products and re-sync them to MailerLite. |
| 6 |
*/ |
| 7 |
class WooMailerLiteProductVariantsMigrationJob extends WooMailerLiteAbstractJob |
| 8 |
{ |
| 9 |
public function handle($data = []) |
| 10 |
{ |
| 11 |
WooMailerLiteLog()->info('variants:migration:handle'); |
| 12 |
|
| 13 |
$products = WooMailerLiteProduct::tracked()->get(100); |
| 14 |
if ($products->hasItems()) { |
| 15 |
foreach ($products->items as $product) { |
| 16 |
$product->tracked = false; |
| 17 |
$product->save(); |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
if (isset(self::$jobModel)) { |
| 22 |
self::$jobModel->delete(); |
| 23 |
} |
| 24 |
|
| 25 |
if (WooMailerLiteProduct::getTrackedProductsCount()) { |
| 26 |
self::dispatchSync(); |
| 27 |
} else { |
| 28 |
WooMailerLiteProductSyncJob::dispatch(); |
| 29 |
WooMailerLiteLog()->info('variants:migration:products-reset-complete'); |
| 30 |
} |
| 31 |
} |
| 32 |
} |
| 33 |
|