diff --git a/src/Import/Importer.php b/src/Import/Importer.php index bff42328f2c5931efed79ad68a22c85a8b02b4ad..4ab6889b418cfe0ef3d703147668d0747bd29049 100644 --- a/src/Import/Importer.php +++ b/src/Import/Importer.php @@ -26,23 +26,29 @@ class Importer implements ImporterInterface for ($i = 1; $i <= 100; ++$i) { try { $files = file_get_contents($this->gitlabRepoTreeUrl.'&access_token='.$this->gitlabRepoToken.'&page='.$i); - $files = json_decode($files, true); - foreach ($files as $file) { - if ([] !== $invalidTeiList && !in_array(trim($file['name']), $invalidTeiList)) { - $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); + if (is_string($files)) { + $files = json_decode($files, true); - try { - $filesystem->dumpFile($this->teiDir.$file['name'], base64_decode($fileData['content'])); - } catch (FileException $exception) { + foreach ($files as $file) { + if ([] !== $invalidTeiList && !in_array(trim($file['name']), $invalidTeiList)) { + $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) { + echo $file['name'].' could not be imported.'; + } + } else { + // TODO retry to download the file again echo $file['name'].' could not be imported.'; } - } else { - // TODO retry to download the file again - echo $file['name'].' could not be imported.'; } } }