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 / DeleteFormsController.php

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

84 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 IvyForms\Controllers\Form;
4
5 // phpcs:disable PSR1.Files.SideEffects
6 if (!defined('ABSPATH')) {
7 exit; // Exit if accessed directly
8 }
9
10 use IvyForms\Common\Exceptions\ForbiddenException;
11 use IvyForms\Common\Exceptions\InvalidArgumentException;
12 use IvyForms\Common\Exceptions\NotFoundException;
13 use IvyForms\Common\Sanitizer\Sanitizer;
14 use IvyForms\Controllers\Controller;
15 use IvyForms\Services\Confirmation\ConfirmationService;
16 use IvyForms\Services\Field\FieldService;
17 use IvyForms\Services\Form\FormService;
18 use IvyForms\Services\Notification\NotificationService;
19 use IvyForms\Services\Translations\BackendStrings;
20 use WP_REST_Request;
21 use WP_REST_Response;
22
23 class DeleteFormsController extends Controller
24 {
25 private FormService $formService;
26 private FieldService $fieldService;
27 private NotificationService $notificationService;
28 private ConfirmationService $confirmationService;
29
30 public function __construct(
31 FormService $formService,
32 FieldService $fieldService,
33 NotificationService $notificationService,
34 ConfirmationService $confirmationService
35 ) {
36 $this->formService = $formService;
37 $this->fieldService = $fieldService;
38 $this->notificationService = $notificationService;
39 $this->confirmationService = $confirmationService;
40 }
41
42 /**
43 * Delete forms by IDs
44 *
45 * @param WP_REST_Request $data
46 *
47 * @return WP_REST_Response
48 *
49 * @throws InvalidArgumentException
50 * @throws NotFoundException
51 * @throws ForbiddenException
52 *
53 */
54 public function handle(WP_REST_Request $data): WP_REST_Response
55 {
56 // Verify the nonce
57 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
58
59 // Check if the form IDs are provided
60 if (empty($data->get_params())) {
61 throw new InvalidArgumentException(
62 BackendStrings::getExceptionStrings()['invalid_request_data']
63 );
64 }
65
66 $ids = Sanitizer::sanitizeIds($data->get_param('ids')) ;
67
68 foreach ($ids as $id) {
69 $this->formService->deleteForm($id);
70 $this->fieldService->deleteFieldsByFormId($id);
71 $this->notificationService->deleteNotificationsByFormId($id);
72 $this->confirmationService->deleteConfirmationsByFormId($id);
73 }
74
75 return new WP_REST_Response(
76 [
77 'message' => BackendStrings::getCommonStrings()['ok'],
78 'data' => [],
79 ],
80 200
81 );
82 }
83 }
84