PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.14
ووسلام – همگام سازی ووکامرس و باسلام v1.10.14
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 / TicketActions / CreateTicketItem.php

CreateTicketItem.php in ووسلام – همگام سازی ووکامرس و باسلام 1.10.14, at includes/Actions/Controller/TicketActions/CreateTicketItem.php

92 lines 3.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\TicketActions;
4
5 use SyncBasalam\Actions\Controller\ActionController;
6 use SyncBasalam\Services\TicketServiceManager;
7 use SyncBasalam\Utilities\TicketExtraInfoFormatter;
8 use SyncBasalam\Utilities\TicketAccessData;
9 use SyncBasalam\Utilities\TicketFlashNotice;
10
11 defined('ABSPATH') || exit;
12
13 class CreateTicketItem extends ActionController
14 {
15 public function __invoke()
16 {
17 if (!current_user_can('manage_options')) {
18 wp_die('دسترسی غیر�
19 جاز!');
20 }
21
22 try {
23 $this->processSubmission();
24 } catch (\Throwable $e) {
25 $message = $e instanceof \InvalidArgumentException || $e instanceof \RuntimeException
26 ? $e->getMessage()
27 : 'خطای غیر�
28 نتظره‌ای در ارسال پاسخ تیکت رخ داد. لطفا �
29 جددا تلاش کنید.';
30 TicketFlashNotice::push($message, 'error');
31
32 $ticketId = isset($_POST['ticket_id']) ? intval(wp_unslash($_POST['ticket_id'])) : 0;
33 $redirectUrl = $ticketId > 0
34 ? admin_url('admin.php?page=sync_basalam_ticket&ticket_id=' . $ticketId)
35 : admin_url('admin.php?page=sync_basalam_tickets');
36 wp_safe_redirect($redirectUrl);
37 exit();
38 }
39 }
40
41 /** Run reply creation before the optional access replacement. */
42 public function processSubmission(?TicketServiceManager $ticketManager = null): void
43 {
44 $ticketManager = $ticketManager ?: new TicketServiceManager();
45
46 $content = isset($_POST['content']) ? TicketExtraInfoFormatter::sanitizeContent($_POST['content']) : '';
47 try {
48 $accessData = TicketAccessData::fromRequest($_POST);
49 } catch (\InvalidArgumentException $e) {
50 throw $e;
51 }
52 if ($content === '' && !empty($accessData)) {
53 $content = 'اطلاعات دسترسی به‌روزرسانی شد.';
54 }
55 $ticketId = isset($_POST['ticket_id']) ? intval(\wp_unslash($_POST['ticket_id'])) : 0;
56
57 if ($ticketId <= 0) {
58 throw new \RuntimeException('شناسه تیکت �
59 عتبر نیست.');
60 }
61
62 $ticketResponse = $ticketManager->fetchTicket($ticketId);
63 $ticket = isset($ticketResponse['body']) ? json_decode($ticketResponse['body'], true) : null;
64
65 if (is_array($ticket) && TicketServiceManager::isTicketClosed($ticket)) {
66 throw new \RuntimeException('این تیکت بسته شده است و ا�
67 کان ارسال پاسخ جدید وجود ندارد.');
68 }
69
70 $fileIds = isset($_POST['file_ids']) && is_array($_POST['file_ids'])
71 ? array_map('intval', $_POST['file_ids'])
72 : [];
73
74 $itemResult = $ticketManager->createTicketItem($ticketId, $content, $fileIds);
75 if (!TicketServiceManager::isSuccessful($itemResult)) {
76 throw new \RuntimeException('خطایی در ارسال پاسخ تیکت رخ داد. لطفا �
77 جددا تلاش کنید.');
78 }
79
80 if (!empty($accessData)) {
81 $accessResult = $ticketManager->upsertTicketSiteAccess($ticketId, $accessData);
82 if (!TicketServiceManager::isSuccessful($accessResult)) {
83 throw new \RuntimeException(
84 'پاسخ تیکت ثبت شد، ا�
85 ا اطلاعات دسترسی ذخیره نشد. '
86 . 'لطفا دوباره اطلاعات دسترسی را ارسال کنید.'
87 );
88 }
89 }
90 }
91 }
92