PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.19
ووسلام – همگام سازی ووکامرس و باسلام v1.10.19
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
← All changes | includes/Actions/Controller/TicketActions/CreateTicket.php +60 -13 1.10.61.10.19 View file →
@@ -5,22 +5,57 @@
5 5 use SyncBasalam\Actions\Controller\ActionController;
6 6 use SyncBasalam\Services\TicketServiceManager;
7 7 use SyncBasalam\Utilities\TicketExtraInfoFormatter;
8 8 use SyncBasalam\Utilities\TicketAccessData;
9 +use SyncBasalam\Utilities\TicketFlashNotice;
9 10
10 11 defined('ABSPATH') || exit;
11 12
12 13 class CreateTicket extends ActionController
13 14 {
15 + private $createdTicketId = 0;
16 +
14 17 public function __invoke()
15 18 {
16 19 if (!current_user_can('manage_options')) {
20 + if (wp_doing_ajax()) {
21 + wp_send_json_error(['message' => 'دسترسی غیرمجاز!'], 403);
22 + }
17 23 wp_die('دسترسی غیرمجاز!');
18 24 }
19 25
20 - $ticketId = $this->processSubmission();
26 + try {
27 + $ticketId = $this->processSubmission();
28 + } catch (\Throwable $e) {
29 + $message = $e instanceof \InvalidArgumentException || $e instanceof \RuntimeException
30 + ? $e->getMessage()
31 + : 'خطای غیرمنتظره‌ای در ثبت تیکت رخ داد. لطفا مجددا تلاش کنید.';
21 32
22 - wp_safe_redirect(admin_url("admin.php?page=sync_basalam_ticket&ticket_id=" . $ticketId));
33 + if (wp_doing_ajax()) {
34 + wp_send_json_error([
35 + 'message' => $message,
36 + 'ticket_id' => $this->createdTicketId,
37 + ], 400);
38 + }
39 +
40 + TicketFlashNotice::push($message, 'error');
41 +
42 + $redirectUrl = $this->createdTicketId > 0
43 + ? admin_url('admin.php?page=sync_basalam_ticket&ticket_id=' . $this->createdTicketId)
44 + : admin_url('admin.php?page=sync_basalam_new_ticket');
45 + wp_safe_redirect($redirectUrl);
46 + exit();
47 + }
48 +
49 + $redirectUrl = admin_url('admin.php?page=sync_basalam_ticket&ticket_id=' . $ticketId);
50 + if (wp_doing_ajax()) {
51 + wp_send_json_success([
52 + 'ticket_id' => $ticketId,
53 + 'redirect_url' => $redirectUrl,
54 + ]);
55 + }
56 +
57 + wp_safe_redirect($redirectUrl);
23 58 exit();
24 59 }
25 60
26 61 /**
@@ -39,9 +74,9 @@
39 74
40 75 try {
41 76 $accessData = TicketAccessData::fromRequest($_POST);
42 77 } catch (\InvalidArgumentException $e) {
43 - wp_die(esc_html($e->getMessage()));
78 + throw $e;
44 79 }
45 80
46 81 $fileIds = isset($_POST['file_ids']) && is_array($_POST['file_ids'])
47 82 ? array_map('intval', $_POST['file_ids'])
@@ -46,27 +81,39 @@
46 81 $fileIds = isset($_POST['file_ids']) && is_array($_POST['file_ids'])
47 82 ? array_map('intval', $_POST['file_ids'])
48 83 : [];
49 84
50 - $result = $ticketManager->createTicket($title, $subject, $content, $fileIds);
51 - if (TicketServiceManager::isSuccessful($result) && isset($result['body'])) {
52 - $ticket = json_decode($result['body'], true);
85 + $existingTicketId = isset($_POST['existing_ticket_id'])
86 + ? intval(wp_unslash($_POST['existing_ticket_id']))
87 + : 0;
88 + if ($existingTicketId > 0) {
89 + if (empty($accessData)) {
90 + throw new \RuntimeException('اطلاعات دسترسی برای ارسال مجدد کامل نیست.');
91 + }
92 + $ticketId = $existingTicketId;
93 + $this->createdTicketId = $ticketId;
53 94 } else {
54 - wp_die('خطایی در ارسال تیکت رخ داده است. لطفا مجددا تلاش کنید.');
55 - }
95 + $result = $ticketManager->createTicket($title, $subject, $content, $fileIds);
96 + if (TicketServiceManager::isSuccessful($result) && isset($result['body'])) {
97 + $ticket = json_decode($result['body'], true);
98 + } else {
99 + throw new \RuntimeException('خطایی در ارسال تیکت رخ داده است. لطفا مجددا تلاش کنید.');
100 + }
56 101
57 - $ticketId = intval($ticket['data']['id'] ?? 0);
58 - if ($ticketId <= 0) {
59 - wp_die('پاسخ ایجاد تیکت معتبر نیست. لطفا مجددا تلاش کنید.');
102 + $ticketId = intval($ticket['data']['id'] ?? 0);
103 + if ($ticketId <= 0) {
104 + throw new \RuntimeException('پاسخ ایجاد تیکت معتبر نیست. لطفا مجددا تلاش کنید.');
105 + }
106 + $this->createdTicketId = $ticketId;
60 107 }
61 108
62 109 if (!empty($accessData)) {
63 110 $accessResult = $ticketManager->upsertTicketSiteAccess($ticketId, $accessData);
64 111 if (!TicketServiceManager::isSuccessful($accessResult)) {
65 - wp_die(esc_html(
112 + throw new \RuntimeException(
66 113 'تیکت شماره ' . $ticketId . ' ثبت شد، اما اطلاعات دسترسی ذخیره نشد. '
67 114 . 'لطفا از صفحه تیکت دوباره اطلاعات دسترسی را ارسال کنید.'
68 - ));
115 + );
69 116 }
70 117 }
71 118
72 119 return $ticketId;