Skip to content

Commit

Permalink
add cleanNotifs in getJson
Browse files Browse the repository at this point in the history
  • Loading branch information
Sekiro-kost committed Aug 5, 2024
1 parent 0fc9df0 commit 26c6154
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/api/mobile.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,13 @@ function saveMenuFromAppV2($menu, $mobile)
log::add('mobile', 'debug', '| [INFO] CustomENVOICONFIGSAPI GETJSON > ' . json_encode($return[$idBox]['configs']));
log::add('mobile', 'debug', '| [INFO] Retour vers App > ' . json_encode($return));
log::add('mobile', 'debug', '└───────────────────────────────────────────');

$retentionTime = config::byKey('retentionTime', 'mobile', null);
if(isset($retentionTime) && $retentionTime != null) {
log::add('mobile', 'debug', '| [INFO] Nettoyage des notifs et images > ');
mobile::getNotificationsWithRetentioNTime($params['Iq'], $retentionTime);
}

$jsonrpc->makeSuccess($return);
}

Expand Down Expand Up @@ -672,6 +679,7 @@ function saveMenuFromAppV2($menu, $mobile)
$retentionTime = $params['notifsTime'];

if(isset($retentionTime)){
config::save('retentionTime', $retentionTime, 'mobile');
log::add('mobile', 'debug', '| Durée de retention actuelle : '. $retentionTime . ' jours');
$retentionSeconds = intVal($retentionTime) * 24 * 60 * 60;
$currentTime = time();
Expand Down
60 changes: 60 additions & 0 deletions core/class/mobile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,66 @@ public static function discovery_multi($cmds)
return $array_cmd_multi;
}


public static function getNotificationsWithRetentioNTime($Iq, $retentionTime){
log::add('mobile', 'debug', '┌────◀︎ getNotificationsFromFile ──────────');

log::add('mobile', 'debug', '| Durée de retention actuelle : '. $retentionTime . ' jours');
$retentionSeconds = intVal($retentionTime) * 24 * 60 * 60;
$currentTime = time();

$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);
}
}
}

$filePath = dirname(__FILE__) . '/../data/notifications/' . $Iq . '.json';
$notifications = 'noNotifications';
if (file_exists($filePath)) {
$notifications = file_get_contents($filePath);
if ($notifications) {
$notifications = json_decode($notifications, true);
$notificationsModified = false;

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 ($notificationsModified) {
file_put_contents($filePath, $notifications);
}
$notifications = json_encode($notifications);
log::add('mobile', 'debug', '| [INFO] Notifications > ' . $notifications);
log::add('mobile', 'debug', '└───────────────────────────────────────────');
}

}
}

public static function change_cmdAndeqLogic($_cmds, $_eqLogics)
{
$findEqLogic = array();
Expand Down

0 comments on commit 26c6154

Please sign in to comment.