| 1 |
<?php |
| 2 |
|
| 3 |
namespace Bookit\Classes\Vendor; |
| 4 |
|
| 5 |
abstract class BookitUpdates { |
| 6 |
|
| 7 |
private static $updates = array( |
| 8 |
'2.0.1' => array( 'add_services_icon' ), |
| 9 |
'2.0.9' => array( 'add_currency' ), |
| 10 |
'2.1.0' => array( 'add_appointment_deleted_email_templates', 'add_appointment_notes' ), |
| 11 |
'2.1.3' => array( |
| 12 |
'add_time_slot_duration_setting', |
| 13 |
'add_payment_table', |
| 14 |
'add_discount_table', |
| 15 |
'add_coupon_table', |
| 16 |
'refactor_exist_appointments', |
| 17 |
), |
| 18 |
'2.1.5' => array( |
| 19 |
'update_payment_type_enum_field', |
| 20 |
), |
| 21 |
'2.1.7' => array( |
| 22 |
'add_wp_user_to_staff', |
| 23 |
'add_clean_all_on_delete', |
| 24 |
'add_bookit_user_roles_and_capabilitites', |
| 25 |
'add_senders', |
| 26 |
'add_appointment_status_changed_admin_template', |
| 27 |
'replace_theme_to_calendar_view', |
| 28 |
), |
| 29 |
'2.2.0' => array( 'add_calendar_view_type_to_settings' ), |
| 30 |
'2.2.1' => array( 'add_admin_notification_transient' ), |
| 31 |
'2.2.5' => array( 'update_payment_methods_enum' ), |
| 32 |
'2.2.6' => array( 'add_payment_transaction_claim_schema' ), |
| 33 |
); |
| 34 |
|
| 35 |
/** |
| 36 |
* Init Bookit Updates |
| 37 |
*/ |
| 38 |
public static function init() { |
| 39 |
if ( version_compare( get_option( 'bookit_version' ), BOOKIT_VERSION, '<' ) ) { |
| 40 |
self::update_version(); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Get All Updates |
| 46 |
* @return array |
| 47 |
*/ |
| 48 |
public static function get_updates() { |
| 49 |
return self::$updates; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Check If Needs Updates |
| 54 |
* @return bool |
| 55 |
*/ |
| 56 |
public static function needs_to_update() { |
| 57 |
$current_db_version = get_option( 'bookit_db_version' ); |
| 58 |
$update_versions = array_keys( self::get_updates() ); |
| 59 |
usort( $update_versions, 'version_compare' ); |
| 60 |
|
| 61 |
return ! empty( $current_db_version ) && version_compare( $current_db_version, end( $update_versions ), '<' ); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Run Needed Updates |
| 66 |
*/ |
| 67 |
private static function maybe_update_db_version() { |
| 68 |
if ( self::needs_to_update() ) { |
| 69 |
$current_db_version = get_option( 'bookit_db_version' ); |
| 70 |
$updates = self::get_updates(); |
| 71 |
|
| 72 |
foreach ( $updates as $version => $callback_arr ) { |
| 73 |
if ( version_compare( $current_db_version, $version, '<' ) ) { |
| 74 |
foreach ( $callback_arr as $callback ) { |
| 75 |
call_user_func( |
| 76 |
array( '\\Bookit\\Classes\\Vendor\\BookitUpdateCallbacks', $callback ) |
| 77 |
); |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
update_option( 'bookit_db_version', BOOKIT_DB_VERSION, true ); |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Update Plugin Version |
| 88 |
*/ |
| 89 |
public static function update_version() { |
| 90 |
update_option( 'bookit_version', BOOKIT_VERSION, true ); |
| 91 |
self::maybe_update_db_version(); |
| 92 |
} |
| 93 |
} |
| 94 |
|