PluginProbe
The Innovative Form Builder – IvyForms / 1.0
The Innovative Form Builder – IvyForms v1.0
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
ivyforms / backend / src / Controllers / Entry / DeleteEntriesController.php

DeleteEntriesController.php in The Innovative Form Builder – IvyForms 1.0, at backend/src/Controllers/Entry/DeleteEntriesController.php

64 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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\Entry;
9
10 use IvyForms\Common\Exceptions\ForbiddenException;
11 use IvyForms\Common\Exceptions\InvalidArgumentException;
12 use IvyForms\Common\Exceptions\NotFoundException;
13 use IvyForms\Common\Sanitizer\Sanitizer;
14 use IvyForms\Controllers\Controller;
15 use IvyForms\Services\Entry\EntryService;
16 use IvyForms\Services\Translations\BackendStrings;
17 use WP_REST_Request;
18 use WP_REST_Response;
19
20 class DeleteEntriesController extends Controller
21 {
22 private EntryService $entryService;
23
24 public function __construct(
25 EntryService $entryService
26 ) {
27 $this->entryService = $entryService;
28 }
29
30 /**
31 * @param WP_REST_Request $data
32 *
33 * @return WP_REST_Response
34 * @throws NotFoundException
35 * @throws InvalidArgumentException
36 * @throws ForbiddenException
37 */
38 public function handle(WP_REST_Request $data): WP_REST_Response
39 {
40 // Verify the nonce
41 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
42
43 // Check if the form IDs are provided
44 if (empty($data->get_params())) {
45 throw new InvalidArgumentException(
46 BackendStrings::getExceptionStrings()['invalid_request_data']
47 );
48 }
49
50 $ids = Sanitizer::sanitizeIds($data->get_param('ids')) ;
51
52 // Bulk delete all entry fields for these entries
53 $this->entryService->getDeletionManager()->deleteEntryFieldsByEntryIds($ids);
54 // Bulk delete all entries
55 $this->entryService->getDeletionManager()->deleteEntriesByIds($ids);
56
57 // Return a success response
58 return new WP_REST_Response([
59 'message' => BackendStrings::getCommonStrings()['ok'],
60 'data' => null,
61 ], 200);
62 }
63 }
64