Cms\Classes\Asset\HasOperations
Overview
HasOperations implements editor-side CRUD operations against a CMS theme's assets directory. Pulled out of Editor\Traits\FileSystemFunctions so the Asset class is the single seam for any future cross-cutting concerns (shared storage publishing, audit logging, events, etc.).
Consuming class must provide a {@link \Cms\Classes\Theme} via $this->theme and an "assets" subdirectory name via $this->dirName.
Public Methods
public createDirectory()
public createDirectory($newName, $parent): void
createDirectory creates a directory under a parent path within the assets root.
public deletePaths()
public deletePaths($fileList): void
deletePaths removes the given list of files or directories under the assets root. Directories must be empty.
public move()
public move($selectedList, $destinationDir): void
move relocates a list of files or directories into a destination directory under the assets root.
public rename()
public rename($newName, $originalPath): void
rename renames a single file or directory within the assets root.
public upload()
public upload($uploadedFile, $destinationDir): void
upload accepts a single uploaded file into a destination directory under the theme's assets root. SVG content is sanitised before being written.
Protected Methods
protected assertNoDatabaseCollision()
protected assertNoDatabaseCollision(
$source,
$basePath,
$newPath,
$name = null
): void
assertNoDatabaseCollision throws when the target path is already occupied by an active row or an unsuppressed filesystem file.
protected assertNotRenamingToVector()
protected assertNotRenamingToVector(
$newName,
$originalPath,
$allowedExtensions
): void
assertNotRenamingToVector blocks renaming a non-svg file to svg, since only uploads pass through the vector sanitizer.
protected deletePathsWithDatabase()
protected deletePathsWithDatabase($fileList): void
deletePathsWithDatabase deletes against the database layer, removing assets disk objects and tombstoning rows.
protected getOperationBasePath()
protected getOperationBasePath(): string
getOperationBasePath returns the absolute path to the theme's assets directory, used as the root for all operations.
protected getOperationExtensions()
protected getOperationExtensions(): array
getOperationExtensions returns allowed extensions for upload/rename operations. Includes all asset types defined in the asset definitions, with preprocessor types removed when safe mode is enabled.
protected listTransferablePathsUnderPrefix()
protected listTransferablePathsUnderPrefix($prefix): array
listTransferablePathsUnderPrefix returns the union of active row paths and unsuppressed filesystem file paths beneath a directory prefix.
protected moveWithDatabase()
protected moveWithDatabase($selectedList, $destinationDir): void
moveWithDatabase relocates files and directories against the database layer and the assets disk, re-keying directory contents the same way as renameWithDatabase.
protected normalizeOperationPath()
protected normalizeOperationPath($path): string
normalizeOperationPath produces the canonical relative path used as the SourceFile path key, matching the normalization in Asset::getInternal().
protected renameWithDatabase()
protected renameWithDatabase($newName, $originalPath): void
renameWithDatabase performs a rename against the database layer and the assets disk. Directory renames re-key every file beneath the prefix so shipped assets keep working at their new URLs across all instances, leaving the local filesystem untouched.
protected transferPathWithDatabase()
protected transferPathWithDatabase(
$oldPath,
$newPath,
&$invalidatePaths
): void
transferPathWithDatabase re-keys a single file from one path to another: bytes land at the new disk key, the old row is tombstoned and its disk object removed. Inline rows (directory placeholders) stay inline and touch no disk objects.
protected validateOperationFileExtension()
protected validateOperationFileExtension($name, $allowedExtensions): bool
validateOperationFileExtension checks a filename against the allowed extension list.
protected validateOperationName()
protected validateOperationName($name): bool
validateOperationName ensures a single file or directory name contains only safe characters.
protected validateOperationPath()
protected validateOperationPath($path): bool
validateOperationPath ensures a relative path does not escape the assets root or contain unsafe characters.