| 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_campaigns table |
| 13 |
*/ |
| 14 |
class CreateCampaignsTable extends Migration |
| 15 |
{ |
| 16 |
/** |
| 17 |
* @inheritdoc |
| 18 |
*/ |
| 19 |
public static function id(): string |
| 20 |
{ |
| 21 |
return 'give-campaigns-create-give-campaigns-table'; |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* @inheritdoc |
| 26 |
*/ |
| 27 |
public static function title(): string |
| 28 |
{ |
| 29 |
return 'Create give_campaigns table from core'; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* @inheritdoc |
| 34 |
*/ |
| 35 |
public static function timestamp(): string |
| 36 |
{ |
| 37 |
return strtotime('2024-08-26 00:00:00'); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* @inheritDoc |
| 42 |
* @throws DatabaseMigrationException |
| 43 |
*/ |
| 44 |
public function run() |
| 45 |
{ |
| 46 |
global $wpdb; |
| 47 |
|
| 48 |
$table = $wpdb->give_campaigns; |
| 49 |
$charset = DB::get_charset_collate(); |
| 50 |
|
| 51 |
$sql = "CREATE TABLE $table ( |
| 52 |
id INT UNSIGNED NOT NULL AUTO_INCREMENT, |
| 53 |
campaign_page_id INT UNSIGNED NULL, |
| 54 |
form_id INT NOT NULL, |
| 55 |
campaign_type VARCHAR(12) NOT NULL DEFAULT '', |
| 56 |
campaign_title TEXT NOT NULL, |
| 57 |
campaign_url TEXT NOT NULL, |
| 58 |
short_desc TEXT NOT NULL, |
| 59 |
long_desc TEXT NOT NULL, |
| 60 |
campaign_logo TEXT NOT NULL, |
| 61 |
campaign_image TEXT NOT NULL, |
| 62 |
primary_color VARCHAR(7) NOT NULL, |
| 63 |
secondary_color VARCHAR(7) NOT NULL, |
| 64 |
campaign_goal INT UNSIGNED NOT NULL, |
| 65 |
goal_type VARCHAR(24) NOT NULL DEFAULT 'amount', |
| 66 |
status VARCHAR(12) NOT NULL, |
| 67 |
start_date DATETIME NULL, |
| 68 |
end_date DATETIME NULL, |
| 69 |
date_created DATETIME NOT NULL, |
| 70 |
PRIMARY KEY (id) |
| 71 |
) $charset"; |
| 72 |
|
| 73 |
try { |
| 74 |
DB::delta($sql); |
| 75 |
} catch (DatabaseQueryException $exception) { |
| 76 |
throw new DatabaseMigrationException("An error occurred while creating the $table table", 0, $exception); |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
|