SetPayPalStandardGatewayId.php
72 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\PaymentGateways\PayPalStandard\Migrations; |
| 4 | |
| 5 | use Give\Framework\Migrations\Contracts\Migration; |
| 6 | |
| 7 | /** |
| 8 | * Class SetPayPalStandardGatewayId |
| 9 | * @package Give\PaymentGateways\PayPalStandard\Migrations |
| 10 | * |
| 11 | * This migration fixes a bug that was introduced in 2.9.0 wherein the PayPal Standard gateway ID was changed from |
| 12 | * paypal to paypal-standard. This caused problems on existing sites using PayPal Standard. The purpose of this |
| 13 | * migration is to help those that are on 2.9.0 to recover to using the paypal ID for the gateway. |
| 14 | * |
| 15 | * @since 2.9.1 |
| 16 | */ |
| 17 | class SetPayPalStandardGatewayId extends Migration { |
| 18 | |
| 19 | /** |
| 20 | * @inheritdoc |
| 21 | */ |
| 22 | public function run() { |
| 23 | // Reset paypal gateway id to paypal. |
| 24 | $give_settings = give_get_settings(); |
| 25 | $gateways = $give_settings['gateways']; |
| 26 | $updateSettings = false; |
| 27 | |
| 28 | if ( array_key_exists( 'paypal-standard', $gateways ) ) { |
| 29 | unset( $gateways['paypal-standard'] ); |
| 30 | $gateways['paypal'] = '1'; |
| 31 | $give_settings['gateways'] = $gateways; |
| 32 | |
| 33 | $updateSettings = true; |
| 34 | } |
| 35 | |
| 36 | // Reset paypal gateway custom label. |
| 37 | if ( isset( $give_settings['gateways_label'] ) ) { |
| 38 | $gateways_label = $give_settings['gateways_label']; |
| 39 | if ( array_key_exists( 'paypal-standard', $gateways_label ) ) { |
| 40 | $gateways_label['paypal'] = $gateways_label['paypal-standard']; |
| 41 | unset( $gateways_label['paypal-standard'] ); |
| 42 | $give_settings['gateways_label'] = $gateways_label; |
| 43 | $updateSettings = true; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | // Set paypal standard as default payment gateway. |
| 48 | if ( 'paypal-standard' === $give_settings['default_gateway'] ) { |
| 49 | $give_settings['default_gateway'] = 'paypal'; |
| 50 | $updateSettings = true; |
| 51 | } |
| 52 | |
| 53 | if ( $updateSettings ) { |
| 54 | update_option( 'give_settings', $give_settings ); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @inheritdoc |
| 60 | */ |
| 61 | public static function id() { |
| 62 | return 'set_paypal_standard_id_to_paypal_from_paypal_standard'; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @inheritdoc |
| 67 | */ |
| 68 | public static function timestamp() { |
| 69 | return strtotime( '2020-10-28' ); |
| 70 | } |
| 71 | } |
| 72 |