PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.6
ووسلام – همگام سازی ووکامرس و باسلام v1.10.6
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 / CreateTicket.php

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

81 lines 2.8 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
10 defined('ABSPATH') || exit;
11
12 class CreateTicket extends ActionController
13 {
14 public function __invoke()
15 {
16 if (!current_user_can('manage_options')) {
17 wp_die('دسترسی غیر�
18 جاز!');
19 }
20
21 $ticketId = $this->processSubmission();
22
23 wp_safe_redirect(admin_url("admin.php?page=sync_basalam_ticket&ticket_id=" . $ticketId));
24 exit();
25 }
26
27 /**
28 * Run the two-step submission without redirecting.
29 *
30 * The optional manager keeps the action flow directly testable while the
31 * normal WordPress invocation still creates the production manager.
32 */
33 public function processSubmission(?TicketServiceManager $ticketManager = null): int
34 {
35 $ticketManager = $ticketManager ?: new TicketServiceManager();
36
37 $title = isset($_POST['title']) ? \sanitize_text_field(\wp_unslash($_POST['title'])) : null;
38 $subject = isset($_POST['subject']) ? \sanitize_text_field(\wp_unslash($_POST['subject'])) : null;
39 $content = isset($_POST['content']) ? TicketExtraInfoFormatter::sanitizeContent($_POST['content']) : '';
40
41 try {
42 $accessData = TicketAccessData::fromRequest($_POST);
43 } catch (\InvalidArgumentException $e) {
44 wp_die(esc_html($e->getMessage()));
45 }
46
47 $fileIds = isset($_POST['file_ids']) && is_array($_POST['file_ids'])
48 ? array_map('intval', $_POST['file_ids'])
49 : [];
50
51 $result = $ticketManager->createTicket($title, $subject, $content, $fileIds);
52 if (TicketServiceManager::isSuccessful($result) && isset($result['body'])) {
53 $ticket = json_decode($result['body'], true);
54 } else {
55 wp_die('خطایی در ارسال تیکت رخ داده است. لطفا �
56 جددا تلاش کنید.');
57 }
58
59 $ticketId = intval($ticket['data']['id'] ?? 0);
60 if ($ticketId <= 0) {
61 wp_die('پاسخ ایجاد تیکت �
62 عتبر نیست. لطفا �
63 جددا تلاش کنید.');
64 }
65
66 if (!empty($accessData)) {
67 $accessResult = $ticketManager->upsertTicketSiteAccess($ticketId, $accessData);
68 if (!TicketServiceManager::isSuccessful($accessResult)) {
69 wp_die(esc_html(
70 'تیکت ش�
71 اره ' . $ticketId . ' ثبت شد، ا�
72 ا اطلاعات دسترسی ذخیره نشد. '
73 . 'لطفا از صفحه تیکت دوباره اطلاعات دسترسی را ارسال کنید.'
74 ));
75 }
76 }
77
78 return $ticketId;
79 }
80 }
81