CoolCMS API

ComplaintFileTrait

Multi-upload of complaint attachments.

Simplified from AdvertAssetTrait::processFiles(): only a File entity plus a relation, without the asset/image-variant machinery. A file collection does not use AssetPathTrait (it covers a single string path only).

Files live in a private directory outside the web root (params.4.eshopComplaintDir) and are served through a controlled admin action, never a public URL.

Requires $paramsConfig (BaseManager decorator), $fileManager (System FileManager) and updateColumn() / updateAllRelations() (SaveTrait).

Table of Contents

Constants

MAX_FILE_SIZE  : int = 5 * 1024 * 1024
MAX_FILES  : int = 5
Attachment limits per complaint.

Properties

$pendingComplaintDirs  : array<int, string>
Attachment directories created by this save (deleted when they stay empty).
$pendingComplaintFiles  : array<int, string>
Absolute paths of files written during the currently running complaint save.

Methods

rejectionReasonForNewFiles()  : string|null
Pre-write guard for new attachments, called by {@see \App\UI\Api\Eshop\Models\Managers\ComplaintManager::submitForUser()}.
complaintAssetDir()  : string
complaintFilesWriteResult()  : Result|null
Returns a failure for `afterSave()` (rollback) when the relation write failed, `null` on success.
discardPendingComplaintFiles()  : void
Deletes files (and empty directories) written by the running save; called when it fails.
forgetPendingComplaintFiles()  : void
The save finished (success) or was already cleaned up: files stop being pending.
processComplaintFiles()  : Result|null
Processes the ordered attachment list (existing and new items in one array).
writeComplaintFiles()  : Result|null

Constants

Properties

$pendingComplaintDirs

Attachment directories created by this save (deleted when they stay empty).

private array<int, string> $pendingComplaintDirs = []

$pendingComplaintFiles

Absolute paths of files written during the currently running complaint save.

private array<int, string> $pendingComplaintFiles = []

A transaction rollback does not touch the disk, so when the save fails after a file was written, self::discardPendingComplaintFiles() deletes them; otherwise private/ would keep files with no row in cms_system_files. Emptied by ComplaintManager::save() on success.

Methods

rejectionReasonForNewFiles()

Pre-write guard for new attachments, called by {@see \App\UI\Api\Eshop\Models\Managers\ComplaintManager::submitForUser()}.

public rejectionReasonForNewFiles(array<int, array<int|string, mixed>> $newFiles) : string|null

Runs on the whole list before the complaint is persisted so one bad file rejects the entire submit (no partial write). Returns null when all is fine, otherwise a ResultCode name (FILE_TYPE_NOT_ALLOWED / VALIDATION_FAILED).

An item carries data (base64) or path (file in the dropzone temp directory, internal calls only). Content is read one file at a time by Manager::readUploadedItem(); for path the size is checked with filesize() before reading.

Parameters
$newFiles : array<int, array<int|string, mixed>>

bridge payload, untrusted input

Return values
string|null

complaintAssetDir()

private complaintAssetDir(string $type) : string
Parameters
$type : string
Return values
string

complaintFilesWriteResult()

Returns a failure for `afterSave()` (rollback) when the relation write failed, `null` on success.

private complaintFilesWriteResult(Result $result) : Result|null
Parameters
$result : Result
Return values
Result|null

discardPendingComplaintFiles()

Deletes files (and empty directories) written by the running save; called when it fails.

private discardPendingComplaintFiles() : void

Best-effort: what cannot be deleted is logged (cleanup must not mask the original error).

forgetPendingComplaintFiles()

The save finished (success) or was already cleaned up: files stop being pending.

private forgetPendingComplaintFiles() : void

processComplaintFiles()

Processes the ordered attachment list (existing and new items in one array).

private processComplaintFiles(Complaint &$entity, array<int, array{type: string, fileId?: int, name?: string, data?: string, path?: string, order?: int}> $orderedFiles) : Result|null

Item shape: {type: 'existing', fileId, order} or {type: 'new', name, data|path, order}. Returns null when everything is stored, otherwise a failure that ComplaintManager::afterSave() propagates so SaveTrait rolls back the whole complaint; a bad new attachment or failed File save must never leave a confirmed complaint without its attachment. Files written by this call are deleted at once on failure or exception (the exception propagates); on a later save failure ComplaintManager::save() deletes them.

Parameters
$entity : Complaint
$orderedFiles : array<int, array{type: string, fileId?: int, name?: string, data?: string, path?: string, order?: int}>
Return values
Result|null

writeComplaintFiles()

private writeComplaintFiles(Complaint $entity, int $complaintId, array<int, array{type: string, fileId?: int, name?: string, data?: string, path?: string, order?: int}> $orderedFiles) : Result|null
Parameters
$entity : Complaint
$complaintId : int
$orderedFiles : array<int, array{type: string, fileId?: int, name?: string, data?: string, path?: string, order?: int}>
Return values
Result|null
On this page

Search results