PluginProbe
The Innovative Form Builder – IvyForms / 1.0
The Innovative Form Builder – IvyForms v1.0
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 1.0, at backend/src/Controllers/Form/DeleteFormsController.php

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