PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.9.0
ووسلام – همگام سازی ووکامرس و باسلام v1.9.0
1.10.19 1.10.20 1.10.18 1.10.17 1.10.15 1.10.14 1.10.13 1.10.12 1.10.10 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.2 1.9.1 1.9.0 1.8.8 1.8.5 1.8.6 All 53 releases
sync-basalam / includes / Actions / Controller / ProductActions / UpdateAllProducts.php

UpdateAllProducts.php in ووسلام – همگام سازی ووکامرس و باسلام 1.9.0, at includes/Actions/Controller/ProductActions/UpdateAllProducts.php

83 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SyncBasalam\Actions\Controller\ProductActions;
4
5 use SyncBasalam\JobManager;
6 use SyncBasalam\Actions\Controller\ActionController;
7
8 defined('ABSPATH') || exit;
9
10 class UpdateAllProducts extends ActionController
11 {
12 public function __invoke()
13 {
14 $updateType = isset($_POST['update_type']) ? sanitize_text_field(wp_unslash($_POST['update_type'])) : null;
15 if (!$updateType) {
16 return wp_send_json_error(['message' => 'نوع بروزرسانی نا�
17 عتبر است.'], 400);
18 }
19 $jobManager = syncBasalamContainer()->get(JobManager::class);
20
21 if ($updateType === 'full') {
22 $existingJob = $jobManager->getJob([
23 'job_type' => 'sync_basalam_update_all_products',
24 'status' => 'pending',
25 ]);
26
27 if ($existingJob) {
28 return wp_send_json_error(['message' => 'در حال حاضر یک ع�
29 لیات بروزرسانی کا�
30 ل در صف انتظار است.'], 409);
31 }
32
33 $initialData = json_encode([
34 'offset' => 0,
35 ]);
36
37 $response = $jobManager->createJob(
38 'sync_basalam_update_all_products',
39 'pending',
40 $initialData
41 );
42
43 if (!$response) {
44 return wp_send_json_error(['message' => 'خطا در ایجاد فرایند بروزرسانی.'], 500);
45 }
46
47 wp_send_json_success([
48 'message' => 'بروزرسانی ت�
49 ا�
50 اطلاعات �
51 حصول با �
52 وفقیت آغاز شد.',
53 ], 200);
54 } else {
55 $existingJob = $jobManager->getJob([
56 'job_type' => 'sync_basalam_bulk_update_products',
57 'status' => 'pending',
58 ]);
59
60 if ($existingJob) {
61 return wp_send_json_error(['message' => 'در حال حاضر یک ع�
62 لیات بروزرسانی در صف انتظار است.'], 409);
63 }
64
65 $response = $jobManager->createJob(
66 'sync_basalam_bulk_update_products',
67 'pending',
68 0,
69 );
70
71 if (!$response) {
72 return wp_send_json_error(['message' => 'خطا در ایجاد فرایند بروزرسانی فوری �
73 حصولات.'], 500);
74 }
75
76 wp_send_json_success(['message' => 'فرایند بروزرسانی قی�
77 ت و �
78 وجودی با �
79 وفقیت آغاز شد.'], 200);
80 }
81 }
82 }
83