diff --git a/src/Campaigns/Migrations/Tables/CreateCampaignFormsTable.php b/src/Campaigns/Migrations/Tables/CreateCampaignFormsTable.php new file mode 100644 index 0000000000..1fa058c382 --- /dev/null +++ b/src/Campaigns/Migrations/Tables/CreateCampaignFormsTable.php @@ -0,0 +1,64 @@ +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); + } + } +} diff --git a/src/Campaigns/Migrations/Tables/CreateCampaignsTable.php b/src/Campaigns/Migrations/Tables/CreateCampaignsTable.php new file mode 100644 index 0000000000..8bd6b2dec8 --- /dev/null +++ b/src/Campaigns/Migrations/Tables/CreateCampaignsTable.php @@ -0,0 +1,77 @@ +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); + } + } +} diff --git a/src/Campaigns/ServiceProvider.php b/src/Campaigns/ServiceProvider.php index 17e1171543..8e8935f337 100644 --- a/src/Campaigns/ServiceProvider.php +++ b/src/Campaigns/ServiceProvider.php @@ -2,6 +2,9 @@ namespace Give\Campaigns; +use Give\Campaigns\Migrations\Tables\CreateCampaignFormsTable; +use Give\Campaigns\Migrations\Tables\CreateCampaignsTable; +use Give\Framework\Migrations\MigrationsRegister; use Give\Helpers\Hooks; use Give\ServiceProviders\ServiceProvider as ServiceProviderInterface; @@ -16,7 +19,7 @@ class ServiceProvider implements ServiceProviderInterface */ public function register(): void { - // + $this->registerTableNames(); } /** @@ -28,9 +31,36 @@ public function boot(): void // Hooks::addAction('init', Actions\MyAction::class); // Hooks::addAction('rest_api_init', Controllers\MyEndpoint::class); + $this->registerMigrations(); $this->registerMenus(); } + + /** + * @unreleased + */ + private function registerMigrations(): void + { + give(MigrationsRegister::class)->addMigrations( + [ + CreateCampaignsTable::class, + CreateCampaignFormsTable::class, + ] + ); + } + + + /** + * @unreleased + */ + private function registerTableNames(): void + { + global $wpdb; + + $wpdb->give_campaigns = $wpdb->prefix . 'give_campaigns'; + $wpdb->give_campaign_forms = $wpdb->prefix . 'give_campaign_forms'; + } + /** * @unreleased */