@@ -188,31 +188,6 @@ public function getHostWithProfile(string $profile)
188
188
return $ this ->model ->getHostWithProfile ($ profile );
189
189
}
190
190
191
- /**
192
- * Récupère la liste des paquets présents sur l'hôte
193
- */
194
- public function getPackagesInventory ()
195
- {
196
- return $ this ->model ->getPackagesInventory ();
197
- }
198
-
199
- /**
200
- * Retourne les paquets installés sur l'hôte
201
- */
202
- public function getPackagesInstalled ()
203
- {
204
- return $ this ->model ->getPackagesInstalled ();
205
- }
206
-
207
- /**
208
- * Retrieve the list of packages available for update on the host
209
- * It is possible to add an offset to the request
210
- */
211
- public function getPackagesAvailable (bool $ withOffset = false , int $ offset = 0 )
212
- {
213
- return $ this ->model ->getPackagesAvailable ($ withOffset , $ offset );
214
- }
215
-
216
191
/**
217
192
* Retrieve the list of requests sent to the host
218
193
* It is possible to add an offset to the request
@@ -230,15 +205,6 @@ public function getLastPendingRequest(int $id)
230
205
return $ this ->model ->getLastPendingRequest ($ id );
231
206
}
232
207
233
- /**
234
- * Retrieve information about all actions performed on host packages (install, update, remove...)
235
- * It is possible to add an offset to the request
236
- */
237
- public function getEventsHistory (bool $ withOffset = false , int $ offset = 0 )
238
- {
239
- return $ this ->model ->getEventsHistory ($ withOffset , $ offset );
240
- }
241
-
242
208
/**
243
209
* Récupère la liste des paquets issus d'un évènemnt et dont l'état des paquets est défini par $packageState (installed, upgraded, removed)
244
210
* Les informations sont récupérées à la fois dans la table packages et dans packages_history
@@ -248,189 +214,6 @@ public function getEventPackagesList(string $eventId, string $packageState)
248
214
return $ this ->model ->getEventPackagesList ($ eventId , $ packageState );
249
215
}
250
216
251
- /**
252
- * Récupère le détails d'un évènement sur un type de paquets en particulier (installés, mis à jour, etc...)
253
- * Cette fonction est notamment déclenchée au passage de la souris sur une ligne de l'historique des évènements
254
- */
255
- public function getEventDetails (string $ id , string $ eventId , string $ packageState )
256
- {
257
- /**
258
- * Si il manque l'id de l'hôte, on quitte car on en a besoin pour ouvrir sa BDD dédiée
259
- */
260
- if (empty ($ id )) {
261
- throw new Exception ('Host Id must be specified ' );
262
- }
263
-
264
- $ packageState = \Controllers \Common::validateData ($ packageState );
265
-
266
- /**
267
- * Ouverture de la BDD dédiée de l'hôte
268
- */
269
- $ this ->model ->openHostDb ($ id );
270
-
271
- $ packages = $ this ->model ->getEventDetails ($ eventId , $ packageState );
272
-
273
- if ($ packageState == 'installed ' ) {
274
- $ content = '<p><b>Installed:</b></p> ' ;
275
- }
276
- if ($ packageState == 'dep-installed ' ) {
277
- $ content = '<p><b>Installed dependencies:</b></p> ' ;
278
- }
279
- if ($ packageState == 'upgraded ' ) {
280
- $ content = '<p><b>Updated:</b></p> ' ;
281
- }
282
- if ($ packageState == 'removed ' ) {
283
- $ content = '<p><b>Uninstalled:</b></p> ' ;
284
- }
285
- if ($ packageState == 'downgraded ' ) {
286
- $ content = '<p><b>Downgraded:</b></p> ' ;
287
- }
288
-
289
- $ content .= '<div class="grid grid-2 column-gap-10 row-gap-6 justify-space-between"> ' ;
290
-
291
- foreach ($ packages as $ package ) {
292
- $ content .= '<div class="flex align-item-center column-gap-5 min-width-200"> ' ;
293
- $ content .= \Controllers \Common::printProductIcon ($ package ['Name ' ]);
294
- $ content .= '<span class="copy"> ' . $ package ['Name ' ] . '</span> ' ;
295
- $ content .= '</div> ' ;
296
- $ content .= '<span class="copy"> ' . $ package ['Version ' ] . '</span> ' ;
297
- }
298
-
299
- $ content .= '</div> ' ;
300
-
301
- return $ content ;
302
- }
303
-
304
- /**
305
- * Retrieve the complete history of a package (its installation, its updates, etc...)
306
- */
307
- public function getPackageTimeline (string $ id , string $ packageName )
308
- {
309
- /**
310
- * If the host id is missing, we quit because we need it to open its dedicated DB
311
- */
312
- if (empty ($ id )) {
313
- throw new Exception ('Host Id must be specified ' );
314
- }
315
-
316
- /**
317
- * Open the dedicated DB of the host
318
- */
319
- $ this ->model ->openHostDb ($ id );
320
-
321
- $ events = $ this ->model ->getPackageTimeline ($ packageName );
322
-
323
- /**
324
- * Build the timeline to display and send it back to the ajax controller because it is jquery that will take care of displaying it afterwards
325
- */
326
- $ content = '<div class="timeline"> ' ;
327
-
328
- /**
329
- * The first block will be displayed on the left in the timeline
330
- */
331
- $ contentPosition = 'left ' ;
332
-
333
- foreach ($ events as $ event ) {
334
- /**
335
- * Add the date, time and state of the package
336
- */
337
- if ($ event ['State ' ] == "inventored " ) {
338
- $ contentIcon = 'package ' ;
339
- $ contentText = 'Inventored ' ;
340
- }
341
- if ($ event ['State ' ] == "installed " ) {
342
- $ contentIcon = 'down ' ;
343
- $ contentText = 'Installed ' ;
344
- }
345
- if ($ event ['State ' ] == "dep-installed " ) {
346
- $ contentIcon = 'down ' ;
347
- $ contentText = 'Installed (as depencency) ' ;
348
- }
349
- if ($ event ['State ' ] == "upgraded " ) {
350
- $ contentIcon = 'update ' ;
351
- $ contentText = 'Updated ' ;
352
- }
353
- if ($ event ['State ' ] == "removed " ) {
354
- $ contentIcon = 'delete ' ;
355
- $ contentText = 'Uninstalled ' ;
356
- }
357
- if ($ event ['State ' ] == "downgraded " ) {
358
- $ contentIcon = 'arrow-back ' ;
359
- $ contentText = 'Downgraded ' ;
360
- }
361
- if ($ event ['State ' ] == "reinstalled " ) {
362
- $ contentIcon = 'down ' ;
363
- $ contentText = 'Reinstalled ' ;
364
- }
365
- if ($ event ['State ' ] == "purged " ) {
366
- $ contentIcon = 'delete ' ;
367
- $ contentText = 'Uninstalled (purged) ' ;
368
- }
369
-
370
- /**
371
- * Position of the container block in the timeline according to the last displayed
372
- */
373
- $ content .= '<div class="timeline-container timeline-container- ' . $ contentPosition . '"> ' ;
374
-
375
- /**
376
- * Display the date, time and state of the package
377
- */
378
- $ content .= '<div class="table-container"> ' ;
379
- $ content .= '<img src="/assets/icons/ ' . $ contentIcon . '.svg" class="icon" /> ' ;
380
- $ content .= '<div class="flex flex-direction-column"> ' ;
381
- $ content .= '<p> ' . DateTime::createFromFormat ('Y-m-d ' , $ event ['Date ' ])->format ('d-m-Y ' ) . '</p> ' ;
382
- $ content .= '<p class="lowopacity-cst"> ' . $ event ['Time ' ] . '</p> ' ;
383
- $ content .= '</div> ' ;
384
- $ content .= '<div class="flex flex-direction-column"> ' ;
385
- $ content .= '<p> ' . $ contentText . '</p> ' ;
386
- $ content .= '<p class="lowopacity-cst copy">Version: ' . $ event ['Version ' ] . '</p> ' ;
387
- $ content .= '</div> ' ;
388
- $ content .= '</div> ' ;
389
-
390
- /**
391
- * If this event is the result of an update, install or uninstall event, then we indicate the Id of the event
392
- */
393
- // if (!empty($event['Id_event'])) {
394
- // $content .= '<a href="#' . $event['Id_event'] . '" >';
395
- // }
396
-
397
- /**
398
- * If the previous block was on the left, we display the next one on the right and vice versa
399
- */
400
- if ($ contentPosition == "left " ) {
401
- $ contentPosition = 'right ' ;
402
- } elseif ($ contentPosition == "right " ) {
403
- $ contentPosition = 'left ' ;
404
- }
405
-
406
- $ content .= '</div> ' ;
407
- }
408
-
409
- /**
410
- * Close the timeline
411
- */
412
- $ content .= '</div> ' ;
413
-
414
- return $ content ;
415
- }
416
-
417
- /**
418
- * Compte le nombre de paquets installés, mis à jour, désinstallés... au cours des X derniers jours.
419
- * Retourne un array contenant les dates => nombre de paquet
420
- * Fonction utilisées notamment pour la création du graphique ChrtJS de type 'line' sur la page d'un hôte
421
- */
422
- public function getLastPackagesStatusCount (string $ status , string $ days )
423
- {
424
- if ($ status != 'installed ' and $ status != 'upgraded ' and $ status != 'removed ' ) {
425
- throw new Exception ("Invalid status " );
426
- }
427
-
428
- $ dateEnd = date ('Y-m-d ' );
429
- $ dateStart = date_create ($ dateEnd )->modify ("- $ {days} days " )->format ('Y-m-d ' );
430
-
431
- return $ this ->model ->getLastPackagesStatusCount ($ status , $ dateStart , $ dateEnd );
432
- }
433
-
434
217
/**
435
218
* Edit the display settings on the hosts page
436
219
*/
@@ -998,9 +781,9 @@ public function register()
998
781
/**
999
782
* Lorsque appelé par l'api, HOSTS_DIR n'est pas setté, donc on le fait
1000
783
*/
1001
- if (!defined ('HOSTS_DIR ' )) {
1002
- define ('HOSTS_DIR ' , ROOT . '/hosts ' );
1003
- }
784
+ // if (!defined('HOSTS_DIR')) {
785
+ // define('HOSTS_DIR', DATA_DIR . '/hosts');
786
+ // }
1004
787
1005
788
/**
1006
789
* Si on n'a pas renseigné l'IP ou le hostname alors on quitte
@@ -1083,9 +866,9 @@ public function register()
1083
866
*/
1084
867
} else {
1085
868
/**
1086
- * Ajout de l'hôte en base de données
869
+ * Add the host in database
1087
870
*/
1088
- $ this ->model ->addHost ($ this ->ip , $ this ->hostname , $ this ->authId , $ this ->token , $ this ->onlineStatus , date ('Y-m-d ' ), date ('H:i:s ' ));
871
+ $ this ->model ->add ($ this ->ip , $ this ->hostname , $ this ->authId , $ this ->token , $ this ->onlineStatus , date ('Y-m-d ' ), date ('H:i:s ' ));
1089
872
1090
873
/**
1091
874
* Récupération de l'Id de l'hôte ajouté en BDD
@@ -1118,14 +901,30 @@ public function register()
1118
901
}
1119
902
1120
903
/**
1121
- * Suppression d'un hôte depuis l'api
904
+ * Delete a host from the database
1122
905
*/
1123
- public function unregister ( )
906
+ public function delete ( int $ id )
1124
907
{
908
+ $ hostRequestController = new \Controllers \Host \Request ();
909
+
1125
910
/**
1126
- * Changement du status de l'hôte en base de données ('deleted')
911
+ * Delete host from database
1127
912
*/
1128
- $ this ->model ->setHostInactive ($ this ->id );
913
+ $ this ->model ->delete ($ id );
914
+
915
+ /**
916
+ * Add a new ws request to disconnect the host
917
+ */
918
+ $ hostRequestController ->new ($ id , 'disconnect ' );
919
+
920
+ /**
921
+ * Delete host's dedicated database
922
+ */
923
+ if (is_dir (HOSTS_DIR . '/ ' . $ id )) {
924
+ \Controllers \Filesystem \Directory::deleteRecursive (HOSTS_DIR . '/ ' . $ id );
925
+ }
926
+
927
+ unset($ hostRequestController );
1129
928
}
1130
929
1131
930
/**
@@ -1211,20 +1010,10 @@ public function hostExec(array $hostsId, string $action)
1211
1010
* Case where the requested action is a delete
1212
1011
*/
1213
1012
if ($ action == 'delete ' ) {
1214
- /**
1215
- * First, reset host data in database
1216
- */
1217
- $ this ->model ->resetHost ($ hostId );
1218
-
1219
1013
/**
1220
1014
* Set host status to 'deleted' in database
1221
1015
*/
1222
- $ this ->model ->setHostInactive ($ hostId );
1223
-
1224
- /**
1225
- * Add a new ws request to disconnect the host
1226
- */
1227
- $ hostRequestController ->new ($ hostId , 'disconnect ' );
1016
+ $ this ->delete ($ hostId );
1228
1017
}
1229
1018
1230
1019
/**
0 commit comments