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