-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathhook.php
More file actions
203 lines (173 loc) · 6.79 KB
/
hook.php
File metadata and controls
203 lines (173 loc) · 6.79 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
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
195
196
197
198
199
200
201
202
203
<?php
/*
* @version $Id: HEADER 15930 2011-10-30 15:47:55Z tsmr $
-------------------------------------------------------------------------
satisfaction plugin for GLPI
Copyright (C) 2016-2022 by the satisfaction Development Team.
https://github.com/pluginsglpi/satisfaction
-------------------------------------------------------------------------
LICENSE
This file is part of satisfaction.
satisfaction is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
satisfaction is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with satisfaction. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
use GlpiPlugin\Satisfaction\Menu;
use GlpiPlugin\Satisfaction\NotificationTargetTicket;
use GlpiPlugin\Satisfaction\Profile;
use GlpiPlugin\Satisfaction\Reminder;
use GlpiPlugin\Satisfaction\Survey;
/**
* @return bool
*/
function plugin_satisfaction_install()
{
global $DB;
if (!$DB->tableExists("glpi_plugin_satisfaction_surveys")) {
$DB->runFile(Plugin::getPhpDir('satisfaction') . "/install/sql/empty-1.6.0.sql");
} else {
if (!$DB->fieldExists("glpi_plugin_satisfaction_surveyquestions", "type")) {
$DB->runFile(Plugin::getPhpDir('satisfaction') . "/install/sql/update-1.1.0.sql");
}
//version 1.2.1
if (!$DB->fieldExists("glpi_plugin_satisfaction_surveyquestions", "default_value")) {
$DB->runFile(Plugin::getPhpDir('satisfaction') . "/install/sql/update-1.2.2.sql");
}
//version 1.4.1
if (!$DB->tableExists("glpi_plugin_satisfaction_surveytranslations")) {
$DB->runFile(Plugin::getPhpDir('satisfaction') . "/install/sql/update-1.4.1.sql");
}
//version 1.4.3
if (!$DB->tableExists("glpi_plugin_satisfaction_surveyreminders")) {
$DB->runFile(Plugin::getPhpDir('satisfaction') . "/install/sql/update-1.4.3.sql");
}
//version 1.4.5
if (!$DB->fieldExists("glpi_plugin_satisfaction_surveys", "reminders_days")) {
$DB->runFile(Plugin::getPhpDir('satisfaction') . "/install/sql/update-1.4.5.sql");
}
//version 1.7.1
$DB->runFile(Plugin::getPhpDir('satisfaction') . "/install/sql/update-1.7.1.sql");
}
//DisplayPreferences Migration
$classes = ['PluginSatisfactionSurvey' => Survey::class];
foreach ($classes as $old => $new) {
$displayusers = $DB->request([
'SELECT' => [
'users_id'
],
'DISTINCT' => true,
'FROM' => 'glpi_displaypreferences',
'WHERE' => [
'itemtype' => $old,
],
]);
if (count($displayusers) > 0) {
foreach ($displayusers as $displayuser) {
$iterator = $DB->request([
'SELECT' => [
'num',
'id'
],
'FROM' => 'glpi_displaypreferences',
'WHERE' => [
'itemtype' => $old,
'users_id' => $displayuser['users_id'],
'interface' => 'central'
],
]);
if (count($iterator) > 0) {
foreach ($iterator as $data) {
$iterator2 = $DB->request([
'SELECT' => [
'id'
],
'FROM' => 'glpi_displaypreferences',
'WHERE' => [
'itemtype' => $new,
'users_id' => $displayuser['users_id'],
'num' => $data['num'],
'interface' => 'central'
],
]);
if (count($iterator2) > 0) {
foreach ($iterator2 as $dataid) {
$query = $DB->buildDelete(
'glpi_displaypreferences',
[
'id' => $dataid['id'],
]
);
$DB->doQuery($query);
}
} else {
$query = $DB->buildUpdate(
'glpi_displaypreferences',
[
'itemtype' => $new,
],
[
'id' => $data['id'],
]
);
$DB->doQuery($query);
}
}
}
}
}
}
NotificationTargetTicket::install();
Profile::initProfile();
Profile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
CronTask::Register(Reminder::class, Reminder::CRON_TASK_NAME, DAY_TIMESTAMP);
return true;
}
/**
* @return bool
*/
function plugin_satisfaction_uninstall()
{
global $DB;
$tables = [
"glpi_plugin_satisfaction_surveys",
"glpi_plugin_satisfaction_surveyquestions",
"glpi_plugin_satisfaction_surveyanswers",
"glpi_plugin_satisfaction_surveyreminders",
"glpi_plugin_satisfaction_surveytranslations",
"glpi_plugin_satisfaction_reminders",
];
foreach ($tables as $table) {
$DB->dropTable($table, true);
}
$itemtypes = ['Alert',
'DisplayPreference',
'Document_Item',
'ImpactItem',
'Item_Ticket',
'Link_Itemtype',
'Notepad',
'SavedSearch',
'DropdownTranslation'];
foreach ($itemtypes as $itemtype) {
$item = new $itemtype();
$item->deleteByCriteria(['itemtype' => Survey::class]);
}
//Delete rights associated with the plugin
$profileRight = new ProfileRight();
foreach (Profile::getAllRights() as $right) {
$profileRight->deleteByCriteria(['name' => $right['field']]);
}
Profile::removeRightsFromSession();
Menu::removeRightsFromSession();
NotificationTargetTicket::uninstall();
CronTask::Register(Reminder::class, Reminder::CRON_TASK_NAME, DAY_TIMESTAMP);
return true;
}