PluginProbe
The Innovative Form Builder – IvyForms / 1.5
The Innovative Form Builder – IvyForms v1.5
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
← All changes | backend/src/Controllers/Form/DeleteFormController.php +86 -0 0.6.1 → 1.5 View file →
@@ -1,0 +1,86 @@
1 +<?php
2 +
3 +/**
4 + * @copyright © Melograno Venture Studio. All rights reserved.
5 + * @licence See COPYING.md for license details.
6 + */
7 +
8 +namespace IvyForms\Controllers\Form;
9 +
10 +use IvyForms\Common\Exceptions\ForbiddenException;
11 +use IvyForms\Common\Exceptions\InvalidArgumentException;
12 +use IvyForms\Common\Exceptions\QueryExecutionException;
13 +use IvyForms\Common\Sanitizer\Sanitizer;
14 +use IvyForms\Controllers\Controller;
15 +use IvyForms\Services\Confirmation\ConfirmationService;
16 +use IvyForms\Services\Entry\EntryService;
17 +use IvyForms\Services\Field\FieldService;
18 +use IvyForms\Services\Form\FormService;
19 +use IvyForms\Services\Notification\NotificationService;
20 +use IvyForms\Services\Translations\BackendStrings;
21 +use WP_REST_Request;
22 +use WP_REST_Response;
23 +
24 +/**
25 + * Class DeleteFormController
26 + *
27 + * @package IvyForms\Controllers\Form
28 + */
29 +class DeleteFormController extends Controller
30 +{
31 + private FormService $formService;
32 + private FieldService $fieldService;
33 + private NotificationService $notificationService;
34 + private ConfirmationService $confirmationService;
35 + private EntryService $entryService;
36 +
37 + public function __construct(
38 + FormService $formService,
39 + FieldService $fieldService,
40 + NotificationService $notificationService,
41 + ConfirmationService $confirmationService,
42 + EntryService $entryService
43 + ) {
44 + $this->formService = $formService;
45 + $this->fieldService = $fieldService;
46 + $this->notificationService = $notificationService;
47 + $this->confirmationService = $confirmationService;
48 + $this->entryService = $entryService;
49 + }
50 +
51 + /**
52 + * @param WP_REST_Request $data
53 + *
54 + * @return WP_REST_Response
55 + *
56 + * @throws InvalidArgumentException
57 + * @throws ForbiddenException
58 + * @throws QueryExecutionException
59 + */
60 + public function handle(WP_REST_Request $data): WP_REST_Response
61 + {
62 + // Verify the nonce
63 + Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
64 +
65 + // Check if the form ID is provided
66 + if (empty($data->get_param('id'))) {
67 + throw new InvalidArgumentException(
68 + BackendStrings::getExceptionStrings()['form_id_required']
69 + );
70 + }
71 +
72 + // Sanitize the input data
73 + $formId = Sanitizer::sanitizeId($data->get_param('id'));
74 +
75 + $this->entryService->getDeletionManager()->deleteEntriesByFormIds([$formId]);
76 + $this->confirmationService->deleteConfirmationsByFormIds([$formId]);
77 + $this->notificationService->deleteNotificationsByFormIds([$formId]);
78 + $this->fieldService->deleteFieldsByFormIds([$formId]);
79 + $this->formService->deleteForm($formId);
80 +
81 + return new WP_REST_Response([
82 + 'message' => BackendStrings::getCommonStrings()['ok'],
83 + 'data' => []
84 + ], 200);
85 + }
86 +}