PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.4
Booking for Appointments and Events Calendar – Amelia v2.4.4
2.4.4 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 / ProvidersGoogleCalendarTable.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
ProvidersGoogleCalendarTable.php
115 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 ProvidersGoogleCalendarTable
13 *
14 * @package AmeliaBooking\Infrastructure\WP\InstallActions\DB\User\Provider
15 */
16 class ProvidersGoogleCalendarTable extends AbstractDatabaseTable
17 {
18 public const TABLE = 'providers_to_google_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 /**
48 * @return array
49 */
50 public static function alterTable()
51 {
52 $table = self::getTableName();
53
54 global $wpdb;
55
56 /** @var SettingsService $settingsService */
57 $settingsService = new SettingsService(
58 new SettingsStorage()
59 );
60
61 $googleCalendarSettings = $settingsService->getCategorySettings('googleCalendar');
62
63 // Set default values for existing rows (runs only during 9.4.x versions)
64 if (
65 $googleCalendarSettings &&
66 version_compare(AMELIA_VERSION, '9.4', '>=') &&
67 version_compare(AMELIA_VERSION, '9.5', '<')
68 ) {
69 // Update insertPendingAppointments
70 $insertPendingAppointments = $googleCalendarSettings['insertPendingAppointments'];
71 $wpdb->query(
72 $wpdb->prepare(
73 "UPDATE {$table} SET insertPendingAppointments = %d WHERE insertPendingAppointments = 0",
74 $insertPendingAppointments
75 )
76 );
77
78 // Update includeBufferTime
79 $includeBufferTime = $googleCalendarSettings['includeBufferTimeGoogleCalendar'];
80 $wpdb->query(
81 $wpdb->prepare(
82 "UPDATE {$table} SET includeBufferTime = %d WHERE includeBufferTime = 0",
83 $includeBufferTime
84 )
85 );
86
87 // Update title
88 $titleJson = json_encode([
89 'appointment' => $googleCalendarSettings['title']['appointment'],
90 'event' => $googleCalendarSettings['title']['event']
91 ]);
92 $wpdb->query(
93 $wpdb->prepare(
94 "UPDATE {$table} SET title = %s WHERE title IS NULL",
95 $titleJson
96 )
97 );
98
99 // Update description
100 $descriptionJson = json_encode([
101 'appointment' => $googleCalendarSettings['description']['appointment'],
102 'event' => $googleCalendarSettings['description']['event']
103 ]);
104 $wpdb->query(
105 $wpdb->prepare(
106 "UPDATE {$table} SET description = %s WHERE description IS NULL",
107 $descriptionJson
108 )
109 );
110 }
111
112 return [];
113 }
114 }
115