-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
172 additions
and
1 deletion.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/Campaigns/Migrations/Tables/CreateCampaignFormsTable.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace Give\Campaigns\Migrations\Tables; | ||
|
||
use Give\Framework\Database\DB; | ||
use Give\Framework\Database\Exceptions\DatabaseQueryException; | ||
use Give\Framework\Migrations\Contracts\Migration; | ||
use Give\Framework\Migrations\Exceptions\DatabaseMigrationException; | ||
|
||
/** | ||
* @unreleased | ||
* Creates give_campaign_forms table | ||
*/ | ||
class CreateCampaignFormsTable extends Migration | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public static function id(): string | ||
{ | ||
return 'give-campaigns-create-give-campaign-forms-table'; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public static function title(): string | ||
{ | ||
return 'Create give_campaign_forms table'; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public static function timestamp(): string | ||
{ | ||
return strtotime('2024-08-26 00:00:01'); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
* @throws DatabaseMigrationException | ||
*/ | ||
public function run(): void | ||
{ | ||
global $wpdb; | ||
|
||
$table = $wpdb->prefix . 'give_campaign_forms'; | ||
$charset = DB::get_charset_collate(); | ||
|
||
$sql = "CREATE TABLE $table ( | ||
campaign_id INT UNSIGNED NOT NULL, | ||
form_id INT UNSIGNED NOT NULL, | ||
PRIMARY KEY (campaign_id), | ||
KEY form_id (form_id) | ||
) $charset"; | ||
|
||
try { | ||
DB::delta($sql); | ||
} catch (DatabaseQueryException $exception) { | ||
throw new DatabaseMigrationException("An error occurred while creating the $table table", 0, $exception); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace Give\Campaigns\Migrations\Tables; | ||
|
||
use Give\Framework\Database\DB; | ||
use Give\Framework\Database\Exceptions\DatabaseQueryException; | ||
use Give\Framework\Migrations\Contracts\Migration; | ||
use Give\Framework\Migrations\Exceptions\DatabaseMigrationException; | ||
|
||
/** | ||
* @unreleased | ||
* Creates give_campaigns table | ||
*/ | ||
class CreateCampaignsTable extends Migration | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public static function id(): string | ||
{ | ||
return 'give-campaigns-create-give-core-campaigns-table'; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public static function title(): string | ||
{ | ||
return 'Create give_campaigns table from core'; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public static function timestamp(): string | ||
{ | ||
return strtotime('2024-08-26 00:00:00'); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
* @throws DatabaseMigrationException | ||
*/ | ||
public function run() | ||
{ | ||
global $wpdb; | ||
|
||
$table = $wpdb->prefix . 'give_campaigns'; | ||
$charset = DB::get_charset_collate(); | ||
|
||
$sql = "CREATE TABLE $table ( | ||
id INT UNSIGNED NOT NULL AUTO_INCREMENT, | ||
form_id INT NOT NULL, | ||
campaign_type VARCHAR(12) NOT NULL DEFAULT '', | ||
campaign_title TEXT NOT NULL, | ||
campaign_url TEXT NOT NULL, | ||
short_desc TEXT NOT NULL, | ||
long_desc TEXT NOT NULL, | ||
campaign_logo TEXT NOT NULL, | ||
campaign_image TEXT NOT NULL, | ||
primary_color VARCHAR(7) NOT NULL, | ||
secondary_color VARCHAR(7) NOT NULL, | ||
campaign_goal INT UNSIGNED NOT NULL, | ||
status VARCHAR(12) NOT NULL, | ||
start_date DATETIME NULL, | ||
end_date DATETIME NULL, | ||
date_created DATETIME NOT NULL, | ||
PRIMARY KEY (id) | ||
) $charset"; | ||
|
||
try { | ||
DB::delta($sql); | ||
} catch (DatabaseQueryException $exception) { | ||
throw new DatabaseMigrationException("An error occurred while creating the $table table", 0, $exception); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters