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