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/Entry/DeleteEntriesController.php +37 -11 0.3 → 1.5 View file →
@@ -1,18 +1,13 @@
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\Entry;
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 12 use IvyForms\Common\Exceptions\NotFoundException;
18 13 use IvyForms\Common\Sanitizer\Sanitizer;
@@ -17,8 +12,10 @@
17 12 use IvyForms\Common\Exceptions\NotFoundException;
18 13 use IvyForms\Common\Sanitizer\Sanitizer;
19 14 use IvyForms\Controllers\Controller;
20 15 use IvyForms\Services\Entry\EntryService;
16 +use IvyForms\Services\Permissions\PermissionResourceResolver;
17 +use IvyForms\Services\Permissions\RoutePermissionService;
21 18 use IvyForms\Services\Translations\BackendStrings;
22 19 use WP_REST_Request;
23 20 use WP_REST_Response;
24 21
@@ -25,12 +22,20 @@
25 22 class DeleteEntriesController extends Controller
26 23 {
27 24 private EntryService $entryService;
28 25
26 + private RoutePermissionService $routePermissionService;
27 +
28 + private PermissionResourceResolver $permissionResourceResolver;
29 +
29 30 public function __construct(
30 - EntryService $entryService
31 + EntryService $entryService,
32 + RoutePermissionService $routePermissionService,
33 + PermissionResourceResolver $permissionResourceResolver
31 34 ) {
32 - $this->entryService = $entryService;
35 + $this->entryService = $entryService;
36 + $this->routePermissionService = $routePermissionService;
37 + $this->permissionResourceResolver = $permissionResourceResolver;
33 38 }
34 39
35 40 /**
36 41 * @param WP_REST_Request $data
@@ -51,14 +56,35 @@
51 56 BackendStrings::getExceptionStrings()['invalid_request_data']
52 57 );
53 58 }
54 59
55 - $ids = Sanitizer::sanitizeIds($data->get_param('ids')) ;
60 + $ids = Sanitizer::sanitizeIds($data->get_param('ids'));
61 + if ($ids === []) {
62 + return new WP_REST_Response([
63 + 'success' => false,
64 + 'message' => BackendStrings::getExceptionStrings()['invalid_or_missing_ids'],
65 + ], 400);
66 + }
56 67
68 + $formIdsByEntryId = $this->permissionResourceResolver->formIdsFromEntryIds($ids);
69 +
70 + foreach ($ids as $entryId) {
71 + $id = (int) $entryId;
72 + if (!isset($formIdsByEntryId[$id])) {
73 + throw new ForbiddenException('forbidden');
74 + }
75 + }
76 +
77 + foreach (array_unique(array_values($formIdsByEntryId)) as $formId) {
78 + if (!$this->routePermissionService->canDeleteEntries($formId)) {
79 + throw new ForbiddenException('forbidden');
80 + }
81 + }
82 +
57 83 // Bulk delete all entry fields for these entries
58 - $this->entryService->deleteEntryFieldsByEntryIds($ids);
84 + $this->entryService->getDeletionManager()->deleteEntryFieldsByEntryIds($ids);
59 85 // Bulk delete all entries
60 - $this->entryService->deleteEntriesByIds($ids);
86 + $this->entryService->getDeletionManager()->deleteEntriesByIds($ids);
61 87
62 88 // Return a success response
63 89 return new WP_REST_Response([
64 90 'message' => BackendStrings::getCommonStrings()['ok'],