Issues (4868)

resources/setup/tables_update.inc.php (1 issue)

Severity
1
<?php
2
/**
3
 * eGroupWare - resources
4
 * http://www.egroupware.org
5
 * Created by eTemplates DB-Tools written by [email protected]
6
 *
7
 * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
8
 * @package resources
9
 * @subpackage setup
10
 * @author Cornelius Weiss <[email protected]>
11
 */
12
13
use EGroupware\Api;
14
use EGroupware\Api\Vfs;
15
16
function resources_upgrade0_0_1_008()
17
{
18
	$GLOBALS['phpgw_setup']->oProc->AddColumn('egw_resources','picture_src',array(
19
		'type' => 'varchar',
20
		'precision' => '20'
21
	));
22
23
	$GLOBALS['setup_info']['resources']['currentver'] = '0.0.1.012';
24
	return $GLOBALS['setup_info']['resources']['currentver'];
25
}
26
27
28
function resources_upgrade0_0_1_012()
29
{
30
	$GLOBALS['phpgw_setup']->oProc->AddColumn('egw_resources','picture_thumb',array(
31
		'type' => 'blob'
32
	));
33
34
	$GLOBALS['setup_info']['resources']['currentver'] = '0.0.1.013';
35
	return $GLOBALS['setup_info']['resources']['currentver'];
36
}
37
38
39
function resources_upgrade0_0_1_013()
40
{
41
	$GLOBALS['phpgw_setup']->oProc->DropColumn('egw_resources',array(
42
		'fd' => array(
43
			'id' => array('type' => 'auto'),
44
			'name' => array('type' => 'varchar','precision' => '100'),
45
			'short_description' => array('type' => 'varchar','precision' => '100'),
46
			'cat_id' => array('type' => 'int','precision' => '11','nullable' => False),
47
			'quantity' => array('type' => 'int','precision' => '11'),
48
			'useable' => array('type' => 'int','precision' => '11'),
49
			'location' => array('type' => 'varchar','precision' => '100'),
50
			'bookable' => array('type' => 'varchar','precision' => '1'),
51
			'buyable' => array('type' => 'varchar','precision' => '1'),
52
			'prize' => array('type' => 'varchar','precision' => '200'),
53
			'long_description' => array('type' => 'longtext'),
54
			'accessories' => array('type' => 'varchar','precision' => '50'),
55
			'picture_src' => array('type' => 'varchar','precision' => '20'),
56
			'picture_thumb' => array('type' => 'blob')
57
		),
58
		'pk' => array('id'),
59
		'fk' => array(),
60
		'ix' => array(),
61
		'uc' => array()
62
	),'picture');
63
	$GLOBALS['phpgw_setup']->oProc->DropColumn('egw_resources',array(
64
		'fd' => array(
65
			'id' => array('type' => 'auto'),
66
			'name' => array('type' => 'varchar','precision' => '100'),
67
			'short_description' => array('type' => 'varchar','precision' => '100'),
68
			'cat_id' => array('type' => 'int','precision' => '11','nullable' => False),
69
			'quantity' => array('type' => 'int','precision' => '11'),
70
			'useable' => array('type' => 'int','precision' => '11'),
71
			'location' => array('type' => 'varchar','precision' => '100'),
72
			'bookable' => array('type' => 'varchar','precision' => '1'),
73
			'buyable' => array('type' => 'varchar','precision' => '1'),
74
			'prize' => array('type' => 'varchar','precision' => '200'),
75
			'long_description' => array('type' => 'longtext'),
76
			'accessories' => array('type' => 'varchar','precision' => '50'),
77
			'picture_src' => array('type' => 'varchar','precision' => '20')
78
		),
79
		'pk' => array('id'),
80
		'fk' => array(),
81
		'ix' => array(),
82
		'uc' => array()
83
	),'picture_thumb');
84
85
	$GLOBALS['setup_info']['resources']['currentver'] = '0.0.1.014';
86
	return $GLOBALS['setup_info']['resources']['currentver'];
87
}
88
89
90
function resources_upgrade0_0_1_014()
91
{
92
	$GLOBALS['phpgw_setup']->oProc->AlterColumn('egw_resources','quantity',array(
93
		'type' => 'int',
94
		'precision' => '11',
95
		'default' => '1'
96
	));
97
	$GLOBALS['phpgw_setup']->oProc->AlterColumn('egw_resources','useable',array(
98
		'type' => 'int',
99
		'precision' => '11',
100
		'default' => '1'
101
	));
102
103
	$GLOBALS['setup_info']['resources']['currentver'] = '0.0.1.015';
104
	return $GLOBALS['setup_info']['resources']['currentver'];
105
}
106
107
108
function resources_upgrade0_0_1_015()
109
{
110
	$GLOBALS['phpgw_setup']->oProc->AlterColumn('egw_resources','accessories',array(
111
		'type' => 'varchar',
112
		'precision' => '100'
113
	));
114
	$GLOBALS['phpgw_setup']->oProc->AddColumn('egw_resources','accessory_only',array(
115
		'type' => 'varchar',
116
		'precision' => '1',
117
		'default' => '0'
118
	));
119
	$GLOBALS['phpgw_setup']->oProc->AddColumn('egw_resources','relatives',array(
120
		'type' => 'varchar',
121
		'precision' => '100'
122
	));
123
124
	$GLOBALS['setup_info']['resources']['currentver'] = '0.0.1.016';
125
	return $GLOBALS['setup_info']['resources']['currentver'];
126
}
127
128
129
function resources_upgrade0_0_1_016()
130
{
131
	$GLOBALS['phpgw_setup']->oProc->DropColumn('egw_resources',array(
132
		'fd' => array(
133
			'id' => array('type' => 'auto'),
134
			'name' => array('type' => 'varchar','precision' => '100'),
135
			'short_description' => array('type' => 'varchar','precision' => '100'),
136
			'cat_id' => array('type' => 'int','precision' => '11','nullable' => False),
137
			'quantity' => array('type' => 'int','precision' => '11','default' => '1'),
138
			'useable' => array('type' => 'int','precision' => '11','default' => '1'),
139
			'location' => array('type' => 'varchar','precision' => '100'),
140
			'bookable' => array('type' => 'varchar','precision' => '1'),
141
			'buyable' => array('type' => 'varchar','precision' => '1'),
142
			'prize' => array('type' => 'varchar','precision' => '200'),
143
			'long_description' => array('type' => 'longtext'),
144
			'accessories' => array('type' => 'varchar','precision' => '100'),
145
			'picture_src' => array('type' => 'varchar','precision' => '20'),
146
			'relatives' => array('type' => 'varchar','precision' => '100')
147
		),
148
		'pk' => array('id'),
149
		'fk' => array(),
150
		'ix' => array(),
151
		'uc' => array()
152
	),'accessory_only');
153
	$GLOBALS['phpgw_setup']->oProc->DropColumn('egw_resources',array(
154
		'fd' => array(
155
			'id' => array('type' => 'auto'),
156
			'name' => array('type' => 'varchar','precision' => '100'),
157
			'short_description' => array('type' => 'varchar','precision' => '100'),
158
			'cat_id' => array('type' => 'int','precision' => '11','nullable' => False),
159
			'quantity' => array('type' => 'int','precision' => '11','default' => '1'),
160
			'useable' => array('type' => 'int','precision' => '11','default' => '1'),
161
			'location' => array('type' => 'varchar','precision' => '100'),
162
			'bookable' => array('type' => 'varchar','precision' => '1'),
163
			'buyable' => array('type' => 'varchar','precision' => '1'),
164
			'prize' => array('type' => 'varchar','precision' => '200'),
165
			'long_description' => array('type' => 'longtext'),
166
			'accessories' => array('type' => 'varchar','precision' => '100'),
167
			'picture_src' => array('type' => 'varchar','precision' => '20')
168
		),
169
		'pk' => array('id'),
170
		'fk' => array(),
171
		'ix' => array(),
172
		'uc' => array()
173
	),'relatives');
174
	$GLOBALS['phpgw_setup']->oProc->DropColumn('egw_resources',array(
175
		'fd' => array(
176
			'id' => array('type' => 'auto'),
177
			'name' => array('type' => 'varchar','precision' => '100'),
178
			'short_description' => array('type' => 'varchar','precision' => '100'),
179
			'cat_id' => array('type' => 'int','precision' => '11','nullable' => False),
180
			'quantity' => array('type' => 'int','precision' => '11','default' => '1'),
181
			'useable' => array('type' => 'int','precision' => '11','default' => '1'),
182
			'location' => array('type' => 'varchar','precision' => '100'),
183
			'bookable' => array('type' => 'varchar','precision' => '1'),
184
			'buyable' => array('type' => 'varchar','precision' => '1'),
185
			'prize' => array('type' => 'varchar','precision' => '200'),
186
			'long_description' => array('type' => 'longtext'),
187
			'picture_src' => array('type' => 'varchar','precision' => '20')
188
		),
189
		'pk' => array('id'),
190
		'fk' => array(),
191
		'ix' => array(),
192
		'uc' => array()
193
	),'accessories');
194
	$GLOBALS['phpgw_setup']->oProc->AddColumn('egw_resources','accessory_of',array(
195
		'type' => 'int',
196
		'precision' => '11',
197
		'default' => '-1'
198
	));
199
	$GLOBALS['setup_info']['resources']['currentver'] = '0.0.1.017';
200
	return $GLOBALS['setup_info']['resources']['currentver'];
201
}
202
203
204
function resources_upgrade0_0_1_017()
205
{
206
	$GLOBALS['phpgw_setup']->oProc->RenameColumn('egw_resources','id','res_id');
207
	$GLOBALS['phpgw_setup']->oProc->RefreshTable('egw_resources',array(
208
		'fd' => array(
209
			'res_id' => array('type' => 'auto'),
210
			'name' => array('type' => 'varchar','precision' => '100'),
211
			'short_description' => array('type' => 'varchar','precision' => '100'),
212
			'cat_id' => array('type' => 'int','precision' => '11','nullable' => False),
213
			'quantity' => array('type' => 'int','precision' => '11','default' => '1'),
214
			'useable' => array('type' => 'int','precision' => '11','default' => '1'),
215
			'location' => array('type' => 'varchar','precision' => '100'),
216
			'bookable' => array('type' => 'varchar','precision' => '1'),
217
			'buyable' => array('type' => 'varchar','precision' => '1'),
218
			'prize' => array('type' => 'varchar','precision' => '200'),
219
			'long_description' => array('type' => 'longtext'),
220
			'picture_src' => array('type' => 'varchar','precision' => '20'),
221
			'accessory_of' => array('type' => 'int','precision' => '11','default' => '-1')
222
		),
223
		'pk' => array('res_id'),
224
		'fk' => array(),
225
		'ix' => array(),
226
		'uc' => array()
227
	));
228
229
	$GLOBALS['setup_info']['resources']['currentver'] = '0.0.1.018';
230
	return $GLOBALS['setup_info']['resources']['currentver'];
231
}
232
233
234
function resources_upgrade0_0_1_018()
235
{
236
	$GLOBALS['phpgw_setup']->oProc->AddColumn('egw_resources','storage_info',array(
237
		'type' => 'varchar',
238
		'precision' => '200'
239
	));
240
241
	$GLOBALS['setup_info']['resources']['currentver'] = '0.0.1.019';
242
	return $GLOBALS['setup_info']['resources']['currentver'];
243
}
244
245
246
function resources_upgrade0_0_1_019()
247
{
248
	$GLOBALS['phpgw_setup']->oProc->AddColumn('egw_resources','inventory_number',array(
249
		'type' => 'varchar',
250
		'precision' => '20'
251
	));
252
253
	$GLOBALS['setup_info']['resources']['currentver'] = '0.0.1.020';
254
	return $GLOBALS['setup_info']['resources']['currentver'];
255
}
256
257
258
function resources_upgrade0_0_1_020()
259
{
260
	$GLOBALS['egw_setup']->oProc->CreateTable('egw_resources_extra',array(
261
		'fd' => array(
262
			'extra_id' => array('type' => 'int','precision' => '4','nullable' => False),
263
			'extra_name' => array('type' => 'varchar','precision' => '40','nullable' => False),
264
			'extra_owner' => array('type' => 'int','precision' => '4','nullable' => False,'default' => '-1'),
265
			'extra_value' => array('type' => 'varchar','precision' => '255','nullable' => False,'default' => '')
266
		),
267
		'pk' => array('extra_id','extra_name','extra_owner'),
268
		'fk' => array(),
269
		'ix' => array(),
270
		'uc' => array()
271
	));
272
273
	return $GLOBALS['setup_info']['resources']['currentver'] = '0.0.1.021';
274
}
275
276
277
function resources_upgrade0_0_1_021()
278
{
279
	return $GLOBALS['setup_info']['resources']['currentver'] = '1.2';
280
}
281
282
283
function resources_upgrade1_2()
284
{
285
	return $GLOBALS['setup_info']['resources']['currentver'] = '1.4';
286
}
287
288
289
/**
290
 * Move resource pictures into the regular attachmen dirs with name .picture.jpg
291
 *
292
 * @return string
293
 */
294
function resources_upgrade1_4()
295
{
296
	Vfs::$is_root = true;
297
	Vfs::load_wrapper('sqlfs');
298
	if (Vfs::is_dir('/resources/pictures'))
299
	{
300
		Vfs::remove('/resources/pictures/thumbs');	// remove thumb dir incl. thumbnails
301
		foreach(Vfs::find('sqlfs://default/resources/pictures',array('url' => true)) as $url)
302
		{
303
			if (is_numeric($id = basename($url,'.jpg')))
304
			{
305
				if (!Vfs::is_dir($dir = "/apps/resources/$id"))
306
				{
307
					Vfs::mkdir($dir,0777,STREAM_MKDIR_RECURSIVE);
308
				}
309
				rename($url,'sqlfs://default'.$dir.'/.picture.jpg');	// we need to rename on the same wrapper!
310
			}
311
		}
312
		Vfs::rmdir('/resources/pictures',0);
0 ignored issues
show
The call to EGroupware\Api\Vfs::rmdir() has too many arguments starting with 0. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

312
		Vfs::/** @scrutinizer ignore-call */ 
313
       rmdir('/resources/pictures',0);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
313
		Vfs::rmdir('/resources',0);
314
	}
315
	return $GLOBALS['setup_info']['resources']['currentver'] = '1.6';
316
}
317
318
319
function resources_upgrade1_6()
320
{
321
	return $GLOBALS['setup_info']['resources']['currentver'] = '1.8';
322
}
323
324
325
function resources_upgrade1_8()
326
{
327
	// add location category required for CalDAV to distinguish between locations and resources
328
	$GLOBALS['egw_setup']->db->insert($GLOBALS['egw_setup']->cats_table,array('cat_parent' => 0, 'cat_owner' => Api\Categories::GLOBAL_ACCOUNT,'cat_access' => 'public','cat_appname' => 'resources','cat_name' => 'Locations','cat_description' => 'This category has been added by setup','last_mod' => time()),false,__LINE__,__FILE__);
329
	$locations_cat_id = $GLOBALS['egw_setup']->db->get_last_insert_id($GLOBALS['egw_setup']->cats_table,'cat_id');
330
	Api\Config::save_value('location_cats', $locations_cat_id, 'resources');
331
332
	// Give default group all rights to this general cat
333
	$defaultgroup = $GLOBALS['egw_setup']->add_account('Default','Default','Group',False,False);
334
	$GLOBALS['egw_setup']->add_acl('resources','run',$defaultgroup);
335
	$GLOBALS['egw_setup']->add_acl('resources',"L$locations_cat_id",$defaultgroup,399);
336
337
	return $GLOBALS['setup_info']['resources']['currentver'] = '1.9.001';
338
}
339
340
341
function resources_upgrade1_9_001()
342
{
343
	$GLOBALS['egw_setup']->oProc->AddColumn('egw_resources','deleted',array(
344
		'type' => 'int',
345
		'precision' => '8'
346
	));
347
348
	return $GLOBALS['setup_info']['resources']['currentver'] = '1.9.002';
349
}
350
351
352
function resources_upgrade1_9_002()
353
{
354
	return $GLOBALS['setup_info']['resources']['currentver'] = '1.9.003';
355
}
356
357
358
function resources_upgrade1_9_003()
359
{
360
	$GLOBALS['egw_setup']->oProc->AddColumn('egw_resources','res_creator',array(
361
		'type' => 'int',
362
		'meta' => 'user',
363
		'precision' => '11'
364
	));
365
	$GLOBALS['egw_setup']->oProc->AddColumn('egw_resources','res_created',array(
366
		'type' => 'int',
367
		'meta' => 'timestamp',
368
		'precision' => '8'
369
	));
370
	$GLOBALS['egw_setup']->oProc->AddColumn('egw_resources','res_modifier',array(
371
		'type' => 'int',
372
		'meta' => 'user',
373
		'precision' => '11'
374
	));
375
	$GLOBALS['egw_setup']->oProc->AddColumn('egw_resources','res_modified',array(
376
		'type' => 'int',
377
		'meta' => 'timestamp',
378
		'precision' => '8'
379
	));
380
381
	return $GLOBALS['setup_info']['resources']['currentver'] = '1.9.004';
382
}
383
384
function resources_upgrade1_9_004()
385
{
386
	return $GLOBALS['setup_info']['resources']['currentver'] = '14.1';
387
}
388
389
function resources_upgrade14_1()
390
{
391
	return $GLOBALS['setup_info']['resources']['currentver'] = '16.1';
392
}
393
394
function resources_upgrade16_1()
395
{
396
	return $GLOBALS['setup_info']['resources']['currentver'] = '17.1';
397
}
398
399
/**
400
 * Bump version to 19.1
401
 *
402
 * @return string
403
 */
404
function resources_upgrade17_1()
405
{
406
	return $GLOBALS['setup_info']['resources']['currentver'] = '19.1';
407
}
408
409
function resources_upgrade19_1()
410
{
411
	$GLOBALS['egw_setup']->oProc->AlterColumn('egw_resources_extra','extra_value',array(
412
		'type' => 'varchar',
413
		'meta' => 'cfvalue',
414
		'precision' => '16384',
415
		'nullable' => False,
416
		'default' => ''
417
	));
418
419
	return $GLOBALS['setup_info']['resources']['currentver'] = '19.1.001';
420
}
421
422