ClearCompletedUpgrade.php
32 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\Migrations\Actions; |
| 4 | |
| 5 | use InvalidArgumentException; |
| 6 | |
| 7 | /** |
| 8 | * Class ClearCompletedUpgrade |
| 9 | * |
| 10 | * Clears an upgrade from the list of completed upgrades so it can be ran again |
| 11 | */ |
| 12 | class ClearCompletedUpgrade { |
| 13 | /** |
| 14 | * @since 2.9.2 |
| 15 | * |
| 16 | * @param string $upgradeId |
| 17 | */ |
| 18 | public function __invoke( $upgradeId ) { |
| 19 | $completedUpgrades = get_option( 'give_completed_upgrades' ); |
| 20 | |
| 21 | $upgradeIndex = array_search( $upgradeId, $completedUpgrades, true ); |
| 22 | |
| 23 | if ( false === $upgradeIndex ) { |
| 24 | throw new InvalidArgumentException( "No upgrade for the given ID: $upgradeId" ); |
| 25 | } |
| 26 | |
| 27 | array_splice( $completedUpgrades, $upgradeIndex, 1 ); |
| 28 | |
| 29 | update_option( 'give_completed_upgrades', $completedUpgrades ); |
| 30 | } |
| 31 | } |
| 32 |