| 1 |
<?php |
| 2 |
|
| 3 |
namespace Bookit\Classes\Vendor; |
| 4 |
|
| 5 |
use Bookit\Classes\Admin\SettingsController; |
| 6 |
use Bookit\Classes\Base\User; |
| 7 |
use Bookit\Classes\Customization; |
| 8 |
use Bookit\Classes\Database\Appointments; |
| 9 |
use Bookit\Classes\Database\Coupons; |
| 10 |
use Bookit\Classes\Database\Discounts; |
| 11 |
use Bookit\Classes\Database\Services; |
| 12 |
use Bookit\Classes\Database\Payments; |
| 13 |
use Bookit\Classes\Database\Staff; |
| 14 |
use Bookit\Helpers\MailTemplateHelper; |
| 15 |
|
| 16 |
abstract class BookitUpdateCallbacks { |
| 17 |
|
| 18 |
/** 2.0.1 */ |
| 19 |
public static function add_services_icon() { |
| 20 |
global $wpdb; |
| 21 |
/** |
| 22 |
* Add ICON column to Services table. |
| 23 |
*/ |
| 24 |
if ( ! $wpdb->get_var( sprintf( "SHOW COLUMNS FROM `%s` LIKE 'icon_id';", esc_sql( Services::_table() ) ) ) ) { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 25 |
$wpdb->query( sprintf( 'ALTER TABLE `%s` ADD `icon_id` INT NULL;', esc_sql( Services::_table() ) ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* 2.0.9 |
| 31 |
* Add currency default value to main settings. |
| 32 |
*/ |
| 33 |
public static function add_currency() { |
| 34 |
$currency = get_option_by_path( 'bookit_settings.currency' ); |
| 35 |
|
| 36 |
if ( ! $currency ) { |
| 37 |
$settings = SettingsController::get_settings(); |
| 38 |
$settings['currency'] = SettingsController::$default_currency; |
| 39 |
SettingsController::save_settings( $settings ); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
/** 2.1.0 */ |
| 44 |
public static function add_appointment_deleted_email_templates() { |
| 45 |
|
| 46 |
$appointment_deleted_customer = get_option_by_path( 'bookit_settings.emails.appointment_deleted_customer' ); |
| 47 |
$appointment_deleted_staff = get_option_by_path( 'bookit_settings.emails.appointment_deleted_staff' ); |
| 48 |
|
| 49 |
$settings = SettingsController::get_settings(); |
| 50 |
if ( ! $appointment_deleted_customer ) { |
| 51 |
$settings['emails']['appointment_deleted_customer'] |
| 52 |
= MailTemplateHelper::getTemplatesByName( 'appointment_deleted_customer' ); |
| 53 |
} |
| 54 |
|
| 55 |
if ( ! $appointment_deleted_staff ) { |
| 56 |
$settings['emails']['appointment_deleted_staff'] |
| 57 |
= MailTemplateHelper::getTemplatesByName( 'appointment_deleted_staff' ); |
| 58 |
} |
| 59 |
|
| 60 |
SettingsController::save_settings( $settings ); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* 2.1.0 |
| 65 |
* Add notes column to Appointment table. |
| 66 |
*/ |
| 67 |
public static function add_appointment_notes() { |
| 68 |
global $wpdb; |
| 69 |
if ( ! $wpdb->get_var( sprintf( "SHOW COLUMNS FROM `%s` LIKE 'notes';", esc_sql( Appointments::_table() ) ) ) ) { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 70 |
$wpdb->query( sprintf( 'ALTER TABLE `%s` ADD `notes` longtext DEFAULT NULL;', esc_sql( Appointments::_table() ) ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
/** 2.1.3 */ |
| 75 |
public static function add_time_slot_duration_setting() { |
| 76 |
$time_slot_duration = get_option_by_path( 'bookit_settings.time_slot_duration' ); |
| 77 |
|
| 78 |
if ( ! $time_slot_duration ) { |
| 79 |
$settings = SettingsController::get_settings(); |
| 80 |
$settings['time_slot_duration'] = SettingsController::$time_slot_default_duration; |
| 81 |
SettingsController::save_settings( $settings ); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* 2.1.3 |
| 87 |
* Add Payments table. |
| 88 |
*/ |
| 89 |
public static function add_payment_table() { |
| 90 |
Payments::create_table(); |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* 2.1.3 |
| 95 |
* Add Discounts table. |
| 96 |
*/ |
| 97 |
public static function add_discount_table() { |
| 98 |
Discounts::create_table(); |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* 2.1.3 |
| 103 |
* Add Coupons table. |
| 104 |
*/ |
| 105 |
public static function add_coupon_table() { |
| 106 |
Coupons::create_table(); |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* 2.1.3 |
| 111 |
* Update Appointment table |
| 112 |
* add created_at, updated_at, created_from fields |
| 113 |
*/ |
| 114 |
public static function add_appointment_table_fields() { |
| 115 |
global $wpdb; |
| 116 |
if ( ! $wpdb->get_var( sprintf( "SHOW COLUMNS FROM `%s` LIKE 'created_from';", esc_sql( Appointments::_table() ) ) ) ) { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 117 |
$wpdb->query( sprintf( "ALTER TABLE `%s` ADD `created_from` ENUM( 'front', 'back' ) NOT NULL DEFAULT 'front';", esc_sql( Appointments::_table() ) ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 118 |
} |
| 119 |
|
| 120 |
if ( ! $wpdb->get_var( sprintf( "SHOW COLUMNS FROM `%s` LIKE 'created_at';", esc_sql( Appointments::_table() ) ) ) ) { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 121 |
$wpdb->query( sprintf( 'ALTER TABLE `%s` ADD `created_at` DATETIME NOT NULL;', esc_sql( Appointments::_table() ) ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* 2.1.3 |
| 127 |
* Update Appointment table, remove payment_method and payment_status |
| 128 |
*/ |
| 129 |
public static function drop_appointment_table_payment_fields() { |
| 130 |
global $wpdb; |
| 131 |
if ( $wpdb->get_var( sprintf( "SHOW COLUMNS FROM `%s` LIKE 'payment_method';", esc_sql( Appointments::_table() ) ) ) ) { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 132 |
$wpdb->query( sprintf( 'ALTER TABLE `%s` DROP COLUMN `payment_method`;', esc_sql( Appointments::_table() ) ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 133 |
} |
| 134 |
|
| 135 |
if ( $wpdb->get_var( sprintf( "SHOW COLUMNS FROM `%s` LIKE 'payment_status';", esc_sql( Appointments::_table() ) ) ) ) { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 136 |
$wpdb->query( sprintf( 'ALTER TABLE `%s` DROP COLUMN `payment_status`;', esc_sql( Appointments::_table() ) ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
/** 2.1.3 */ |
| 141 |
public static function refactor_exist_appointments() { |
| 142 |
global $wpdb; |
| 143 |
|
| 144 |
/** add new appointment fields before refactoring */ |
| 145 |
self::add_appointment_table_fields(); |
| 146 |
|
| 147 |
$appointments = Appointments::get_all(); |
| 148 |
foreach ( $appointments as $appointment ) { |
| 149 |
$exist = Payments::get( 'appointment_id', $appointment['id'] ); |
| 150 |
if ( null != $exist ) { |
| 151 |
continue; |
| 152 |
} |
| 153 |
$created_at = date_i18n( 'Y-m-d H:i:s', $appointment['start_time'] ); |
| 154 |
$payment = array( |
| 155 |
'appointment_id' => $appointment['id'], |
| 156 |
'type' => $appointment['payment_method'] ?: Payments::$defaultType, // phpcs:ignore WordPress.PHP.DisallowShortTernary.Found |
| 157 |
'status' => $appointment['payment_status'] ?: Payments::$defaultStatus, // phpcs:ignore WordPress.PHP.DisallowShortTernary.Found |
| 158 |
'total' => $appointment['price'], |
| 159 |
'created_at' => $created_at, |
| 160 |
'updated_at' => $created_at, |
| 161 |
); |
| 162 |
|
| 163 |
$wpdb->update( |
| 164 |
Appointments::_table(), |
| 165 |
array( |
| 166 |
'created_at' => $created_at, |
| 167 |
'updated_at' => $created_at, |
| 168 |
), |
| 169 |
array( 'id' => $appointment['id'] ) |
| 170 |
); |
| 171 |
Payments::insert( $payment ); |
| 172 |
} |
| 173 |
|
| 174 |
/** remove appointment payment fields after refactoring */ |
| 175 |
self::drop_appointment_table_payment_fields(); |
| 176 |
} |
| 177 |
|
| 178 |
/** 2.1.5 */ |
| 179 |
public static function update_payment_type_enum_field() { |
| 180 |
global $wpdb; |
| 181 |
if ( $wpdb->get_var( sprintf( "SHOW COLUMNS FROM `%s` LIKE 'type';", esc_sql( Payments::_table() ) ) ) ) { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 182 |
$wpdb->query( |
| 183 |
sprintf( |
| 184 |
"ALTER TABLE `%s` MODIFY `type` ENUM( 'locally', 'stripeConnect', 'paypal', 'stripe', 'woocommerce', 'free' );", |
| 185 |
esc_sql( Payments::_table() ) // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 186 |
) |
| 187 |
); |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
/** 2.1.7 */ |
| 192 |
public static function add_senders() { |
| 193 |
|
| 194 |
$sender_name = get_option_by_path( 'bookit_settings.sender_name' ); |
| 195 |
$sender_email = get_option_by_path( 'bookit_settings.sender_email' ); |
| 196 |
|
| 197 |
if ( ! $sender_name && ! $sender_email ) { |
| 198 |
$settings = SettingsController::get_settings(); |
| 199 |
$settings['sender_name'] = SettingsController::$default_sender_name; |
| 200 |
$settings['sender_email'] = SettingsController::$default_sender_email; |
| 201 |
SettingsController::save_settings( $settings ); |
| 202 |
} |
| 203 |
|
| 204 |
} |
| 205 |
|
| 206 |
/** 2.1.7 */ |
| 207 |
public static function add_wp_user_to_staff() { |
| 208 |
global $wpdb; |
| 209 |
if ( ! $wpdb->get_var( sprintf( "SHOW COLUMNS FROM `%s` LIKE 'wp_user_id';", esc_sql( Staff::_table() ) ) ) ) { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 210 |
$wpdb->query( sprintf( 'ALTER TABLE `%s` ADD `wp_user_id` BIGINT(20);', esc_sql( Staff::_table() ) ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
/** 2.1.7 */ |
| 215 |
public static function add_bookit_user_roles_and_capabilitites() { |
| 216 |
User::addBookitUserRoles(); |
| 217 |
User::addBookitCapabilitiesToWpRoles(); |
| 218 |
} |
| 219 |
|
| 220 |
/** 2.1.7 */ |
| 221 |
public static function add_clean_all_on_delete() { |
| 222 |
if ( ! get_option_by_path( 'bookit_settings.clean_all_on_delete' ) ) { |
| 223 |
$settings = SettingsController::get_settings(); |
| 224 |
$settings['clean_all_on_delete'] = false; |
| 225 |
SettingsController::save_settings( $settings ); |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
/** 2.1.7 */ |
| 230 |
public static function add_appointment_status_changed_admin_template() { |
| 231 |
$template = get_option_by_path( 'bookit_settings.emails.appointment_status_changed_admin' ); |
| 232 |
$settings = SettingsController::get_settings(); |
| 233 |
if ( ! $template ) { |
| 234 |
$settings['emails']['appointment_status_changed_admin'] |
| 235 |
= MailTemplateHelper::getTemplatesByName( 'appointment_status_changed_admin' ); |
| 236 |
} |
| 237 |
SettingsController::save_settings( $settings ); |
| 238 |
} |
| 239 |
|
| 240 |
/** 2.1.7 */ |
| 241 |
public static function replace_theme_to_calendar_view() { |
| 242 |
$is_theme = get_option_by_path( 'bookit_settings.theme' ); |
| 243 |
|
| 244 |
if ( $is_theme ) { |
| 245 |
$settings = SettingsController::get_settings(); |
| 246 |
$settings['calendar_view'] = SettingsController::$default_view_type; |
| 247 |
unset( $settings['theme'] ); |
| 248 |
|
| 249 |
SettingsController::save_settings( $settings ); |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
/** |
| 254 |
* 2.2.0 |
| 255 |
* Add calendar_view default value to main settings. |
| 256 |
*/ |
| 257 |
public static function add_calendar_view_type_to_settings() { |
| 258 |
$calendar_view = get_option_by_path( 'bookit_settings.calendar_view' ); |
| 259 |
$settings = SettingsController::get_settings(); |
| 260 |
|
| 261 |
if ( ! $calendar_view ) { |
| 262 |
$settings['calendar_view'] = SettingsController::$default_view_type; |
| 263 |
SettingsController::save_settings( $settings ); |
| 264 |
} |
| 265 |
|
| 266 |
Customization::custom_colors( $settings, true ); |
| 267 |
} |
| 268 |
|
| 269 |
/** 2.2.1 */ |
| 270 |
public static function add_admin_notification_transient() { |
| 271 |
set_transient( |
| 272 |
'stm_bookit_notice_setting', |
| 273 |
array( |
| 274 |
'show_time' => DAY_IN_SECONDS * 3 + time(), |
| 275 |
'step' => 0, |
| 276 |
'prev_action' => '', |
| 277 |
) |
| 278 |
); |
| 279 |
} |
| 280 |
|
| 281 |
/** |
| 282 |
* Update Payment method enum. |
| 283 |
* |
| 284 |
* @since 2.5.0 |
| 285 |
*/ |
| 286 |
public static function update_payment_methods_enum() { |
| 287 |
Payments::update_payment_methods_enum(); |
| 288 |
} |
| 289 |
|
| 290 |
/** |
| 291 |
* Add a unique index on the payments `transaction` column. |
| 292 |
* |
| 293 |
* @since 2.6.0.4 |
| 294 |
*/ |
| 295 |
public static function add_payment_transaction_claim_schema() { |
| 296 |
Payments::add_payment_transaction_claim_schema(); |
| 297 |
} |
| 298 |
} |
| 299 |
|