chore: bootstrap module from working instance and add install guide

This commit is contained in:
Kelin Rescue Hub
2026-04-09 14:18:10 -04:00
parent 97ad7da6f4
commit 6cda47760e
35 changed files with 6267 additions and 4 deletions

View File

@@ -0,0 +1,157 @@
<?php
use humhub\components\Migration;
class m260404_000000_initial extends Migration
{
public function safeUp()
{
$this->safeCreateTable('rescue_donation_provider_config', [
'id' => $this->primaryKey(),
'contentcontainer_id' => $this->integer()->notNull(),
'paypal_enabled' => $this->boolean()->notNull()->defaultValue(0),
'paypal_recurring_enabled' => $this->boolean()->notNull()->defaultValue(0),
'paypal_client_id' => $this->string(255)->null(),
'paypal_client_secret' => $this->string(255)->null(),
'paypal_webhook_id' => $this->string(255)->null(),
'stripe_enabled' => $this->boolean()->notNull()->defaultValue(0),
'stripe_recurring_enabled' => $this->boolean()->notNull()->defaultValue(0),
'stripe_publishable_key' => $this->string(255)->null(),
'stripe_secret_key' => $this->string(255)->null(),
'stripe_webhook_secret' => $this->string(255)->null(),
'sandbox_mode' => $this->boolean()->notNull()->defaultValue(1),
'default_currency' => $this->string(8)->notNull()->defaultValue('USD'),
'created_at' => $this->dateTime()->null(),
'updated_at' => $this->dateTime()->null(),
]);
$this->safeCreateIndex('ux_rescue_donation_provider_config_container', 'rescue_donation_provider_config', 'contentcontainer_id', true);
$this->safeAddForeignKey('fk_rescue_donation_provider_config_container', 'rescue_donation_provider_config', 'contentcontainer_id', 'contentcontainer', 'id', 'CASCADE', 'CASCADE');
$this->safeCreateTable('rescue_donation_goal', [
'id' => $this->primaryKey(),
'contentcontainer_id' => $this->integer()->notNull(),
'goal_type' => $this->string(32)->notNull(),
'target_animal_id' => $this->integer()->null(),
'title' => $this->string(190)->notNull(),
'description' => $this->text()->null(),
'image_path' => $this->string(255)->null(),
'target_amount' => $this->decimal(12, 2)->notNull()->defaultValue(0),
'current_amount' => $this->decimal(12, 2)->notNull()->defaultValue(0),
'currency' => $this->string(8)->notNull()->defaultValue('USD'),
'is_active' => $this->boolean()->notNull()->defaultValue(1),
'created_at' => $this->dateTime()->null(),
'updated_at' => $this->dateTime()->null(),
]);
$this->safeCreateIndex('idx_rescue_donation_goal_container', 'rescue_donation_goal', 'contentcontainer_id', false);
$this->safeCreateIndex('idx_rescue_donation_goal_type', 'rescue_donation_goal', 'goal_type', false);
$this->safeCreateIndex('idx_rescue_donation_goal_active', 'rescue_donation_goal', 'is_active', false);
$this->safeCreateIndex('idx_rescue_donation_goal_animal', 'rescue_donation_goal', 'target_animal_id', false);
$this->safeAddForeignKey('fk_rescue_donation_goal_container', 'rescue_donation_goal', 'contentcontainer_id', 'contentcontainer', 'id', 'CASCADE', 'CASCADE');
$this->safeCreateTable('rescue_donation_transaction', [
'id' => $this->primaryKey(),
'contentcontainer_id' => $this->integer()->notNull(),
'donor_user_id' => $this->integer()->null(),
'provider' => $this->string(32)->notNull(),
'mode' => $this->string(16)->notNull(),
'status' => $this->string(32)->notNull(),
'amount' => $this->decimal(12, 2)->notNull(),
'currency' => $this->string(8)->notNull()->defaultValue('USD'),
'is_anonymous' => $this->boolean()->notNull()->defaultValue(0),
'goal_id' => $this->integer()->null(),
'goal_type' => $this->string(32)->null(),
'target_animal_id' => $this->integer()->null(),
'provider_payment_id' => $this->string(190)->null(),
'provider_checkout_id' => $this->string(190)->null(),
'provider_subscription_id' => $this->string(190)->null(),
'provider_customer_id' => $this->string(190)->null(),
'metadata_json' => $this->text()->null(),
'created_at' => $this->dateTime()->null(),
'updated_at' => $this->dateTime()->null(),
]);
$this->safeCreateIndex('idx_rescue_donation_transaction_container', 'rescue_donation_transaction', 'contentcontainer_id', false);
$this->safeCreateIndex('idx_rescue_donation_transaction_status', 'rescue_donation_transaction', 'status', false);
$this->safeCreateIndex('idx_rescue_donation_transaction_provider', 'rescue_donation_transaction', 'provider', false);
$this->safeCreateIndex('idx_rescue_donation_transaction_goal', 'rescue_donation_transaction', 'goal_id', false);
$this->safeCreateIndex('idx_rescue_donation_transaction_user', 'rescue_donation_transaction', 'donor_user_id', false);
$this->safeAddForeignKey('fk_rescue_donation_transaction_container', 'rescue_donation_transaction', 'contentcontainer_id', 'contentcontainer', 'id', 'CASCADE', 'CASCADE');
$this->safeAddForeignKey('fk_rescue_donation_transaction_goal', 'rescue_donation_transaction', 'goal_id', 'rescue_donation_goal', 'id', 'SET NULL', 'CASCADE');
if ($this->db->getSchema()->getTableSchema('user', true) !== null) {
$this->safeAddForeignKey('fk_rescue_donation_transaction_user', 'rescue_donation_transaction', 'donor_user_id', 'user', 'id', 'SET NULL', 'CASCADE');
}
$this->safeCreateTable('rescue_donation_webhook_event', [
'id' => $this->primaryKey(),
'provider' => $this->string(32)->notNull(),
'provider_event_id' => $this->string(190)->notNull(),
'event_type' => $this->string(120)->null(),
'payload_json' => $this->text()->null(),
'is_processed' => $this->boolean()->notNull()->defaultValue(0),
'processed_at' => $this->dateTime()->null(),
'created_at' => $this->dateTime()->null(),
]);
$this->safeCreateIndex('ux_rescue_donation_webhook_provider_event', 'rescue_donation_webhook_event', ['provider', 'provider_event_id'], true);
$this->safeCreateIndex('idx_rescue_donation_webhook_processed', 'rescue_donation_webhook_event', 'is_processed', false);
$this->safeCreateTable('rescue_donation_subscription', [
'id' => $this->primaryKey(),
'contentcontainer_id' => $this->integer()->notNull(),
'donor_user_id' => $this->integer()->null(),
'provider' => $this->string(32)->notNull(),
'provider_subscription_id' => $this->string(190)->notNull(),
'status' => $this->string(32)->notNull(),
'amount' => $this->decimal(12, 2)->notNull(),
'currency' => $this->string(8)->notNull()->defaultValue('USD'),
'interval_unit' => $this->string(16)->notNull()->defaultValue('month'),
'interval_count' => $this->integer()->notNull()->defaultValue(1),
'goal_id' => $this->integer()->null(),
'next_billing_at' => $this->dateTime()->null(),
'cancelled_at' => $this->dateTime()->null(),
'created_at' => $this->dateTime()->null(),
'updated_at' => $this->dateTime()->null(),
]);
$this->safeCreateIndex('idx_rescue_donation_subscription_container', 'rescue_donation_subscription', 'contentcontainer_id', false);
$this->safeCreateIndex('idx_rescue_donation_subscription_status', 'rescue_donation_subscription', 'status', false);
$this->safeCreateIndex('idx_rescue_donation_subscription_goal', 'rescue_donation_subscription', 'goal_id', false);
$this->safeCreateIndex('ux_rescue_donation_subscription_provider_id', 'rescue_donation_subscription', ['provider', 'provider_subscription_id'], true);
$this->safeAddForeignKey('fk_rescue_donation_subscription_container', 'rescue_donation_subscription', 'contentcontainer_id', 'contentcontainer', 'id', 'CASCADE', 'CASCADE');
$this->safeAddForeignKey('fk_rescue_donation_subscription_goal', 'rescue_donation_subscription', 'goal_id', 'rescue_donation_goal', 'id', 'SET NULL', 'CASCADE');
if ($this->db->getSchema()->getTableSchema('user', true) !== null) {
$this->safeAddForeignKey('fk_rescue_donation_subscription_user', 'rescue_donation_subscription', 'donor_user_id', 'user', 'id', 'SET NULL', 'CASCADE');
}
$this->safeCreateTable('rescue_donation_block', [
'id' => $this->primaryKey(),
'contentcontainer_id' => $this->integer()->notNull(),
'placement' => $this->string(64)->notNull(),
'goal_id' => $this->integer()->null(),
'header' => $this->string(190)->null(),
'is_active' => $this->boolean()->notNull()->defaultValue(1),
'sort_order' => $this->integer()->notNull()->defaultValue(100),
'created_at' => $this->dateTime()->null(),
'updated_at' => $this->dateTime()->null(),
]);
$this->safeCreateIndex('idx_rescue_donation_block_container_placement', 'rescue_donation_block', ['contentcontainer_id', 'placement'], false);
$this->safeCreateIndex('idx_rescue_donation_block_goal', 'rescue_donation_block', 'goal_id', false);
$this->safeAddForeignKey('fk_rescue_donation_block_container', 'rescue_donation_block', 'contentcontainer_id', 'contentcontainer', 'id', 'CASCADE', 'CASCADE');
$this->safeAddForeignKey('fk_rescue_donation_block_goal', 'rescue_donation_block', 'goal_id', 'rescue_donation_goal', 'id', 'SET NULL', 'CASCADE');
}
public function safeDown()
{
$this->safeDropTable('rescue_donation_block');
$this->safeDropTable('rescue_donation_subscription');
$this->safeDropTable('rescue_donation_webhook_event');
$this->safeDropTable('rescue_donation_transaction');
$this->safeDropTable('rescue_donation_goal');
$this->safeDropTable('rescue_donation_provider_config');
}
}