From 10946340efbe53159e74561e791235be5efe761a Mon Sep 17 00:00:00 2001 From: asajedi Date: Wed, 24 Nov 2021 04:15:52 +0100 Subject: [PATCH] Check for the TEI files list --- src/Import/Importer.php | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Import/Importer.php b/src/Import/Importer.php index bff4232..4ab6889 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.'; } } } -- GitLab