| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\Campaigns\Migrations\Tables; |
| 4 |
|
| 5 |
use Give\Framework\Database\DB; |
| 6 |
use Give\Framework\Database\Exceptions\DatabaseQueryException; |
| 7 |
use Give\Framework\Migrations\Contracts\Migration; |
| 8 |
use Give\Framework\Migrations\Exceptions\DatabaseMigrationException; |
| 9 |
|
| 10 |
/** |
| 11 |
* @since 4.0.0 |
| 12 |
* Creates give_campaign_forms table |
| 13 |
*/ |
| 14 |
class CreateCampaignFormsTable extends Migration |
| 15 |
{ |
| 16 |
/** |
| 17 |
* @inheritdoc |
| 18 |
*/ |
| 19 |
public static function id(): string |
| 20 |
{ |
| 21 |
return 'give-campaigns-create-give-campaign-forms-table'; |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* @inheritdoc |
| 26 |
*/ |
| 27 |
public static function title(): string |
| 28 |
{ |
| 29 |
return 'Create give_campaign_forms table'; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* @inheritdoc |
| 34 |
*/ |
| 35 |
public static function timestamp(): string |
| 36 |
{ |
| 37 |
return strtotime('2024-08-26 00:00:01'); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* @inheritDoc |
| 42 |
* @throws DatabaseMigrationException |
| 43 |
*/ |
| 44 |
public function run(): void |
| 45 |
{ |
| 46 |
global $wpdb; |
| 47 |
|
| 48 |
$table = $wpdb->give_campaign_forms; |
| 49 |
$charset = DB::get_charset_collate(); |
| 50 |
|
| 51 |
$sql = "CREATE TABLE $table ( |
| 52 |
campaign_id INT UNSIGNED NOT NULL, |
| 53 |
form_id INT UNSIGNED NOT NULL, |
| 54 |
KEY form_id (form_id), |
| 55 |
KEY campaign_id (campaign_id), |
| 56 |
PRIMARY KEY (campaign_id, form_id) |
| 57 |
) $charset"; |
| 58 |
|
| 59 |
try { |
| 60 |
DB::delta($sql); |
| 61 |
} catch (DatabaseQueryException $exception) { |
| 62 |
throw new DatabaseMigrationException("An error occurred while creating the $table table", 0, $exception); |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
|