ProductImportAddFormTrait
Import `add` action: one uploaded file plus the job settings form.
The file is moved, not copied as base64 over the bridge: with the 100 MB limit base64 + JSON in an
internal call would needlessly double the memory peak (the meta['files'] channel of
ComplaintFileUploaderTrait is designed for images of a
few MB). It goes from the dropzone temp folder to privateDir (same filesystem), and only metadata
(fileName/filePath/format) is created through the generic save() of the Admin manager. On success a
dry-run validation runs synchronously and the admin lands on edit with the finished report.
NOTE: fileName is the server-generated dropzone name ({time}_{rand}.{ext}), not the original upload
name: UploaderDropzone keeps the original name only in client JS (handleUpload() reads it just
for the extension).
Table of Contents
Properties
Methods
- onAddFormSuccess() : void
- createComponentAddForm() : Form
- createComponentImportUploader() : UploaderDropzone
- cleanupMovedImportFile() : void
- Cleans up exactly the one file that {@see moveUploadedImportFile()} moved and its random directory, and only when nothing else is in it.
- createProductImportJob() : bool
- Moves the uploaded file, creates the job and runs the dry-run validation; flashes its own errors.
- moveUploadedImportFile() : ProductImportFormat, absolutePath: string, absoluteDir: string}|null|false
- Moves the single uploaded file from the dropzone temp folder to `privateDir` (outside the webroot).
- resolveImportUploaderToken() : string|null
- runProductImportValidation() : void
- Runs the dry-run validation of the job and turns the result into a flash message. Shared by `add` (right after upload) and "validate again" in `edit`; both paths must report the same.
Properties
$uploaderDropzoneFactory
public
UploaderDropzoneFactory
$uploaderDropzoneFactory
Attributes
- #[Inject]
Methods
onAddFormSuccess()
public
onAddFormSuccess(Form $form, ArrayHash $values) : void
Parameters
- $form : Form
- $values : ArrayHash
createComponentAddForm()
protected
createComponentAddForm() : Form
Return values
FormcreateComponentImportUploader()
protected
createComponentImportUploader() : UploaderDropzone
Return values
UploaderDropzonecleanupMovedImportFile()
Cleans up exactly the one file that {@see moveUploadedImportFile()} moved and its random directory, and only when nothing else is in it.
private
cleanupMovedImportFile(array{absolutePath: string, absoluteDir: string} $moved) : void
IMPORTANT: no recursive delete on purpose. The import root (eshop/product-imports/YYYY/MM/DD) is shared
by all jobs of the day, so deleting more than the own random folder would remove files of other jobs.
Parameters
- $moved : array{absolutePath: string, absoluteDir: string}
-
only the paths created by moveUploadedImportFile()
createProductImportJob()
Moves the uploaded file, creates the job and runs the dry-run validation; flashes its own errors.
private
createProductImportJob(ArrayHash<string|int, mixed> $values) : bool
Sets $savedEntityId to the new job.
Parameters
- $values : ArrayHash<string|int, mixed>
Return values
boolmoveUploadedImportFile()
Moves the single uploaded file from the dropzone temp folder to `privateDir` (outside the webroot).
private
moveUploadedImportFile(UploaderDropzone $uploader) : ProductImportFormat, absolutePath: string, absoluteDir: string}|null|false
Returns null when no file arrived or the extension is not a supported format (the dropzone checks it
too, this is the server-side certainty about what lies on disk).
The per-format size limit (XML 100 MB, CSV/JSON 20 MB) is checked here, because the dropzone knows
only one common cap before upload; exceeding it returns false (the file is deleted from temp and
nothing is created).
Parameters
- $uploader : UploaderDropzone
Return values
ProductImportFormat, absolutePath: string, absoluteDir: string}|null|falseresolveImportUploaderToken()
private
resolveImportUploaderToken() : string|null
Return values
string|nullrunProductImportValidation()
Runs the dry-run validation of the job and turns the result into a flash message. Shared by `add` (right after upload) and "validate again" in `edit`; both paths must report the same.
private
runProductImportValidation(int $id) : void
Parameters
- $id : int