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.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / classes / Upgrader.php
tutor / classes Last commit date
Addons.php 11 months ago Admin.php 11 months ago Ajax.php 1 year ago Announcements.php 1 year ago Assets.php 11 months ago Backend_Page_Trait.php 1 year ago BaseController.php 1 year ago Config.php 11 months ago Container.php 11 months ago Course.php 10 months ago Course_Embed.php 3 years ago Course_Filter.php 1 year ago Course_List.php 10 months ago Course_Settings_Tabs.php 1 year ago Course_Widget.php 1 year ago Custom_Validation.php 3 years ago Dashboard.php 1 year ago Earnings.php 1 year ago FormHandler.php 2 years ago Frontend.php 1 year ago Gutenberg.php 1 year ago Icon.php 10 months ago Input.php 1 year ago Instructor.php 1 year ago Instructors_List.php 11 months ago Lesson.php 10 months ago Options_V2.php 11 months ago Permalink.php 2 years ago Post_types.php 1 year ago Private_Course_Access.php 1 year ago Q_And_A.php 10 months ago Question_Answers_List.php 11 months ago Quiz.php 10 months ago QuizBuilder.php 11 months ago Quiz_Attempts_List.php 11 months ago RestAPI.php 2 years ago Reviews.php 11 months ago Rewrite_Rules.php 2 years ago Shortcode.php 1 year ago Singleton.php 1 year ago Student.php 1 year ago Students_List.php 1 year ago Taxonomies.php 1 year ago Template.php 11 months ago Theme_Compatibility.php 3 years ago Tools.php 1 year ago Tools_V2.php 1 year ago Tutor.php 10 months ago TutorEDD.php 1 year ago Tutor_Base.php 2 years ago Tutor_Setup.php 1 year ago Upgrader.php 10 months ago User.php 1 year ago Utils.php 10 months ago Video_Stream.php 3 years ago WhatsNew.php 2 years ago Withdraw.php 1 year ago Withdraw_Requests_List.php 11 months ago WooCommerce.php 11 months ago
Upgrader.php
319 lines
1 <?php
2 /**
3 * Tutor up grader
4 *
5 * @package Tutor\UpGrader
6 * @author Themeum <support@themeum.com>
7 * @link https://themeum.com
8 * @since 1.0.0
9 */
10
11 namespace TUTOR;
12
13 use Tutor\Ecommerce\CartController;
14 use Tutor\Ecommerce\CheckoutController;
15 use Tutor\Helpers\QueryHelper;
16
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit;
19 }
20
21 /**
22 * Manage up grade
23 *
24 * @since 1.0.0
25 */
26 class Upgrader {
27
28 /**
29 * Installed version number
30 *
31 * @since 2.6.0
32 *
33 * @var string
34 */
35 public $installed_version;
36
37 /**
38 * Register hooks
39 *
40 * @since 1.0.0
41 */
42 public function __construct() {
43 $this->installed_version = get_option( 'tutor_version' );
44
45 add_action( 'admin_init', array( $this, 'init_upgrader' ) );
46
47 /**
48 * Installing Gradebook Addon from TutorPro
49 */
50 add_action( 'tutor_addon_before_enable_tutor-pro/addons/gradebook/gradebook.php', array( $this, 'install_gradebook' ) );
51 add_action( 'tutor_addon_before_enable_tutor-pro/addons/tutor-email/tutor-email.php', array( $this, 'install_tutor_email_queue' ) );
52 add_action( 'upgrader_process_complete', array( $this, 'init_email_table_deployment' ), 10, 2 );
53 }
54
55 /**
56 * Init up grader
57 *
58 * @since 1.0.0
59 *
60 * @return void
61 */
62 public function init_upgrader() {
63 $upgrades = $this->available_upgrades();
64
65 if ( tutor_utils()->count( $upgrades ) ) {
66 foreach ( $upgrades as $upgrade ) {
67 $this->{$upgrade}();
68 }
69 }
70 }
71
72 /**
73 * Check availability
74 *
75 * @since 1.0.0
76 *
77 * @return array
78 */
79 public function available_upgrades() {
80 $version = get_option( 'tutor_version' );
81
82 $upgrades = array();
83 if ( $version ) {
84 $upgrades[] = 'upgrade_to_1_3_1';
85 $upgrades[] = 'upgrade_to_2_6_0';
86 $upgrades[] = 'upgrade_to_3_0_0';
87 $upgrades[] = 'upgrade_to_3_7_1';
88 }
89
90 return $upgrades;
91 }
92
93 /**
94 * Upgrade to version 1.3.1
95 *
96 * @since 1.0.0
97 *
98 * @return void
99 */
100 public function upgrade_to_1_3_1() {
101 if ( version_compare( get_option( 'tutor_version' ), '1.3.1', '<' ) ) {
102 global $wpdb;
103
104 if ( ! get_option( 'is_course_post_type_updated' ) ) {
105 $wpdb->update( $wpdb->posts, array( 'post_type' => tutor()->course_post_type ), array( 'post_type' => 'course' ) );
106 update_option( 'is_course_post_type_updated', true );
107 update_option( 'tutor_version', '1.3.1' );
108 Permalink::set_permalink_flag();
109 }
110 }
111 }
112
113 /**
114 * Migration logic when user upgrade to 2.6.0.
115 *
116 * @return void
117 */
118 public function upgrade_to_2_6_0() {
119 if ( version_compare( $this->installed_version, '2.6.0', '<' ) ) {
120 if ( false === Permalink::update_required() ) {
121 Permalink::set_permalink_flag();
122 }
123
124 do_action( 'before_tutor_version_upgrade_to_2_6_0', $this->installed_version );
125 update_option( 'tutor_version', TUTOR_VERSION );
126 }
127 }
128
129 /**
130 * Migration logic when user upgrade to 3.0.0.
131 *
132 * @return void
133 */
134 public function upgrade_to_3_0_0() {
135 global $wpdb;
136
137 if ( version_compare( $this->installed_version, '3.0.0', '<' ) ) {
138 $table_name = $wpdb->prefix . 'tutor_orders';
139 if ( ! QueryHelper::table_exists( $table_name ) ) {
140 Tutor::tutor_activate();
141 }
142 update_option( 'tutor_version', TUTOR_VERSION );
143 }
144
145 // Beta upgrade.
146 if ( version_compare( TUTOR_VERSION, '3.0.0-beta2', '>=' ) ) {
147 $order_items_table = $wpdb->prefix . 'tutor_order_items';
148 if ( ! QueryHelper::column_exist( $order_items_table, 'discount_price' ) ) {
149 // If 'discount_price' does not exist, alter the table to add 'discount_price' and 'coupon_code', and update 'sale_price'.
150 $wpdb->query(
151 //phpcs:ignore
152 "ALTER TABLE {$order_items_table}
153 ADD COLUMN discount_price VARCHAR(13) DEFAULT NULL,
154 ADD COLUMN coupon_code VARCHAR(255) DEFAULT NULL,
155 MODIFY COLUMN sale_price VARCHAR(13) NULL"
156 );
157 }
158 }
159
160 // New field added coupon_amount in orders table.
161 if ( version_compare( TUTOR_VERSION, '3.0.0-beta4', '>=' ) ) {
162 $order_table = $wpdb->prefix . 'tutor_orders';
163
164 $coupon_amount = 'coupon_amount';
165 if ( ! QueryHelper::column_exist( $order_table, $coupon_amount ) ) {
166 $wpdb->query( "ALTER TABLE {$order_table} ADD COLUMN $coupon_amount DECIMAL(13, 2) DEFAULT NULL AFTER coupon_code" );//phpcs:ignore
167 }
168
169 /**
170 * Tax Type: inclusive, exclusive
171 */
172 $tax_type = 'tax_type';
173 if ( ! QueryHelper::column_exist( $order_table, $tax_type ) ) {
174 $wpdb->query( "ALTER TABLE {$order_table} ADD COLUMN $tax_type VARCHAR(50) DEFAULT NULL AFTER discount_reason" );//phpcs:ignore
175 }
176 }
177
178 CartController::create_cart_page();
179 CheckoutController::create_checkout_page();
180 }
181
182 /**
183 * Migration logic when user upgrade to 3.7.1
184 *
185 * @return void
186 */
187 public function upgrade_to_3_7_1() {
188 global $wpdb;
189
190 /**
191 * Result column and index added.
192 */
193 $result = 'result';
194 $attempt_table = $wpdb->tutor_quiz_attempts;
195 if ( QueryHelper::table_exists( $attempt_table ) && ! QueryHelper::column_exist( $attempt_table, $result ) ) {
196 $wpdb->query( "ALTER TABLE {$attempt_table} ADD COLUMN result VARCHAR(10);" ); //phpcs:ignore
197
198 // Index Added to improve query performance.
199 $wpdb->query(
200 //phpcs:ignore
201 "ALTER TABLE {$attempt_table}
202 ADD INDEX (course_id),
203 ADD INDEX (quiz_id),
204 ADD INDEX (user_id),
205 ADD INDEX (result);"
206 );
207 }
208
209 /**
210 * For content bank question.
211 * Column `content_id` is added to the `tutor_quiz_questions` table
212 *
213 * @since 3.7.0
214 */
215 $question_table = $wpdb->prefix . 'tutor_quiz_questions';
216 if ( QueryHelper::table_exists( $question_table ) && ! QueryHelper::column_exist( $question_table, 'content_id' ) ) {
217 $wpdb->query( "ALTER TABLE {$question_table} ADD COLUMN content_id BIGINT UNSIGNED DEFAULT NULL AFTER question_id" ); //phpcs:ignore
218 $wpdb->query( "ALTER TABLE {$question_table} ADD INDEX content_id(content_id)" );//phpcs:ignore
219 }
220 }
221
222 /**
223 * Installing Gradebook if Tutor Pro exists
224 *
225 * @since v1.4.2
226 *
227 * @return void
228 */
229 public function install_gradebook() {
230 global $wpdb;
231
232 $exists_gradebook_table = $wpdb->query( "SHOW TABLES LIKE '{$wpdb->tutor_gradebooks}';" );
233 $exists_gradebook_results_table = $wpdb->query( "SHOW TABLES LIKE '{$wpdb->tutor_gradebooks_results}';" );
234 $charset_collate = $wpdb->get_charset_collate();
235
236 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
237
238 if ( ! $exists_gradebook_table ) {
239 $gradebook_table = "CREATE TABLE IF NOT EXISTS {$wpdb->tutor_gradebooks} (
240 gradebook_id bigint(20) NOT NULL AUTO_INCREMENT,
241 grade_name varchar(50) DEFAULT NULL,
242 grade_point varchar(20) DEFAULT NULL,
243 grade_point_to varchar(20) DEFAULT NULL,
244 percent_from int(3) DEFAULT NULL,
245 percent_to int(3) DEFAULT NULL,
246 grade_config longtext,
247 PRIMARY KEY (gradebook_id)
248 ) $charset_collate;";
249 dbDelta( $gradebook_table );
250 }
251 if ( ! $exists_gradebook_results_table ) {
252 $gradebook_results = "CREATE TABLE IF NOT EXISTS {$wpdb->tutor_gradebooks_results} (
253 gradebook_result_id bigint(20) NOT NULL AUTO_INCREMENT,
254 user_id bigint(20) DEFAULT NULL,
255 course_id bigint(20) DEFAULT NULL,
256 quiz_id bigint(20) DEFAULT NULL,
257 assignment_id bigint(20) DEFAULT NULL,
258 gradebook_id bigint(20) DEFAULT NULL,
259 result_for varchar(50) DEFAULT NULL,
260 grade_name varchar(50) DEFAULT NULL,
261 grade_point varchar(20) DEFAULT NULL,
262 earned_grade_point varchar(20) DEFAULT NULL,
263 earned_percent int(3) DEFAULT NULL,
264 generate_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
265 update_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
266 PRIMARY KEY (gradebook_result_id)
267 ) {$charset_collate};";
268 dbDelta( $gradebook_results );
269 }
270 }
271
272 /**
273 * Email table deployment
274 *
275 * @param mixed $upgrader_object up grader obj.
276 * @param mixed $options options.
277 *
278 * @return void
279 */
280 public function init_email_table_deployment( $upgrader_object, $options ) {
281
282 if ( is_object( $upgrader_object ) && is_array( $upgrader_object->result ) && isset( $upgrader_object->result['destination_name'] ) && 'tutor-pro' == $upgrader_object->result['destination_name'] ) {
283 $addon_config = tutor_utils()->get_addon_config( 'tutor-pro/addons/tutor-email/tutor-email.php' );
284 $is_enable = (bool) tutor_utils()->avalue_dot( 'is_enable', $addon_config );
285
286 $is_enable ? $this->install_tutor_email_queue() : 0;
287 }
288 }
289
290 /**
291 * Installing email addon if Tutor Pro exists
292 *
293 * @since 1.8.6
294 *
295 * @return void
296 */
297 public function install_tutor_email_queue() {
298
299 global $wpdb;
300 $charset_collate = $wpdb->get_charset_collate();
301
302 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
303
304 if ( ! QueryHelper::table_exists( $wpdb->tutor_email_queue ) ) {
305 $table = "CREATE TABLE IF NOT EXISTS {$wpdb->tutor_email_queue} (
306 id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
307 mail_to varchar(255) NOT NULL,
308 subject text NOT NULL,
309 message text NOT NULL,
310 headers text NOT NULL,
311 batch varchar(50) NULL,
312 PRIMARY KEY (id)
313 ) {$charset_collate};";
314
315 dbDelta( $table );
316 }
317 }
318 }
319