Skip to content

Commit

Permalink
fix isset retention
Browse files Browse the repository at this point in the history
  • Loading branch information
Sekiro-kost committed Jul 22, 2024
1 parent 8c4077f commit b33122a
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions core/api/mobile.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,12 @@ function saveMenuFromAppV2($menu, $mobile)
log::add('mobile', 'debug', '┌────◀︎ getNotificationsFromFile ──────────');
$Iq = $params['Iq'];
$retentionTime = $params['notifsTime'];
log::add('mobile', 'debug', '| Durée de retention actuelle : '. $retentionTime . ' jours');
$retentionSeconds = intVal($retentionTime) * 24 * 60 * 60;
$currentTime = time();
if(isset($retentionTime)){
log::add('mobile', 'debug', '| Durée de retention actuelle : '. $retentionTime . ' jours');
$retentionSeconds = intVal($retentionTime) * 24 * 60 * 60;
$currentTime = time();
}


$filePath = dirname(__FILE__) . '/../data/notifications/' . $Iq . '.json';
$notifications = 'noNotifications';
Expand All @@ -684,16 +687,34 @@ function saveMenuFromAppV2($menu, $mobile)

foreach ($notifications as $id => $value) {
$notificationDate = strtotime($value['data']['date']);
if (($currentTime - $notificationDate) > $retentionSeconds) {
unset($notifications[$id]);
$notificationsModified = true;
} else {
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;
// } 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 ($notificationsModified) {
file_put_contents($filePath, $notifications);
Expand Down

0 comments on commit b33122a

Please sign in to comment.