11<?php
2+
23/*
34 * @version $Id: HEADER 15930 2011-10-30 15:47:55Z tsmr $
45 -------------------------------------------------------------------------
2728 --------------------------------------------------------------------------
2829 */
2930
31+ use GlpiPlugin \Satisfaction \Menu ;
32+ use GlpiPlugin \Satisfaction \NotificationTargetTicket ;
33+ use GlpiPlugin \Satisfaction \Profile ;
34+ use GlpiPlugin \Satisfaction \Reminder ;
35+ use GlpiPlugin \Satisfaction \Survey ;
36+
3037/**
3138 * @return bool
3239 */
3340function plugin_satisfaction_install ()
3441{
3542 global $ DB ;
3643
37- include_once (Plugin::getPhpDir ('satisfaction ' )."/inc/profile.class.php " );
38- include_once (Plugin::getPhpDir ('satisfaction ' )."/inc/notificationtargetticket.class.php " );
39-
4044 if (!$ DB ->tableExists ("glpi_plugin_satisfaction_surveys " )) {
41- $ DB ->runFile (Plugin::getPhpDir ('satisfaction ' ). "/install/sql/empty-1.6.0.sql " );
45+ $ DB ->runFile (Plugin::getPhpDir ('satisfaction ' ) . "/install/sql/empty-1.6.0.sql " );
4246 } else {
4347 if (!$ DB ->fieldExists ("glpi_plugin_satisfaction_surveyquestions " , "type " )) {
44- $ DB ->runFile (Plugin::getPhpDir ('satisfaction ' ). "/install/sql/update-1.1.0.sql " );
48+ $ DB ->runFile (Plugin::getPhpDir ('satisfaction ' ) . "/install/sql/update-1.1.0.sql " );
4549 }
46- //version 1.2.1
50+ //version 1.2.1
4751 if (!$ DB ->fieldExists ("glpi_plugin_satisfaction_surveyquestions " , "default_value " )) {
48- $ DB ->runFile (Plugin::getPhpDir ('satisfaction ' ). "/install/sql/update-1.2.2.sql " );
52+ $ DB ->runFile (Plugin::getPhpDir ('satisfaction ' ) . "/install/sql/update-1.2.2.sql " );
4953 }
50- //version 1.4.1
54+ //version 1.4.1
5155 if (!$ DB ->tableExists ("glpi_plugin_satisfaction_surveytranslations " )) {
52- $ DB ->runFile (Plugin::getPhpDir ('satisfaction ' ). "/install/sql/update-1.4.1.sql " );
56+ $ DB ->runFile (Plugin::getPhpDir ('satisfaction ' ) . "/install/sql/update-1.4.1.sql " );
5357 }
5458
55- //version 1.4.3
59+ //version 1.4.3
5660 if (!$ DB ->tableExists ("glpi_plugin_satisfaction_surveyreminders " )) {
57- $ DB ->runFile (Plugin::getPhpDir ('satisfaction ' ). "/install/sql/update-1.4.3.sql " );
61+ $ DB ->runFile (Plugin::getPhpDir ('satisfaction ' ) . "/install/sql/update-1.4.3.sql " );
5862 }
5963
60- //version 1.4.5
64+ //version 1.4.5
6165 if (!$ DB ->fieldExists ("glpi_plugin_satisfaction_surveys " , "reminders_days " )) {
62- $ DB ->runFile (Plugin::getPhpDir ('satisfaction ' )."/install/sql/update-1.4.5.sql " );
66+ $ DB ->runFile (Plugin::getPhpDir ('satisfaction ' ) . "/install/sql/update-1.4.5.sql " );
67+ }
68+
69+ //version 1.7.1
70+ $ DB ->runFile (Plugin::getPhpDir ('satisfaction ' ) . "/install/sql/update-1.7.1.sql " );
71+
72+ }
73+
74+ //DisplayPreferences Migration
75+ $ classes = ['PluginSatisfactionSurvey ' => Survey::class];
76+
77+ foreach ($ classes as $ old => $ new ) {
78+ $ displayusers = $ DB ->request ([
79+ 'SELECT ' => [
80+ 'users_id '
81+ ],
82+ 'DISTINCT ' => true ,
83+ 'FROM ' => 'glpi_displaypreferences ' ,
84+ 'WHERE ' => [
85+ 'itemtype ' => $ old ,
86+ ],
87+ ]);
88+
89+ if (count ($ displayusers ) > 0 ) {
90+ foreach ($ displayusers as $ displayuser ) {
91+ $ iterator = $ DB ->request ([
92+ 'SELECT ' => [
93+ 'num ' ,
94+ 'id '
95+ ],
96+ 'FROM ' => 'glpi_displaypreferences ' ,
97+ 'WHERE ' => [
98+ 'itemtype ' => $ old ,
99+ 'users_id ' => $ displayuser ['users_id ' ],
100+ 'interface ' => 'central '
101+ ],
102+ ]);
103+
104+ if (count ($ iterator ) > 0 ) {
105+ foreach ($ iterator as $ data ) {
106+ $ iterator2 = $ DB ->request ([
107+ 'SELECT ' => [
108+ 'id '
109+ ],
110+ 'FROM ' => 'glpi_displaypreferences ' ,
111+ 'WHERE ' => [
112+ 'itemtype ' => $ new ,
113+ 'users_id ' => $ displayuser ['users_id ' ],
114+ 'num ' => $ data ['num ' ],
115+ 'interface ' => 'central '
116+ ],
117+ ]);
118+ if (count ($ iterator2 ) > 0 ) {
119+ foreach ($ iterator2 as $ dataid ) {
120+ $ query = $ DB ->buildDelete (
121+ 'glpi_displaypreferences ' ,
122+ [
123+ 'id ' => $ dataid ['id ' ],
124+ ]
125+ );
126+ $ DB ->doQuery ($ query );
127+ }
128+ } else {
129+ $ query = $ DB ->buildUpdate (
130+ 'glpi_displaypreferences ' ,
131+ [
132+ 'itemtype ' => $ new ,
133+ ],
134+ [
135+ 'id ' => $ data ['id ' ],
136+ ]
137+ );
138+ $ DB ->doQuery ($ query );
139+ }
140+ }
141+ }
142+ }
63143 }
64144 }
65145
66- PluginSatisfactionNotificationTargetTicket ::install ();
67- PluginSatisfactionProfile ::initProfile ();
68- PluginSatisfactionProfile ::createFirstAccess ($ _SESSION ['glpiactiveprofile ' ]['id ' ]);
146+ NotificationTargetTicket ::install ();
147+ Profile ::initProfile ();
148+ Profile ::createFirstAccess ($ _SESSION ['glpiactiveprofile ' ]['id ' ]);
69149
70- CronTask::Register (PluginSatisfactionReminder ::class, PluginSatisfactionReminder ::CRON_TASK_NAME , DAY_TIMESTAMP );
150+ CronTask::Register (Reminder ::class, Reminder ::CRON_TASK_NAME , DAY_TIMESTAMP );
71151 return true ;
72152}
73153
@@ -78,42 +158,46 @@ function plugin_satisfaction_uninstall()
78158{
79159 global $ DB ;
80160
81- include_once (Plugin::getPhpDir ('satisfaction ' )."/inc/profile.class.php " );
82- include_once (Plugin::getPhpDir ('satisfaction ' )."/inc/menu.class.php " );
83- include_once (Plugin::getPhpDir ('satisfaction ' )."/inc/notificationtargetticket.class.php " );
84-
85161 $ tables = [
86- "glpi_plugin_satisfaction_surveys " ,
87- "glpi_plugin_satisfaction_surveyquestions " ,
88- "glpi_plugin_satisfaction_surveyanswers " ,
89- "glpi_plugin_satisfaction_surveyreminders " ,
90- "glpi_plugin_satisfaction_surveytranslations " ,
91- "glpi_plugin_satisfaction_reminders "
162+ "glpi_plugin_satisfaction_surveys " ,
163+ "glpi_plugin_satisfaction_surveyquestions " ,
164+ "glpi_plugin_satisfaction_surveyanswers " ,
165+ "glpi_plugin_satisfaction_surveyreminders " ,
166+ "glpi_plugin_satisfaction_surveytranslations " ,
167+ "glpi_plugin_satisfaction_reminders " ,
92168 ];
93169
94170 foreach ($ tables as $ table ) {
95171 $ DB ->dropTable ($ table , true );
96172 }
97173
98- $ tables_glpi = ["glpi_logs " ];
99-
100- foreach ($ tables_glpi as $ table_glpi ) {
101- $ DB ->delete ($ table_glpi , ['itemtype ' => ['LIKE ' => 'PluginSatisfaction% ' ]]);
174+ $ itemtypes = ['Alert ' ,
175+ 'DisplayPreference ' ,
176+ 'Document_Item ' ,
177+ 'ImpactItem ' ,
178+ 'Item_Ticket ' ,
179+ 'Link_Itemtype ' ,
180+ 'Notepad ' ,
181+ 'SavedSearch ' ,
182+ 'DropdownTranslation ' ];
183+ foreach ($ itemtypes as $ itemtype ) {
184+ $ item = new $ itemtype ();
185+ $ item ->deleteByCriteria (['itemtype ' => Survey::class]);
102186 }
103187
104188
105- //Delete rights associated with the plugin
189+ //Delete rights associated with the plugin
106190 $ profileRight = new ProfileRight ();
107- foreach (PluginSatisfactionProfile ::getAllRights () as $ right ) {
191+ foreach (Profile ::getAllRights () as $ right ) {
108192 $ profileRight ->deleteByCriteria (['name ' => $ right ['field ' ]]);
109193 }
110- PluginSatisfactionProfile ::removeRightsFromSession ();
194+ Profile ::removeRightsFromSession ();
111195
112- PluginSatisfactionMenu ::removeRightsFromSession ();
196+ Menu ::removeRightsFromSession ();
113197
114- PluginSatisfactionNotificationTargetTicket ::uninstall ();
198+ NotificationTargetTicket ::uninstall ();
115199
116- CronTask::Register (PluginSatisfactionReminder ::class, PluginSatisfactionReminder ::CRON_TASK_NAME , DAY_TIMESTAMP );
200+ CronTask::Register (Reminder ::class, Reminder ::CRON_TASK_NAME , DAY_TIMESTAMP );
117201
118202 return true ;
119203}
0 commit comments