activities_helper.php
3 months ago
agent_helper.php
3 months ago
analytics_helper.php
1 week ago
auth_helper.php
6 days ago
blocks_helper.php
2 weeks ago
booking_helper.php
4 days ago
bricks_helper.php
3 months ago
bundles_helper.php
4 days ago
calendar_helper.php
2 days ago
carts_helper.php
3 months ago
connector_helper.php
3 months ago
csv_helper.php
3 months ago
customer_helper.php
1 month ago
customer_import_helper.php
1 month ago
database_helper.php
1 week ago
debug_helper.php
3 months ago
defaults_helper.php
3 months ago
elementor_helper.php
3 months ago
email_helper.php
3 months ago
encrypt_helper.php
3 months ago
events_helper.php
3 months ago
form_helper.php
3 months ago
icalendar_helper.php
3 months ago
image_helper.php
3 months ago
invoices_helper.php
2 weeks ago
license_helper.php
3 months ago
location_helper.php
3 months ago
marketing_systems_helper.php
3 months ago
meeting_systems_helper.php
3 months ago
menu_helper.php
2 weeks ago
meta_helper.php
3 months ago
migrations_helper.php
3 months ago
money_helper.php
3 months ago
notifications_helper.php
3 months ago
nps_survey_helper.php
3 months ago
order_intent_helper.php
2 months ago
orders_helper.php
3 months ago
otp_helper.php
3 months ago
pages_helper.php
3 months ago
params_helper.php
3 months ago
payments_helper.php
2 months ago
plugin_version_update_helper.php
2 months ago
price_breakdown_helper.php
3 months ago
process_jobs_helper.php
3 months ago
processes_helper.php
3 months ago
razorpay_connect_helper.php
1 week ago
replacer_helper.php
3 months ago
resource_helper.php
4 days ago
roles_helper.php
2 weeks ago
router_helper.php
3 months ago
service_helper.php
3 months ago
sessions_helper.php
3 months ago
settings_helper.php
1 week ago
short_links_systems_helper.php
3 months ago
shortcodes_helper.php
2 weeks ago
sms_helper.php
3 months ago
steps_helper.php
1 week ago
stripe_connect_helper.php
1 week ago
styles_helper.php
3 months ago
support_topics_helper.php
3 months ago
time_helper.php
2 months ago
timeline_helper.php
2 months ago
transaction_helper.php
1 month ago
transaction_intent_helper.php
3 months ago
util_helper.php
1 month ago
version_specific_updates_helper.php
3 months ago
whatsapp_helper.php
1 month ago
work_periods_helper.php
3 months ago
wp_datetime.php
3 months ago
wp_user_helper.php
3 months ago
version_specific_updates_helper.php
540 lines
| 1 | <?php |
| 2 | |
| 3 | class OsVersionSpecificUpdatesHelper { |
| 4 | |
| 5 | |
| 6 | /** |
| 7 | * |
| 8 | * Used to target a specific version during an update |
| 9 | * |
| 10 | * @return bool |
| 11 | */ |
| 12 | public static function run_version_specific_updates() { |
| 13 | $current_db_version = OsSettingsHelper::get_db_version(); |
| 14 | if ( ! $current_db_version ) { |
| 15 | return false; |
| 16 | } |
| 17 | $sqls = []; |
| 18 | if ( version_compare( '1.0.2', $current_db_version ) > 0 ) { |
| 19 | // lower than 1.0.2 |
| 20 | $sqls = self::get_queries_for_nullable_columns(); |
| 21 | OsDatabaseHelper::run_queries( $sqls ); |
| 22 | } |
| 23 | if ( version_compare( '1.1.0', $current_db_version ) > 0 ) { |
| 24 | // lower than 1.1.0 |
| 25 | $sqls = self::set_end_date_for_bookings(); |
| 26 | OsDatabaseHelper::run_queries( $sqls ); |
| 27 | } |
| 28 | if ( version_compare( '1.3.0', $current_db_version ) > 0 ) { |
| 29 | // lower than 1.3.0 |
| 30 | $sqls = []; |
| 31 | $sqls[] = 'UPDATE ' . LATEPOINT_TABLE_BOOKINGS . ' SET total_attendees = 1 WHERE total_attendees IS NULL;'; |
| 32 | $sqls[] = 'UPDATE ' . LATEPOINT_TABLE_SERVICES . " SET visibility = '" . LATEPOINT_SERVICE_VISIBILITY_VISIBLE . "' WHERE visibility IS NULL OR visibility = '';"; |
| 33 | $sqls[] = 'UPDATE ' . LATEPOINT_TABLE_SERVICES . ' SET capacity_min = 1 WHERE capacity_min IS NULL;'; |
| 34 | $sqls[] = 'UPDATE ' . LATEPOINT_TABLE_SERVICES . ' SET capacity_max = 1 WHERE capacity_max IS NULL;'; |
| 35 | OsDatabaseHelper::run_queries( $sqls ); |
| 36 | } |
| 37 | if ( version_compare( '1.3.1', $current_db_version ) > 0 ) { |
| 38 | $sqls = []; |
| 39 | $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_CUSTOMERS . ' MODIFY COLUMN first_name varchar(255)'; |
| 40 | OsDatabaseHelper::run_queries( $sqls ); |
| 41 | } |
| 42 | if ( version_compare( '1.3.7', $current_db_version ) > 0 ) { |
| 43 | $sqls = []; |
| 44 | $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_AGENTS . ' MODIFY COLUMN wp_user_id int(11)'; |
| 45 | OsDatabaseHelper::run_queries( $sqls ); |
| 46 | } |
| 47 | if ( version_compare( '1.4.8', $current_db_version ) > 0 ) { |
| 48 | update_option( 'latepoint_db_seeded', true ); |
| 49 | OsSettingsHelper::save_setting_by_name( 'timeslot_blocking_statuses', LATEPOINT_BOOKING_STATUS_APPROVED ); |
| 50 | OsSettingsHelper::save_setting_by_name( 'calendar_hidden_statuses', LATEPOINT_BOOKING_STATUS_CANCELLED ); |
| 51 | OsSettingsHelper::save_setting_by_name( 'need_action_statuses', implode( ',', [ LATEPOINT_BOOKING_STATUS_PENDING, LATEPOINT_BOOKING_STATUS_PAYMENT_PENDING ] ) ); |
| 52 | $tile_info = OsSettingsHelper::get_booking_template_for_calendar(); |
| 53 | $tile_info = OsUtilHelper::replace_single_curly_with_double( $tile_info ); |
| 54 | OsSettingsHelper::save_setting_by_name( 'booking_template_for_calendar', $tile_info ); |
| 55 | |
| 56 | // ------- |
| 57 | // Update {var} to {{var}} |
| 58 | // ------- |
| 59 | |
| 60 | // password reset message |
| 61 | $content_to_replace = OsUtilHelper::replace_single_curly_with_double( OsSettingsHelper::get_settings_value( 'email_customer_password_reset_request_content', '' ) ); |
| 62 | OsSettingsHelper::save_setting_by_name( 'email_customer_password_reset_request_content', $content_to_replace ); |
| 63 | |
| 64 | // new message (chat) |
| 65 | $content_to_replace = OsUtilHelper::replace_single_curly_with_double( OsSettingsHelper::get_settings_value( 'email_notification_customer_has_new_message_content', '' ) ); |
| 66 | OsSettingsHelper::save_setting_by_name( 'email_notification_customer_has_new_message_content', $content_to_replace ); |
| 67 | |
| 68 | // js tracking code |
| 69 | $content_to_replace = OsUtilHelper::replace_single_curly_with_double( OsSettingsHelper::get_settings_value( 'confirmation_step_tracking_code', '' ) ); |
| 70 | OsSettingsHelper::save_setting_by_name( 'confirmation_step_tracking_code', $content_to_replace ); |
| 71 | |
| 72 | // Google calendar |
| 73 | $content_to_replace = OsUtilHelper::replace_single_curly_with_double( OsSettingsHelper::get_settings_value( 'google_calendar_event_summary_template', '' ) ); |
| 74 | if ( ! empty( $content_to_replace ) ) { |
| 75 | OsSettingsHelper::save_setting_by_name( 'google_calendar_event_summary_template', $content_to_replace ); |
| 76 | } |
| 77 | $content_to_replace = OsUtilHelper::replace_single_curly_with_double( OsSettingsHelper::get_settings_value( 'google_calendar_event_description_template', '' ) ); |
| 78 | if ( ! empty( $content_to_replace ) ) { |
| 79 | OsSettingsHelper::save_setting_by_name( 'google_calendar_event_description_template', $content_to_replace ); |
| 80 | } |
| 81 | |
| 82 | |
| 83 | // ------- |
| 84 | // migrate old notification system to processes |
| 85 | // ------- |
| 86 | |
| 87 | $process_actions = []; |
| 88 | // STATUS CHANGE NOTIFICATION |
| 89 | |
| 90 | if ( OsSettingsHelper::is_on( 'notifications_email' ) ) { |
| 91 | |
| 92 | |
| 93 | foreach ( [ 'agent', 'customer' ] as $user_type ) { |
| 94 | $action = []; |
| 95 | if ( OsSettingsHelper::is_on( 'notification_' . $user_type . '_booking_status_changed' ) ) { |
| 96 | $action['type'] = 'send_email'; |
| 97 | $action['settings']['to_email'] = '{{' . $user_type . '_full_name}} <{{' . $user_type . '_email}}>'; |
| 98 | $action['settings']['subject'] = OsUtilHelper::replace_single_curly_with_double( OsSettingsHelper::get_settings_value( 'notification_' . $user_type . '_booking_status_changed_notification_subject', '' ) ); |
| 99 | $action['settings']['content'] = OsUtilHelper::replace_single_curly_with_double( OsSettingsHelper::get_settings_value( 'notification_' . $user_type . '_booking_status_changed_notification_content', '' ) ); |
| 100 | $process_actions[ \LatePoint\Misc\ProcessAction::generate_id() ] = $action; |
| 101 | } |
| 102 | } |
| 103 | if ( $process_actions ) { |
| 104 | // put all under single process with multiple actions |
| 105 | $process = new OsProcessModel(); |
| 106 | $process->event_type = 'booking_updated'; |
| 107 | $process->name = 'Booking status change notification'; |
| 108 | |
| 109 | $trigger_conditions[] = [ |
| 110 | 'object' => 'old_booking', |
| 111 | 'property' => 'old_booking__status', |
| 112 | 'operator' => 'changed', |
| 113 | 'value' => '', |
| 114 | ]; |
| 115 | $process_actions = OsProcessesHelper::iterate_trigger_conditions( $trigger_conditions, $process_actions ); |
| 116 | $process_actions[0]['time_offset'] = []; |
| 117 | $process->actions_json = wp_json_encode( $process_actions ); |
| 118 | if ( ! OsProcessesHelper::check_if_process_exists( $process ) ) { |
| 119 | $process->save(); |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | |
| 125 | $process_actions = []; |
| 126 | // NEW BOOKING NOTIFICATION |
| 127 | if ( OsSettingsHelper::is_on( 'notifications_email' ) ) { |
| 128 | OsSettingsHelper::save_setting_by_name( 'notifications_email_processor', 'wp_mail' ); |
| 129 | |
| 130 | foreach ( [ 'agent', 'customer' ] as $user_type ) { |
| 131 | $action = []; |
| 132 | if ( OsSettingsHelper::is_on( 'notification_' . $user_type . '_confirmation' ) ) { |
| 133 | $action['type'] = 'send_email'; |
| 134 | $action['settings']['to_email'] = '{{' . $user_type . '_email}}'; |
| 135 | $action['settings']['subject'] = OsUtilHelper::replace_single_curly_with_double( OsSettingsHelper::get_settings_value( ( ( $user_type == 'agent' ) ? 'notification_agent_new_booking_notification_subject' : 'notification_customer_booking_confirmation_subject' ), '' ) ); |
| 136 | $action['settings']['content'] = OsUtilHelper::replace_single_curly_with_double( OsSettingsHelper::get_settings_value( ( ( $user_type == 'agent' ) ? 'notification_agent_new_booking_notification_content' : 'notification_customer_booking_confirmation_content' ), '' ) ); |
| 137 | $process_actions[ \LatePoint\Misc\ProcessAction::generate_id() ] = $action; |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | if ( OsSettingsHelper::is_on( 'notifications_sms' ) ) { |
| 142 | OsSettingsHelper::save_setting_by_name( 'notifications_sms_processor', 'twilio' ); |
| 143 | // sms |
| 144 | foreach ( [ 'agent', 'customer' ] as $user_type ) { |
| 145 | $action = []; |
| 146 | if ( OsSettingsHelper::is_on( 'notification_sms_' . $user_type . '_confirmation' ) ) { |
| 147 | $action['type'] = 'send_sms'; |
| 148 | $action['settings']['to_phone'] = '{{' . $user_type . '_phone}}'; |
| 149 | $action['settings']['content'] = OsUtilHelper::replace_single_curly_with_double( OsSettingsHelper::get_settings_value( ( ( $user_type == 'agent' ) ? 'notification_sms_agent_new_booking_notification_message' : 'notification_sms_customer_booking_confirmation_message' ), '' ) ); |
| 150 | $process_actions[ \LatePoint\Misc\ProcessAction::generate_id() ] = $action; |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | |
| 156 | // webhooks for new booking |
| 157 | |
| 158 | // migrate webhooks for new booking into processes |
| 159 | $webhooks = json_decode( OsSettingsHelper::get_settings_value( 'webhooks', '' ), true ); |
| 160 | if ( $webhooks ) { |
| 161 | foreach ( $webhooks as $webhook ) { |
| 162 | // only process new booking |
| 163 | if ( $webhook['status'] != 'active' || $webhook['trigger'] != 'new_booking' ) { |
| 164 | continue; |
| 165 | } |
| 166 | $action = []; |
| 167 | $action['type'] = 'trigger_webhook'; |
| 168 | $action['settings']['url'] = $webhook['url']; |
| 169 | $process_actions[ $webhook['id'] ] = $action; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | // CREATE NEW BOOKING PROCESSES IF THERE ARE ANY ACTIONS |
| 174 | if ( $process_actions ) { |
| 175 | // put all under single process with multiple actions |
| 176 | $process = new OsProcessModel(); |
| 177 | $process->event_type = 'booking_created'; |
| 178 | $process->name = 'Booking created notification'; |
| 179 | |
| 180 | $process_actions = OsProcessesHelper::iterate_trigger_conditions( [], $process_actions ); |
| 181 | $process_actions[0]['time_offset'] = []; |
| 182 | $process->actions_json = wp_json_encode( $process_actions ); |
| 183 | if ( ! OsProcessesHelper::check_if_process_exists( $process ) ) { |
| 184 | $process->save(); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | // migrate other webhooks (not new booking) into processes |
| 189 | if ( $webhooks ) { |
| 190 | $process_actions_for_triggers = [ |
| 191 | 'updated_booking' => [], |
| 192 | 'new_customer' => [], |
| 193 | 'new_transaction' => [], |
| 194 | ]; |
| 195 | foreach ( $webhooks as $webhook ) { |
| 196 | if ( $webhook['status'] != 'active' || ! in_array( $webhook['trigger'], [ 'updated_booking', 'new_customer', 'new_transaction' ] ) ) { |
| 197 | continue; |
| 198 | } |
| 199 | $process_actions_for_triggers[ $webhook['trigger'] ][ $webhook['id'] ] = [ |
| 200 | 'type' => 'trigger_webhook', |
| 201 | 'settings' => [ 'url' => $webhook['url'] ], |
| 202 | ]; |
| 203 | } |
| 204 | foreach ( $process_actions_for_triggers as $webhook_trigger => $actions ) { |
| 205 | if ( $actions ) { |
| 206 | $process = new OsProcessModel(); |
| 207 | switch ( $webhook_trigger ) { |
| 208 | case 'updated_booking': |
| 209 | $process->name = 'Booking updated notification'; |
| 210 | $process->event_type = 'booking_updated'; |
| 211 | break; |
| 212 | case 'new_customer': |
| 213 | $process->name = 'New customer notification'; |
| 214 | $process->event_type = 'customer_created'; |
| 215 | break; |
| 216 | case 'new_transaction': |
| 217 | $process->name = 'New transaction notification'; |
| 218 | $process->event_type = 'transaction_created'; |
| 219 | break; |
| 220 | } |
| 221 | $process_actions = OsProcessesHelper::iterate_trigger_conditions( [], $actions ); |
| 222 | $process_actions[0]['time_offset'] = []; |
| 223 | $process->actions_json = wp_json_encode( $process_actions ); |
| 224 | if ( ! OsProcessesHelper::check_if_process_exists( $process ) ) { |
| 225 | $process->save(); |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | // migrate reminders into processes |
| 232 | // old example: {"rem_0zMZzZVY":{"name":"Reminder to customer","medium":"email","receiver":"customer","value":"7","unit":"day","when":"before","subject":"Reminder","content":"<p>Testing<\/p>","id":"rem_0zMZzZVY"}} |
| 233 | // multiple: {"rem_POtZuDDd":{"name":"Sms Reminder before","medium":"sms","receiver":"customer","value":"7","unit":"day","when":"before","subject":"","content":"<p>Testing<\/p>","id":"rem_POtZuDDd"},"rem_q4kA6JwC":{"name":"Sms Reminder after","medium":"sms","receiver":"agent","value":"7","unit":"day","when":"after","subject":"test","content":"Testing","id":"rem_q4kA6JwC"},"rem_hR6YOF3w":{"name":"Email Reminder after","medium":"email","receiver":"agent","value":"7","unit":"day","when":"after","subject":"test","content":"Testing","id":"rem_hR6YOF3w"}} |
| 234 | $reminders = json_decode( OsSettingsHelper::get_settings_value( 'reminders', '' ), true ); |
| 235 | if ( $reminders ) { |
| 236 | $processes = []; |
| 237 | $actions = []; |
| 238 | foreach ( $reminders as $reminder ) { |
| 239 | |
| 240 | // create action |
| 241 | $action = []; |
| 242 | $action_id = \LatePoint\Misc\ProcessAction::generate_id(); |
| 243 | $action['settings']['content'] = OsUtilHelper::replace_single_curly_with_double( $reminder['content'] ?? '' ); |
| 244 | switch ( $reminder['medium'] ) { |
| 245 | case 'sms': |
| 246 | $action['type'] = 'send_sms'; |
| 247 | $action['settings']['to_phone'] = ( $reminder['receiver'] == 'customer' ) ? '{{customer_phone}}' : '{{agent_phone}}'; |
| 248 | break; |
| 249 | case 'email': |
| 250 | $action['type'] = 'send_email'; |
| 251 | $action['settings']['to_email'] = ( $reminder['receiver'] == 'customer' ) ? '{{customer_email}}' : '{{agent_email}}'; |
| 252 | $action['settings']['subject'] = OsUtilHelper::replace_single_curly_with_double( $reminder['subject'] ); |
| 253 | break; |
| 254 | } |
| 255 | |
| 256 | // generate time offset |
| 257 | $time_offset = [ |
| 258 | 'value' => $reminder['value'], |
| 259 | 'unit' => $reminder['unit'], |
| 260 | 'before_after' => $reminder['when'], |
| 261 | ]; |
| 262 | |
| 263 | // attach to process |
| 264 | if ( $processes ) { |
| 265 | $existing = false; |
| 266 | // try to find process that matches parameters |
| 267 | for ( $i = 0; $i < count( $processes ); $i++ ) { |
| 268 | if ( $processes[ $i ]['time_offset'] == $time_offset ) { |
| 269 | $processes[ $i ]['actions'][ $action_id ] = $action; |
| 270 | $existing = true; |
| 271 | break; |
| 272 | } |
| 273 | } |
| 274 | // didn't find process with same time offset, create new |
| 275 | if ( ! $existing ) { |
| 276 | $process = [ |
| 277 | 'name' => $reminder['name'], |
| 278 | 'event_type' => 'booking_start', |
| 279 | 'time_offset' => $time_offset, |
| 280 | 'actions' => [], |
| 281 | ]; |
| 282 | $process['actions'][ $action_id ] = $action; |
| 283 | $processes[] = $process; |
| 284 | } |
| 285 | } else { |
| 286 | $process = [ |
| 287 | 'name' => $reminder['name'], |
| 288 | 'event_type' => 'booking_start', |
| 289 | 'time_offset' => $time_offset, |
| 290 | 'actions' => [], |
| 291 | ]; |
| 292 | $process['actions'][ $action_id ] = $action; |
| 293 | $processes[] = $process; |
| 294 | } |
| 295 | } |
| 296 | if ( $processes ) { |
| 297 | foreach ( $processes as $process_data ) { |
| 298 | $process = new OsProcessModel(); |
| 299 | $process->event_type = $process_data['event_type']; |
| 300 | $process->name = $process_data['name']; |
| 301 | |
| 302 | $process_actions = OsProcessesHelper::iterate_trigger_conditions( [], $process_data['actions'] ); |
| 303 | $process_actions[0]['time_offset'] = $process_data['time_offset']; |
| 304 | $process->actions_json = wp_json_encode( $process_actions ); |
| 305 | if ( ! OsProcessesHelper::check_if_process_exists( $process ) ) { |
| 306 | $process->save(); |
| 307 | } |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | // Update customer phone numbers to new E.164 format based on the country that was selected in settings |
| 313 | $customers = new OsCustomerModel(); |
| 314 | $customers = $customers->get_results_as_models(); |
| 315 | foreach ( $customers as $customer ) { |
| 316 | if ( empty( $customer->phone ) ) { |
| 317 | continue; |
| 318 | } |
| 319 | $formatted_phone = OsUtilHelper::sanitize_phone_number( $customer->phone, OsSettingsHelper::get_settings_value( 'country_phone_code', '' ) ); |
| 320 | if ( ! empty( $formatted_phone ) ) { |
| 321 | $customer->update_attributes( [ 'phone' => $formatted_phone ] ); |
| 322 | } |
| 323 | } |
| 324 | // update agent phone numbers |
| 325 | $agents = new OsAgentModel(); |
| 326 | $agents = $agents->get_results_as_models(); |
| 327 | foreach ( $agents as $agent ) { |
| 328 | if ( empty( $agent->phone ) ) { |
| 329 | continue; |
| 330 | } |
| 331 | $formatted_phone = OsUtilHelper::sanitize_phone_number( $agent->phone, OsSettingsHelper::get_settings_value( 'country_phone_code', '' ) ); |
| 332 | if ( ! empty( $formatted_phone ) ) { |
| 333 | $agent->update_attributes( [ 'phone' => $formatted_phone ] ); |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | if ( version_compare( '1.4.91', $current_db_version ) > 0 ) { |
| 339 | $sqls = []; |
| 340 | $has_column = OsDatabaseHelper::run_query( 'SHOW COLUMNS FROM ' . LATEPOINT_TABLE_BOOKINGS . " LIKE 'start_datetime_gmt'" ); |
| 341 | if ( $has_column ) { |
| 342 | $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_BOOKINGS . ' DROP COLUMN start_datetime_gmt'; |
| 343 | } |
| 344 | |
| 345 | $has_column = OsDatabaseHelper::run_query( 'SHOW COLUMNS FROM ' . LATEPOINT_TABLE_BOOKINGS . " LIKE 'end_datetime_gmt'" ); |
| 346 | if ( $has_column ) { |
| 347 | $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_BOOKINGS . ' DROP COLUMN end_datetime_gmt'; |
| 348 | } |
| 349 | |
| 350 | if ( ! empty( $sqls ) ) { |
| 351 | OsDatabaseHelper::run_queries( $sqls ); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | |
| 356 | if ( version_compare( '2.0.0', $current_db_version ) > 0 ) { |
| 357 | // we used to have a typo in a column name, check if it still exists and assign its values to a correctly named column |
| 358 | $has_typo = OsDatabaseHelper::run_query( 'SHOW COLUMNS FROM ' . LATEPOINT_TABLE_BOOKINGS . " LIKE 'total_attendies'" ); |
| 359 | if ( $has_typo ) { |
| 360 | $sqls = []; |
| 361 | $sqls[] = 'UPDATE ' . LATEPOINT_TABLE_BOOKINGS . ' SET total_attendees = total_attendies WHERE total_attendees IS NULL'; |
| 362 | OsDatabaseHelper::run_queries( $sqls ); |
| 363 | } |
| 364 | |
| 365 | // deactivate old addons that are replaced by a PRO addon |
| 366 | $plugins_to_deactivate = [ |
| 367 | 'latepoint-custom-fields/latepoint-custom-fields.php', |
| 368 | 'latepoint-locations/latepoint-locations.php', |
| 369 | 'latepoint-webhooks/latepoint-webhooks.php', |
| 370 | 'latepoint-qr-code/latepoint-qr-code.php', |
| 371 | 'latepoint-reminders/latepoint-reminders.php', |
| 372 | 'latepoint-role-manager/latepoint-role-manager.php', |
| 373 | 'latepoint-timezone-selector/latepoint-timezone-selector.php', |
| 374 | 'latepoint-group-bookings/latepoint-group-bookings.php', |
| 375 | 'latepoint-taxes/latepoint-taxes.php', |
| 376 | 'latepoint-service-durations/latepoint-service-durations.php', |
| 377 | 'latepoint-service-extras/latepoint-service-extras.php', |
| 378 | 'latepoint-messages/latepoint-messages.php', |
| 379 | 'latepoint-coupons/latepoint-coupons.php', |
| 380 | ]; |
| 381 | $deactivated_plugins = []; |
| 382 | |
| 383 | foreach ( $plugins_to_deactivate as $plugin ) { |
| 384 | if ( is_plugin_active( $plugin ) ) { |
| 385 | $deactivated_plugins[] = OsUtilHelper::extract_plugin_name_from_path( $plugin ); |
| 386 | deactivate_plugins( $plugin ); |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | $report = OsMigrationsHelper::migrate_from_version_4(); |
| 391 | |
| 392 | if ( $deactivated_plugins ) { |
| 393 | OsSettingsHelper::save_setting_by_name( 'migration_version_5_deactivated_plugins', implode( ', ', $deactivated_plugins ) ); |
| 394 | } |
| 395 | |
| 396 | // if wizard has not been visited yet - redirect to it |
| 397 | add_option( 'latepoint_show_version_5_modal', true ); |
| 398 | } |
| 399 | if ( version_compare( '2.2.5', $current_db_version ) > 0 ) { |
| 400 | $sqls = []; |
| 401 | $sqls = 'ALTER TABLE ' . LATEPOINT_TABLE_CUSTOMERS . ' MODIFY COLUMN email VARCHAR(320) NULL'; |
| 402 | OsDatabaseHelper::run_queries( $sqls ); |
| 403 | |
| 404 | |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Hook your updates to database that need to be run for specific version of database |
| 409 | * |
| 410 | * @since 1.0.0 |
| 411 | * @hook latepoint_run_version_specific_updates |
| 412 | * |
| 413 | * @param {string} version of database before the update |
| 414 | */ |
| 415 | do_action( 'latepoint_run_version_specific_updates', $current_db_version ); |
| 416 | return true; |
| 417 | } |
| 418 | |
| 419 | |
| 420 | |
| 421 | public static function set_end_date_for_bookings() { |
| 422 | $sqls = []; |
| 423 | |
| 424 | $sqls[] = 'UPDATE ' . LATEPOINT_TABLE_BOOKINGS . ' SET end_date = start_date WHERE end_date IS NULL;'; |
| 425 | return $sqls; |
| 426 | } |
| 427 | |
| 428 | public static function get_queries_for_nullable_columns() { |
| 429 | $sqls = []; |
| 430 | |
| 431 | $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_BOOKINGS . ' |
| 432 | MODIFY COLUMN ip_address varchar(55), |
| 433 | MODIFY COLUMN created_at datetime, |
| 434 | MODIFY COLUMN updated_at datetime;'; |
| 435 | |
| 436 | |
| 437 | $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_CUSTOMER_META . ' |
| 438 | MODIFY COLUMN meta_value text, |
| 439 | MODIFY COLUMN created_at datetime, |
| 440 | MODIFY COLUMN updated_at datetime;'; |
| 441 | |
| 442 | $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_SETTINGS . ' |
| 443 | MODIFY COLUMN value text, |
| 444 | MODIFY COLUMN created_at datetime, |
| 445 | MODIFY COLUMN updated_at datetime;'; |
| 446 | |
| 447 | $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_SERVICES . ' |
| 448 | MODIFY COLUMN short_description text, |
| 449 | MODIFY COLUMN is_price_variable boolean, |
| 450 | MODIFY COLUMN price_min decimal(20,4), |
| 451 | MODIFY COLUMN price_max decimal(20,4), |
| 452 | MODIFY COLUMN charge_amount decimal(20,4), |
| 453 | MODIFY COLUMN is_deposit_required boolean, |
| 454 | MODIFY COLUMN buffer_before int(11), |
| 455 | MODIFY COLUMN buffer_after int(11), |
| 456 | MODIFY COLUMN category_id int(11), |
| 457 | MODIFY COLUMN order_number int(11), |
| 458 | MODIFY COLUMN selection_image_id int(11), |
| 459 | MODIFY COLUMN description_image_id int(11), |
| 460 | MODIFY COLUMN bg_color varchar(20), |
| 461 | MODIFY COLUMN created_at datetime, |
| 462 | MODIFY COLUMN updated_at datetime;'; |
| 463 | |
| 464 | $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_AGENTS . ' |
| 465 | MODIFY COLUMN avatar_image_id int(11), |
| 466 | MODIFY COLUMN last_name varchar(255), |
| 467 | MODIFY COLUMN phone varchar(255), |
| 468 | MODIFY COLUMN password varchar(255), |
| 469 | MODIFY COLUMN custom_hours boolean, |
| 470 | MODIFY COLUMN created_at datetime, |
| 471 | MODIFY COLUMN updated_at datetime;'; |
| 472 | |
| 473 | $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_STEP_SETTINGS . ' |
| 474 | MODIFY COLUMN value text, |
| 475 | MODIFY COLUMN step varchar(50), |
| 476 | MODIFY COLUMN created_at datetime, |
| 477 | MODIFY COLUMN updated_at datetime;'; |
| 478 | |
| 479 | $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_CUSTOMERS . ' |
| 480 | MODIFY COLUMN last_name varchar(255), |
| 481 | MODIFY COLUMN phone varchar(255), |
| 482 | MODIFY COLUMN avatar_image_id int(11), |
| 483 | MODIFY COLUMN password varchar(255), |
| 484 | MODIFY COLUMN activation_key varchar(255), |
| 485 | MODIFY COLUMN account_nonse varchar(255), |
| 486 | MODIFY COLUMN google_user_id varchar(255), |
| 487 | MODIFY COLUMN facebook_user_id varchar(255), |
| 488 | MODIFY COLUMN is_guest boolean, |
| 489 | MODIFY COLUMN notes text, |
| 490 | MODIFY COLUMN created_at datetime, |
| 491 | MODIFY COLUMN updated_at datetime;'; |
| 492 | |
| 493 | $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_SERVICE_CATEGORIES . ' |
| 494 | MODIFY COLUMN short_description text, |
| 495 | MODIFY COLUMN parent_id mediumint(9), |
| 496 | MODIFY COLUMN selection_image_id int(11), |
| 497 | MODIFY COLUMN order_number int(11), |
| 498 | MODIFY COLUMN created_at datetime, |
| 499 | MODIFY COLUMN updated_at datetime'; |
| 500 | |
| 501 | $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_CUSTOM_PRICES . ' |
| 502 | MODIFY COLUMN is_price_variable boolean, |
| 503 | MODIFY COLUMN price_min decimal(20,4), |
| 504 | MODIFY COLUMN price_max decimal(20,4), |
| 505 | MODIFY COLUMN charge_amount decimal(20,4), |
| 506 | MODIFY COLUMN is_deposit_required boolean, |
| 507 | MODIFY COLUMN created_at datetime, |
| 508 | MODIFY COLUMN updated_at datetime'; |
| 509 | |
| 510 | $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_WORK_PERIODS . ' |
| 511 | MODIFY COLUMN custom_date date, |
| 512 | MODIFY COLUMN created_at datetime, |
| 513 | MODIFY COLUMN updated_at datetime'; |
| 514 | |
| 515 | $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_AGENTS_SERVICES . ' |
| 516 | MODIFY COLUMN is_custom_hours BOOLEAN, |
| 517 | MODIFY COLUMN is_custom_price BOOLEAN, |
| 518 | MODIFY COLUMN is_custom_duration BOOLEAN, |
| 519 | MODIFY COLUMN created_at datetime, |
| 520 | MODIFY COLUMN updated_at datetime'; |
| 521 | |
| 522 | $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_ACTIVITIES . ' |
| 523 | MODIFY COLUMN agent_id int(11), |
| 524 | MODIFY COLUMN booking_id int(11), |
| 525 | MODIFY COLUMN service_id int(11), |
| 526 | MODIFY COLUMN customer_id int(11), |
| 527 | MODIFY COLUMN description text, |
| 528 | MODIFY COLUMN initiated_by varchar(100), |
| 529 | MODIFY COLUMN initiated_by_id int(11), |
| 530 | MODIFY COLUMN created_at datetime, |
| 531 | MODIFY COLUMN updated_at datetime'; |
| 532 | |
| 533 | $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_TRANSACTIONS . ' |
| 534 | MODIFY COLUMN notes text, |
| 535 | MODIFY COLUMN created_at datetime, |
| 536 | MODIFY COLUMN updated_at datetime'; |
| 537 | return $sqls; |
| 538 | } |
| 539 | } |
| 540 |