26
26
--------------------------------------------------------------------------
27
27
*/
28
28
29
- if (!function_exists ('arTableExists ' )) {
30
- function arTableExists ($ table ) {
31
- global $ DB ;
32
- if (method_exists ( $ DB , 'tableExists ' )) {
33
- return $ DB ->tableExists ($ table );
34
- } else {
35
- return TableExists ($ table );
36
- }
37
- }
38
- }
39
-
40
- if (!function_exists ('arFieldExists ' )) {
41
- function arFieldExists ($ table , $ field , $ usecache = true ) {
42
- global $ DB ;
43
- if (method_exists ( $ DB , 'fieldExists ' )) {
44
- return $ DB ->fieldExists ($ table , $ field , $ usecache );
45
- } else {
46
- return FieldExists ($ table , $ field , $ usecache );
47
- }
48
- }
49
- }
50
-
51
29
/**
52
30
* Summary of plugin_formvalidation_install
53
31
* @return boolean
54
32
*/
55
33
function plugin_formvalidation_install () {
56
34
global $ DB ;
35
+ $ dbu = new DbUtils ();
57
36
58
- if (!arTableExists ("glpi_plugin_formvalidation_configs " )) {
59
- $ query = "CREATE TABLE `glpi_plugin_formvalidation_configs` (
37
+ if (!$ DB -> tableExists ("glpi_plugin_formvalidation_configs " )) {
38
+ $ query = "CREATE TABLE `glpi_plugin_formvalidation_configs` (
60
39
`id` INT(11) NOT NULL AUTO_INCREMENT,
61
40
`css_mandatory` VARCHAR(200) NOT NULL DEFAULT '{ \"background-color \": \"lightgrey \", \"font-weight \": \"bold \"}',
62
- `css_error` VARCHAR(200) NOT NULL DEFAULT '{ \"background-color \": \"red \"}',
41
+ `css_error` VARCHAR(200) NOT NULL DEFAULT '{ \"background-color \": \"red \"}',
63
42
PRIMARY KEY (`id`)
64
43
)
65
44
ENGINE=InnoDB
66
45
;
67
46
" ;
68
47
69
- $ DB ->query ($ query ) or die ("Error creating glpi_plugin_formvalidation_configs " . $ DB ->error ());
70
-
71
- $ query = "INSERT INTO `glpi_plugin_formvalidation_configs` (`id`) VALUES (1); " ;
72
- $ DB ->query ($ query ) or die ("Error inserting default config into glpi_plugin_formvalidation_configs " . $ DB ->error ());
48
+ $ DB ->query ($ query ) or die ("Error creating glpi_plugin_formvalidation_configs " . $ DB ->error ());
49
+ $ DB ->insertOrDie (
50
+ 'glpi_plugin_formvalidation_configs ' , [
51
+ 'id ' => '1 ' ,
52
+ ],
53
+ "Error inserting default config into glpi_plugin_formvalidation_configs "
54
+ );
55
+ // $query = "INSERT INTO `glpi_plugin_formvalidation_configs` (`id`) VALUES (1);";
56
+ // $DB->query($query) or die("Error inserting default config into glpi_plugin_formvalidation_configs " . $DB->error());
73
57
}
74
58
75
- if (!arTableExists ("glpi_plugin_formvalidation_itemtypes " )) {
59
+ if (!$ DB -> tableExists ("glpi_plugin_formvalidation_itemtypes " )) {
76
60
$ query = "CREATE TABLE `glpi_plugin_formvalidation_itemtypes` (
77
61
`id` INT(11) NOT NULL AUTO_INCREMENT,
78
62
`name` VARCHAR(255) NOT NULL,
@@ -123,7 +107,7 @@ function plugin_formvalidation_install() {
123
107
124
108
}
125
109
126
- if (!arTableExists ("glpi_plugin_formvalidation_pages " )) {
110
+ if (!$ DB -> tableExists ("glpi_plugin_formvalidation_pages " )) {
127
111
$ query = "CREATE TABLE `glpi_plugin_formvalidation_pages` (
128
112
`id` INT(11) NOT NULL AUTO_INCREMENT,
129
113
`name` VARCHAR(200) NULL DEFAULT NULL,
@@ -153,7 +137,7 @@ function plugin_formvalidation_install() {
153
137
$ DB ->query ($ query ) or die ("Error inserting default pages into glpi_plugin_formvalidation_pages " . $ DB ->error ());
154
138
155
139
} else {
156
- if (!arFieldExists ('glpi_plugin_formvalidation_pages ' , 'itemtypes_id ' )) {
140
+ if (!$ DB -> fieldExists ('glpi_plugin_formvalidation_pages ' , 'itemtypes_id ' )) {
157
141
$ query = "ALTER TABLE `glpi_plugin_formvalidation_pages`
158
142
ADD COLUMN `itemtypes_id` INT(11) NOT NULL DEFAULT '0' AFTER `itemtype`,
159
143
ADD INDEX `itemtypes_id` (`itemtypes_id`);
@@ -162,7 +146,7 @@ function plugin_formvalidation_install() {
162
146
}
163
147
164
148
// check if migration is neccessary
165
- $ pages = getAllDatasFromTable ('glpi_plugin_formvalidation_pages ' , 'itemtypes_id = 0 ' );
149
+ $ pages = $ dbu -> getAllDataFromTable ('glpi_plugin_formvalidation_pages ' , [ 'itemtypes_id ' => ' 0 ' ] );
166
150
if (count ($ pages )) {
167
151
// migration of itemtype into itemtypes_id
168
152
$ query = "UPDATE glpi_plugin_formvalidation_pages AS gpfp, glpi_plugin_formvalidation_itemtypes AS gpfi
@@ -171,15 +155,15 @@ function plugin_formvalidation_install() {
171
155
$ DB ->query ($ query ) or die ("Error migrating itemtype into itemtypes_id field in glpi_plugin_formvalidation_pages " . $ DB ->error ());
172
156
173
157
// check if all pages have been migrated
174
- $ pages = getAllDatasFromTable ('glpi_plugin_formvalidation_pages ' , 'itemtypes_id = 0 ' );
158
+ $ pages = $ dbu -> getAllDataFromTable ('glpi_plugin_formvalidation_pages ' , [ 'itemtypes_id ' => ' 0 ' ] );
175
159
if (count ($ pages )) {
176
160
die ("Error some itemtype can't be migrated into itemtypes_id field from glpi_plugin_formvalidation_pages, </br>
177
161
please check the list of itemtype in glpi_plugin_formvalidation_pages and in glpi_plugin_formvalidation_itemtypes,</br>
178
162
fix the issue and restart install of the plugin. " );
179
163
}
180
164
}
181
165
182
- if (arFieldExists ('glpi_plugin_formvalidation_pages ' , 'itemtype ' ) && !count ($ pages )) {
166
+ if ($ DB -> fieldExists ('glpi_plugin_formvalidation_pages ' , 'itemtype ' ) && !count ($ pages )) {
183
167
// delete itemtype field after migration is done
184
168
$ query = "ALTER TABLE `glpi_plugin_formvalidation_pages`
185
169
DROP COLUMN `itemtype`,
@@ -195,7 +179,7 @@ function plugin_formvalidation_install() {
195
179
}
196
180
}
197
181
198
- if (!arTableExists ("glpi_plugin_formvalidation_forms " )) {
182
+ if (!$ DB -> tableExists ("glpi_plugin_formvalidation_forms " )) {
199
183
$ query = "CREATE TABLE `glpi_plugin_formvalidation_forms` (
200
184
`id` INT(11) NOT NULL AUTO_INCREMENT,
201
185
`name` VARCHAR(200) NULL DEFAULT NULL,
@@ -230,15 +214,15 @@ function plugin_formvalidation_install() {
230
214
$ DB ->query ($ query ) or die ("Error inserting default data into glpi_plugin_formvalidation_forms " . $ DB ->error ());
231
215
232
216
} else {
233
- if (!arFieldExists ('glpi_plugin_formvalidation_forms ' , 'use_for_massiveaction ' )) {
217
+ if (!$ DB -> fieldExists ('glpi_plugin_formvalidation_forms ' , 'use_for_massiveaction ' )) {
234
218
$ query = "ALTER TABLE `glpi_plugin_formvalidation_forms`
235
219
ADD COLUMN `use_for_massiveaction` TINYINT(1) NOT NULL DEFAULT '0' AFTER `is_active`;
236
220
" ;
237
221
$ DB ->query ($ query ) or die ("Error inserting use_for_massiveaction field into glpi_plugin_formvalidation_forms " . $ DB ->error ());
238
222
}
239
223
}
240
224
241
- if (!arTableExists ("glpi_plugin_formvalidation_fields " )) {
225
+ if (!$ DB -> tableExists ("glpi_plugin_formvalidation_fields " )) {
242
226
$ query = "CREATE TABLE `glpi_plugin_formvalidation_fields` (
243
227
`id` INT(11) NOT NULL AUTO_INCREMENT,
244
228
`name` VARCHAR(200) NULL DEFAULT NULL,
0 commit comments