| 1 |
<?php |
| 2 |
|
| 3 |
namespace Payplug\PayplugWoocommerce\Service; |
| 4 |
|
| 5 |
use Payplug\PayplugWoocommerce\Traits\GatewayGetter; |
| 6 |
use Payplug\PayplugWoocommerce\Traits\ServiceGetter; |
| 7 |
|
| 8 |
class Upgrade |
| 9 |
{ |
| 10 |
use ServiceGetter; |
| 11 |
use GatewayGetter; |
| 12 |
|
| 13 |
public function run_upgrade(): void |
| 14 |
{ |
| 15 |
// Check if new options need to be setted |
| 16 |
$configuration = $this->get_service('configuration'); |
| 17 |
|
| 18 |
if (empty($configuration->get_option('email'))) { |
| 19 |
return; |
| 20 |
} |
| 21 |
|
| 22 |
$version = $configuration->get_option('version'); |
| 23 |
|
| 24 |
if (!empty($version) && version_compare($version, PAYPLUG_MAX_VERSION_FOR_UPGRADE, '>=')) { |
| 25 |
return; |
| 26 |
} |
| 27 |
|
| 28 |
$options = $configuration->validate_configuration(); |
| 29 |
|
| 30 |
if (empty($options)) { |
| 31 |
return; |
| 32 |
} |
| 33 |
|
| 34 |
// set the current version |
| 35 |
$options['version'] = PAYPLUG_GATEWAY_VERSION; |
| 36 |
|
| 37 |
// replace current option by new one |
| 38 |
$configuration->clean_option(); |
| 39 |
$configuration->update_options($options); |
| 40 |
|
| 41 |
// then refresh the permissions |
| 42 |
$account_gateway = $this->get_gateway('account'); |
| 43 |
|
| 44 |
// then get permissions |
| 45 |
$formated_account_permissions = $account_gateway->get_permissions(); |
| 46 |
|
| 47 |
// and update options |
| 48 |
$configuration->update_options($formated_account_permissions['global']); |
| 49 |
$configuration->update_payment_permissions($formated_account_permissions['payment_methods']); |
| 50 |
|
| 51 |
return; |
| 52 |
} |
| 53 |
} |
| 54 |
|