Admin
4 weeks ago
AdminBarDashboardAccess
3 years ago
Classes
1 week ago
ContentProtection
1 month ago
Functions
4 months ago
Integrations
1 year ago
Membership
1 week ago
NavigationMenuLinks
2 years ago
RegisterActivation
9 months ago
ShortcodeParser
3 weeks ago
Themes
2 months ago
Widgets
10 months ago
lib
3 years ago
templates
1 month ago
Base.php
2 months ago
Cron.php
2 years ago
DBTables.php
3 years ago
DBUpdates.php
1 month ago
LoginRedirect.php
9 months ago
RegisterScripts.php
4 months ago
eu-vat-rates.json
10 months ago
DBUpdates.php
222 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core; |
| 4 | |
| 5 | use ProfilePress\Core\Classes\ExtensionManager; |
| 6 | use ProfilePress\Core\Membership\DigitalProducts\UploadHandler; |
| 7 | use ProfilePress\Libsodium\Licensing\Licensing; |
| 8 | |
| 9 | class DBUpdates |
| 10 | { |
| 11 | public static $instance; |
| 12 | |
| 13 | const DB_VER = 14; |
| 14 | |
| 15 | public function init_options() |
| 16 | { |
| 17 | add_option('ppress_db_ver', 0); |
| 18 | } |
| 19 | |
| 20 | public function maybe_update() |
| 21 | { |
| 22 | $this->init_options(); |
| 23 | |
| 24 | if (get_option('ppress_db_ver', 0) >= self::DB_VER) { |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | // update plugin |
| 29 | $this->update(); |
| 30 | } |
| 31 | |
| 32 | public function update() |
| 33 | { |
| 34 | // no PHP timeout for running updates |
| 35 | set_time_limit(0); |
| 36 | |
| 37 | // this is the current database schema version number |
| 38 | $current_db_ver = get_option('ppress_db_ver', 0); |
| 39 | |
| 40 | // this is the target version that we need to reach |
| 41 | $target_db_ver = self::DB_VER; |
| 42 | |
| 43 | // run update routines one by one until the current version number |
| 44 | // reaches the target version number |
| 45 | while ($current_db_ver < $target_db_ver) { |
| 46 | // increment the current db_ver by one |
| 47 | $current_db_ver++; |
| 48 | |
| 49 | // each db version will require a separate update function |
| 50 | $update_method = "update_routine_{$current_db_ver}"; |
| 51 | |
| 52 | if (method_exists($this, $update_method)) { |
| 53 | call_user_func(array($this, $update_method)); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // update the option in the database, so that this process can always |
| 58 | // pick up where it left off |
| 59 | update_option('ppress_db_ver', $current_db_ver); |
| 60 | } |
| 61 | |
| 62 | public function update_routine_1() |
| 63 | { |
| 64 | $a = get_option(ExtensionManager::DB_OPTION_NAME, []); |
| 65 | $a[ExtensionManager::PAYPAL] = 'true'; |
| 66 | update_option(ExtensionManager::DB_OPTION_NAME, $a); |
| 67 | } |
| 68 | |
| 69 | public function update_routine_2() |
| 70 | { |
| 71 | global $wpdb; |
| 72 | |
| 73 | $table1 = DBTables::orders_db_table(); |
| 74 | $table2 = DBTables::subscriptions_db_table(); |
| 75 | $table3 = DBTables::customers_db_table(); |
| 76 | |
| 77 | $wpdb->query("ALTER TABLE $table1 CHANGE date_created date_created datetime NOT NULL;"); |
| 78 | $wpdb->query("ALTER TABLE $table2 CHANGE created_date created_date datetime NOT NULL;"); |
| 79 | $wpdb->query("ALTER TABLE $table3 CHANGE date_created date_created datetime NOT NULL;"); |
| 80 | } |
| 81 | |
| 82 | public function update_routine_3() |
| 83 | { |
| 84 | global $wpdb; |
| 85 | |
| 86 | $table = DBTables::coupons_db_table(); |
| 87 | $table2 = DBTables::subscription_plans_db_table(); |
| 88 | |
| 89 | $wpdb->query("ALTER TABLE $table CHANGE type coupon_type varchar(50) NULL;"); |
| 90 | $wpdb->query("ALTER TABLE $table2 ADD COLUMN order_note text NULL AFTER description;"); |
| 91 | } |
| 92 | |
| 93 | public function update_routine_4() |
| 94 | { |
| 95 | global $wpdb; |
| 96 | |
| 97 | $table = DBTables::subscription_plans_db_table(); |
| 98 | |
| 99 | $wpdb->query("ALTER TABLE $table ADD COLUMN user_role varchar(50) NULL AFTER description;"); |
| 100 | } |
| 101 | |
| 102 | public function update_routine_5() |
| 103 | { |
| 104 | UploadHandler::get_instance()->create_protection_files(true); |
| 105 | |
| 106 | flush_rewrite_rules(); |
| 107 | |
| 108 | if (class_exists('\ProfilePress\Libsodium\Licensing\Licensing')) { |
| 109 | |
| 110 | $response = Licensing::get_instance()->license_control_instance()->check_license(); |
| 111 | |
| 112 | if (is_wp_error($response)) return false; |
| 113 | |
| 114 | if ( ! empty($response->license)) { |
| 115 | if ($response->license == 'valid') { |
| 116 | update_option('ppress_license_status', 'valid'); |
| 117 | update_option('ppress_license_expired_status', 'false'); |
| 118 | } else { |
| 119 | if (in_array($response->license, ['expired', 'disabled'])) { |
| 120 | update_option('ppress_license_expired_status', 'true'); |
| 121 | } |
| 122 | update_option('ppress_license_status', 'invalid'); |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | public function update_routine_6() |
| 129 | { |
| 130 | $a = get_option(ExtensionManager::DB_OPTION_NAME); |
| 131 | $a[ExtensionManager::MOLLIE] = 'true'; |
| 132 | update_option(ExtensionManager::DB_OPTION_NAME, $a); |
| 133 | } |
| 134 | |
| 135 | public function update_routine_7() |
| 136 | { |
| 137 | ppress_update_settings('wordpresscom_button_label', esc_html__('Sign in with WordPress.com', 'wp-user-avatar')); |
| 138 | ppress_update_settings('yahoo_button_label', esc_html__('Sign in with Yahoo', 'wp-user-avatar')); |
| 139 | ppress_update_settings('microsoft_button_label', esc_html__('Sign in with Microsoft', 'wp-user-avatar')); |
| 140 | ppress_update_settings('amazon_button_label', esc_html__('Sign in with Amazon', 'wp-user-avatar')); |
| 141 | } |
| 142 | |
| 143 | public function update_routine_8() |
| 144 | { |
| 145 | $a = get_option(ExtensionManager::DB_OPTION_NAME); |
| 146 | $a[ExtensionManager::RECEIPT] = 'true'; |
| 147 | update_option(ExtensionManager::DB_OPTION_NAME, $a); |
| 148 | } |
| 149 | |
| 150 | public function update_routine_9() |
| 151 | { |
| 152 | global $wpdb; |
| 153 | |
| 154 | $table = DBTables::coupons_db_table(); |
| 155 | |
| 156 | $wpdb->query("ALTER TABLE $table ADD COLUMN is_onetime_use enum('true','false') NOT NULL DEFAULT 'false' AFTER coupon_type;"); |
| 157 | } |
| 158 | |
| 159 | public function update_routine_10() |
| 160 | { |
| 161 | global $wpdb; |
| 162 | |
| 163 | $table = DBTables::profile_fields_db_table(); |
| 164 | |
| 165 | if ($wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table))) { |
| 166 | // Table exists, proceed with altering the table |
| 167 | $wpdb->query("ALTER TABLE $table CHANGE options options longtext NULL;"); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | public function update_routine_11() |
| 172 | { |
| 173 | $linkedin_api_version = ppress_get_setting('linkedin_api_version', ''); |
| 174 | |
| 175 | if (empty($linkedin_api_version)) { |
| 176 | ppress_update_settings('linkedin_api_version', 'deprecated'); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | public function update_routine_12() |
| 181 | { |
| 182 | global $wpdb; |
| 183 | |
| 184 | $table = DBTables::passwordless_login_db_table(); |
| 185 | |
| 186 | // because this db updated might trigger if pro plugin isn't active, i had to also ensure the schema change below |
| 187 | // was added to the CREATE table definition in the pro plugin folder/archive to ensure the update is always present |
| 188 | // this will take care of for when a site already has pro and lite plugins active |
| 189 | if ($wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table))) { |
| 190 | $wpdb->query("ALTER TABLE $table CHANGE id id bigint(20) unsigned NOT NULL AUTO_INCREMENT;"); |
| 191 | $wpdb->query("ALTER TABLE $table CHANGE user_id user_id bigint(20) unsigned NOT NULL;"); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | public function update_routine_13() |
| 196 | { |
| 197 | $db = get_option(ExtensionManager::DB_OPTION_NAME, []); |
| 198 | |
| 199 | if (in_array('true', [ppress_var($db, 'join_buddypress_groups'), ppress_var($db, 'buddypress_sync')])) { |
| 200 | $db['buddypress'] = 'true'; |
| 201 | update_option(ExtensionManager::DB_OPTION_NAME, $db); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | public function update_routine_14() |
| 206 | { |
| 207 | $recaptcha_site_key = ppress_settings_by_key('recaptcha_site_key'); |
| 208 | |
| 209 | if ( ! empty($recaptcha_site_key)) { |
| 210 | ppress_update_settings('recaptcha_api_platform', 'classic'); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | public static function get_instance() |
| 215 | { |
| 216 | if ( ! isset(self::$instance)) { |
| 217 | self::$instance = new self(); |
| 218 | } |
| 219 | |
| 220 | return self::$instance; |
| 221 | } |
| 222 | } |