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/DeleteFormsController.php +33 -19 0.3 → 1.5.1 View file →
@@ -1,22 +1,19 @@
1 1 <?php
2 2
3 3 namespace IvyForms\Controllers\Form;
4 4
5 -// phpcs:disable PSR1.Files.SideEffects
6 -if (!defined('ABSPATH')) {
7 - exit; // Exit if accessed directly
8 -}
9 -
10 5 use IvyForms\Common\Exceptions\ForbiddenException;
11 6 use IvyForms\Common\Exceptions\InvalidArgumentException;
12 -use IvyForms\Common\Exceptions\NotFoundException;
7 +use IvyForms\Common\Exceptions\QueryExecutionException;
13 8 use IvyForms\Common\Sanitizer\Sanitizer;
14 9 use IvyForms\Controllers\Controller;
15 10 use IvyForms\Services\Confirmation\ConfirmationService;
11 +use IvyForms\Services\Entry\EntryService;
16 12 use IvyForms\Services\Field\FieldService;
17 13 use IvyForms\Services\Form\FormService;
18 14 use IvyForms\Services\Notification\NotificationService;
15 +use IvyForms\Services\Permissions\RoutePermissionService;
19 16 use IvyForms\Services\Translations\BackendStrings;
20 17 use WP_REST_Request;
21 18 use WP_REST_Response;
22 19
@@ -25,19 +22,26 @@
25 22 private FormService $formService;
26 23 private FieldService $fieldService;
27 24 private NotificationService $notificationService;
28 25 private ConfirmationService $confirmationService;
26 + private EntryService $entryService;
29 27
28 + private RoutePermissionService $routePermissionService;
29 +
30 30 public function __construct(
31 31 FormService $formService,
32 32 FieldService $fieldService,
33 33 NotificationService $notificationService,
34 - ConfirmationService $confirmationService
34 + ConfirmationService $confirmationService,
35 + EntryService $entryService,
36 + RoutePermissionService $routePermissionService
35 37 ) {
36 - $this->formService = $formService;
37 - $this->fieldService = $fieldService;
38 - $this->notificationService = $notificationService;
39 - $this->confirmationService = $confirmationService;
38 + $this->formService = $formService;
39 + $this->fieldService = $fieldService;
40 + $this->notificationService = $notificationService;
41 + $this->confirmationService = $confirmationService;
42 + $this->entryService = $entryService;
43 + $this->routePermissionService = $routePermissionService;
40 44 }
41 45
42 46 /**
43 47 * Delete forms by IDs
@@ -46,11 +50,10 @@
46 50 *
47 51 * @return WP_REST_Response
48 52 *
49 53 * @throws InvalidArgumentException
50 - * @throws NotFoundException
51 54 * @throws ForbiddenException
52 - *
55 + * @throws QueryExecutionException
53 56 */
54 57 public function handle(WP_REST_Request $data): WP_REST_Response
55 58 {
56 59 // Verify the nonce
@@ -62,16 +65,27 @@
62 65 BackendStrings::getExceptionStrings()['invalid_request_data']
63 66 );
64 67 }
65 68
66 - $ids = Sanitizer::sanitizeIds($data->get_param('ids')) ;
69 + $ids = Sanitizer::sanitizeIds($data->get_param('ids'));
70 + if ($ids === []) {
71 + return new WP_REST_Response([
72 + 'success' => false,
73 + 'message' => BackendStrings::getExceptionStrings()['invalid_or_missing_ids'],
74 + ], 400);
75 + }
67 76
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);
77 + foreach ($ids as $formId) {
78 + if (!$this->routePermissionService->canDeleteForms((int) $formId)) {
79 + throw new ForbiddenException('forbidden');
80 + }
73 81 }
82 +
83 + $this->entryService->getDeletionManager()->deleteEntriesByFormIds($ids);
84 + $this->confirmationService->deleteConfirmationsByFormIds($ids);
85 + $this->notificationService->deleteNotificationsByFormIds($ids);
86 + $this->fieldService->deleteFieldsByFormIds($ids);
87 + $this->formService->deleteForms($ids);
74 88
75 89 return new WP_REST_Response(
76 90 [
77 91 'message' => BackendStrings::getCommonStrings()['ok'],