PluginProbe
The Innovative Form Builder – IvyForms / 1.4
The Innovative Form Builder – IvyForms v1.4
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 / Form / BulkUpdateFormController.php

BulkUpdateFormController.php in The Innovative Form Builder – IvyForms 1.4, at backend/src/Controllers/Form/BulkUpdateFormController.php

82 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Controllers\Form;
4
5 use IvyForms\Common\Exceptions\InvalidArgumentException;
6 use IvyForms\Common\Sanitizer\Sanitizer;
7 use IvyForms\Controllers\Controller;
8 use IvyForms\Services\Form\FormService;
9 use IvyForms\Services\Translations\BackendStrings;
10 use WP_REST_Request;
11 use WP_REST_Response;
12
13 /**
14 * Class BulkUpdateFormController
15 *
16 * @package IvyForms\Controllers\Form
17 */
18 class BulkUpdateFormController extends Controller
19 {
20 private FormService $formService;
21
22 public function __construct(FormService $formService)
23 {
24 $this->formService = $formService;
25 }
26
27 /**
28 * Handle bulk update request for forms
29 *
30 * @param WP_REST_Request $data
31 *
32 * @return WP_REST_Response
33 *
34 * @throws InvalidArgumentException
35 */
36 public function handle(WP_REST_Request $data): WP_REST_Response
37 {
38 // Verify the nonce
39 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
40
41 // Check if the entry data is provided
42 if (empty($data->get_params())) {
43 throw new InvalidArgumentException(
44 BackendStrings::getExceptionStrings()['invalid_request_data']
45 );
46 }
47 // Sanitize request data
48 $sanitized = Sanitizer::sanitizeBulkUpdateData([
49 'column' => $data->get_param('column'),
50 'value' => $data->get_param('value'),
51 'ids' => $data->get_param('ids'),
52 ]);
53
54 // Validate IDs
55 if (empty($sanitized['ids'])) {
56 return new WP_REST_Response([
57 'success' => false,
58 'message' => BackendStrings::getExceptionStrings()['invalid_or_missing_ids'],
59 ], 400);
60 }
61
62 // Validate column
63 if (empty($sanitized['column'])) {
64 return new WP_REST_Response([
65 'success' => false,
66 'message' => BackendStrings::getExceptionStrings()['table_or_attribute_not_allowed'],
67 ], 400);
68 }
69
70 $this->formService->bulkUpdateColumn(
71 $sanitized['column'],
72 $sanitized['value'],
73 $sanitized['ids']
74 );
75
76 return new WP_REST_Response([
77 'success' => true,
78 'message' => BackendStrings::getExceptionStrings()['batch_update_successful'],
79 ], 200);
80 }
81 }
82