11<?php
2+
23/*
34 -------------------------------------------------------------------------
45 MyDashboard plugin for GLPI
2930use GlpiPlugin \Mydashboard \Customswidget ;
3031use GlpiPlugin \Mydashboard \Groupprofile ;
3132use GlpiPlugin \Mydashboard \Menu ;
33+ use GlpiPlugin \Mydashboard \Preference as MydashboardPreference ;
3234use GlpiPlugin \Mydashboard \Profile ;
3335use GlpiPlugin \Mydashboard \Widget ;
34- use GlpiPlugin \Mydashboard \Preference as MydashboardPreference ;
3536
3637/**
3738 * @return bool
@@ -77,8 +78,8 @@ function plugin_mydashboard_install()
7778 "replace_central " ,
7879 "bool " ,
7980 [
80- "update " => $ replace_central ,
81- "value " => 0
81+ "update " => $ replace_central ,
82+ "value " => 0 ,
8283 ]
8384 );
8485
@@ -95,7 +96,7 @@ function plugin_mydashboard_install()
9596 "interface " ,
9697 "bool " ,
9798 [
98- "update " => 1
99+ "update " => 1 ,
99100 ]
100101 );
101102 $ mig ->executeMigration ();
@@ -108,7 +109,7 @@ function plugin_mydashboard_install()
108109 $ DB ->runFile (PLUGIN_MYDASHBOARD_DIR . "/install/sql/update-1.0.5.sql " );
109110
110111 //fill the new table with the data of previous month of this year
111- // fillTableMydashboardStocktickets();
112+ // fillTableMydashboardStocktickets();
112113
113114 $ mig ->executeMigration ();
114115 }
@@ -191,7 +192,7 @@ function plugin_mydashboard_install()
191192 $ DB ->runFile (PLUGIN_MYDASHBOARD_DIR . "/install/sql/update-1.7.5.sql " );
192193 $ mig ->executeMigration ();
193194 transform_prefered_group_to_prefered_groups ();
194- // fillTableMydashboardStockticketsGroup();
195+ // fillTableMydashboardStockticketsGroup();
195196 }
196197
197198 if (!$ DB ->tableExists ("glpi_plugin_mydashboard_itilalerts " )) {
@@ -208,8 +209,8 @@ function plugin_mydashboard_install()
208209 $ queryTruncate = "TRUNCATE TABLE `glpi_plugin_mydashboard_stocktickets` " ;
209210 $ DB ->doQuery ($ queryTruncate );
210211 $ mig ->executeMigration ();
211- // fillTableMydashboardStocktickets();
212- // fillTableMydashboardStockticketsGroup();
212+ // fillTableMydashboardStocktickets();
213+ // fillTableMydashboardStockticketsGroup();
213214
214215 $ config = new Config ();
215216 $ input ['id ' ] = "1 " ;
@@ -243,7 +244,7 @@ function plugin_mydashboard_install()
243244 $ mig = new Migration ("2.0.0 " );
244245 $ DB ->runFile (PLUGIN_MYDASHBOARD_DIR . "/install/sql/update-2.0.0.sql " );
245246 $ mig ->executeMigration ();
246- //ALTER TABLE `glpi_plugin_mydashboard_userwidgets` DROP CONSTRAINT `glpi_plugin_mydashboard_userwidgets_ibfk_1`;
247+ //ALTER TABLE `glpi_plugin_mydashboard_userwidgets` DROP CONSTRAINT `glpi_plugin_mydashboard_userwidgets_ibfk_1`;
247248
248249 $ query = "SELECT `id`, `grid` FROM `glpi_plugin_mydashboard_dashboards` " ;
249250 $ result = $ DB ->doQuery ($ query );
@@ -257,8 +258,8 @@ function plugin_mydashboard_install()
257258 $ newwidget ['id ' ] = $ widgets ['id ' ];
258259 $ newwidget ['x ' ] = $ widgets ['x ' ];
259260 $ newwidget ['y ' ] = $ widgets ['y ' ];
260- $ newwidget ['w ' ] = isset ( $ widgets ['width ' ]) ? $ widgets [ ' width ' ] : $ widgets ['w ' ];
261- $ newwidget ['h ' ] = isset ( $ widgets ['height ' ]) ? $ widgets [ ' height ' ] : $ widgets ['h ' ];
261+ $ newwidget ['w ' ] = $ widgets ['width ' ] ?? $ widgets ['w ' ];
262+ $ newwidget ['h ' ] = $ widgets ['height ' ] ?? $ widgets ['h ' ];
262263
263264 $ newwidgets [] = $ newwidget ;
264265 }
@@ -300,6 +301,37 @@ function plugin_mydashboard_install()
300301 $ DB ->runFile (PLUGIN_MYDASHBOARD_DIR . "/install/sql/update-2.2.2.sql " );
301302 $ mig ->executeMigration ();
302303
304+ //widgetname Migration
305+ $ classes = ['GlpiPluginActivityDashboard ' => 'GlpiPlugin \\\Activity \\\Dashboard ' ,
306+ 'GlpiPluginManageentitiesDashboard ' => 'GlpiPlugin \\\Manageentities \\\Dashboard ' ,
307+ 'GlpiPluginEventsmanagerDashboard ' => 'GlpiPlugin \\\Eventsmanager \\\Dashboard ' ,
308+ 'GlpiPluginOcsinventoryngDashboard ' => 'GlpiPlugin \\\Ocsinventoryng \\\Dashboard ' ,
309+ 'GlpiPluginResourcesDashboard ' => 'GlpiPlugin \\\Resources \\\Dashboard ' ,
310+ 'GlpiPluginSatisfactionDashboard ' => 'GlpiPlugin \\\Satisfaction \\\Dashboard ' ,
311+ 'GlpiPluginServicecatalogIndicator ' => 'GlpiPlugin \\\Servicecatalog \\\Indicator ' ,
312+ 'GlpiPluginTasklistsDashboard ' => 'GlpiPlugin \\\Tasklists \\\Dashboard ' ,
313+ 'GlpiPluginVipDashboard ' => 'GlpiPlugin \\\Vip \\\Dashboard ' ];
314+
315+ foreach ($ classes as $ old => $ new ) {
316+ $ iterator = $ DB ->request ([
317+ 'SELECT ' => [
318+ 'id ' ,
319+ 'name ' ,
320+ ],
321+ 'FROM ' => 'glpi_plugin_mydashboard_widgets ' ,
322+ 'WHERE ' => [
323+ 'name ' => ['LIKE ' , $ old . '% ' ]
324+ ],
325+ ]);
326+
327+ if (count ($ iterator ) > 0 ) {
328+ foreach ($ iterator as $ data ) {
329+ $ query = "UPDATE `glpi_plugin_mydashboard_widgets` set name = REPLACE(name,' $ old',' $ new') where id = ' " . $ data ['id ' ] . "' " ;
330+ $ DB ->doQuery ($ query );
331+ }
332+ }
333+ }
334+
303335 $ config = new Config ();
304336 if (!$ config ->getFromDB ("1 " )) {
305337 $ config ->initConfig ();
@@ -320,27 +352,27 @@ function insertDefaultTitles()
320352 $ DB ->insert (
321353 "glpi_plugin_mydashboard_customswidgets " ,
322354 [
323- 'name ' => __ ('Incidents ' , 'mydashboard ' ),
324- 'content ' => $ startTitle . __ ("Incidents " , 'mydashboard ' ) . $ endTitle ,
325- 'comment ' => ''
355+ 'name ' => __ ('Incidents ' , 'mydashboard ' ),
356+ 'content ' => $ startTitle . __ ("Incidents " , 'mydashboard ' ) . $ endTitle ,
357+ 'comment ' => '' ,
326358 ]
327359 );
328360
329361 $ DB ->insert (
330362 "glpi_plugin_mydashboard_customswidgets " ,
331363 [
332- 'name ' => __ ('Requests ' , 'mydashboard ' ),
333- 'content ' => $ startTitle . __ ("Requests " , 'mydashboard ' ) . $ endTitle ,
334- 'comment ' => ''
364+ 'name ' => __ ('Requests ' , 'mydashboard ' ),
365+ 'content ' => $ startTitle . __ ("Requests " , 'mydashboard ' ) . $ endTitle ,
366+ 'comment ' => '' ,
335367 ]
336368 );
337369
338370 $ DB ->insert (
339371 "glpi_plugin_mydashboard_customswidgets " ,
340372 [
341- 'name ' => __ ('Problems ' ),
342- 'content ' => $ startTitle . __ ("Problems " ) . $ endTitle ,
343- 'comment ' => ''
373+ 'name ' => __ ('Problems ' ),
374+ 'content ' => $ startTitle . __ ("Problems " ) . $ endTitle ,
375+ 'comment ' => '' ,
344376 ]
345377 );
346378}
@@ -363,7 +395,7 @@ function fillTableMydashboardStocktickets()
363395 . "GROUP BY DATE_FORMAT(`glpi_tickets`.`date`, '%Y-%m'), `glpi_tickets`.`entities_id` " ;
364396 $ results = $ DB ->doQuery ($ query );
365397 while ($ data = $ DB ->fetchArray ($ results )) {
366- list ( $ year , $ month) = explode ('- ' , $ data ['month ' ]);
398+ [ $ year , $ month] = explode ('- ' , $ data ['month ' ]);
367399 $ nbdays = date ("t " , mktime (0 , 0 , 0 , $ month , 1 , $ year ));
368400 $ entities_id = $ data ["entities_id " ];
369401 $ query = "SELECT COUNT(*) as count FROM `glpi_tickets`
@@ -398,7 +430,7 @@ function fillTableMydashboardStockticketsGroup()
398430 GROUP BY DATE_FORMAT(`glpi_tickets`.`date`, '%Y-%m'), `glpi_tickets`.`entities_id`, `glpi_groups_tickets`.`groups_id` " ;
399431 $ results = $ DB ->doQuery ($ query );
400432 while ($ data = $ DB ->fetchArray ($ results )) {
401- list ( $ year , $ month) = explode ('- ' , $ data ['month ' ]);
433+ [ $ year , $ month] = explode ('- ' , $ data ['month ' ]);
402434 $ nbdays = date ("t " , mktime (0 , 0 , 0 , $ month , 1 , $ year ));
403435 $ entities_id = $ data ["entities_id " ];
404436 $ groups_id = $ data ["groups_id " ];
@@ -473,22 +505,22 @@ function plugin_mydashboard_uninstall()
473505
474506 // Plugin tables deletion
475507 $ tables = [
476- "glpi_plugin_mydashboard_profileauthorizedwidgets " ,
477- "glpi_plugin_mydashboard_widgets " ,
478- "glpi_plugin_mydashboard_userwidgets " ,
479- "glpi_plugin_mydashboard_configs " ,
480- "glpi_plugin_mydashboard_preferences " ,
481- "glpi_plugin_mydashboard_preferenceuserblacklists " ,
482- "glpi_plugin_mydashboard_alerts " ,
483- "glpi_plugin_mydashboard_stockwidgets " ,
484- "glpi_plugin_mydashboard_stocktickets " ,
485- "glpi_plugin_mydashboard_itilalerts " ,
486- "glpi_plugin_mydashboard_changealerts " ,
487- "glpi_plugin_mydashboard_dashboards " ,
488- "glpi_plugin_mydashboard_groupprofiles " ,
489- "glpi_plugin_mydashboard_customswidgets " ,
490- "glpi_plugin_mydashboard_configtranslations " ,
491- "glpi_plugin_mydashboard_stockticketindicators " ];
508+ "glpi_plugin_mydashboard_profileauthorizedwidgets " ,
509+ "glpi_plugin_mydashboard_widgets " ,
510+ "glpi_plugin_mydashboard_userwidgets " ,
511+ "glpi_plugin_mydashboard_configs " ,
512+ "glpi_plugin_mydashboard_preferences " ,
513+ "glpi_plugin_mydashboard_preferenceuserblacklists " ,
514+ "glpi_plugin_mydashboard_alerts " ,
515+ "glpi_plugin_mydashboard_stockwidgets " ,
516+ "glpi_plugin_mydashboard_stocktickets " ,
517+ "glpi_plugin_mydashboard_itilalerts " ,
518+ "glpi_plugin_mydashboard_changealerts " ,
519+ "glpi_plugin_mydashboard_dashboards " ,
520+ "glpi_plugin_mydashboard_groupprofiles " ,
521+ "glpi_plugin_mydashboard_customswidgets " ,
522+ "glpi_plugin_mydashboard_configtranslations " ,
523+ "glpi_plugin_mydashboard_stockticketindicators " ];
492524
493525 foreach ($ tables as $ table ) {
494526 $ DB ->dropTable ($ table , true );
@@ -540,12 +572,12 @@ function plugin_mydashboard_display_login()
540572function plugin_mydashboard_getDatabaseRelations ()
541573{
542574 return ["glpi_groups " => [
543- 'glpi_plugin_mydashboard_stocktickets ' => "groups_id " ,
575+ 'glpi_plugin_mydashboard_stocktickets ' => "groups_id " ,
544576 ],
545- "glpi_reminders " => [
546- 'glpi_plugin_mydashboard_itilalerts ' => "reminders_id " ,
547- 'glpi_plugin_mydashboard_alerts ' => "reminders_id " ,
548- ],
577+ "glpi_reminders " => [
578+ 'glpi_plugin_mydashboard_itilalerts ' => "reminders_id " ,
579+ 'glpi_plugin_mydashboard_alerts ' => "reminders_id " ,
580+ ],
549581 ];
550582}
551583
@@ -554,7 +586,7 @@ function plugin_mydashboard_getDropdown()
554586{
555587 if (Plugin::isPluginActive ("mydashboard " )) {
556588 return [
557- Customswidget::class => Customswidget::getTypeName (2 ),];
589+ Customswidget::class => Customswidget::getTypeName (2 ),];
558590 } else {
559591 return [];
560592 }
0 commit comments