diff --git a/src/Import/Importer.php b/src/Import/Importer.php index 91883413c26fb7f431d0728d248e4e7e0477b872..bff42328f2c5931efed79ad68a22c85a8b02b4ad 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'; } } }