 pronamic    /
                    wp-pronamic-ideal
                      pronamic    /
                    wp-pronamic-ideal
                
                            | 1 | <?php | ||
| 2 | /** | ||
| 3 | * Update 2.0.0 | ||
| 4 | * | ||
| 5 | * @author Pronamic <[email protected]> | ||
| 6 | * @copyright 2005-2020 Pronamic | ||
| 7 | * @license GPL-3.0-or-later | ||
| 8 | * @package Pronamic\WordPress\Pay | ||
| 9 | */ | ||
| 10 | |||
| 11 | /** | ||
| 12 | * Execute changes made in Pronamic Pay 2.0.0 | ||
| 13 | * | ||
| 14 | * @link https://github.com/WordPress/WordPress/blob/3.5.1/wp-admin/includes/upgrade.php#L413 | ||
| 15 | * @since 2.0.0 | ||
| 16 | */ | ||
| 17 | |||
| 18 | // Check if there is not already an upgrade running | ||
| 19 | if ( get_transient( 'pronamic_pay_upgrade_200' ) ) { | ||
| 20 | return; | ||
| 21 | } | ||
| 22 | |||
| 23 | set_transient( 'pronamic_pay_upgrade_200', true, 3600 ); // 60 minutes | ||
| 24 | |||
| 25 | // Upgrade | ||
| 26 | global $wpdb; | ||
| 27 | |||
| 28 | require_once ABSPATH . '/wp-admin/includes/upgrade.php'; | ||
| 29 | |||
| 30 | $charset_collate = ''; | ||
| 31 | if ( ! empty( $wpdb->charset ) ) { | ||
| 32 | $charset_collate = 'DEFAULT CHARACTER SET ' . $wpdb->charset; | ||
| 33 | } | ||
| 34 | if ( ! empty( $wpdb->collate ) ) { | ||
| 35 | $charset_collate .= ' COLLATE ' . $wpdb->collate; | ||
| 36 | } | ||
| 37 | |||
| 38 | /* | ||
| 39 | |||
| 40 | -- You can undo the database upgrade by executing the following queries | ||
| 41 | |||
| 42 | UPDATE wp_pronamic_ideal_configurations SET post_id = null; | ||
| 43 | DELETE FROM wp_posts WHERE post_type = 'pronamic_gateway'; | ||
| 44 | |||
| 45 | UPDATE wp_pronamic_ideal_payments SET post_id = null; | ||
| 46 | DELETE FROM wp_posts WHERE post_type = 'pronamic_payment'; | ||
| 47 | |||
| 48 | UPDATE wp_rg_ideal_feeds SET post_id = null; | ||
| 49 | DELETE FROM wp_posts WHERE post_type = 'pronamic_pay_gf'; | ||
| 50 | |||
| 51 | UPDATE wp_options SET option_value = 0 WHERE option_name = 'pronamic_pay_db_version'; | ||
| 52 | |||
| 53 | DELETE FROM wp_postmeta WHERE post_id NOT IN ( SELECT ID FROM wp_posts ); | ||
| 54 | |||
| 55 | */ | ||
| 56 | |||
| 57 | /** | ||
| 58 | * Configs | ||
| 59 | */ | ||
| 60 | |||
| 61 | global $pronamic_ideal; | ||
| 62 | |||
| 63 | $config_table = $wpdb->prefix . 'pronamic_ideal_configurations'; | ||
| 64 | |||
| 65 | $sql = "CREATE TABLE $config_table ( | ||
| 66 | id MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT, | ||
| 67 | post_id BIGINT(20) UNSIGNED NULL, | ||
| 68 | variant_id VARCHAR(64) NULL, | ||
| 69 | merchant_id VARCHAR(64) NULL, | ||
| 70 | sub_id VARCHAR(64) NULL, | ||
| 71 | mode VARCHAR(64) NULL, | ||
| 72 | hash_key VARCHAR(64) NULL, | ||
| 73 | private_key TEXT NULL, | ||
| 74 | private_key_password VARCHAR(64) NULL, | ||
| 75 | private_certificate TEXT NULL, | ||
| 76 | meta LONGTEXT, | ||
| 77 | PRIMARY KEY (id) | ||
| 78 | ) $charset_collate;"; | ||
| 79 | |||
| 80 | dbDelta( $sql ); | ||
| 81 | |||
| 82 | // Query | ||
| 83 | $query = " | ||
| 84 | SELECT | ||
| 85 | * | ||
| 86 | FROM | ||
| 87 | $config_table | ||
| 88 | WHERE | ||
| 89 | post_id IS NULL | ||
| 90 | LIMIT | ||
| 91 | 1 | ||
| 92 | ; | ||
| 93 | "; | ||
| 94 | |||
| 95 | $have_configs = true; | ||
| 96 | |||
| 97 | while ( $have_configs ) { | ||
| 98 | $configs = $wpdb->get_results( $query ); // WPCS: unprepared SQL ok. | ||
| 99 | |||
| 100 | $have_configs = ! empty( $configs ); | ||
| 101 | |||
| 102 | 	foreach ( $configs as $config ) { | ||
| 103 | $title = sprintf( __( 'Configuration %d', 'pronamic_ideal' ), $config->id ); | ||
| 104 | |||
| 105 | // Post | ||
| 106 | $post = array( | ||
| 107 | 'post_title' => $title, | ||
| 108 | 'post_type' => 'pronamic_gateway', | ||
| 109 | 'post_status' => 'publish', | ||
| 110 | ); | ||
| 111 | |||
| 112 | $post_id = wp_insert_post( $post ); | ||
| 113 | |||
| 114 | 		if ( $post_id ) { | ||
| 115 | $wpdb->update( | ||
| 116 | $config_table, | ||
| 117 | array( | ||
| 118 | 'post_id' => $post_id, | ||
| 119 | ), | ||
| 120 | array( | ||
| 121 | 'id' => $config->id, | ||
| 122 | ), | ||
| 123 | '%d', | ||
| 124 | '%d' | ||
| 125 | ); | ||
| 126 | |||
| 127 | // Meta | ||
| 128 | // We ignore (@) all notice of not existing properties | ||
| 129 | $config_meta = json_decode( $config->meta ); | ||
| 130 | |||
| 131 | $meta = array(); | ||
| 132 | |||
| 133 | $meta['legacy_id'] = $config->id; | ||
| 134 | $meta['id'] = $config->variant_id; | ||
| 135 | $meta['mode'] = $config->mode; | ||
| 136 | |||
| 137 | // iDEAL | ||
| 138 | $meta['ideal_merchant_id'] = $config->merchant_id; | ||
| 139 | $meta['ideal_sub_id'] = $config->sub_id; | ||
| 140 | |||
| 141 | // iDEAL Basic | ||
| 142 | $meta['ideal_hash_key'] = $config->hash_key; | ||
| 143 | |||
| 144 | // iDEAL Advanced | ||
| 145 | $meta['ideal_private_key'] = $config->private_key; | ||
| 146 | $meta['ideal_private_key_password'] = $config->private_key_password; | ||
| 147 | $meta['ideal_private_certificate'] = $config->private_certificate; | ||
| 148 | |||
| 149 | // OmniKassa | ||
| 150 | 			if ( 'rabobank-omnikassa' === $config->variant_id ) { | ||
| 151 | $meta['omnikassa_merchant_id'] = $config->merchant_id; | ||
| 152 | $meta['omnikassa_secret_key'] = $config->hash_key; | ||
| 153 | |||
| 154 | $key_version = @$config_meta->keyVersion; | ||
| 155 | // In Pronamic iDEAL v1.0 we stored the key version in the iDEAL sub ID | ||
| 156 | $key_version = empty( $key_version ) ? $config->sub_id : $key_version; | ||
| 157 | |||
| 158 | $meta['omnikassa_key_version'] = $key_version; | ||
| 159 | |||
| 160 | unset( $meta['ideal_merchant_id'] ); | ||
| 161 | unset( $meta['ideal_hash_key'] ); | ||
| 162 | } | ||
| 163 | |||
| 164 | // Buckaroo | ||
| 165 | $meta['buckaroo_website_key'] = @$config_meta->buckarooWebsiteKey; | ||
| 166 | $meta['buckaroo_secret_key'] = @$config_meta->buckarooSecretKey; | ||
| 167 | |||
| 168 | // Icepay | ||
| 169 | $meta['icepay_merchant_id'] = @$config_meta->icepayMerchantId; | ||
| 170 | $meta['icepay_secret_code'] = @$config_meta->icepaySecretCode; | ||
| 171 | |||
| 172 | // Mollie | ||
| 173 | $meta['mollie_partner_id'] = @$config_meta->molliePartnerId; | ||
| 174 | $meta['mollie_profile_key'] = @$config_meta->mollieProfileKey; | ||
| 175 | |||
| 176 | // Sisow | ||
| 177 | $meta['sisow_merchant_id'] = @$config_meta->sisowMerchantId; | ||
| 178 | $meta['sisow_merchant_key'] = @$config_meta->sisowMerchantKey; | ||
| 179 | |||
| 180 | // TargetPay | ||
| 181 | $meta['targetpay_layout_code'] = @$config_meta->targetPayLayoutCode; | ||
| 182 | |||
| 183 | // Qantani | ||
| 184 | $meta['qantani_merchant_id'] = @$config_meta->qantani_merchant_id; | ||
| 185 | $meta['qantani_merchant_key'] = @$config_meta->qantani_merchant_key; | ||
| 186 | $meta['qantani_merchant_secret'] = @$config_meta->qantani_merchant_secret; | ||
| 187 | |||
| 188 | // Ogone | ||
| 189 | $meta['ogone_psp_id'] = @$config_meta->pspId; | ||
| 190 | $meta['ogone_sha_in_pass_phrase'] = @$config_meta->shaInPassPhrase; | ||
| 191 | $meta['ogone_sha_out_pass_phrase'] = @$config_meta->shaOutPassPhrase; | ||
| 192 | $meta['ogone_user_id'] = @$config_meta->ogone_user_id; | ||
| 193 | $meta['ogone_password'] = @$config_meta->ogone_password; | ||
| 194 | |||
| 195 | // Other | ||
| 196 | $meta['country'] = @$config_meta->country; | ||
| 197 | $meta['state_or_province'] = @$config_meta->stateOrProvince; | ||
| 198 | $meta['locality'] = @$config_meta->locality; | ||
| 199 | $meta['organization'] = @$config_meta->organization; | ||
| 200 | $meta['organization_unit'] = @$config_meta->organizationUnit; | ||
| 201 | $meta['common_name'] = @$config_meta->commonName; | ||
| 202 | $meta['email'] = @$config_meta->eMailAddress; | ||
| 203 | |||
| 204 | 			foreach ( $meta as $key => $value ) { | ||
| 205 | 				if ( ! empty( $value ) ) { | ||
| 206 | $meta_key = '_pronamic_gateway_' . $key; | ||
| 207 | |||
| 208 | update_post_meta( $post_id, $meta_key, $value ); | ||
| 0 ignored issues–
                            show             Bug
    
    
    
        introduced 
                            by  
  Loading history... | |||
| 209 | } | ||
| 210 | } | ||
| 211 | } | ||
| 212 | } | ||
| 213 | } | ||
| 214 | |||
| 215 | /** | ||
| 216 | * Config IDs map | ||
| 217 | */ | ||
| 218 | $query = " | ||
| 219 | SELECT | ||
| 220 | id, | ||
| 221 | post_id | ||
| 222 | FROM | ||
| 223 | $config_table | ||
| 224 | ; | ||
| 225 | "; | ||
| 226 | |||
| 227 | $config_ids_map = array(); | ||
| 228 | |||
| 229 | $config_ids = $wpdb->get_results( $query ); // WPCS: unprepared SQL ok. | ||
| 230 | |||
| 231 | foreach ( $config_ids as $config_id ) { | ||
| 232 | $config_ids_map[ $config_id->id ] = $config_id->post_id; | ||
| 233 | } | ||
| 234 | |||
| 235 | /** | ||
| 236 | * Gravity Forms payment feeds | ||
| 237 | */ | ||
| 238 | $feeds_table = $wpdb->prefix . 'rg_ideal_feeds'; | ||
| 239 | |||
| 240 | $sql = "CREATE TABLE $feeds_table ( | ||
| 241 | id MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT, | ||
| 242 | post_id BIGINT(20) UNSIGNED NULL, | ||
| 243 | form_id MEDIUMINT(8) UNSIGNED NOT NULL, | ||
| 244 | configuration_id MEDIUMINT(8) UNSIGNED NOT NULL, | ||
| 245 | is_active TINYINT(1) NOT NULL DEFAULT 1, | ||
| 246 | meta LONGTEXT, | ||
| 247 | PRIMARY KEY (id), | ||
| 248 | KEY form_id (form_id), | ||
| 249 | KEY configuration_id (configuration_id) | ||
| 250 | ) $charset_collate;"; | ||
| 251 | |||
| 252 | dbDelta( $sql ); | ||
| 253 | |||
| 254 | // Query | ||
| 255 | $query = " | ||
| 256 | SELECT | ||
| 257 | * | ||
| 258 | FROM | ||
| 259 | $feeds_table | ||
| 260 | WHERE | ||
| 261 | post_id IS NULL | ||
| 262 | LIMIT | ||
| 263 | 1 | ||
| 264 | ; | ||
| 265 | "; | ||
| 266 | |||
| 267 | $have_feeds = true; | ||
| 268 | |||
| 269 | while ( $have_feeds ) { | ||
| 270 | $feeds = $wpdb->get_results( $query ); // WPCS: unprepared SQL ok. | ||
| 271 | |||
| 272 | $have_feeds = ! empty( $feeds ); | ||
| 273 | |||
| 274 | 	foreach ( $feeds as $feed ) { | ||
| 275 | // Post | ||
| 276 | $post = array( | ||
| 277 | 'post_title' => sprintf( __( 'Payment Form %d', 'pronamic_ideal' ), $feed->id ), | ||
| 278 | 'post_type' => 'pronamic_pay_gf', | ||
| 279 | 'post_status' => 'publish', | ||
| 280 | ); | ||
| 281 | |||
| 282 | $post_id = wp_insert_post( $post ); | ||
| 283 | |||
| 284 | 		if ( $post_id ) { | ||
| 285 | $wpdb->update( | ||
| 286 | $feeds_table, | ||
| 287 | array( | ||
| 288 | 'post_id' => $post_id, | ||
| 289 | ), | ||
| 290 | array( | ||
| 291 | 'id' => $feed->id, | ||
| 292 | ), | ||
| 293 | '%d', | ||
| 294 | '%d' | ||
| 295 | ); | ||
| 296 | |||
| 297 | // Meta | ||
| 298 | // We ignore (@) all notice of not existing properties | ||
| 299 | $meta = array(); | ||
| 300 | |||
| 301 | $feed_meta = json_decode( $feed->meta, true ); | ||
| 302 | |||
| 303 | $meta['form_id'] = $feed->form_id; | ||
| 304 | $meta['config_id'] = @$config_ids_map[ $feed->configuration_id ]; | ||
| 305 | $meta['is_active'] = $feed->is_active; | ||
| 306 | $meta['transaction_description'] = @$feed_meta['transactionDescription']; | ||
| 307 | $meta['delay_notification_ids'] = @$feed_meta['delayNotificationIds']; | ||
| 308 | $meta['delay_admin_notification'] = @$feed_meta['delayAdminNotification']; | ||
| 309 | $meta['delay_user_notification'] = @$feed_meta['delayUserNotification']; | ||
| 310 | $meta['delay_post_creation'] = @$feed_meta['delayPostCreation']; | ||
| 311 | $meta['condition_enabled'] = @$feed_meta['conditionEnabled']; | ||
| 312 | $meta['condition_field_id'] = @$feed_meta['conditionFieldId']; | ||
| 313 | $meta['condition_operator'] = @$feed_meta['conditionOperator']; | ||
| 314 | $meta['condition_value'] = @$feed_meta['conditionValue']; | ||
| 315 | $meta['user_role_field_id'] = @$feed_meta['userRoleFieldId']; | ||
| 316 | $meta['fields'] = @$feed_meta['fields']; | ||
| 317 | $meta['links'] = @$feed_meta['links']; | ||
| 318 | |||
| 319 | 			if ( is_array( $meta['links'] ) ) { | ||
| 320 | 				foreach ( $meta['links'] as &$link ) { | ||
| 321 | 					if ( isset( $link['pageId'] ) ) { | ||
| 322 | $link['page_id'] = $link['pageId']; | ||
| 323 | } | ||
| 324 | } | ||
| 325 | } | ||
| 326 | |||
| 327 | 			foreach ( $meta as $key => $value ) { | ||
| 328 | 				if ( ! empty( $value ) ) { | ||
| 329 | $meta_key = '_pronamic_pay_gf_' . $key; | ||
| 330 | |||
| 331 | update_post_meta( $post_id, $meta_key, $value ); | ||
| 332 | } | ||
| 333 | } | ||
| 334 | } | ||
| 335 | } | ||
| 336 | } | ||
| 337 | |||
| 338 | /** | ||
| 339 | * Payments. | ||
| 340 | */ | ||
| 341 | $payments_table = $wpdb->prefix . 'pronamic_ideal_payments'; | ||
| 342 | |||
| 343 | $sql = "CREATE TABLE $payments_table ( | ||
| 344 | id MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT, | ||
| 345 | post_id BIGINT(20) UNSIGNED NULL, | ||
| 346 | configuration_id MEDIUMINT(8) UNSIGNED NOT NULL, | ||
| 347 | purchase_id VARCHAR(16) NULL, | ||
| 348 | transaction_id VARCHAR(32) NULL, | ||
| 349 | date_gmt DATETIME NOT NULL, | ||
| 350 | amount DECIMAL(10, 2) NOT NULL, | ||
| 351 | currency VARCHAR(8) NOT NULL, | ||
| 352 | expiration_period VARCHAR(8) NOT NULL, | ||
| 353 | language VARCHAR(8) NOT NULL, | ||
| 354 | entrance_code VARCHAR(40) NULL, | ||
| 355 | description TEXT NOT NULL, | ||
| 356 | consumer_name VARCHAR(35) NULL, | ||
| 357 | consumer_account_number VARCHAR(10) NULL, | ||
| 358 | consumer_iban VARCHAR(34) NULL, | ||
| 359 | consumer_bic VARCHAR(11) NULL, | ||
| 360 | consumer_city VARCHAR(24) NULL, | ||
| 361 | status VARCHAR(32) NULL DEFAULT NULL, | ||
| 362 | status_requests MEDIUMINT(8) DEFAULT 0, | ||
| 363 | source VARCHAR(32) NULL DEFAULT NULL, | ||
| 364 | source_id VARCHAR(32) NULL DEFAULT NULL, | ||
| 365 | email VARCHAR(128) NULL DEFAULT NULL, | ||
| 366 | PRIMARY KEY (id) | ||
| 367 | ) $charset_collate;"; | ||
| 368 | |||
| 369 | dbDelta( $sql ); | ||
| 370 | |||
| 371 | // We convert the payments in groups of 100 so not everything will load in memory at once. | ||
| 372 | $query = " | ||
| 373 | SELECT | ||
| 374 | * | ||
| 375 | FROM | ||
| 376 | $payments_table | ||
| 377 | WHERE | ||
| 378 | post_id IS NULL | ||
| 379 | LIMIT | ||
| 380 | 1 | ||
| 381 | ; | ||
| 382 | "; | ||
| 383 | |||
| 384 | $have_payments = true; | ||
| 385 | |||
| 386 | while ( $have_payments ) { | ||
| 387 | $payments = $wpdb->get_results( $query ); // WPCS: unprepared SQL ok. | ||
| 388 | |||
| 389 | $have_payments = ! empty( $payments ); | ||
| 390 | |||
| 391 | 	foreach ( $payments as $payment ) { | ||
| 392 | // Post | ||
| 393 | $post = array( | ||
| 394 | 'post_title' => sprintf( __( 'Payment %d', 'pronamic_ideal' ), $payment->id ), | ||
| 395 | 'post_date' => get_date_from_gmt( $payment->date_gmt ), | ||
| 396 | 'post_date_gmt' => $payment->date_gmt, | ||
| 397 | 'post_type' => 'pronamic_payment', | ||
| 398 | 'post_status' => 'publish', | ||
| 399 | ); | ||
| 400 | |||
| 401 | $post_id = wp_insert_post( $post ); | ||
| 402 | |||
| 403 | 		if ( $post_id ) { | ||
| 404 | $wpdb->update( | ||
| 405 | $payments_table, | ||
| 406 | array( | ||
| 407 | 'post_id' => $post_id, | ||
| 408 | ), | ||
| 409 | array( | ||
| 410 | 'id' => $payment->id, | ||
| 411 | ), | ||
| 412 | '%d', | ||
| 413 | '%d' | ||
| 414 | ); | ||
| 415 | |||
| 416 | // Meta | ||
| 417 | $meta = array( | ||
| 418 | 'config_id' => @$config_ids_map[ $payment->configuration_id ], | ||
| 419 | 'purchase_id' => $payment->purchase_id, | ||
| 420 | 'transaction_id' => $payment->transaction_id, | ||
| 421 | 'currency' => $payment->currency, | ||
| 422 | 'amount' => $payment->amount, | ||
| 423 | 'expiration_period' => $payment->expiration_period, | ||
| 424 | 'language' => $payment->language, | ||
| 425 | 'entrance_code' => $payment->entrance_code, | ||
| 426 | 'description' => $payment->description, | ||
| 427 | 'consumer_name' => $payment->consumer_name, | ||
| 428 | 'consumer_account_number' => $payment->consumer_account_number, | ||
| 429 | 'consumer_iban' => $payment->consumer_iban, | ||
| 430 | 'consumer_bic' => $payment->consumer_bic, | ||
| 431 | 'consumer_city' => $payment->consumer_city, | ||
| 432 | 'status' => $payment->status, | ||
| 433 | 'source' => $payment->source, | ||
| 434 | 'source_id' => $payment->source_id, | ||
| 435 | 'email' => $payment->email, | ||
| 436 | ); | ||
| 437 | |||
| 438 | 			foreach ( $meta as $key => $value ) { | ||
| 439 | 				if ( ! empty( $value ) ) { | ||
| 440 | $meta_key = '_pronamic_payment_' . $key; | ||
| 441 | |||
| 442 | update_post_meta( $post_id, $meta_key, $value ); | ||
| 443 | } | ||
| 444 | } | ||
| 445 | } | ||
| 446 | } | ||
| 447 | } | ||
| 448 | |||
| 449 | ////////////////////////////////////////////////// | ||
| 450 | // Options config IDs | ||
| 451 | ////////////////////////////////////////////////// | ||
| 452 | |||
| 453 | $options = array( | ||
| 454 | // EventEspresso | ||
| 455 | // @link https://github.com/pronamic/wp-pronamic-ideal/blob/1.3.4/classes/Pronamic/EventEspresso/IDeal/AddOn.php#L72 | ||
| 456 | 'pronamic_ideal_event_espresso_configuration_id' => 'pronamic_pay_ideal_event_espreso_config_id', | ||
| 457 | // Jigoshop | ||
| 458 | // @link https://github.com/pronamic/wp-pronamic-ideal/blob/1.3.4/classes/Pronamic/Jigoshop/IDeal/IDealGateway.php#L62 | ||
| 459 | 'jigoshop_pronamic_ideal_enabled' => 'pronamic_pay_ideal_jigoshop_enabled', | ||
| 460 | 'jigoshop_pronamic_ideal_title' => 'pronamic_pay_ideal_jigoshop_title', | ||
| 461 | 'jigoshop_pronamic_ideal_description' => 'pronamic_pay_ideal_jigoshop_description', | ||
| 462 | 'jigoshop_pronamic_ideal_configuration_id' => 'pronamic_pay_ideal_jigoshop_config_id', | ||
| 463 | // Membership | ||
| 464 | 'pronamic_ideal_membership_chosen_configuration' => 'pronamic_pay_ideal_membership_config_id', | ||
| 465 | // s2Member | ||
| 466 | // @link https://github.com/pronamic/wp-pronamic-ideal/blob/1.3.4/classes/Pronamic/S2Member/Bridge/Settings.php#L52 | ||
| 467 | 'pronamic_ideal_s2member_chosen_configuration' => 'pronamic_pay_ideal_s2member_config_id', | ||
| 468 | // WP e-Commerce | ||
| 469 | // @link https://github.com/pronamic/wp-pronamic-ideal/blob/1.3.4/classes/Pronamic/WPeCommerce/IDeal/IDealMerchant.php#L35 | ||
| 470 | 'pronamic_ideal_wpsc_configuration_id' => 'pronamic_pay_ideal_wpsc_config_id', | ||
| 471 | ); | ||
| 472 | |||
| 473 | foreach ( $options as $key_old => $key_new ) { | ||
| 474 | $value = get_option( $key_old ); | ||
| 475 | |||
| 476 | 	if ( ! empty( $value ) ) { | ||
| 477 | $value_new = @$config_ids_map[ $value ]; | ||
| 478 | |||
| 479 | update_option( $key_new, $value_new ); | ||
| 480 | } | ||
| 481 | } | ||
| 482 | |||
| 483 | ////////////////////////////////////////////////// | ||
| 484 | // Complex options config IDs | ||
| 485 | ////////////////////////////////////////////////// | ||
| 486 | |||
| 487 | // Shopp | ||
| 488 | // @link https://github.com/pronamic/wp-pronamic-ideal/blob/1.3.4/classes/Pronamic/Shopp/IDeal/GatewayModule.php#L72 | ||
| 489 | $shopp_meta_table = $wpdb->prefix . 'shopp_meta'; | ||
| 490 | |||
| 491 | // @link http://cube3x.com/2013/04/how-to-check-if-table-exists-in-wordpress-database/ | ||
| 492 | if ( $shopp_meta_table === $wpdb->get_var( "SHOW TABLES LIKE '$shopp_meta_table';" ) ) { // WPCS: unprepared SQL ok. | ||
| 493 | $query = "SELECT id, value FROM $shopp_meta_table WHERE type = 'setting' AND name = 'Pronamic_Shopp_IDeal_GatewayModule';"; | ||
| 494 | |||
| 495 | $row = $wpdb->get_row( $query ); // WPCS: unprepared SQL ok. | ||
| 496 | |||
| 497 | 	if ( $row ) { | ||
| 498 | $settings = maybe_unserialize( $row->value ); | ||
| 499 | |||
| 500 | 		if ( is_array( $settings ) && isset( $settings['pronamic_shopp_ideal_configuration'] ) ) { | ||
| 501 | $value = $settings['pronamic_shopp_ideal_configuration']; | ||
| 502 | |||
| 503 | $settings['config_id'] = @$config_ids_map[ $value ]; | ||
| 504 | |||
| 505 | $wpdb->update( | ||
| 506 | $shopp_meta_table, | ||
| 507 | array( | ||
| 508 | 'value' => serialize( $settings ), | ||
| 509 | ), | ||
| 510 | array( | ||
| 511 | 'id' => $row->id, | ||
| 512 | ) | ||
| 513 | ); | ||
| 514 | } | ||
| 515 | } | ||
| 516 | } | ||
| 517 | |||
| 518 | // WooCommerce | ||
| 519 | // @link https://github.com/pronamic/wp-pronamic-ideal/blob/1.3.4/classes/Pronamic/WooCommerce/IDeal/IDealGateway.php#L42 | ||
| 520 | $settings = get_option( 'woocommerce_pronamic_ideal_settings' ); | ||
| 521 | |||
| 522 | if ( is_array( $settings ) && isset( $settings['configuration_id'] ) ) { | ||
| 523 | $value = $settings['configuration_id']; | ||
| 524 | |||
| 525 | $settings['config_id'] = @$config_ids_map[ $value ]; | ||
| 526 | |||
| 527 | unset( $settings['configuration_id'] ); | ||
| 528 | |||
| 529 | update_option( 'woocommerce_pronamic_pay_ideal_settings', $settings ); | ||
| 530 | } | ||
| 531 | |||
| 532 | delete_transient( 'pronamic_pay_upgrade_200' ); | ||
| 533 | 
