revert 2d7d975c8b
revert Send List as csv instead of converting to xlsx to prevent memory exhausting
This commit is contained in:
parent
2d7d975c8b
commit
3bbf1f8ddc
|
|
@ -72,75 +72,45 @@ function convertcsvToXlsx(string $csvFile, string $xlsxFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
while($latesEndTime - time() > 30){
|
while($latesEndTime - time() > 30){
|
||||||
|
|
||||||
// If the directory for Tasks is already created
|
// If the directory for Tasks is already created
|
||||||
if(is_dir($taskDir)) {
|
if(is_dir($taskDir)) {
|
||||||
|
|
||||||
$taskfiles = scandir($taskDir);
|
$taskfiles = scandir($taskDir);
|
||||||
$taskfiles = array_diff($taskfiles, array('.', '..'));
|
$taskfiles = array_diff($taskfiles, array('.', '..'));
|
||||||
sort($taskfiles);
|
sort($taskfiles);
|
||||||
|
// if there are any taks which are older then min oldness. To be sure the file writing process is finished.
|
||||||
// if there are any tasks which are older then min oldness
|
|
||||||
if(count($taskfiles) > 0 && intval(explode("-", $taskfiles[0])[0]) + $minTaskOldness < time()) {
|
if(count($taskfiles) > 0 && intval(explode("-", $taskfiles[0])[0]) + $minTaskOldness < time()) {
|
||||||
|
$taskString = file_get_contents($taskDir.'/'.$taskfiles[0]);
|
||||||
$taskFilePath = $taskDir.'/'.$taskfiles[0];
|
|
||||||
$csvFilePath = str_replace(".json", ".csv", $downloadDir.'/'.$taskfiles[0]);
|
|
||||||
|
|
||||||
$taskString = file_get_contents($taskFilePath);
|
|
||||||
$task = json_decode($taskString, true);
|
$task = json_decode($taskString, true);
|
||||||
|
|
||||||
// if there are any requests to do, do the first
|
// if there are any requests to do, do the first
|
||||||
if(count($task['requests']) > 0) {
|
if(count($task['requests']) > 0) {
|
||||||
|
$nextOffset = doRequest($task['requests'][0], str_replace(".json", ".csv", $downloadDir.'/'.$taskfiles[0]), $username , $password);
|
||||||
$nextOffset = doRequest(
|
|
||||||
$task['requests'][0],
|
|
||||||
$csvFilePath,
|
|
||||||
$username,
|
|
||||||
$password
|
|
||||||
);
|
|
||||||
|
|
||||||
if($nextOffset){
|
if($nextOffset){
|
||||||
$task['requests'][0]['offset'] = $nextOffset;
|
$task['requests'][0]['offset'] = $nextOffset;
|
||||||
} else {
|
} else {
|
||||||
array_shift($task['requests']);
|
array_shift($task['requests']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$taskString = json_encode($task);
|
$taskString = json_encode($task);
|
||||||
|
$taskfile = fopen($taskDir.'/'.$taskfiles[0], 'w');
|
||||||
$taskfile = fopen($taskFilePath, 'w');
|
|
||||||
|
|
||||||
if($taskfile){
|
if($taskfile){
|
||||||
fwrite($taskfile, $taskString);
|
fwrite($taskfile, $taskString);
|
||||||
fclose($taskfile);
|
fclose($taskfile);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
// if there are no Requests left, send the E-Mail
|
||||||
|
else {
|
||||||
// No requests left -> send CSV directly by email
|
convertcsvToXlsx(str_replace(".json", ".csv", $downloadDir.'/'.$taskfiles[0]), str_replace(".json", ".xlsx", $downloadDir.'/'.$taskfiles[0]));
|
||||||
|
unlink(str_replace(".json", ".csv", $downloadDir.'/'.$taskfiles[0]));
|
||||||
unlink($taskFilePath);
|
unlink($taskDir.'/'.$taskfiles[0]);
|
||||||
|
|
||||||
echo "Task File deleted";
|
echo "Task File deleted";
|
||||||
echo "<br>";
|
echo "<br>";
|
||||||
|
sendEmail($task['email'], str_replace(".json", ".xlsx", $downloadDir.'/'.$taskfiles[0]), $smtppassword);
|
||||||
sendEmail(
|
|
||||||
$task['email'],
|
|
||||||
$csvFilePath,
|
|
||||||
$smtppassword
|
|
||||||
);
|
|
||||||
|
|
||||||
echo "CSV sent by email";
|
|
||||||
echo "<br>";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
// acutal Time - start time
|
||||||
// actual Time - start time
|
|
||||||
echo "nothing to do after: ".strval(time() - ($latesEndTime - $maxExecutionTime));
|
echo "nothing to do after: ".strval(time() - ($latesEndTime - $maxExecutionTime));
|
||||||
echo "<br>";
|
|
||||||
echo "sleeping 10 seconds";
|
echo "sleeping 10 seconds";
|
||||||
echo "<br>";
|
echo "<br>";
|
||||||
|
|
||||||
sleep(10);
|
sleep(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue