PluginProbe ʕ •ᴥ•ʔ
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.6.8
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.6.8
5.6.8 5.6.7 5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / helpers / version_specific_updates_helper.php
latepoint / lib / helpers Last commit date
activities_helper.php 4 months ago agent_helper.php 4 months ago analytics_helper.php 2 weeks ago auth_helper.php 1 week ago blocks_helper.php 3 weeks ago booking_helper.php 1 week ago bricks_helper.php 4 months ago bundles_helper.php 1 week ago calendar_helper.php 1 week ago carts_helper.php 4 months ago connector_helper.php 4 months ago csv_helper.php 4 months ago customer_helper.php 1 month ago customer_import_helper.php 1 month ago database_helper.php 1 day ago debug_helper.php 4 months ago defaults_helper.php 4 months ago elementor_helper.php 4 months ago email_helper.php 4 months ago encrypt_helper.php 4 months ago events_helper.php 3 months ago form_helper.php 4 months ago icalendar_helper.php 4 months ago image_helper.php 4 months ago invoices_helper.php 1 day ago license_helper.php 4 months ago location_helper.php 4 months ago marketing_systems_helper.php 4 months ago meeting_systems_helper.php 4 months ago menu_helper.php 3 weeks ago meta_helper.php 4 months ago migrations_helper.php 4 months ago money_helper.php 3 months ago notifications_helper.php 4 months ago nps_survey_helper.php 4 months ago order_intent_helper.php 2 months ago orders_helper.php 4 days ago otp_helper.php 3 months ago pages_helper.php 4 months ago params_helper.php 4 months ago payments_helper.php 4 days ago plugin_version_update_helper.php 2 months ago price_breakdown_helper.php 4 months ago process_jobs_helper.php 4 months ago processes_helper.php 4 months ago razorpay_connect_helper.php 1 day ago replacer_helper.php 4 months ago resource_helper.php 1 week ago roles_helper.php 3 weeks ago router_helper.php 4 months ago service_helper.php 4 months ago sessions_helper.php 4 months ago settings_helper.php 2 weeks ago short_links_systems_helper.php 4 months ago shortcodes_helper.php 3 weeks ago sms_helper.php 4 months ago steps_helper.php 1 day ago stripe_connect_helper.php 2 weeks ago styles_helper.php 4 months ago support_topics_helper.php 4 months ago time_helper.php 2 months ago timeline_helper.php 2 months ago transaction_helper.php 1 month ago transaction_intent_helper.php 4 months ago util_helper.php 1 month ago version_specific_updates_helper.php 1 day ago whatsapp_helper.php 1 month ago work_periods_helper.php 3 months ago wp_datetime.php 4 months ago wp_user_helper.php 4 months ago
version_specific_updates_helper.php
559 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 // email
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 // email
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 if ( version_compare( '2.3.2', $current_db_version ) > 0 ) {
408 global $wpdb;
409
410 // Widen invoice_number column so long prefixes and the default format are not truncated.
411 $sqls = [];
412 $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_ORDER_INVOICES . ' MODIFY COLUMN invoice_number VARCHAR(50)';
413 OsDatabaseHelper::run_queries( $sqls );
414
415 // Do not change anything for existing. Backfill any legacy invoices whose number was never materialized (empty or NULL).
416 // This freezes the current prefix onto those rows so a future prefix change cannot alter them.
417 // $prefix = OsSettingsHelper::get_settings_value( 'invoices_number_prefix', 'INV-' );
418 // $wpdb->query(
419 // $wpdb->prepare(
420 // 'UPDATE ' . LATEPOINT_TABLE_ORDER_INVOICES . " SET invoice_number = CONCAT(%s, '1', LPAD(id, 6, '0')) WHERE (invoice_number IS NULL OR invoice_number = '')",
421 // $prefix
422 // )
423 // );
424 }
425
426 /**
427 * Hook your updates to database that need to be run for specific version of database
428 *
429 * @since 1.0.0
430 * @hook latepoint_run_version_specific_updates
431 *
432 * @param {string} version of database before the update
433 */
434 do_action( 'latepoint_run_version_specific_updates', $current_db_version );
435 return true;
436 }
437
438
439
440 public static function set_end_date_for_bookings() {
441 $sqls = [];
442
443 $sqls[] = 'UPDATE ' . LATEPOINT_TABLE_BOOKINGS . ' SET end_date = start_date WHERE end_date IS NULL;';
444 return $sqls;
445 }
446
447 public static function get_queries_for_nullable_columns() {
448 $sqls = [];
449
450 $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_BOOKINGS . '
451 MODIFY COLUMN ip_address varchar(55),
452 MODIFY COLUMN created_at datetime,
453 MODIFY COLUMN updated_at datetime;';
454
455
456 $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_CUSTOMER_META . '
457 MODIFY COLUMN meta_value text,
458 MODIFY COLUMN created_at datetime,
459 MODIFY COLUMN updated_at datetime;';
460
461 $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_SETTINGS . '
462 MODIFY COLUMN value text,
463 MODIFY COLUMN created_at datetime,
464 MODIFY COLUMN updated_at datetime;';
465
466 $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_SERVICES . '
467 MODIFY COLUMN short_description text,
468 MODIFY COLUMN is_price_variable boolean,
469 MODIFY COLUMN price_min decimal(20,4),
470 MODIFY COLUMN price_max decimal(20,4),
471 MODIFY COLUMN charge_amount decimal(20,4),
472 MODIFY COLUMN is_deposit_required boolean,
473 MODIFY COLUMN buffer_before int(11),
474 MODIFY COLUMN buffer_after int(11),
475 MODIFY COLUMN category_id int(11),
476 MODIFY COLUMN order_number int(11),
477 MODIFY COLUMN selection_image_id int(11),
478 MODIFY COLUMN description_image_id int(11),
479 MODIFY COLUMN bg_color varchar(20),
480 MODIFY COLUMN created_at datetime,
481 MODIFY COLUMN updated_at datetime;';
482
483 $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_AGENTS . '
484 MODIFY COLUMN avatar_image_id int(11),
485 MODIFY COLUMN last_name varchar(255),
486 MODIFY COLUMN phone varchar(255),
487 MODIFY COLUMN password varchar(255),
488 MODIFY COLUMN custom_hours boolean,
489 MODIFY COLUMN created_at datetime,
490 MODIFY COLUMN updated_at datetime;';
491
492 $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_STEP_SETTINGS . '
493 MODIFY COLUMN value text,
494 MODIFY COLUMN step varchar(50),
495 MODIFY COLUMN created_at datetime,
496 MODIFY COLUMN updated_at datetime;';
497
498 $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_CUSTOMERS . '
499 MODIFY COLUMN last_name varchar(255),
500 MODIFY COLUMN phone varchar(255),
501 MODIFY COLUMN avatar_image_id int(11),
502 MODIFY COLUMN password varchar(255),
503 MODIFY COLUMN activation_key varchar(255),
504 MODIFY COLUMN account_nonse varchar(255),
505 MODIFY COLUMN google_user_id varchar(255),
506 MODIFY COLUMN facebook_user_id varchar(255),
507 MODIFY COLUMN is_guest boolean,
508 MODIFY COLUMN notes text,
509 MODIFY COLUMN created_at datetime,
510 MODIFY COLUMN updated_at datetime;';
511
512 $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_SERVICE_CATEGORIES . '
513 MODIFY COLUMN short_description text,
514 MODIFY COLUMN parent_id mediumint(9),
515 MODIFY COLUMN selection_image_id int(11),
516 MODIFY COLUMN order_number int(11),
517 MODIFY COLUMN created_at datetime,
518 MODIFY COLUMN updated_at datetime';
519
520 $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_CUSTOM_PRICES . '
521 MODIFY COLUMN is_price_variable boolean,
522 MODIFY COLUMN price_min decimal(20,4),
523 MODIFY COLUMN price_max decimal(20,4),
524 MODIFY COLUMN charge_amount decimal(20,4),
525 MODIFY COLUMN is_deposit_required boolean,
526 MODIFY COLUMN created_at datetime,
527 MODIFY COLUMN updated_at datetime';
528
529 $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_WORK_PERIODS . '
530 MODIFY COLUMN custom_date date,
531 MODIFY COLUMN created_at datetime,
532 MODIFY COLUMN updated_at datetime';
533
534 $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_AGENTS_SERVICES . '
535 MODIFY COLUMN is_custom_hours BOOLEAN,
536 MODIFY COLUMN is_custom_price BOOLEAN,
537 MODIFY COLUMN is_custom_duration BOOLEAN,
538 MODIFY COLUMN created_at datetime,
539 MODIFY COLUMN updated_at datetime';
540
541 $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_ACTIVITIES . '
542 MODIFY COLUMN agent_id int(11),
543 MODIFY COLUMN booking_id int(11),
544 MODIFY COLUMN service_id int(11),
545 MODIFY COLUMN customer_id int(11),
546 MODIFY COLUMN description text,
547 MODIFY COLUMN initiated_by varchar(100),
548 MODIFY COLUMN initiated_by_id int(11),
549 MODIFY COLUMN created_at datetime,
550 MODIFY COLUMN updated_at datetime';
551
552 $sqls[] = 'ALTER TABLE ' . LATEPOINT_TABLE_TRANSACTIONS . '
553 MODIFY COLUMN notes text,
554 MODIFY COLUMN created_at datetime,
555 MODIFY COLUMN updated_at datetime';
556 return $sqls;
557 }
558 }
559