PluginProbe
The Innovative Form Builder – IvyForms / 0.3
The Innovative Form Builder – IvyForms v0.3
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / Controllers / Form / DeleteFormController.php

DeleteFormController.php in The Innovative Form Builder – IvyForms 0.3, at backend/src/Controllers/Form/DeleteFormController.php

90 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @copyright © TMS-Plugins. All rights reserved.
5 * @licence See COPYING.md for license details.
6 */
7
8 namespace IvyForms\Controllers\Form;
9
10 // phpcs:disable PSR1.Files.SideEffects
11 if (!defined('ABSPATH')) {
12 exit; // Exit if accessed directly
13 }
14
15 use IvyForms\Common\Exceptions\ForbiddenException;
16 use IvyForms\Common\Exceptions\InvalidArgumentException;
17 use IvyForms\Common\Exceptions\NotFoundException;
18 use IvyForms\Common\Sanitizer\Sanitizer;
19 use IvyForms\Controllers\Controller;
20 use IvyForms\Services\Confirmation\ConfirmationService;
21 use IvyForms\Services\Field\FieldService;
22 use IvyForms\Services\Form\FormService;
23 use IvyForms\Services\Notification\NotificationService;
24 use IvyForms\Services\Translations\BackendStrings;
25 use WP_REST_Request;
26 use WP_REST_Response;
27
28 /**
29 * Class DeleteFormController
30 *
31 * @package IvyForms\Controllers\Form
32 */
33 class DeleteFormController extends Controller
34 {
35 private FormService $formService;
36 private FieldService $fieldService;
37 private NotificationService $notificationService;
38 private ConfirmationService $confirmationService;
39
40 public function __construct(
41 FormService $formService,
42 FieldService $fieldService,
43 NotificationService $notificationService,
44 ConfirmationService $confirmationService
45 ) {
46 $this->formService = $formService;
47 $this->fieldService = $fieldService;
48 $this->notificationService = $notificationService;
49 $this->confirmationService = $confirmationService;
50 }
51
52 /**
53 * @param WP_REST_Request $data
54 *
55 * @return WP_REST_Response
56 *
57 * @throws NotFoundException
58 * @throws InvalidArgumentException
59 * @throws ForbiddenException
60 */
61 public function handle(WP_REST_Request $data): WP_REST_Response
62 {
63 // Verify the nonce
64 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
65
66 // Check if the form ID is provided
67 if (empty($data->get_param('id'))) {
68 throw new InvalidArgumentException(
69 BackendStrings::getExceptionStrings()['form_id_required']
70 );
71 }
72
73 // Sanitize the input data
74 $formId = Sanitizer::sanitizeId($data->get_param('id'));
75
76 $this->formService->deleteForm($formId);
77
78 $this->fieldService->deleteFieldsByFormId($formId);
79
80 $this->notificationService->deleteNotificationsByFormId($formId);
81
82 $this->confirmationService->deleteConfirmationsByFormId($formId);
83
84 return new WP_REST_Response([
85 'message' => BackendStrings::getCommonStrings()['ok'],
86 'data' => []
87 ], 200);
88 }
89 }
90