-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathactivation.php
85 lines (69 loc) · 2.48 KB
/
activation.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
function odoo_conn_activation_function()
{
require_once(ABSPATH . "wp-admin/includes/upgrade.php");
odoo_conn_create_odoo_connections_table();
odoo_conn_create_odoo_form_table();
odoo_conn_create_odoo_form_field_mapping();
}
function odoo_conn_create_odoo_connections_table()
{
global $wpdb, $table_prefix;
$table_name = $table_prefix . "odoo_conn_connection";
$charset_collate = $wpdb->get_charset_collate();
$sql = "
CREATE TABLE `$table_name` (
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(30) NOT NULL,
`username` VARCHAR(100) NOT NULL,
`api_key` VARCHAR(150) NOT NULL,
`url` VARCHAR(300) NOT NULL,
`database_name` VARCHAR(200) NOT NULL,
PRIMARY KEY (id)
) $charset_collate;
";
dbDelta($sql);
}
function odoo_conn_create_odoo_form_table()
{
global $wpdb, $table_prefix;
$table_name = $table_prefix . "odoo_conn_form";
$odoo_conn_table = $table_prefix . "odoo_conn_connection";
// contact form 7 stores forms in the generic wordpress posts
// to know if it is a contact 7 form "post": post_type = wpcf7_contact_form
$contact_7_form_table = $wpdb->posts;
$charset_collate = $wpdb->get_charset_collate();
$sql = "
CREATE TABLE `$table_name` (
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`odoo_connection_id` BIGINT(20) UNSIGNED NOT NULL,
`odoo_model` VARCHAR(50) NOT NULL,
`name` VARCHAR(30) NOT NULL,
`contact_7_id` BIGINT(20) UNSIGNED NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (odoo_connection_id) REFERENCES $odoo_conn_table(id) ON DELETE CASCADE,
FOREIGN KEY (contact_7_id) REFERENCES $contact_7_form_table(ID) ON DELETE CASCADE
) $charset_collate;
";
dbDelta($sql);
}
function odoo_conn_create_odoo_form_field_mapping()
{
global $wpdb, $table_prefix;
$table_name = $table_prefix . "odoo_conn_form_mapping";
$odoo_form_table = $table_prefix . "odoo_conn_form";
$charset_collate = $wpdb->get_charset_collate();
$sql = "
CREATE TABLE `$table_name` (
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`odoo_form_id` BIGINT(20) UNSIGNED NOT NULL,
`cf7_field_name` VARCHAR(100) NOT NULL,
`odoo_field_name` VARCHAR(100) NOT NULL,
`constant_value` VARCHAR(200) NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (odoo_form_id) REFERENCES $odoo_form_table(id) ON DELETE CASCADE
) $charset_collate;
";
dbDelta($sql);
}
?>