| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Databases\Migrations; |
| 4 |
|
| 5 |
class FormAnalytics |
| 6 |
{ |
| 7 |
|
| 8 |
/** |
| 9 |
* Migrate the table. |
| 10 |
* |
| 11 |
* @return void |
| 12 |
*/ |
| 13 |
public static function migrate() |
| 14 |
{ |
| 15 |
global $wpdb; |
| 16 |
|
| 17 |
$charsetCollate = $wpdb->get_charset_collate(); |
| 18 |
|
| 19 |
$table = $wpdb->prefix.'fluentform_form_analytics'; |
| 20 |
|
| 21 |
$formTable = $wpdb->prefix.'fluentform_forms'; |
| 22 |
|
| 23 |
if ($wpdb->get_var("SHOW TABLES LIKE '$table'") != $table) { |
| 24 |
$sql = "CREATE TABLE $table ( |
| 25 |
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT, |
| 26 |
`form_id` INT UNSIGNED NULL, |
| 27 |
`user_id` INT UNSIGNED NULL, |
| 28 |
`source_url` VARCHAR(255) NOT NULL, |
| 29 |
`platform` CHAR(30) NULL, |
| 30 |
`browser` CHAR(30) NULL, |
| 31 |
`city` VARCHAR (100) NULL, |
| 32 |
`country` VARCHAR (100) NULL, |
| 33 |
`ip` CHAR(15) NULL, |
| 34 |
`count` INT DEFAULT 1, |
| 35 |
`created_at` TIMESTAMP NULL, |
| 36 |
PRIMARY KEY (`id`), |
| 37 |
INDEX `fluent_analytics_form_id_idx` (`form_id` ASC), |
| 38 |
CONSTRAINT `fk_fluent_form_meta_analytics_id` |
| 39 |
FOREIGN KEY (`form_id`) |
| 40 |
REFERENCES $formTable (`id`) |
| 41 |
ON DELETE CASCADE |
| 42 |
ON UPDATE CASCADE) $charsetCollate;"; |
| 43 |
|
| 44 |
require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
| 45 |
|
| 46 |
dbDelta($sql); |
| 47 |
} |
| 48 |
} |
| 49 |
} |