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 / Bookable / PackagesCustomersServicesTable.php
ameliabooking / src / Infrastructure / WP / InstallActions / DB / Bookable Last commit date
CategoriesTable.php 3 months ago CategoriesTableInsertRows.php 6 months ago ExtrasTable.php 3 months ago PackagesCustomersServicesTable.php 3 months ago PackagesCustomersTable.php 3 weeks ago PackagesServicesLocationsTable.php 3 months ago PackagesServicesProvidersTable.php 3 months ago PackagesServicesTable.php 3 months ago PackagesTable.php 3 months ago ResourcesTable.php 3 months ago ResourcesToEntitiesTable.php 3 months ago ServicesTable.php 3 months ago ServicesViewsTable.php 3 months ago
PackagesCustomersServicesTable.php
69 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\WP\InstallActions\DB\Bookable;
4
5 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
6 use AmeliaBooking\Infrastructure\WP\InstallActions\DB\AbstractDatabaseTable;
7 use AmeliaBooking\Infrastructure\WP\InstallActions\DB\User\UsersTable;
8
9 /**
10 * Class PackagesCustomersServicesTable
11 *
12 * @package AmeliaBooking\Infrastructure\WP\InstallActions\DB\Bookable
13 */
14 class PackagesCustomersServicesTable extends AbstractDatabaseTable
15 {
16 public const TABLE = 'packages_customers_to_services';
17
18 /**
19 * @return string
20 * @throws InvalidArgumentException
21 */
22 public static function buildTable()
23 {
24 $table = self::getTableName();
25
26 $charsetCollate = self::getCharsetCollate();
27
28 return "CREATE TABLE {$table} (
29 `id` INT(11) NOT NULL AUTO_INCREMENT,
30 `packageCustomerId` INT(11) NOT NULL,
31 `serviceId` INT(11) NOT NULL,
32 `providerId` INT(11) NULL,
33 `locationId` INT(11) NULL,
34 `bookingsCount` INT(5) DEFAULT NULL,
35 PRIMARY KEY (`id`)
36 ) {$charsetCollate};";
37 }
38
39 /**
40 * @return array
41 * @throws InvalidArgumentException
42 */
43 public static function alterTable()
44 {
45 $table = self::getTableName();
46
47 $usersTable = UsersTable::getTableName();
48
49 global $wpdb;
50
51 $deletedProviderIds = $wpdb->get_col(
52 "SELECT t1.providerId FROM {$table} t1
53 WHERE t1.providerId NOT IN (SELECT t2.id FROM {$usersTable} t2)"
54 );
55
56 foreach ($deletedProviderIds as $key => $id) {
57 $deletedProviderIds[$key] = (int)$deletedProviderIds[$key];
58 }
59
60 if ($deletedProviderIds) {
61 $deletedProvidersIdsQuery = implode(', ', $deletedProviderIds);
62
63 $wpdb->query("UPDATE {$table} SET providerId = NULL WHERE providerId IN ({$deletedProvidersIdsQuery})");
64 }
65
66 return [];
67 }
68 }
69