| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Yatra\Upgrades\Versions; |
| 6 |
|
| 7 |
use Yatra\Services\InstallerService; |
| 8 |
use Yatra\Upgrades\AbstractUpgradeStep; |
| 9 |
|
| 10 |
/** |
| 11 |
* Free 3.0.3: drop legacy payment-token tables after Pro (or nothing) has migrated scheduled rows. |
| 12 |
* |
| 13 |
* Canonical table name matches Pro {@see \YatraPro\Upgrades\Versions\Upgrade_3_0_0_1} (`wp_*_yatra_payment_tokens`). |
| 14 |
* Some installs may still have a mistaken `yatra_new_payment_tokens` name from early builds; drop both if present. |
| 15 |
*/ |
| 16 |
final class Upgrade_3_0_3 extends AbstractUpgradeStep |
| 17 |
{ |
| 18 |
public static function targetVersion(): string |
| 19 |
{ |
| 20 |
return '3.0.3'; |
| 21 |
} |
| 22 |
|
| 23 |
public static function runOnHooks(): array |
| 24 |
{ |
| 25 |
return ['admin_init']; |
| 26 |
} |
| 27 |
|
| 28 |
public static function run(string $fromVersion, string $toVersion): void |
| 29 |
{ |
| 30 |
unset($fromVersion, $toVersion); |
| 31 |
|
| 32 |
global $wpdb; |
| 33 |
|
| 34 |
$suffixes = [ |
| 35 |
'yatra_payment_tokens', |
| 36 |
'yatra_new_payment_tokens', |
| 37 |
]; |
| 38 |
|
| 39 |
foreach ($suffixes as $suffix) { |
| 40 |
$table = $wpdb->prefix . $suffix; |
| 41 |
if (!InstallerService::databaseTableExists($table)) { |
| 42 |
continue; |
| 43 |
} |
| 44 |
|
| 45 |
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- table name is escaped. |
| 46 |
$wpdb->query('DROP TABLE IF EXISTS `' . esc_sql($table) . '`'); |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
|