Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions livewhale-client-modules/ems/global.application.ems.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,20 +535,20 @@ public function onChangeDatabaseHost($before_host, $after_host) { // switches ho
public function onBeforeLogin() { // on before login
global $_LW;
$ts=strtotime('-1 month'); // set TS for 1 month ago
foreach(['reservations', 'attachments'] as $type) {
if (is_dir($_LW->INCLUDES_DIR_PATH.'/data/ems/reservations')) {
if (!file_exists($_LW->INCLUDES_DIR_PATH.'/data/ems/reservations/last_check') || filemtime($_LW->INCLUDES_DIR_PATH.'/data/ems/reservations/last_check')<$ts) { // once a month
touch($_LW->INCLUDES_DIR_PATH.'/data/ems/reservations/last_check'); // mark as cleaned
if ($res_dirs=@scandir($_LW->INCLUDES_DIR_PATH.'/data/ems/reservations')) { // clear cached reservations and attachments not updated within the last 1 month
foreach(['reservations', 'attachments', 'udfs'] as $type) {
if (is_dir($_LW->INCLUDES_DIR_PATH.'/data/ems/'.$type.'')) {
if (!file_exists($_LW->INCLUDES_DIR_PATH.'/data/ems/'.$type.'/last_check') || filemtime($_LW->INCLUDES_DIR_PATH.'/data/ems/'.$type.'/last_check')<$ts) { // once a month
touch($_LW->INCLUDES_DIR_PATH.'/data/ems/'.$type.'/last_check'); // mark as cleaned
if ($res_dirs=@scandir($_LW->INCLUDES_DIR_PATH.'/data/ems/'.$type.'')) { // clear cached items not updated within the last 1 month
foreach($res_dirs as $dir) {
if ($dir[0]!='.') {
if (is_dir($_LW->INCLUDES_DIR_PATH.'/data/ems/reservations/'.$dir)) {
if ($files=@scandir($_LW->INCLUDES_DIR_PATH.'/data/ems/reservations/'.$dir)) {
if (is_dir($_LW->INCLUDES_DIR_PATH.'/data/ems/'.$type.'/'.$dir)) {
if ($files=@scandir($_LW->INCLUDES_DIR_PATH.'/data/ems/'.$type.'/'.$dir)) {
foreach($files as $file) {
if ($file[0]!='.') {
if ($file_ts=@filemtime($_LW->INCLUDES_DIR_PATH.'/data/ems/reservations/'.$dir.'/'.$file)) {
if ($file_ts=@filemtime($_LW->INCLUDES_DIR_PATH.'/data/ems/'.$type.'/'.$dir.'/'.$file)) {
if ($file_ts<$ts) {
@unlink($_LW->INCLUDES_DIR_PATH.'/data/ems/reservations/'.$dir.'/'.$file);
@unlink($_LW->INCLUDES_DIR_PATH.'/data/ems/'.$type.'/'.$dir.'/'.$file);
};
};
};
Expand Down
26 changes: 26 additions & 0 deletions livewhale-client-modules/ems/includes/class.ems_rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,23 @@ public function getReservationById($id) { // fetches a reservation's info

public function getUDFs($username, $password, $parent_id, $parent_type) { // fetches EMS UDFs
global $_LW;
static $map;
if (!isset($map)) {
$map=[];
};
if (isset($map[$parent_type][$parent_id])) { // return cached response if possible
return $map[$parent_type][$parent_id];
};
$cache_key=hash('md5', $parent_type.$parent_id); // hash the cache key
$cache_path=$_LW->INCLUDES_DIR_PATH.'/data/ems/udfs/'.$cache_key[0].$cache_key[1].'/'.$cache_key; // get the cache path
if (@filemtime($cache_path)>$_SERVER['REQUEST_TIME']-3600) { // return cached response if possible
if ($output=@file_get_contents($cache_path)) {
if ($output=@unserialize($output)) {
$map[$parent_type][$parent_id]=$output;
return $output;
};
};
};
$output=[];
$params=['pageSize'=>2000];
if (!in_array($parent_type,['bookings', 'reservations'])) {
Expand Down Expand Up @@ -577,6 +594,15 @@ public function getUDFs($username, $password, $parent_id, $parent_type) { // fet
};
};
};
foreach([$_LW->INCLUDES_DIR_PATH.'/data/ems', $_LW->INCLUDES_DIR_PATH.'/data/ems/udfs', $_LW->INCLUDES_DIR_PATH.'/data/ems/udfs/'.$cache_key[0].$cache_key[1]] as $dir) {
if (!is_dir($dir)) {
@mkdir($dir);
};
};
if (is_dir($_LW->INCLUDES_DIR_PATH.'/data/ems/udfs/'.$cache_key[0].$cache_key[1])) {
@file_put_contents($cache_path, serialize($output), LOCK_EX); // file cache the reservation
};
$map[$parent_type][$parent_id]=$output; // static cache the reservation
};
return $output;
}
Expand Down