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
learnpress / inc / admin / class-lp-updater.php

class-lp-updater.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.9, at inc/admin/class-lp-updater.php

129 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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();
129