Updates
This commit is contained in:
parent
05c4610654
commit
ac3a36e489
@ -35,17 +35,19 @@ class ListEggs extends ListRecords
|
|||||||
/** @var EggImporterService $eggImportService */
|
/** @var EggImporterService $eggImportService */
|
||||||
$eggImportService = resolve(EggImporterService::class);
|
$eggImportService = resolve(EggImporterService::class);
|
||||||
|
|
||||||
try {
|
foreach ($eggFile as $file) {
|
||||||
$eggImportService->handle($eggFile);
|
try {
|
||||||
} catch (Exception $exception) {
|
$eggImportService->handle($file);
|
||||||
Notification::make()
|
} catch (Exception $exception) {
|
||||||
->title('Egg Import Failed')
|
Notification::make()
|
||||||
->danger()
|
->title('Egg Import Failed')
|
||||||
->send();
|
->danger()
|
||||||
|
->send();
|
||||||
|
|
||||||
report($exception);
|
report($exception);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Notification::make()
|
Notification::make()
|
||||||
|
@ -5,6 +5,7 @@ namespace App\Services\Eggs\Sharing;
|
|||||||
use Ramsey\Uuid\Uuid;
|
use Ramsey\Uuid\Uuid;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use App\Models\Egg;
|
use App\Models\Egg;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
use App\Models\EggVariable;
|
use App\Models\EggVariable;
|
||||||
use Illuminate\Database\ConnectionInterface;
|
use Illuminate\Database\ConnectionInterface;
|
||||||
use App\Services\Eggs\EggParserService;
|
use App\Services\Eggs\EggParserService;
|
||||||
@ -20,31 +21,25 @@ class EggImporterService
|
|||||||
*
|
*
|
||||||
* @throws \App\Exceptions\Service\InvalidFileUploadException|\Throwable
|
* @throws \App\Exceptions\Service\InvalidFileUploadException|\Throwable
|
||||||
*/
|
*/
|
||||||
public function handle(array $files): array
|
public function handle(UploadedFile $file): Egg
|
||||||
{
|
{
|
||||||
$eggs = [];
|
$parsed = $this->parser->handle($file);
|
||||||
|
|
||||||
foreach ($files as $file) {
|
return $this->connection->transaction(function () use ($parsed) {
|
||||||
$parsed = $this->parser->handle($file);
|
$egg = (new Egg())->forceFill([
|
||||||
|
'uuid' => Uuid::uuid4()->toString(),
|
||||||
|
'author' => Arr::get($parsed, 'author'),
|
||||||
|
'copy_script_from' => null,
|
||||||
|
]);
|
||||||
|
|
||||||
$egg = $this->connection->transaction(function () use ($parsed) {
|
$egg = $this->parser->fillFromParsed($egg, $parsed);
|
||||||
$egg = (new Egg())->forceFill([
|
$egg->save();
|
||||||
'uuid' => Uuid::uuid4()->toString(),
|
|
||||||
'author' => Arr::get($parsed, 'author'),
|
|
||||||
'copy_script_from' => null,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$egg = $this->parser->fillFromParsed($egg, $parsed);
|
foreach ($parsed['variables'] ?? [] as $variable) {
|
||||||
$egg->save();
|
EggVariable::query()->forceCreate(array_merge($variable, ['egg_id' => $egg->id]));
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($parsed['variables'] ?? [] as $variable) {
|
return $egg;
|
||||||
EggVariable::query()->forceCreate(array_merge($variable, ['egg_id' => $egg->id]));
|
});
|
||||||
}
|
|
||||||
|
|
||||||
return $egg;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return $eggs;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user