Skip to content

Commit

Permalink
fix cleanImages
Browse files Browse the repository at this point in the history
  • Loading branch information
Sekiro-kost committed Aug 5, 2024
1 parent 26c6154 commit 0947e85
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 28 deletions.
2 changes: 1 addition & 1 deletion core/api/mobile.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ function saveMenuFromAppV2($menu, $mobile)
}

if ($jsonrpc->getMethod() == 'getNotificationsFromFile') {
log::add('mobile', 'debug', '┌────◀︎ getNotificationsFromFile ──────────');
log::add('mobile', 'debug', '┌──────────▶︎ fg-warning: Recuperation des Notifications :/fg: ──────────');
$Iq = $params['Iq'];
$retentionTime = $params['notifsTime'];

Expand Down
36 changes: 9 additions & 27 deletions core/class/mobile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public static function discovery_multi($cmds)


public static function getNotificationsWithRetentioNTime($Iq, $retentionTime){
log::add('mobile', 'debug', '┌────◀︎ getNotificationsFromFile ──────────');
log::add('mobile', 'debug', '┌──────────▶︎ fg-warning: Nettoyage des Notifications et Images :/fg: ──────────');

log::add('mobile', 'debug', '| Durée de retention actuelle : '. $retentionTime . ' jours');
$retentionSeconds = intVal($retentionTime) * 24 * 60 * 60;
Expand All @@ -316,11 +316,10 @@ public static function getNotificationsWithRetentioNTime($Iq, $retentionTime){
$pathImages = dirname(__FILE__) . '/../data/images/';
if(is_dir($pathImages)){
$images = glob($pathImages . '*.jpg');

foreach ($images as $image) {
$fileCreationTime = filemtime($image);
if ($fileCreationTime < ($currentTime - $retentionSeconds)) {
unlink($file);
unlink($image);
}
}
}
Expand All @@ -335,34 +334,17 @@ public static function getNotificationsWithRetentioNTime($Iq, $retentionTime){

foreach ($notifications as $id => $value) {
$notificationDate = strtotime($value['data']['date']);
if(isset($retentionSeconds)){
if (($currentTime - $notificationDate) > $retentionSeconds) {
unset($notifications[$id]);
$notificationsModified = true;
} else {
$dateNew = substr($value['data']['date'], 0, 10);
$horaire = substr($value['data']['date'], -8);
$horaireFormat = substr($horaire, 0, 5);
$notifications[$id]['data']['newDate'] = $dateNew;
$notifications[$id]['data']['horaireFormat'] = $horaireFormat;
}
}else{
$dateNew = substr($value['data']['date'], 0, 10);
$horaire = substr($value['data']['date'], -8);
$horaireFormat = substr($horaire, 0, 5);
$notifications[$id]['data']['newDate'] = $dateNew;
$notifications[$id]['data']['horaireFormat'] = $horaireFormat;
}
if (($currentTime - $notificationDate) > $retentionSeconds) {
unset($notifications[$id]);
$notificationsModified = true;
}
}
if ($notificationsModified) {
file_put_contents($filePath, $notifications);
}
$notifications = json_encode($notifications);
log::add('mobile', 'debug', '| [INFO] Notifications > ' . $notifications);
log::add('mobile', 'debug', '└───────────────────────────────────────────');

}

}
log::add('mobile', 'debug', '| Fin du nettoyage des Notifications et Images');
log::add('mobile', 'debug', '└───────────────────────────────────────────');
}

public static function change_cmdAndeqLogic($_cmds, $_eqLogics)
Expand Down

0 comments on commit 0947e85

Please sign in to comment.