| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Databases\Migrations; |
| 4 |
|
| 5 |
class FormSubmissionMeta |
| 6 |
{ |
| 7 |
/** |
| 8 |
* Migrate the table. |
| 9 |
* |
| 10 |
* @return void |
| 11 |
*/ |
| 12 |
public static function migrate() |
| 13 |
{ |
| 14 |
global $wpdb; |
| 15 |
|
| 16 |
$charsetCollate = $wpdb->get_charset_collate(); |
| 17 |
|
| 18 |
$table = $wpdb->prefix.'fluentform_submission_meta'; |
| 19 |
|
| 20 |
$submissionsTable = $wpdb->prefix.'fluentform_submissions'; |
| 21 |
|
| 22 |
$formTable = $wpdb->prefix.'fluentform_forms'; |
| 23 |
|
| 24 |
if ($wpdb->get_var("SHOW TABLES LIKE '$table'") != $table) { |
| 25 |
$sql = "CREATE TABLE $table ( |
| 26 |
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, |
| 27 |
`response_id` BIGINT(20) UNSIGNED NULL, |
| 28 |
`form_id` INT UNSIGNED NULL, |
| 29 |
`meta_key` VARCHAR(45) NULL, |
| 30 |
`value` LONGTEXT NULL, |
| 31 |
`status` VARCHAR(45) NULL, |
| 32 |
`user_id` INT UNSIGNED NULL, |
| 33 |
`name` VARCHAR(45) NULL, |
| 34 |
`created_at` TIMESTAMP NULL, |
| 35 |
`updated_at` TIMESTAMP NULL, |
| 36 |
PRIMARY KEY (`id`), |
| 37 |
INDEX `fluent_response_id_idx` (`response_id` ASC), |
| 38 |
CONSTRAINT `fk_fluent_response_meta_response_id` |
| 39 |
FOREIGN KEY (`response_id`) |
| 40 |
REFERENCES $submissionsTable (`id`) |
| 41 |
ON DELETE CASCADE |
| 42 |
ON UPDATE CASCADE, |
| 43 |
CONSTRAINT `fk_fluent_response_meta_form_id` |
| 44 |
FOREIGN KEY (`form_id`) |
| 45 |
REFERENCES $formTable (`id`) |
| 46 |
ON DELETE CASCADE |
| 47 |
ON UPDATE CASCADE) $charsetCollate;"; |
| 48 |
|
| 49 |
require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
| 50 |
dbDelta($sql); |
| 51 |
} |
| 52 |
} |
| 53 |
} |