mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-06-15 13:32:43 +01:00
31 lines
832 B
PHP
31 lines
832 B
PHP
<?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): ReportDto
|
|
{
|
|
/** @var ImporterContract $importer */
|
|
$importer = app(ImporterProvider::class)->getImporter($importerType);
|
|
$importer->init($organization);
|
|
DB::transaction(function () use (&$importer, &$data) {
|
|
$importer->importData($data);
|
|
});
|
|
|
|
return $importer->getReport();
|
|
}
|
|
}
|