-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhook.php
More file actions
94 lines (80 loc) · 2.29 KB
/
hook.php
File metadata and controls
94 lines (80 loc) · 2.29 KB
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
<?php
/**
* Install hook
*
* @return boolean
*/
function plugin_fleetbooking_install()
{
global $DB;
// Execute install.php if it exists
if (file_exists(__DIR__ . '/sql/install.php')) {
include_once __DIR__ . '/sql/install.php';
if (function_exists('plugin_fleetbooking_install_db')) {
plugin_fleetbooking_install_db();
}
}
// Default configuration insertion placeholder
// Handle migrations
return true;
}
/**
* Upgrade hook
*
* @param string $old_version
* @return boolean
*/
function plugin_fleetbooking_upgrade($old_version)
{
global $DB;
// We simply run install again to ensure tables and paths are correct
$res = plugin_fleetbooking_install();
if ($res) {
// Enforce version bump in DB dynamically to avoid GLPI looping the update state
$DB->updateOrInsert(
\Plugin::getTable(),
['version' => PLUGIN_FLEETBOOKING_VERSION, 'state' => 1],
['directory' => 'fleetbooking']
);
}
return $res;
}
/**
* Uninstall hook
*
* @return boolean
*/
function plugin_fleetbooking_uninstall()
{
global $DB;
$tables = [
'glpi_plugin_fleetbooking_requests',
'glpi_plugin_fleetbooking_groupmanagers',
'glpi_plugin_fleetbooking_holidays',
'glpi_plugin_fleetbooking_configs'
];
foreach ($tables as $table) {
if ($DB->tableExists($table)) {
$DB->dropTable($table);
}
}
// Remove rights
$DB->delete(\ProfileRight::getTable(), ['name' => ['LIKE', 'fleetbooking%']]);
// Clean up custom asset definitions created by plugin (any system_name variant)
$assetSystemNames = ['veiculofrota', 'VehicleFleet'];
foreach ($assetSystemNames as $sysName) {
$assetDef = $DB->request([
'SELECT' => ['id'],
'FROM' => \Glpi\Asset\AssetDefinition::getTable(),
'WHERE' => ['system_name' => $sysName]
])->current();
if ($assetDef) {
$assetDefId = (int) $assetDef['id'];
$DB->delete(\Glpi\Asset\CustomFieldDefinition::getTable(), [
'assets_assetdefinitions_id' => $assetDefId
]);
$DB->delete(\Glpi\Asset\AssetDefinition::getTable(), ['id' => $assetDefId]);
}
}
return true;
}