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 / OrderItems.php

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

77 lines 3.1 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 OrderItems
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_order_items';
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 form_id int(11) NOT NULL,
30 submission_id int(11) NOT NULL,
31 type varchar(255) DEFAULT 'single',
32 parent_holder varchar(255),
33 billing_interval varchar(255),
34 item_name varchar(255),
35 quantity int(11) DEFAULT 1,
36 item_price BIGINT UNSIGNED,
37 line_total BIGINT UNSIGNED,
38 created_at timestamp NULL,
39 updated_at timestamp NULL,
40 PRIMARY KEY (id)
41 ) $charsetCollate;";
42 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
43 dbDelta($sql);
44 } else {
45 self::maybeAlterColumns();
46 }
47 }
48
49
50 public static function maybeAlterColumns()
51 {
52 global $wpdb;
53 $table = $wpdb->prefix . 'fluentform_order_items';
54 // find the data types of each column
55 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder -- Migration file, checking table structure, %1s is for identifier
56 $results = $wpdb->get_results($wpdb->prepare("DESCRIBE %1s", $table));
57 $items = [];
58 foreach ($results as $result) {
59 $items[$result->Field] = $result->Type;
60 }
61
62 $isBigInItemPrice = strpos($items['item_price'], 'bigint') !== false;;
63 $isBigInitPrice = strpos($items['line_total'], 'bigint') !== false;;
64
65 // if not big int convert to big int
66 if (!$isBigInItemPrice) {
67 // 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
68 $wpdb->query($wpdb->prepare("ALTER TABLE %1s MODIFY item_price BIGINT UNSIGNED", $table));
69 }
70
71 if (!$isBigInitPrice) {
72 // 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
73 $wpdb->query($wpdb->prepare("ALTER TABLE %1s MODIFY line_total BIGINT UNSIGNED", $table));
74 }
75 }
76 }
77