PluginProbe
MailerLite – WooCommerce integration / 3.1.22
MailerLite – WooCommerce integration v3.1.22
3.1.25 3.1.26 3.1.24 3.1.23 3.1.22 3.1.21 3.1.20 3.1.19 3.1.18 3.1.17 3.1.16 3.1.15 1.8.7 1.8.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 All 147 releases
woo-mailerlite / admin / controllers / WooMailerLiteAdminSyncController.php

WooMailerLiteAdminSyncController.php in MailerLite – WooCommerce integration 3.1.22, at admin/controllers/WooMailerLiteAdminSyncController.php

48 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class WooMailerLiteAdminSyncController extends WooMailerLiteController
4 {
5 public function sync()
6 {
7 $this->authorize();
8 $alreadyStarted = WooMailerLiteCache::get('manual_sync', false);
9 if (!$alreadyStarted) {
10 WooMailerLiteCache::set('manual_sync', true, 18000);
11 }
12
13 // save count in cache
14 $untrackedCategories = WooMailerLiteCategory::getUntrackedCategoriesCount();
15 $untrackedProducts = WooMailerLiteProduct::getUntrackedProductsCount();
16 $untrackedCustomers = WooMailerLiteCustomer::getUntrackedCustomersCount();
17 WooMailerLiteCache::set('resource_sync_counts', [
18 'categories' => $untrackedCategories,
19 'products' => $untrackedProducts,
20 'customers' => $untrackedCustomers,
21 ], 18000);
22 $totalUntrackedResources = $untrackedCategories + $untrackedProducts + $untrackedCustomers;
23 if ($totalUntrackedResources == 0) {
24 WooMailerLiteCache::delete('manual_sync');
25 return $this->response('no resources to sync', 200);
26 }
27
28 WooMailerLiteCategorySyncJob::dispatch();
29
30 return $this->response([
31 'message' => 'Sync in progress',
32 'data' => [
33 'totalUntrackedResources' => $totalUntrackedResources
34 ]
35 ], function_exists('as_enqueue_async_action') ? 203 : 202);
36 }
37
38 public function resetSync()
39 {
40 $this->authorize();
41 WooMailerLiteCache::delete('manual_sync');
42 WooMailerLiteProductSyncResetJob::dispatchSync();
43 return $this->response(['message' => 'reset sync completed', 'data' => [
44 'totalUntrackedResources' => WooMailerLiteCategory::getUntrackedCategoriesCount() + WooMailerLiteProduct::getUntrackedProductsCount() + WooMailerLiteCustomer::getUntrackedCustomersCount()
45 ]], 202);
46 }
47 }
48