Skip to content

Commit

Permalink
Touch xls file if response is 304
Browse files Browse the repository at this point in the history
  • Loading branch information
ariselseng committed Feb 4, 2020
1 parent 2286d64 commit 5e916e9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/NorwegianBanks.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ private function downloadData()
{

$xlsFileExists = file_exists($this->xlsFilePath);
if ($xlsFileExists && filemtime($this->xlsFilePath) <= (time() - self::xlsFileTtl)) {
$xlsFileMTime = $xlsFileExists ? filemtime($this->xlsFilePath) : 0;
$xlsTooOld = $xlsFileMTime <= (time() - self::xlsFileTtl);

if ($xlsFileExists && $xlsTooOld) {
$headers = [
'If-Modified-Since' => gmdate('D, d M Y H:i:s T', filemtime($this->xlsFilePath)),
'If-Modified-Since' => gmdate('D, d M Y H:i:s T', $xlsFileMTime),
];
} else if (!$xlsFileExists) {
$headers = null;

} else {
return;
}
Expand All @@ -41,6 +43,8 @@ private function downloadData()

if ($response->getStatusCode() === 200 && $response->getBody()->getSize() > 0) {
file_put_contents($this->xlsFilePath, $response->getBody()->getContents(), LOCK_EX);
} else if ($response->getStatusCode() === 304) {
touch($this->xlsFilePath);
}
}

Expand Down

0 comments on commit 5e916e9

Please # to comment.