Refactor: Create shared AttachmentService and AttachmentModel

- Created common AttachmentService for all modules (app/Services/)
- Created common AttachmentModel (app/Models/)
- Created common migration (app/Database/Migrations/)
- Updated Tasks module to use shared AttachmentService
- Added Twig functions: format_filesize(), get_file_icon()
- Removed duplicate TaskAttachmentModel and task_attachments migration
- AttachmentService can be used by any module: task, deal, contact, etc.
This commit is contained in:
2026-02-08 20:34:11 +00:00
parent 9c4aacefbe
commit 052560c9b4
7 changed files with 226 additions and 74 deletions
@@ -4,7 +4,7 @@ namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateTaskAttachmentsTable extends Migration
class CreateAttachmentsTable extends Migration
{
public function up()
{
@@ -15,10 +15,15 @@ class CreateTaskAttachmentsTable extends Migration
'unsigned' => true,
'auto_increment' => true,
],
'task_id' => [
'entity_type' => [
'type' => 'VARCHAR',
'constraint' => 50,
'null' => false,
'comment' => 'Тип сущности: task, deal, contact, etc.',
],
'entity_id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'null' => false,
],
'file_name' => [
@@ -57,14 +62,14 @@ class CreateTaskAttachmentsTable extends Migration
]);
$this->forge->addKey('id', true);
$this->forge->addKey('task_id');
$this->forge->addForeignKey('task_id', 'tasks', 'id', '', 'CASCADE');
$this->forge->addKey(['entity_type', 'entity_id']);
$this->forge->addKey('uploaded_by');
$this->forge->createTable('task_attachments');
$this->forge->createTable('attachments');
}
public function down()
{
$this->forge->dropTable('task_attachments');
$this->forge->dropTable('attachments');
}
}