PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 1.5.21
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v1.5.21
2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 1.7.2 All 33 releases
fluent-booking / app / Hooks / Handlers / DataImporter.php

DataImporter.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 1.5.21, at app/Hooks/Handlers/DataImporter.php

54 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBooking\App\Hooks\Handlers;
4
5 use FluentBooking\App\App;
6 use FluentBooking\App\Services\CalendarService;
7
8 class DataImporter
9 {
10 public function importCalendar()
11 {
12 $app = App::getInstance();
13
14 $data = $app->request->all();
15
16 if (empty($data['type'] || empty($data['user_id'] || empty($data['author_timezone'])))) {
17 wp_send_json_error([
18 'message' => __('Please provide all required data', 'fluent-booking'),
19 ]);
20 }
21
22 $file = $app->request->file('file');
23
24 if (empty($file) || $file->getClientOriginalExtension() != 'json') {
25 wp_send_json_error([
26 'message' => __('Invalid file. Please provide a valid JSON file', 'fluent-booking'),
27 ]);
28 }
29
30 $fileContent = $file->getContents();
31
32 $calendarData = wp_parse_args($data, json_decode($fileContent, true));
33
34 if (empty($calendarData)) {
35 wp_send_json_error([
36 'message' => __('Invalid file. Please provide a valid JSON file', 'fluent-booking'),
37 ]);
38 }
39
40 $calendar = CalendarService::createCalendar($calendarData, false, true);
41
42 if (is_wp_error($calendar)) {
43 wp_send_json_error([
44 'message' => $calendar->get_error_message(),
45 ]);
46 }
47
48 wp_send_json([
49 'success' => true,
50 'message' => __('Calendar imported successfully', 'fluent-booking'),
51 ]);
52 }
53 }
54