PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.19.6
GiveWP – Donation Plugin and Fundraising Platform v2.19.6
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / Subscriptions / Migrations / CreateSubscriptionTables.php
CreateSubscriptionTables.php
77 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Subscriptions\Migrations;
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 class CreateSubscriptionTables extends Migration
11 {
12 public static function id()
13 {
14 return 'create_subscription_tables';
15 }
16
17 public function run()
18 {
19 global $wpdb;
20
21 $charset_collate = $wpdb->get_charset_collate();
22 $subscriptionTableName = "{$wpdb->prefix}give_subscriptions";
23 $metaTableName = "{$wpdb->prefix}give_subscriptionmeta";
24
25 try {
26 DB::delta(
27 "
28 CREATE TABLE `$subscriptionTableName` (
29 `id` bigint(20) NOT NULL AUTO_INCREMENT,
30 `customer_id` bigint(20) NOT NULL,
31 `period` varchar(20) NOT NULL,
32 `frequency` bigint(20) NOT NULL DEFAULT '1',
33 `initial_amount` decimal(18,10) NOT NULL,
34 `recurring_amount` decimal(18,10) NOT NULL,
35 `recurring_fee_amount` decimal(18,10) NOT NULL,
36 `bill_times` bigint(20) NOT NULL,
37 `transaction_id` varchar(60) NOT NULL,
38 `parent_payment_id` bigint(20) NOT NULL,
39 `product_id` bigint(20) NOT NULL,
40 `created` datetime NOT NULL,
41 `expiration` datetime NOT NULL,
42 `status` varchar(20) NOT NULL,
43 `profile_id` varchar(60) NOT NULL,
44 `notes` longtext NOT NULL,
45 PRIMARY KEY (`id`),
46 KEY `profile_id` (`profile_id`),
47 KEY `customer` (`customer_id`),
48 KEY `transaction` (`transaction_id`),
49 KEY `customer_and_status` (`customer_id`,`status`)
50 ) $charset_collate;
51 "
52 );
53
54 DB::delta(
55 "
56 CREATE TABLE `$metaTableName` (
57 `meta_id` bigint(20) NOT NULL AUTO_INCREMENT,
58 `subscription_id` bigint(20) NOT NULL,
59 `meta_key` varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
60 `meta_value` longtext COLLATE utf8mb4_unicode_520_ci,
61 PRIMARY KEY (`meta_id`),
62 KEY `subscription_id` (`subscription_id`),
63 KEY `meta_key` (`meta_key`(191))
64 ) $charset_collate;
65 "
66 );
67 } catch (DatabaseQueryException $exception) {
68 throw new DatabaseMigrationException('An error occurred creating the subscription tables', 0, $exception);
69 }
70 }
71
72 public static function timestamp()
73 {
74 return strtotime('2022-03-30');
75 }
76 }
77