Addons.php
1 year ago
Admin.php
1 year ago
Ajax.php
1 year ago
Announcements.php
1 year ago
Assets.php
1 year ago
Backend_Page_Trait.php
1 year ago
BaseController.php
1 year ago
Course.php
1 year ago
Course_Embed.php
3 years ago
Course_Filter.php
1 year ago
Course_List.php
1 year 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
Input.php
1 year ago
Instructor.php
1 year ago
Instructors_List.php
1 year ago
Lesson.php
1 year ago
Options_V2.php
1 year ago
Permalink.php
2 years ago
Post_types.php
1 year ago
Private_Course_Access.php
1 year ago
Q_And_A.php
1 year ago
Question_Answers_List.php
3 years ago
Quiz.php
1 year ago
QuizBuilder.php
1 year ago
Quiz_Attempts_List.php
1 year ago
RestAPI.php
2 years ago
Reviews.php
3 years 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
1 year ago
Theme_Compatibility.php
3 years ago
Tools.php
1 year ago
Tools_V2.php
1 year ago
Tutor.php
1 year ago
TutorEDD.php
1 year ago
Tutor_Base.php
2 years ago
Tutor_Setup.php
1 year ago
Upgrader.php
1 year ago
User.php
1 year ago
Utils.php
1 year ago
Video_Stream.php
3 years ago
WhatsNew.php
2 years ago
Withdraw.php
1 year ago
Withdraw_Requests_List.php
1 year ago
WooCommerce.php
1 year ago
Upgrader.php
278 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 | } |
| 88 | |
| 89 | return $upgrades; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Upgrade to version 1.3.1 |
| 94 | * |
| 95 | * @since 1.0.0 |
| 96 | * |
| 97 | * @return void |
| 98 | */ |
| 99 | public function upgrade_to_1_3_1() { |
| 100 | if ( version_compare( get_option( 'tutor_version' ), '1.3.1', '<' ) ) { |
| 101 | global $wpdb; |
| 102 | |
| 103 | if ( ! get_option( 'is_course_post_type_updated' ) ) { |
| 104 | $wpdb->update( $wpdb->posts, array( 'post_type' => tutor()->course_post_type ), array( 'post_type' => 'course' ) ); |
| 105 | update_option( 'is_course_post_type_updated', true ); |
| 106 | update_option( 'tutor_version', '1.3.1' ); |
| 107 | Permalink::set_permalink_flag(); |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Migration logic when user upgrade to 2.6.0. |
| 114 | * |
| 115 | * @return void |
| 116 | */ |
| 117 | public function upgrade_to_2_6_0() { |
| 118 | if ( version_compare( $this->installed_version, '2.6.0', '<' ) ) { |
| 119 | if ( false === Permalink::update_required() ) { |
| 120 | Permalink::set_permalink_flag(); |
| 121 | } |
| 122 | |
| 123 | do_action( 'before_tutor_version_upgrade_to_2_6_0', $this->installed_version ); |
| 124 | update_option( 'tutor_version', TUTOR_VERSION ); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Migration logic when user upgrade to 3.0.0. |
| 130 | * |
| 131 | * @return void |
| 132 | */ |
| 133 | public function upgrade_to_3_0_0() { |
| 134 | global $wpdb; |
| 135 | |
| 136 | if ( version_compare( $this->installed_version, '3.0.0', '<' ) ) { |
| 137 | $table_name = $wpdb->prefix . 'tutor_orders'; |
| 138 | if ( ! QueryHelper::table_exists( $table_name ) ) { |
| 139 | Tutor::tutor_activate(); |
| 140 | } |
| 141 | update_option( 'tutor_version', TUTOR_VERSION ); |
| 142 | } |
| 143 | |
| 144 | // Beta upgrade. |
| 145 | if ( version_compare( TUTOR_VERSION, '3.0.0-beta2', '>=' ) ) { |
| 146 | $order_items_table = $wpdb->prefix . 'tutor_order_items'; |
| 147 | if ( ! QueryHelper::column_exist( $order_items_table, 'discount_price' ) ) { |
| 148 | // If 'discount_price' does not exist, alter the table to add 'discount_price' and 'coupon_code', and update 'sale_price'. |
| 149 | $wpdb->query( |
| 150 | "ALTER TABLE {$order_items_table} |
| 151 | ADD COLUMN discount_price VARCHAR(13) DEFAULT NULL, |
| 152 | ADD COLUMN coupon_code VARCHAR(255) DEFAULT NULL, |
| 153 | MODIFY COLUMN sale_price VARCHAR(13) NULL" |
| 154 | ); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | // New field added coupon_amount in orders table. |
| 159 | if ( version_compare( TUTOR_VERSION, '3.0.0-beta4', '>=' ) ) { |
| 160 | $order_table = $wpdb->prefix . 'tutor_orders'; |
| 161 | |
| 162 | $coupon_amount = 'coupon_amount'; |
| 163 | if ( ! QueryHelper::column_exist( $order_table, $coupon_amount ) ) { |
| 164 | $wpdb->query( "ALTER TABLE {$order_table} ADD COLUMN $coupon_amount DECIMAL(13, 2) DEFAULT NULL AFTER coupon_code" );//phpcs:ignore |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Tax Type: inclusive, exclusive |
| 169 | */ |
| 170 | $tax_type = 'tax_type'; |
| 171 | if ( ! QueryHelper::column_exist( $order_table, $tax_type ) ) { |
| 172 | $wpdb->query( "ALTER TABLE {$order_table} ADD COLUMN $tax_type VARCHAR(50) DEFAULT NULL AFTER discount_reason" );//phpcs:ignore |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | CartController::create_cart_page(); |
| 177 | CheckoutController::create_checkout_page(); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Installing Gradebook if Tutor Pro exists |
| 182 | * |
| 183 | * @since v1.4.2 |
| 184 | * |
| 185 | * @return void |
| 186 | */ |
| 187 | public function install_gradebook() { |
| 188 | global $wpdb; |
| 189 | |
| 190 | $exists_gradebook_table = $wpdb->query( "SHOW TABLES LIKE '{$wpdb->tutor_gradebooks}';" ); |
| 191 | $exists_gradebook_results_table = $wpdb->query( "SHOW TABLES LIKE '{$wpdb->tutor_gradebooks_results}';" ); |
| 192 | $charset_collate = $wpdb->get_charset_collate(); |
| 193 | |
| 194 | require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 195 | |
| 196 | if ( ! $exists_gradebook_table ) { |
| 197 | $gradebook_table = "CREATE TABLE IF NOT EXISTS {$wpdb->tutor_gradebooks} ( |
| 198 | gradebook_id bigint(20) NOT NULL AUTO_INCREMENT, |
| 199 | grade_name varchar(50) DEFAULT NULL, |
| 200 | grade_point varchar(20) DEFAULT NULL, |
| 201 | grade_point_to varchar(20) DEFAULT NULL, |
| 202 | percent_from int(3) DEFAULT NULL, |
| 203 | percent_to int(3) DEFAULT NULL, |
| 204 | grade_config longtext, |
| 205 | PRIMARY KEY (gradebook_id) |
| 206 | ) $charset_collate;"; |
| 207 | dbDelta( $gradebook_table ); |
| 208 | } |
| 209 | if ( ! $exists_gradebook_results_table ) { |
| 210 | $gradebook_results = "CREATE TABLE IF NOT EXISTS {$wpdb->tutor_gradebooks_results} ( |
| 211 | gradebook_result_id bigint(20) NOT NULL AUTO_INCREMENT, |
| 212 | user_id bigint(20) DEFAULT NULL, |
| 213 | course_id bigint(20) DEFAULT NULL, |
| 214 | quiz_id bigint(20) DEFAULT NULL, |
| 215 | assignment_id bigint(20) DEFAULT NULL, |
| 216 | gradebook_id bigint(20) DEFAULT NULL, |
| 217 | result_for varchar(50) DEFAULT NULL, |
| 218 | grade_name varchar(50) DEFAULT NULL, |
| 219 | grade_point varchar(20) DEFAULT NULL, |
| 220 | earned_grade_point varchar(20) DEFAULT NULL, |
| 221 | earned_percent int(3) DEFAULT NULL, |
| 222 | generate_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
| 223 | update_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
| 224 | PRIMARY KEY (gradebook_result_id) |
| 225 | ) {$charset_collate};"; |
| 226 | dbDelta( $gradebook_results ); |
| 227 | } |
| 228 | |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Email table deployment |
| 233 | * |
| 234 | * @param mixed $upgrader_object up grader obj. |
| 235 | * @param mixed $options options. |
| 236 | * |
| 237 | * @return void |
| 238 | */ |
| 239 | public function init_email_table_deployment( $upgrader_object, $options ) { |
| 240 | |
| 241 | if ( is_object( $upgrader_object ) && is_array( $upgrader_object->result ) && isset( $upgrader_object->result['destination_name'] ) && 'tutor-pro' == $upgrader_object->result['destination_name'] ) { |
| 242 | $addon_config = tutor_utils()->get_addon_config( 'tutor-pro/addons/tutor-email/tutor-email.php' ); |
| 243 | $is_enable = (bool) tutor_utils()->avalue_dot( 'is_enable', $addon_config ); |
| 244 | |
| 245 | $is_enable ? $this->install_tutor_email_queue() : 0; |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * Installing email addon if Tutor Pro exists |
| 251 | * |
| 252 | * @since 1.8.6 |
| 253 | * |
| 254 | * @return void |
| 255 | */ |
| 256 | public function install_tutor_email_queue() { |
| 257 | |
| 258 | global $wpdb; |
| 259 | $charset_collate = $wpdb->get_charset_collate(); |
| 260 | |
| 261 | require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 262 | |
| 263 | if ( ! QueryHelper::table_exists( $wpdb->tutor_email_queue ) ) { |
| 264 | $table = "CREATE TABLE IF NOT EXISTS {$wpdb->tutor_email_queue} ( |
| 265 | id bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| 266 | mail_to varchar(255) NOT NULL, |
| 267 | subject text NOT NULL, |
| 268 | message text NOT NULL, |
| 269 | headers text NOT NULL, |
| 270 | batch varchar(50) NULL, |
| 271 | PRIMARY KEY (id) |
| 272 | ) {$charset_collate};"; |
| 273 | |
| 274 | dbDelta( $table ); |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 |