PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.9
4.4.9 4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 All 140 releases
← All changes | inc/admin/class-lp-updater.php +128 -125 4.3.8 → 4.4.9 View file →
@@ -1,125 +1,128 @@
1 -<?php
2 -
3 -/**
4 - * Class LP_Updater
5 - *
6 - * Update helper class providing update functions
7 - *
8 - * @author ThimPress
9 - * @package LearnPress/Classes
10 - * @version 3.0.0
11 - */
12 -class LP_Updater {
13 - /**
14 - * Map version upgrade.
15 - *
16 - * @var array
17 - */
18 - public $db_map_version = array();
19 -
20 - /**
21 - * LP_Updater constructor.
22 - */
23 - protected function __construct() {
24 - $this->db_map_version = apply_filters(
25 - 'lp/upgrade/db/map_version',
26 - array(
27 - '3' => 4, // DB v3 need up DB v4
28 - '4' => 5, // DB v4 need up DB v5
29 - '5' => 6, // DB v4 need up DB v6
30 - )
31 - );
32 - }
33 -
34 - /**
35 - * Check LP Database need upgrade.
36 - *
37 - * @return bool|int
38 - * @author tungnx
39 - * @version 1.0.1
40 - * @since 4.0.0
41 - */
42 - public function check_lp_db_need_upgrade() {
43 - if ( ! current_user_can( 'administrator' ) ) {
44 - return false;
45 - }
46 -
47 - $db_current_version = (int) get_option( LP_KEY_DB_VERSION, 0 );
48 - /*if ( ! $db_current_version ) {
49 - return false;
50 - }*/
51 -
52 - $db_require_version = LearnPress::instance()->db_version;
53 - if ( version_compare( $db_require_version, $db_current_version, '<=' ) ) {
54 - return false;
55 - }
56 -
57 - if ( array_key_exists( $db_current_version, $this->db_map_version ) ) {
58 - return $this->db_map_version[ $db_current_version . '' ];
59 - }
60 -
61 - /**
62 - * For case not have key "learnpress_db_version" on DB, still have columns of learnpress.
63 - * After a long time, need remove fix fast
64 - */
65 - $lp_db = LP_Database::getInstance();
66 - $check_tb_lp_order_items_exists = $lp_db->check_table_exists( $lp_db->tb_lp_order_items );
67 - $check_tb_lp_user_item_results_exists = $lp_db->check_table_exists( $lp_db->tb_lp_user_item_results );
68 - $check_col_item_id_on_lp_order_items = $lp_db->check_col_table( $lp_db->tb_lp_order_items, 'item_id' );
69 -
70 - if ( $check_tb_lp_order_items_exists && ( ! $check_tb_lp_user_item_results_exists || ! $check_col_item_id_on_lp_order_items ) ) {
71 - update_option( LP_KEY_DB_VERSION, 3 );
72 -
73 - return $this->db_map_version['3'];
74 - }
75 -
76 - // End.
77 -
78 - return false;
79 - }
80 -
81 - /**
82 - * Load file upgrade database.
83 - *
84 - * @return null|object
85 - * @author tungnx
86 - * @version 1.0.1
87 - * @since 4.0.0
88 - */
89 - public function load_file_version_upgrade_db() {
90 - $class_handle = null;
91 - $db_version_up_to = $this->check_lp_db_need_upgrade();
92 -
93 - if ( $db_version_up_to ) {
94 - $file_update = LP_PLUGIN_PATH . 'inc/updates/learnpress-upgrade-' . $db_version_up_to . '.php';
95 -
96 - if ( file_exists( $file_update ) ) {
97 - include_once $file_update;
98 - $name_class_handle_upgrade = 'LP_Upgrade_' . $db_version_up_to;
99 -
100 - if ( class_exists( $name_class_handle_upgrade )
101 - && is_callable( array( $name_class_handle_upgrade, 'get_instance' ) ) ) {
102 - $class_handle = $name_class_handle_upgrade::get_instance();
103 - }
104 - }
105 - }
106 -
107 - return $class_handle;
108 - }
109 -
110 - /**
111 - * Get singleton instance of the class.
112 - *
113 - * @return bool|LP_Updater
114 - */
115 - public static function instance() {
116 - static $instance;
117 - if ( is_null( $instance ) ) {
118 - $instance = new self();
119 - }
120 -
121 - return $instance;
122 - }
123 -}
124 -
125 -return LP_Updater::instance();
1 +<?php
2 +
3 +use LearnPress\Databases\DataBase;
4 +
5 +/**
6 + * Class LP_Updater
7 + *
8 + * Update helper class providing update functions
9 + *
10 + * @author ThimPress
11 + * @package LearnPress/Classes
12 + * @version 3.0.0
13 + */
14 +class LP_Updater {
15 + /**
16 + * Map version upgrade.
17 + *
18 + * @var array
19 + */
20 + public $db_map_version = array();
21 +
22 + /**
23 + * LP_Updater constructor.
24 + */
25 + protected function __construct() {
26 + $this->db_map_version = apply_filters(
27 + 'lp/upgrade/db/map_version',
28 + array(
29 + '3' => 4, // DB v3 need up DB v4
30 + '4' => 5, // DB v4 need up DB v5
31 + '5' => 6, // DB v4 need up DB v6
32 + )
33 + );
34 + }
35 +
36 + /**
37 + * Check LP Database need upgrade.
38 + *
39 + * @return bool|int
40 + * @throws Exception
41 + * @version 1.0.1
42 + * @since 4.0.0
43 + * @author tungnx
44 + */
45 + public function check_lp_db_need_upgrade() {
46 + if ( ! current_user_can( 'administrator' ) ) {
47 + return false;
48 + }
49 +
50 + $db_current_version = (int) get_option( LP_KEY_DB_VERSION, 0 );
51 + /*if ( ! $db_current_version ) {
52 + return false;
53 + }*/
54 +
55 + $db_require_version = LearnPress::instance()->db_version;
56 + if ( version_compare( $db_require_version, $db_current_version, '<=' ) ) {
57 + return false;
58 + }
59 +
60 + if ( array_key_exists( $db_current_version, $this->db_map_version ) ) {
61 + return $this->db_map_version[ $db_current_version . '' ];
62 + }
63 +
64 + /**
65 + * For case not have key "learnpress_db_version" on DB, still have columns of learnpress.
66 + * After a long time, need remove fix fast
67 + */
68 + $lp_db = DataBase::getInstance();
69 + $check_tb_lp_order_items_exists = $lp_db->check_table_exists( $lp_db->tb_lp_order_items );
70 + $check_tb_lp_user_item_results_exists = $lp_db->check_table_exists( $lp_db->tb_lp_user_item_results );
71 + $check_col_item_id_on_lp_order_items = $lp_db->check_col_table( $lp_db->tb_lp_order_items, 'item_id' );
72 +
73 + if ( $check_tb_lp_order_items_exists && ( ! $check_tb_lp_user_item_results_exists || ! $check_col_item_id_on_lp_order_items ) ) {
74 + update_option( LP_KEY_DB_VERSION, 3 );
75 +
76 + return $this->db_map_version['3'];
77 + }
78 +
79 + // End.
80 +
81 + return false;
82 + }
83 +
84 + /**
85 + * Load file upgrade database.
86 + *
87 + * @return null|object
88 + * @author tungnx
89 + * @version 1.0.1
90 + * @since 4.0.0
91 + */
92 + public function load_file_version_upgrade_db() {
93 + $class_handle = null;
94 + $db_version_up_to = $this->check_lp_db_need_upgrade();
95 +
96 + if ( $db_version_up_to ) {
97 + $file_update = LP_PLUGIN_PATH . 'inc/updates/learnpress-upgrade-' . $db_version_up_to . '.php';
98 +
99 + if ( file_exists( $file_update ) ) {
100 + include_once $file_update;
101 + $name_class_handle_upgrade = 'LP_Upgrade_' . $db_version_up_to;
102 +
103 + if ( class_exists( $name_class_handle_upgrade )
104 + && is_callable( array( $name_class_handle_upgrade, 'get_instance' ) ) ) {
105 + $class_handle = $name_class_handle_upgrade::get_instance();
106 + }
107 + }
108 + }
109 +
110 + return $class_handle;
111 + }
112 +
113 + /**
114 + * Get singleton instance of the class.
115 + *
116 + * @return bool|LP_Updater
117 + */
118 + public static function instance() {
119 + static $instance;
120 + if ( is_null( $instance ) ) {
121 + $instance = new self();
122 + }
123 +
124 + return $instance;
125 + }
126 +}
127 +
128 +return LP_Updater::instance();