mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-11-08 23:43:32 -05:00
Replaces the synchronous CSV import loop in Customers and Items with one queued job per row (CustomerImportJob / ItemImportJob, processed via CustomerCsvRowProcessor / ItemCsvRowProcessor). Only structural checks that would make every row's job meaningless (upload failure, missing or mismatched headers) are done in the controller; per-row validation happens in the job itself so one bad row can't block the rest of the file. ImportBatch / ImportBatchService track per-import progress so completion can be reported once all rows finish. Issue #3833 Phase 3. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
49 lines
1.2 KiB
PHP
49 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Libraries;
|
|
|
|
use App\Models\ImportBatch;
|
|
|
|
/**
|
|
* Thin wrapper around the ImportBatch model (issue #3833 Phase 3), exposed
|
|
* as service('importBatch') so controllers pushing import jobs and the jobs
|
|
* themselves share one call surface instead of reaching into the model
|
|
* directly.
|
|
*/
|
|
class ImportBatchService
|
|
{
|
|
private ImportBatch $importBatch;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->importBatch = model(ImportBatch::class);
|
|
}
|
|
|
|
/**
|
|
* Creates a new batch and returns its generated id.
|
|
*/
|
|
public function create(string $type, int $total): string
|
|
{
|
|
$batchId = uniqid('import_', true);
|
|
|
|
$this->importBatch->create($batchId, $type, $total);
|
|
|
|
return $batchId;
|
|
}
|
|
|
|
/**
|
|
* Atomically increments completed or failed for the batch.
|
|
*
|
|
* @return bool True if this call completed the batch.
|
|
*/
|
|
public function increment(string $batchId, bool $rowFailed): bool
|
|
{
|
|
return $this->importBatch->increment($batchId, $rowFailed);
|
|
}
|
|
|
|
public function purgeFinished(int $retentionDays): void
|
|
{
|
|
$this->importBatch->purgeFinished($retentionDays);
|
|
}
|
|
}
|