PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.6.9.2
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.6.9.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.6.9.2, at inc/admin/class-lp-updater.php

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