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.0 3.6.0 3.6.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 1 day ago Admin.php 1 day ago Ajax.php 1 day ago Announcements.php 1 day ago Assets.php 1 day ago Backend_Page_Trait.php 1 year ago BaseController.php 1 year ago Config.php 1 day ago Container.php 11 months ago Course.php 1 day ago Course_Embed.php 3 years ago Course_Filter.php 1 day ago Course_List.php 1 day ago Course_Settings_Tabs.php 1 day ago Course_Widget.php 1 year ago Custom_Validation.php 1 day ago Dashboard.php 1 day ago Earnings.php 9 months ago FormHandler.php 1 day ago Frontend.php 1 day ago Gutenberg.php 1 year ago Icon.php 1 day ago Input.php 1 day ago Instructor.php 1 day ago Instructors_List.php 1 day ago Lesson.php 1 day ago Options_V2.php 1 day ago Permalink.php 1 day ago Post_types.php 2 days ago Private_Course_Access.php 1 day ago Q_And_A.php 1 day ago Question_Answers_List.php 11 months ago Quiz.php 1 day ago QuizBuilder.php 1 day ago Quiz_Attempts_List.php 1 day ago RestAPI.php 2 years ago Reviews.php 1 day ago Rewrite_Rules.php 2 years ago SampleCourse.php 1 day ago Shortcode.php 1 day ago Singleton.php 1 year ago Student.php 1 day ago Students_List.php 1 year ago Taxonomies.php 1 year ago Template.php 1 day ago Theme_Compatibility.php 3 years ago Tools.php 1 year ago Tools_V2.php 4 weeks ago Tutor.php 1 day ago TutorEDD.php 1 day ago Tutor_Base.php 2 years ago Tutor_Setup.php 1 day ago Upgrader.php 1 day ago User.php 1 day ago UserPreference.php 1 day ago Utils.php 1 day ago Video_Stream.php 3 years ago WhatsNew.php 10 months ago Withdraw.php 1 day ago Withdraw_Requests_List.php 11 months ago WooCommerce.php 1 day ago
Upgrader.php
430 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 // Required to use dbDelta.
85 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
86
87 $upgrades[] = 'upgrade_to_1_3_1';
88 $upgrades[] = 'upgrade_to_2_6_0';
89 $upgrades[] = 'upgrade_to_3_0_0';
90 $upgrades[] = 'upgrade_to_3_7_1';
91 $upgrades[] = 'upgrade_to_3_8_0';
92 $upgrades[] = 'upgrade_to_3_8_2';
93 }
94
95 return $upgrades;
96 }
97
98 /**
99 * Upgrade to version 1.3.1
100 *
101 * @since 1.0.0
102 *
103 * @return void
104 */
105 public function upgrade_to_1_3_1() {
106 if ( version_compare( get_option( 'tutor_version' ), '1.3.1', '<' ) ) {
107 global $wpdb;
108
109 if ( ! get_option( 'is_course_post_type_updated' ) ) {
110 $wpdb->update( $wpdb->posts, array( 'post_type' => tutor()->course_post_type ), array( 'post_type' => 'course' ) );
111 update_option( 'is_course_post_type_updated', true );
112 update_option( 'tutor_version', '1.3.1' );
113 Permalink::set_permalink_flag();
114 }
115 }
116 }
117
118 /**
119 * Migration logic when user upgrade to 2.6.0.
120 *
121 * @return void
122 */
123 public function upgrade_to_2_6_0() {
124 if ( version_compare( $this->installed_version, '2.6.0', '<' ) ) {
125 if ( false === Permalink::update_required() ) {
126 Permalink::set_permalink_flag();
127 }
128
129 do_action( 'before_tutor_version_upgrade_to_2_6_0', $this->installed_version );
130 update_option( 'tutor_version', TUTOR_VERSION );
131 }
132 }
133
134 /**
135 * Migration logic when user upgrade to 3.0.0.
136 *
137 * @return void
138 */
139 public function upgrade_to_3_0_0() {
140 global $wpdb;
141
142 if ( version_compare( $this->installed_version, '3.0.0', '<' ) ) {
143 $table_name = $wpdb->prefix . 'tutor_orders';
144 if ( ! QueryHelper::table_exists( $table_name ) ) {
145 Tutor::tutor_activate();
146 }
147 update_option( 'tutor_version', TUTOR_VERSION );
148 }
149
150 // Beta upgrade.
151 if ( version_compare( TUTOR_VERSION, '3.0.0-beta2', '>=' ) ) {
152 $order_items_table = $wpdb->prefix . 'tutor_order_items';
153 if ( QueryHelper::table_exists( $order_items_table ) && ! QueryHelper::column_exist( $order_items_table, 'discount_price' ) ) {
154 // If 'discount_price' does not exist, alter the table to add 'discount_price' and 'coupon_code', and update 'sale_price'.
155 $wpdb->query(
156 //phpcs:ignore
157 "ALTER TABLE {$order_items_table}
158 ADD COLUMN discount_price VARCHAR(13) DEFAULT NULL,
159 ADD COLUMN coupon_code VARCHAR(255) DEFAULT NULL,
160 MODIFY COLUMN sale_price VARCHAR(13) NULL"
161 );
162 }
163 }
164
165 // New field added coupon_amount in orders table.
166 if ( version_compare( TUTOR_VERSION, '3.0.0-beta4', '>=' ) ) {
167 $order_table = $wpdb->prefix . 'tutor_orders';
168
169 $coupon_amount = 'coupon_amount';
170 if ( QueryHelper::table_exists( $order_table ) && ! QueryHelper::column_exist( $order_table, $coupon_amount ) ) {
171 $wpdb->query( "ALTER TABLE {$order_table} ADD COLUMN $coupon_amount DECIMAL(13, 2) DEFAULT NULL AFTER coupon_code" );//phpcs:ignore
172 }
173
174 /**
175 * Tax Type: inclusive, exclusive
176 */
177 $tax_type = 'tax_type';
178 if ( QueryHelper::table_exists( $order_table ) && ! QueryHelper::column_exist( $order_table, $tax_type ) ) {
179 $wpdb->query( "ALTER TABLE {$order_table} ADD COLUMN $tax_type VARCHAR(50) DEFAULT NULL AFTER pre_tax_price" );//phpcs:ignore
180 }
181 }
182
183 CartController::create_cart_page();
184 CheckoutController::create_checkout_page();
185 }
186
187 /**
188 * Migration logic when user upgrade to 3.7.1
189 *
190 * @return void
191 */
192 public function upgrade_to_3_7_1() {
193 global $wpdb;
194
195 /**
196 * Result column and index added.
197 */
198 $result = 'result';
199 $attempt_table = $wpdb->tutor_quiz_attempts;
200 if ( QueryHelper::table_exists( $attempt_table ) && ! QueryHelper::column_exist( $attempt_table, $result ) ) {
201 $wpdb->query( "ALTER TABLE {$attempt_table} ADD COLUMN result VARCHAR(10);" ); //phpcs:ignore
202
203 // Index Added to improve query performance.
204 $wpdb->query(
205 //phpcs:ignore
206 "ALTER TABLE {$attempt_table}
207 ADD INDEX (course_id),
208 ADD INDEX (quiz_id),
209 ADD INDEX (user_id),
210 ADD INDEX (result);"
211 );
212 }
213
214 /**
215 * For content bank question.
216 * Column `content_id` is added to the `tutor_quiz_questions` table
217 *
218 * @since 3.7.0
219 */
220 $question_table = $wpdb->prefix . 'tutor_quiz_questions';
221 if ( QueryHelper::table_exists( $question_table ) && ! QueryHelper::column_exist( $question_table, 'content_id' ) ) {
222 $wpdb->query( "ALTER TABLE {$question_table} ADD COLUMN content_id BIGINT UNSIGNED DEFAULT NULL AFTER question_id" ); //phpcs:ignore
223 $wpdb->query( "ALTER TABLE {$question_table} ADD INDEX content_id(content_id)" );//phpcs:ignore
224 }
225 }
226
227 /**
228 * Migration logic when user upgrade to 3.8.0
229 *
230 * @return void
231 */
232 public function upgrade_to_3_8_0() {
233 if ( version_compare( TUTOR_VERSION, '3.8.0', '>=' ) ) {
234 global $wpdb;
235 $order_table = $wpdb->prefix . 'tutor_orders';
236 if ( QueryHelper::table_exists( $order_table ) && ! QueryHelper::column_exist( $order_table, 'pre_tax_price' ) ) {
237 $wpdb->query( "ALTER TABLE {$order_table} ADD COLUMN pre_tax_price DECIMAL(13, 2) NOT NULL AFTER subtotal_price" ); //phpcs:ignore
238 }
239
240 $charset_collate = $wpdb->get_charset_collate();
241 $scheduler_table = QueryHelper::table_exists( $wpdb->prefix . 'tutor_scheduler' );
242 $item_meta_table = QueryHelper::table_exists( $wpdb->prefix . 'tutor_order_itemmeta' );
243
244 // Create tutor_scheduler table.
245 if ( ! $scheduler_table ) {
246 $table_schema = "CREATE TABLE {$wpdb->prefix}tutor_scheduler (
247 id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
248 type VARCHAR(50) NOT NULL COMMENT 'Type of schedule, e.g., gift, email, reminder',
249 reference_id VARCHAR(255) NOT NULL COMMENT 'Unique reference id, token, etc',
250 scheduled_at_gmt DATETIME NOT NULL COMMENT 'When the action should be executed',
251 status VARCHAR(255) NOT NULL DEFAULT 'processing',
252 payload LONGTEXT,
253 created_at_gmt DATETIME,
254 updated_at_gmt DATETIME,
255 scheduled_by BIGINT UNSIGNED COMMENT 'User who scheduled the action',
256 scheduled_for BIGINT UNSIGNED COMMENT 'Target user of the scheduled action',
257 PRIMARY KEY (id),
258 KEY idx_context_status (type, status),
259 KEY idx_status (status),
260 KEY idx_scheduled_at_gmt (scheduled_at_gmt)
261 ) $charset_collate;";
262 dbDelta( $table_schema );
263 }
264
265 // Create order_item_meta table.
266 if ( ! $item_meta_table ) {
267 $item_meta_table = "CREATE TABLE {$wpdb->prefix}tutor_order_itemmeta (
268 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
269 item_id BIGINT(20) UNSIGNED NOT NULL,
270 meta_key VARCHAR(255) NOT NULL,
271 meta_value LONGTEXT NOT NULL,
272 PRIMARY KEY (id),
273 KEY item_id (item_id),
274 KEY meta_key (meta_key),
275 CONSTRAINT fk_tutor_itemmeta FOREIGN KEY (item_id) REFERENCES {$wpdb->prefix}tutor_order_items(id) ON DELETE CASCADE
276 ) $charset_collate;";
277 dbDelta( $item_meta_table );
278 }
279
280 // Check if the column already exists.
281 $cart_item_table = $wpdb->prefix . 'tutor_cart_items';
282 $detail_column = 'item_details';
283 $type_column = 'item_type';
284
285 if ( QueryHelper::table_exists( $cart_item_table ) ) {
286 $is_detail_column_exists = QueryHelper::column_exist( $cart_item_table, $detail_column );
287 $is_type_column_exists = QueryHelper::column_exist( $cart_item_table, $type_column );
288
289 if ( ! $is_detail_column_exists ) {
290 $wpdb->query( "ALTER TABLE {$cart_item_table} ADD {$detail_column} JSON AFTER course_id" );
291 }
292
293 if ( ! $is_type_column_exists ) {
294 $wpdb->query( "ALTER TABLE {$cart_item_table} ADD {$type_column} VARCHAR(255) AFTER course_id" );
295 }
296 }
297 }
298 }
299
300 /**
301 * Upgrade to version 3.8.2
302 *
303 * @since 3.8.2
304 *
305 * @return void
306 */
307 public function upgrade_to_3_8_2() {
308 if ( version_compare( $this->installed_version, '3.8.2', '<' ) ) {
309 update_option( 'tutor_version', '3.8.2' );
310
311 global $wpdb;
312 $earnings_table = $wpdb->prefix . 'tutor_earnings';
313
314 /**
315 * Index added to improve performance.
316 */
317 $wpdb->query(
318 //phpcs:ignore
319 "ALTER TABLE {$earnings_table}
320 ADD INDEX (user_id),
321 ADD INDEX (course_id),
322 ADD INDEX (order_id),
323 ADD INDEX (process_by);"
324 );
325
326 /**
327 * Update process by to 'tutor' where it is 'Tutor'
328 */
329 QueryHelper::update( $earnings_table, array( 'process_by' => 'tutor' ), array( 'process_by' => 'Tutor' ) );
330 }
331 }
332
333 /**
334 * Installing Gradebook if Tutor Pro exists
335 *
336 * @since v1.4.2
337 *
338 * @return void
339 */
340 public function install_gradebook() {
341 global $wpdb;
342
343 $exists_gradebook_table = $wpdb->query( "SHOW TABLES LIKE '{$wpdb->tutor_gradebooks}';" );
344 $exists_gradebook_results_table = $wpdb->query( "SHOW TABLES LIKE '{$wpdb->tutor_gradebooks_results}';" );
345 $charset_collate = $wpdb->get_charset_collate();
346
347 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
348
349 if ( ! $exists_gradebook_table ) {
350 $gradebook_table = "CREATE TABLE IF NOT EXISTS {$wpdb->tutor_gradebooks} (
351 gradebook_id bigint(20) NOT NULL AUTO_INCREMENT,
352 grade_name varchar(50) DEFAULT NULL,
353 grade_point varchar(20) DEFAULT NULL,
354 grade_point_to varchar(20) DEFAULT NULL,
355 percent_from int(3) DEFAULT NULL,
356 percent_to int(3) DEFAULT NULL,
357 grade_config longtext,
358 PRIMARY KEY (gradebook_id)
359 ) $charset_collate;";
360 dbDelta( $gradebook_table );
361 }
362 if ( ! $exists_gradebook_results_table ) {
363 $gradebook_results = "CREATE TABLE IF NOT EXISTS {$wpdb->tutor_gradebooks_results} (
364 gradebook_result_id bigint(20) NOT NULL AUTO_INCREMENT,
365 user_id bigint(20) DEFAULT NULL,
366 course_id bigint(20) DEFAULT NULL,
367 quiz_id bigint(20) DEFAULT NULL,
368 assignment_id bigint(20) DEFAULT NULL,
369 gradebook_id bigint(20) DEFAULT NULL,
370 result_for varchar(50) DEFAULT NULL,
371 grade_name varchar(50) DEFAULT NULL,
372 grade_point varchar(20) DEFAULT NULL,
373 earned_grade_point varchar(20) DEFAULT NULL,
374 earned_percent int(3) DEFAULT NULL,
375 generate_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
376 update_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
377 PRIMARY KEY (gradebook_result_id)
378 ) {$charset_collate};";
379 dbDelta( $gradebook_results );
380 }
381 }
382
383 /**
384 * Email table deployment
385 *
386 * @param mixed $upgrader_object up grader obj.
387 * @param mixed $options options.
388 *
389 * @return void
390 */
391 public function init_email_table_deployment( $upgrader_object, $options ) {
392
393 if ( is_object( $upgrader_object ) && is_array( $upgrader_object->result ) && isset( $upgrader_object->result['destination_name'] ) && 'tutor-pro' == $upgrader_object->result['destination_name'] ) {
394 $addon_config = tutor_utils()->get_addon_config( 'tutor-pro/addons/tutor-email/tutor-email.php' );
395 $is_enable = (bool) tutor_utils()->avalue_dot( 'is_enable', $addon_config );
396
397 $is_enable ? $this->install_tutor_email_queue() : 0;
398 }
399 }
400
401 /**
402 * Installing email addon if Tutor Pro exists
403 *
404 * @since 1.8.6
405 *
406 * @return void
407 */
408 public function install_tutor_email_queue() {
409
410 global $wpdb;
411 $charset_collate = $wpdb->get_charset_collate();
412
413 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
414
415 if ( ! QueryHelper::table_exists( $wpdb->tutor_email_queue ) ) {
416 $table = "CREATE TABLE IF NOT EXISTS {$wpdb->tutor_email_queue} (
417 id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
418 mail_to varchar(255) NOT NULL,
419 subject text NOT NULL,
420 message text NOT NULL,
421 headers text NOT NULL,
422 batch varchar(50) NULL,
423 PRIMARY KEY (id)
424 ) {$charset_collate};";
425
426 dbDelta( $table );
427 }
428 }
429 }
430