| 1 |
<?php |
| 2 |
|
| 3 |
namespace IvyForms\Services\InstallActions\Migrations; |
| 4 |
|
| 5 |
use IvyForms\Common\Exceptions\InvalidArgumentException; |
| 6 |
use IvyForms\Services\InstallActions\DB\Payment\PaymentsTable; |
| 7 |
use IvyForms\Services\Translations\BackendStrings; |
| 8 |
|
| 9 |
/** |
| 10 |
* Stores gateway-specific ids (PayPal orderId / attemptId) off the entries table. |
| 11 |
*/ |
| 12 |
class AddProviderMetaToPayments |
| 13 |
{ |
| 14 |
/** |
| 15 |
* @return bool |
| 16 |
* @throws InvalidArgumentException |
| 17 |
*/ |
| 18 |
public static function run(): bool |
| 19 |
{ |
| 20 |
global $wpdb; |
| 21 |
|
| 22 |
$tableName = PaymentsTable::getTableName(); |
| 23 |
|
| 24 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery |
| 25 |
$columnExists = $wpdb->get_results( |
| 26 |
"SHOW COLUMNS FROM `{$tableName}` LIKE 'providerMeta'" |
| 27 |
); |
| 28 |
|
| 29 |
if (!empty($columnExists)) { |
| 30 |
return true; |
| 31 |
} |
| 32 |
|
| 33 |
$alterQuery = "ALTER TABLE `{$tableName}` ADD COLUMN `providerMeta` TEXT NULL AFTER `status`"; |
| 34 |
|
| 35 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.SchemaChange |
| 36 |
$result = $wpdb->query($alterQuery); |
| 37 |
|
| 38 |
if ($result === false) { |
| 39 |
error_log(sprintf( |
| 40 |
BackendStrings::getExceptionStrings()['migration_error_add_column'], |
| 41 |
'providerMeta', |
| 42 |
$tableName |
| 43 |
)); |
| 44 |
return false; |
| 45 |
} |
| 46 |
|
| 47 |
return true; |
| 48 |
} |
| 49 |
} |
| 50 |
|