PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Infrastructure / WP / InstallActions / DB / User / Provider / ProvidersOutlookCalendarTable.php
ameliabooking / src / Infrastructure / WP / InstallActions / DB / User / Provider Last commit date
ProvidersDayOffTable.php 3 months ago ProvidersGoogleCalendarTable.php 2 months ago ProvidersLocationTable.php 3 months ago ProvidersOutlookCalendarTable.php 2 months ago ProvidersPeriodLocationTable.php 3 months ago ProvidersPeriodServiceTable.php 3 months ago ProvidersPeriodTable.php 3 months ago ProvidersServiceTable.php 3 months ago ProvidersSpecialDayPeriodLocationTable.php 3 months ago ProvidersSpecialDayPeriodServiceTable.php 3 months ago ProvidersSpecialDayPeriodTable.php 3 months ago ProvidersSpecialDayTable.php 3 months ago ProvidersTimeOutTable.php 3 months ago ProvidersViewsTable.php 3 months ago ProvidersWeekDayTable.php 3 months ago
ProvidersOutlookCalendarTable.php
110 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\WP\InstallActions\DB\User\Provider;
4
5 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
6 use AmeliaBooking\Domain\Services\Settings\SettingsService;
7 use AmeliaBooking\Domain\ValueObjects\String\Email;
8 use AmeliaBooking\Infrastructure\WP\InstallActions\DB\AbstractDatabaseTable;
9 use AmeliaBooking\Infrastructure\WP\SettingsService\SettingsStorage;
10
11 /**
12 * Class ProvidersOutlookCalendarTable
13 *
14 * @package AmeliaBooking\Infrastructure\WP\InstallActions\DB\User\Provider
15 */
16 class ProvidersOutlookCalendarTable extends AbstractDatabaseTable
17 {
18 public const TABLE = 'providers_to_outlook_calendar';
19
20 /**
21 * @return string
22 * @throws InvalidArgumentException
23 */
24 public static function buildTable()
25 {
26 $table = self::getTableName();
27
28 $charsetCollate = self::getCharsetCollate();
29
30 $email = Email::MAX_LENGTH;
31
32 return "CREATE TABLE {$table} (
33 `id` INT(11) NOT NULL AUTO_INCREMENT,
34 `userId` INT(11) NOT NULL,
35 `token` TEXT NOT NULL,
36 `calendarId` TEXT({$email}) NULL,
37 `blockedCalendars` TEXT NULL,
38 `insertPendingAppointments` TINYINT(1) DEFAULT 0,
39 `includeBufferTime` TINYINT(1) DEFAULT 0,
40 `title` TEXT NULL,
41 `description` TEXT NULL,
42 PRIMARY KEY (`id`),
43 UNIQUE KEY `id` (`id`)
44 ) {$charsetCollate};";
45 }
46
47 public static function alterTable()
48 {
49 $table = self::getTableName();
50
51 global $wpdb;
52
53 /** @var SettingsService $settingsService */
54 $settingsService = new SettingsService(new SettingsStorage());
55
56 $outlookCalendarSettings = $settingsService->getCategorySettings('outlookCalendar');
57
58 // Set default values for existing rows (runs only during 9.4 versions)
59 if (
60 $outlookCalendarSettings &&
61 version_compare(AMELIA_VERSION, '9.4', '>=') &&
62 version_compare(AMELIA_VERSION, '9.5', '<')
63 ) {
64 // Update insertPendingAppointments
65 $insertPendingAppointments = $outlookCalendarSettings['insertPendingAppointments'];
66 $wpdb->query(
67 $wpdb->prepare(
68 "UPDATE {$table} SET insertPendingAppointments = %d WHERE insertPendingAppointments = 0",
69 $insertPendingAppointments
70 )
71 );
72
73 // Update includeBufferTime
74 $includeBufferTime = $outlookCalendarSettings['includeBufferTimeOutlookCalendar'];
75 $wpdb->query(
76 $wpdb->prepare(
77 "UPDATE {$table} SET includeBufferTime = %d WHERE includeBufferTime = 0",
78 $includeBufferTime
79 )
80 );
81
82 // Update title
83 $titleJson = json_encode([
84 'appointment' => $outlookCalendarSettings['title']['appointment'],
85 'event' => $outlookCalendarSettings['title']['event']
86 ]);
87 $wpdb->query(
88 $wpdb->prepare(
89 "UPDATE {$table} SET title = %s WHERE title IS NULL",
90 $titleJson
91 )
92 );
93
94 // Update description
95 $descriptionJson = json_encode([
96 'appointment' => $outlookCalendarSettings['description']['appointment'],
97 'event' => $outlookCalendarSettings['description']['event']
98 ]);
99 $wpdb->query(
100 $wpdb->prepare(
101 "UPDATE {$table} SET description = %s WHERE description IS NULL",
102 $descriptionJson
103 )
104 );
105 }
106
107 return [];
108 }
109 }
110