forked from backdrop-contrib/webform_civicrm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webform_civicrm.install
executable file
·194 lines (181 loc) · 5.46 KB
/
webform_civicrm.install
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
/**
* @file
* Webform CiviCRM module's install, uninstall and upgrade code.
*/
/**
* Implements hook_requirements().
*/
function webform_civicrm_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
$t = get_t();
$status = _webform_civicrm_status();
if (!$status['webform_civicrm']) {
$requirements['webform_civicrm'] = array(
'title' => 'Webform CiviCRM Integration',
'value' => $t('Version error'),
'severity' => REQUIREMENT_ERROR,
'description' => $t('The versions of the Webform CiviCRM Integration, Webform, CiviCRM enabled are not compatible. ') .
l($t('See the Webform CiviCRM Integration project page for version compatibility'), 'https://backdropcms.org/project/webform_civicrm'),
);
}
else {
$requirements['webform_civicrm'] = array(
'title' => 'Webform CiviCRM Integration',
'severity' => REQUIREMENT_OK,
'value' => t('Required version of CiviCRM and Webform are enabled.'),
);
}
}
return $requirements;
}
/**
* Implements hook_schema().
*/
function webform_civicrm_schema() {
$schema = array();
$schema['webform_civicrm_forms'] = array(
'description' => 'CiviCRM settings for individual Webform nodes.',
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Webform Node ID',
),
'data' => array(
'type' => 'text',
'serialize' => TRUE,
'description' => 'Array of entity data for this webform',
),
'prefix_known' => array(
'description' => 'Form prefix for known users.',
'type' => 'text',
'not null' => TRUE,
),
'prefix_unknown' => array(
'description' => 'Form prefix for unknown users.',
'type' => 'text',
'not null' => TRUE,
),
'message' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Message to show to known users',
),
'confirm_subscription' => array(
'description' => 'Send confirmation for mailing list subscriptions.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'block_unknown_users' => array(
'description' => 'Only allow known contacts to use form.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'create_new_relationship' => array(
'description' => 'Create new relationship if duplicate record exists and is expired or inactive.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'create_fieldsets' => array(
'description' => 'Add fieldsets around contacts.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'new_contact_source' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Source label for newly created contacts',
),
),
'primary key' => array('nid'),
);
$schema['webform_civicrm_submissions'] = array(
'description' => 'Link between form submissions and CiviCRM data.',
'fields' => array(
'sid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Webform Submission ID',
),
'contact_id' => array(
'type' => 'varchar',
'length' => 2000,
'not null' => TRUE,
'default' => '',
'description' => 'CiviCRM contact ids from this submission',
),
'civicrm_data' => array(
'type' => 'text',
'serialize' => TRUE,
'description' => 'Array of entity ids for this submission',
),
),
'primary key' => array('sid'),
);
return $schema;
}
/**
* Implements hook_uninstall().
*/
function webform_civicrm_uninstall() {
config_set('webform.settings', 'webform_table', FALSE);
}
/**
* Implements hook_update_last_removed().
*/
function webform_civicrm_update_last_removed() {
return 7402;
}
/**
* Move Webform CiviCRM settings from variables to config.
*/
function webform_civicrm_update_1000() {
$config = config('webform_civicrm.settings');
$config->set('webform_civicrm_help_seen', update_variable_get('webform_civicrm_help_seen', TRUE));
$config->save();
// Delete variables.
update_variable_del('webform_civicrm_help_seen');
}
/**
* Set the Webform submissions list to a hard-coded table instead of a View as a temporary fix.
* See https://www.drupal.org/node/2389537.
* To change, use Backdrop's Configuration management.
*/
function webform_civicrm_update_1001() {
config_set('webform.settings', 'webform_table', TRUE);
}
/**
* Add field to create new relationship for duplicate records(expired/inactive).
*/
function webform_civicrm_update_1002() {
$field = array(
'description' => 'Create new relationship if duplicate record exists and is expired or inactive.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
);
if (db_table_exists('webform_civicrm_forms')) {
if (!db_field_exists('webform_civicrm_forms', 'create_new_relationship')) {
db_add_field('webform_civicrm_forms', 'create_new_relationship', $field);
}
}
}