| @@ -1,6 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | +use LearnPress\Databases\DataBase; | |
| 4 | + | |
| 3 | 5 | /** |
| 4 | 6 | * Class LP_Updater |
| 5 | 7 | * |
| 6 | 8 | * Update helper class providing update functions |
| @@ -25,31 +27,21 @@ | ||
| 25 | 27 | 'lp/upgrade/db/map_version', |
| 26 | 28 | array( |
| 27 | 29 | '3' => 4, // DB v3 need up DB v4 |
| 28 | 30 | '4' => 5, // DB v4 need up DB v5 |
| 31 | + '5' => 6, // DB v4 need up DB v6 | |
| 29 | 32 | ) |
| 30 | 33 | ); |
| 31 | - add_action( 'admin_notices', array( $this, 'check_update_database_message' ), 0 ); | |
| 32 | 34 | } |
| 33 | 35 | |
| 34 | 36 | /** |
| 35 | - * Show message needs upgrades database compatible with LP version current. | |
| 36 | - */ | |
| 37 | - public function check_update_database_message() { | |
| 38 | - if ( ! $this->check_lp_db_need_upgrade() ) { | |
| 39 | - return; | |
| 40 | - } | |
| 41 | - | |
| 42 | - learn_press_admin_view( 'updates/html-update-message' ); | |
| 43 | - } | |
| 44 | - | |
| 45 | - /** | |
| 46 | 37 | * Check LP Database need upgrade. |
| 47 | 38 | * |
| 48 | 39 | * @return bool|int |
| 49 | - * @author tungnx | |
| 40 | + * @throws Exception | |
| 50 | 41 | * @version 1.0.1 |
| 51 | 42 | * @since 4.0.0 |
| 43 | + * @author tungnx | |
| 52 | 44 | */ |
| 53 | 45 | public function check_lp_db_need_upgrade() { |
| 54 | 46 | if ( ! current_user_can( 'administrator' ) ) { |
| 55 | 47 | return false; |
| @@ -54,20 +46,20 @@ | ||
| 54 | 46 | if ( ! current_user_can( 'administrator' ) ) { |
| 55 | 47 | return false; |
| 56 | 48 | } |
| 57 | 49 | |
| 58 | - $db_current_version = (int) get_option( LP_KEY_DB_VERSION, false ); | |
| 59 | - if ( ! $db_current_version ) { | |
| 50 | + $db_current_version = (int) get_option( LP_KEY_DB_VERSION, 0 ); | |
| 51 | + /*if ( ! $db_current_version ) { | |
| 60 | 52 | return false; |
| 61 | - } | |
| 53 | + }*/ | |
| 62 | 54 | |
| 63 | 55 | $db_require_version = LearnPress::instance()->db_version; |
| 64 | - if ( $db_require_version <= $db_current_version ) { | |
| 56 | + if ( version_compare( $db_require_version, $db_current_version, '<=' ) ) { | |
| 65 | 57 | return false; |
| 66 | 58 | } |
| 67 | 59 | |
| 68 | 60 | if ( array_key_exists( $db_current_version, $this->db_map_version ) ) { |
| 69 | - return $this->db_map_version[ $db_current_version ]; | |
| 61 | + return $this->db_map_version[ $db_current_version . '' ]; | |
| 70 | 62 | } |
| 71 | 63 | |
| 72 | 64 | /** |
| 73 | 65 | * For case not have key "learnpress_db_version" on DB, still have columns of learnpress. |
| @@ -72,9 +64,9 @@ | ||
| 72 | 64 | /** |
| 73 | 65 | * For case not have key "learnpress_db_version" on DB, still have columns of learnpress. |
| 74 | 66 | * After a long time, need remove fix fast |
| 75 | 67 | */ |
| 76 | - $lp_db = LP_Database::getInstance(); | |
| 68 | + $lp_db = DataBase::getInstance(); | |
| 77 | 69 | $check_tb_lp_order_items_exists = $lp_db->check_table_exists( $lp_db->tb_lp_order_items ); |
| 78 | 70 | $check_tb_lp_user_item_results_exists = $lp_db->check_table_exists( $lp_db->tb_lp_user_item_results ); |
| 79 | 71 | $check_col_item_id_on_lp_order_items = $lp_db->check_col_table( $lp_db->tb_lp_order_items, 'item_id' ); |
| 80 | 72 | |
| @@ -123,10 +115,9 @@ | ||
| 123 | 115 | * |
| 124 | 116 | * @return bool|LP_Updater |
| 125 | 117 | */ |
| 126 | 118 | public static function instance() { |
| 127 | - static $instance = null; | |
| 128 | - | |
| 119 | + static $instance; | |
| 129 | 120 | if ( is_null( $instance ) ) { |
| 130 | 121 | $instance = new self(); |
| 131 | 122 | } |
| 132 | 123 | |