mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-11 01:32:16 +01:00
Added import system
This commit is contained in:
30
app/Service/Import/ImportService.php
Normal file
30
app/Service/Import/ImportService.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Import;
|
||||
|
||||
use App\Models\Organization;
|
||||
use App\Service\Import\Importers\ImporterContract;
|
||||
use App\Service\Import\Importers\ImporterProvider;
|
||||
use App\Service\Import\Importers\ImportException;
|
||||
use App\Service\Import\Importers\ReportDto;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ImportService
|
||||
{
|
||||
/**
|
||||
* @throws ImportException
|
||||
*/
|
||||
public function import(Organization $organization, string $importerType, string $data, array $options): ReportDto
|
||||
{
|
||||
/** @var ImporterContract $importer */
|
||||
$importer = app(ImporterProvider::class)->getImporter($importerType);
|
||||
$importer->init($organization);
|
||||
DB::transaction(function () use (&$importer, &$data, &$options, &$organization) {
|
||||
$importer->importData($data, $options);
|
||||
});
|
||||
|
||||
return $importer->getReport();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user