PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.7
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.7
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Modules / Payments / Migrations / Transactions.php

Transactions.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.7, at app/Modules/Payments/Migrations/Transactions.php

82 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Modules\Payments\Migrations;
4
5 if (!defined('ABSPATH')) {
6 exit; // Exit if accessed directly.
7 }
8
9 class Transactions
10 {
11 /**
12 * Migrate the table.
13 *
14 * @return void
15 */
16 public static function migrate()
17 {
18 global $wpdb;
19
20 $charsetCollate = $wpdb->get_charset_collate();
21
22 $table = $wpdb->prefix . 'fluentform_transactions';
23
24 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Migration file, direct query needed
25 if ($wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table)) != $table) {
26 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange -- Migration file, schema change is the purpose
27 $sql = "CREATE TABLE $table (
28 id int(11) NOT NULL AUTO_INCREMENT,
29 transaction_hash varchar(255) NULL,
30 payer_name varchar(255) NULL,
31 payer_email varchar(255) NULL,
32 billing_address varchar(255) NULL,
33 shipping_address varchar(255) NULL,
34 form_id int(11) NOT NULL,
35 user_id int(11) DEFAULT NULL,
36 submission_id int(11) NULL,
37 subscription_id int(11) NULL,
38 transaction_type varchar(255) DEFAULT 'onetime',
39 payment_method varchar(255),
40 card_last_4 int(4),
41 card_brand varchar(255),
42 charge_id varchar(255),
43 payment_total BIGINT UNSIGNED DEFAULT 1,
44 status varchar(255),
45 currency varchar(255),
46 payment_mode varchar(255),
47 payment_note longtext,
48 created_at timestamp NULL,
49 updated_at timestamp NULL,
50 PRIMARY KEY (id)
51 ) $charsetCollate;";
52
53 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
54
55 dbDelta($sql);
56 } else {
57 self::maybeAlterColumns();
58 }
59 }
60
61 public static function maybeAlterColumns()
62 {
63 global $wpdb;
64 $table = $wpdb->prefix . 'fluentform_transactions';
65
66 // find the data types of each column
67 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder -- Migration file, checking table structure, %1s is for identifier
68 $results = $wpdb->get_results($wpdb->prepare("DESCRIBE %1s", $table));
69 $items = [];
70 foreach ($results as $result) {
71 $items[$result->Field] = $result->Type;
72 }
73
74 $paymentTotalMigrated = strpos($items['payment_total'], 'bigint') !== false;
75 if (!$paymentTotalMigrated) {
76 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder -- Migration file, schema change is the purpose, %1s is for identifier
77 $wpdb->query($wpdb->prepare("ALTER TABLE %1s MODIFY payment_total BIGINT UNSIGNED DEFAULT 1", $table));
78 }
79
80 }
81 }
82