Store copy of import data on private disk for debugging

Re-adds the copy of the import data that was removed in 70646a0d. Every import stores its raw data in import/{date}-{organizationId}-{uuid} on the private disk.
This commit is contained in:
Constantin Graf
2026-10-14 10:30:53 +02:00
committed by Constantin Graf
parent 65525791a6
commit 0b2a417788
2 changed files with 13 additions and 4 deletions

View File

@@ -9,8 +9,11 @@ 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\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
class ImportService
{
@@ -22,6 +25,8 @@ class ImportService
/** @var ImporterContract $importer */
$importer = app(ImporterProvider::class)->getImporter($importerType);
$importer->init($organization);
Storage::disk(config('filesystems.private'))
->put('import/'.Carbon::now()->toDateString().'-'.$organization->getKey().'-'.Str::uuid(), $data);
$lock = Cache::lock('import:'.$organization->getKey(), config('octane.max_execution_time', 60) + 1);

View File

@@ -9,6 +9,7 @@ use App\Service\Import\Importers\ImporterProvider;
use App\Service\Import\Importers\ImportException;
use App\Service\Import\ImportService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage;
use PHPUnit\Framework\Attributes\CoversClass;
@@ -23,7 +24,7 @@ class ImportServiceTest extends TestCase
public function test_import_gets_importer_from_provider_runs_importer_and_returns_report(): void
{
// Arrange
Storage::fake(config('filesystems.default'));
Storage::fake(config('filesystems.private'));
$organization = Organization::factory()->create();
$timezone = 'Europe/Vienna';
$data = Storage::disk('testfiles')->get('toggl_time_entries_import_test_1.csv');
@@ -41,13 +42,16 @@ class ImportServiceTest extends TestCase
$this->assertSame(1, $report->usersCreated);
$this->assertSame(2, $report->projectsCreated);
$this->assertSame(1, $report->clientsCreated);
Storage::disk(config('filesystems.default'))->assertDirectoryEmpty('import');
$storedFiles = Storage::disk(config('filesystems.private'))->files('import');
$this->assertCount(1, $storedFiles);
$this->assertStringStartsWith('import/'.Carbon::now()->toDateString().'-'.$organization->getKey().'-', $storedFiles[0]);
$this->assertSame($data, Storage::disk(config('filesystems.private'))->get($storedFiles[0]));
}
public function test_import_releases_lock_if_an_exception_happens_during_the_import(): void
{
// Arrange
Storage::fake(config('filesystems.default'));
Storage::fake(config('filesystems.private'));
$organization = Organization::factory()->create();
$timezone = 'Europe/Vienna';
$data = 'Invalid CSV data';
@@ -66,7 +70,7 @@ class ImportServiceTest extends TestCase
public function test_import_throws_exception_if_import_is_already_in_progress(): void
{
// Arrange
Storage::fake(config('filesystems.default'));
Storage::fake(config('filesystems.private'));
$organization = Organization::factory()->create();
$timezone = 'Europe/Vienna';
$data = Storage::disk('testfiles')->get('toggl_time_entries_import_test_1.csv');