PluginProbe
The Innovative Form Builder – IvyForms / 0.9
The Innovative Form Builder – IvyForms v0.9
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 0.9, at backend/src/Controllers/Form/BulkUpdateFormController.php

87 lines 2.4 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 // phpcs:disable PSR1.Files.SideEffects
6 if (!defined('ABSPATH')) {
7 exit; // Exit if accessed directly
8 }
9
10 use IvyForms\Common\Exceptions\InvalidArgumentException;
11 use IvyForms\Common\Sanitizer\Sanitizer;
12 use IvyForms\Controllers\Controller;
13 use IvyForms\Services\Form\FormService;
14 use IvyForms\Services\Translations\BackendStrings;
15 use WP_REST_Request;
16 use WP_REST_Response;
17
18 /**
19 * Class BulkUpdateFormController
20 *
21 * @package IvyForms\Controllers\Form
22 */
23 class BulkUpdateFormController extends Controller
24 {
25 private FormService $formService;
26
27 public function __construct(FormService $formService)
28 {
29 $this->formService = $formService;
30 }
31
32 /**
33 * Handle bulk update request for forms
34 *
35 * @param WP_REST_Request $data
36 *
37 * @return WP_REST_Response
38 *
39 * @throws InvalidArgumentException
40 */
41 public function handle(WP_REST_Request $data): WP_REST_Response
42 {
43 // Verify the nonce
44 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
45
46 // Check if the entry data is provided
47 if (empty($data->get_params())) {
48 throw new InvalidArgumentException(
49 BackendStrings::getExceptionStrings()['invalid_request_data']
50 );
51 }
52 // Sanitize request data
53 $sanitized = Sanitizer::sanitizeBulkUpdateData([
54 'column' => $data->get_param('column'),
55 'value' => $data->get_param('value'),
56 'ids' => $data->get_param('ids'),
57 ]);
58
59 // Validate IDs
60 if (empty($sanitized['ids'])) {
61 return new WP_REST_Response([
62 'success' => false,
63 'message' => BackendStrings::getExceptionStrings()['invalid_or_missing_ids'],
64 ], 400);
65 }
66
67 // Validate column
68 if (empty($sanitized['column'])) {
69 return new WP_REST_Response([
70 'success' => false,
71 'message' => BackendStrings::getExceptionStrings()['table_or_attribute_not_allowed'],
72 ], 400);
73 }
74
75 $this->formService->bulkUpdateColumn(
76 $sanitized['column'],
77 $sanitized['value'],
78 $sanitized['ids']
79 );
80
81 return new WP_REST_Response([
82 'success' => true,
83 'message' => BackendStrings::getExceptionStrings()['batch_update_successful'],
84 ], 200);
85 }
86 }
87