Skip to content

Commit da39d91

Browse files
committed
Fix seed imports
1 parent b557674 commit da39d91

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

app/Services/Eggs/Sharing/EggImporterService.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,16 @@ public function __construct(
7676
public function handle(UploadedFile $file, int $nest): Egg
7777
{
7878
if ($file->getError() !== UPLOAD_ERR_OK || ! $file->isFile()) {
79-
throw new InvalidFileUploadException(trans('exceptions.nest.importer.file_error'));
79+
throw new InvalidFileUploadException(
80+
sprintf(
81+
'The selected file ["%s"] was not in a valid format to import. (is_file: %s is_valid: %s err_code: %s err: %s)',
82+
$file->getFilename(),
83+
$file->isFile() ? 'true' : 'false',
84+
$file->isValid() ? 'true' : 'false',
85+
$file->getError(),
86+
$file->getErrorMessage()
87+
)
88+
);
8089
}
8190

8291
$parsed = json_decode($file->openFile()->fread($file->getSize()));

app/Services/Eggs/Sharing/EggUpdateImporterService.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,16 @@ public function __construct(
5757
public function handle(int $egg, UploadedFile $file)
5858
{
5959
if ($file->getError() !== UPLOAD_ERR_OK || ! $file->isFile()) {
60-
throw new InvalidFileUploadException(trans('exceptions.nest.importer.file_error'));
60+
throw new InvalidFileUploadException(
61+
sprintf(
62+
'The selected file ["%s"] was not in a valid format to import. (is_file: %s is_valid: %s err_code: %s err: %s)',
63+
$file->getFilename(),
64+
$file->isFile() ? 'true' : 'false',
65+
$file->isValid() ? 'true' : 'false',
66+
$file->getError(),
67+
$file->getErrorMessage()
68+
)
69+
);
6170
}
6271

6372
$parsed = json_decode($file->openFile()->fread($file->getSize()));

database/seeds/EggSeeder.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,15 @@ private function parseEggFiles(Nest $nest)
112112
$files = $this->filesystem->allFiles(database_path('seeds/eggs/' . kebab_case($nest->name)));
113113

114114
$this->command->alert('Updating Eggs for Nest: ' . $nest->name);
115-
collect($files)->each(function ($file) use ($nest) {
115+
Collection::make($files)->each(function ($file) use ($nest) {
116116
/* @var \Symfony\Component\Finder\SplFileInfo $file */
117117
$decoded = json_decode($file->getContents());
118118
if (json_last_error() !== JSON_ERROR_NONE) {
119-
return $this->command->error('JSON decode exception for ' . $file->getFilename() . ': ' . json_last_error_msg());
119+
$this->command->error('JSON decode exception for ' . $file->getFilename() . ': ' . json_last_error_msg());
120+
return;
120121
}
121122

122-
$file = new UploadedFile($file->getPathname(), $file->getFilename(), 'application/json', $file->getSize());
123+
$file = new UploadedFile($file->getPathname(), $file->getFilename(), 'application/json');
123124

124125
try {
125126
$egg = $this->repository->setColumns('id')->findFirstWhere([
@@ -130,11 +131,11 @@ private function parseEggFiles(Nest $nest)
130131

131132
$this->updateImporterService->handle($egg->id, $file);
132133

133-
return $this->command->info('Updated ' . $decoded->name);
134+
$this->command->info('Updated ' . $decoded->name);
134135
} catch (RecordNotFoundException $exception) {
135136
$this->importerService->handle($file, $nest->id);
136137

137-
return $this->command->comment('Created ' . $decoded->name);
138+
$this->command->comment('Created ' . $decoded->name);
138139
}
139140
});
140141

0 commit comments

Comments
 (0)