Files Managements
Introduction
The file management feature used by the ImageUploader component relies on various tables to support the file upload process. These tables—system_files
, deferred_bindings
, and activities
—play critical roles in managing file uploads. Models within the system, such as the Student model (for photos, passports, transcripts, diplomas, etc.) and the Institution model (for photos), establish numerous relationships with files. The functionality and purpose of each table's columns will be elaborated upon in subsequent sections.
Tables
The related tabels in files management are system_files
, deferred_bindings
, and activities
.
system_files
The system_files
table employs the following columns:
- id: An incremental integer serving as the primary key.
- disk_name: Stores the file's name on the server's disk.
- file_name: Holds the actual name of the file uploaded by the user.
- file_size: The file's size.
- content_type: The MIME type of the file, e.g., application/pdf, image/png.
- title: A deprecated column, no longer in use.
- description: Another deprecated column, no longer in use.
- field: Indicates the file type, e.g., photo, passport, diploma.
- attachment_id & attachment_type: Columns for a polymorphic relationship.
- is_public: Determines the file's visibility.
- sort_order: Orders the files.
- created_by: The ID of the user who uploaded the file.
- created_at: Timestamp of the file upload.
- updated_at: Timestamp of the last file update.
- deleted_at: Soft delete column, marking when the file was deleted.
- external_id: For CRM integration, indicating files synced from another system.
deferred_bindings
The deferred_bindings
table is used in OTAS to manage files uploaded through the component that stores files in the System\Models\File
model within the system_files
table, especially before the related model is created. This mechanism ensures files are tracked and associated with the correct model upon its creation, based on the session ID. The table's structure includes:
- id: An incremental integer as the primary key.
- master_type: Specifies the model name that will be attached to the file after the model's database entry is created.
-
master_field: Denotes the file type (e.g., photo, passport, diploma), mirroring the
field
column in thesystem_files
table. -
slave_type & slave_id: Polymorphic relationship columns, typically linked to the
System\Models\File
model in OTAS. - session_key: The session key of the user creating the model and uploading the files.
- is_bind: A boolean flag indicating whether the files have been bound to the model.
- created_at: Timestamp for when the record was created.
- updated_at: Timestamp for the last update to the record.
activities
The activities
table is utilized to track modifications within the data, primarily focusing on logging all changes related to files. The columns in the activities
table include:
- id: An incremental integer serving as the primary key.
- user_id: The ID of the user responsible for the change.
- subject_id & subject_type: Polymorphic relationship columns that reference the model affected by the change.
-
type: Specifies the nature of the change, such as
file_updating
,file_deleted
, etc. - created_at: The timestamp indicating when the record was created.
-
updated_at: The timestamp for the last update; typically mirrors
created_at
since the historical record remains unchanged. - changes: A JSON column detailing the modifications in a {before: {}, after: {}} format, showcasing data before and after the change.
- meta: A JSON column providing metadata about the file change, including model name and ID, in a format like: {"attachment_id":"1","attachment_type":"SpotlayerTeam\InstitutionsPrograms\Models\Student"}.
-
description: Describes the change with messages such as
File has been updated
,File has been deleted
, etc.