Files
opensourcepos/app/Libraries/ImportBatchService.php
T
objecttothisandClaude Sonnet 5 bffeeb117a feat(customers,items): queue CSV imports as background jobs
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>
2026-09-24 20:00:34 +04:00

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);
}
}