| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\Donors\Migrations; |
| 4 |
|
| 5 |
use Give\Framework\Database\Exceptions\DatabaseQueryException; |
| 6 |
use Give\Framework\Migrations\Contracts\Migration; |
| 7 |
use Give\Framework\Migrations\Exceptions\DatabaseMigrationException; |
| 8 |
|
| 9 |
/** |
| 10 |
* @since 3.7.0 |
| 11 |
*/ |
| 12 |
class AddPhoneColumn extends Migration |
| 13 |
{ |
| 14 |
/** |
| 15 |
* @since 3.7.0 |
| 16 |
* |
| 17 |
* @throws DatabaseMigrationException |
| 18 |
*/ |
| 19 |
public function run() |
| 20 |
{ |
| 21 |
global $wpdb; |
| 22 |
|
| 23 |
$donorsTableName = "{$wpdb->prefix}give_donors"; |
| 24 |
|
| 25 |
try { |
| 26 |
maybe_add_column( |
| 27 |
$donorsTableName, |
| 28 |
'phone', |
| 29 |
"ALTER TABLE `$donorsTableName` ADD COLUMN `phone` varchar(50) NOT NULL DEFAULT '' AFTER `name`" |
| 30 |
); |
| 31 |
} catch (DatabaseQueryException $exception) { |
| 32 |
throw new DatabaseMigrationException('An error occurred adding the phone column to the donors table', |
| 33 |
0, $exception); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* @since 3.7.0 |
| 39 |
*/ |
| 40 |
public static function id(): string |
| 41 |
{ |
| 42 |
return 'donors-add-phone-column'; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* @since 3.7.0 |
| 47 |
*/ |
| 48 |
public static function title(): string |
| 49 |
{ |
| 50 |
return 'Add phone column to donors table'; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* @since 3.7.0 |
| 55 |
*/ |
| 56 |
public static function timestamp() |
| 57 |
{ |
| 58 |
return strtotime('2024-03-26'); |
| 59 |
} |
| 60 |
} |
| 61 |
|