PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.7.3.2
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.7.3.2
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 4.2.0 All 139 releases
learnpress / inc / admin / class-lp-updater.php

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

126 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 )
30 );
31 }
32
33 /**
34 * Check LP Database need upgrade.
35 *
36 * @return bool|int
37 * @author tungnx
38 * @version 1.0.1
39 * @since 4.0.0
40 */
41 public function check_lp_db_need_upgrade() {
42 if ( ! current_user_can( 'administrator' ) ) {
43 return false;
44 }
45
46 $db_current_version = (int) get_option( LP_KEY_DB_VERSION, 0 );
47 /*if ( ! $db_current_version ) {
48 return false;
49 }*/
50
51 $db_require_version = LearnPress::instance()->db_version;
52 if ( version_compare( $db_require_version, $db_current_version, '<=' ) ) {
53 return false;
54 }
55
56 if ( array_key_exists( $db_current_version, $this->db_map_version ) ) {
57 return $this->db_map_version[ $db_current_version . '' ];
58 }
59
60 /**
61 * For case not have key "learnpress_db_version" on DB, still have columns of learnpress.
62 * After a long time, need remove fix fast
63 */
64 $lp_db = LP_Database::getInstance();
65 $check_tb_lp_order_items_exists = $lp_db->check_table_exists( $lp_db->tb_lp_order_items );
66 $check_tb_lp_user_item_results_exists = $lp_db->check_table_exists( $lp_db->tb_lp_user_item_results );
67 $check_col_item_id_on_lp_order_items = $lp_db->check_col_table( $lp_db->tb_lp_order_items, 'item_id' );
68
69 if ( $check_tb_lp_order_items_exists && ( ! $check_tb_lp_user_item_results_exists || ! $check_col_item_id_on_lp_order_items ) ) {
70 update_option( LP_KEY_DB_VERSION, 3 );
71
72 return $this->db_map_version['3'];
73 }
74
75 // End.
76
77 return false;
78 }
79
80 /**
81 * Load file upgrade database.
82 *
83 * @return null|object
84 * @author tungnx
85 * @version 1.0.1
86 * @since 4.0.0
87 */
88 public function load_file_version_upgrade_db() {
89 $class_handle = null;
90 $db_version_up_to = $this->check_lp_db_need_upgrade();
91
92 if ( $db_version_up_to ) {
93 $file_update = LP_PLUGIN_PATH . 'inc/updates/learnpress-upgrade-' . $db_version_up_to . '.php';
94
95 if ( file_exists( $file_update ) ) {
96 include_once $file_update;
97 $name_class_handle_upgrade = 'LP_Upgrade_' . $db_version_up_to;
98
99 if ( class_exists( $name_class_handle_upgrade )
100 && is_callable( array( $name_class_handle_upgrade, 'get_instance' ) ) ) {
101 $class_handle = $name_class_handle_upgrade::get_instance();
102 }
103 }
104 }
105
106 return $class_handle;
107 }
108
109 /**
110 * Get singleton instance of the class.
111 *
112 * @return bool|LP_Updater
113 */
114 public static function instance() {
115 static $instance = null;
116
117 if ( is_null( $instance ) ) {
118 $instance = new self();
119 }
120
121 return $instance;
122 }
123 }
124
125 return LP_Updater::instance();
126