From 83bb64217f654cb67e13e58d86da1ee6baf101ae Mon Sep 17 00:00:00 2001 From: asajedi Date: Wed, 24 Nov 2021 02:00:14 +0100 Subject: [PATCH] Check for downloaded TEI file --- src/Import/Importer.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Import/Importer.php b/src/Import/Importer.php index 9188341..bff4232 100644 --- a/src/Import/Importer.php +++ b/src/Import/Importer.php @@ -30,20 +30,24 @@ class Importer implements ImporterInterface foreach ($files as $file) { if ([] !== $invalidTeiList && !in_array(trim($file['name']), $invalidTeiList)) { - $fileData = file_get_contents( - $this->gitlabProcessedTeiRepoUrl.$file['name'].'?access_token='.$this->gitlabRepoToken.'&ref=master' - ); - $fileData = json_decode($fileData, true); + $teiFileUrl = $this->gitlabProcessedTeiRepoUrl.$file['name'].'?access_token='.$this->gitlabRepoToken.'&ref=master'; + $fileData = file_get_contents($teiFileUrl); + if (is_string($fileData)) { + $fileData = json_decode($fileData, true); - try { - $filesystem->dumpFile($this->teiDir.$file['name'], base64_decode($fileData['content'])); - } catch (FileException $exception) { + try { + $filesystem->dumpFile($this->teiDir.$file['name'], base64_decode($fileData['content'])); + } catch (FileException $exception) { + echo $file['name'].' could not be imported.'; + } + } else { + // TODO retry to download the file again echo $file['name'].' could not be imported.'; } } } } catch (FileException $exception) { - echo 'Files could not be imported from gitlab'; + echo 'Files list could not be imported from gitlab'; } } } -- GitLab