Addendum: Schema-Defined Pre-Commit Pipeline
To make the service even more flexible and configurable, the commit process has been re-architected. It is now driven by a dynamic “pipeline” defined directly within the schema file, making the core import job a generic and reusable processor.English
1. Concept
Instead of having hardcoded logic inside theCommitImportJob (e.g., if (option === 'convert_id')), you can now specify a sequence of “pipe” classes in your schema. Each batch of imported records will be passed through every class in this sequence before it is finally saved to the database.
This powerful pattern allows for complex, custom, and reusable data transformations (like formatting names, calculating values, or validating against other systems) to be defined on a per-schema basis without ever touching the core service code.
2. Schema Update
A new required key,pre_commit_pipeline, has been added to the schema file. It must be an array of fully-qualified class names.
| Key | Description | Example |
|---|---|---|
pre_commit_pipeline | Required. An ordered array of pipe classes that data will be sent through before being saved. | pre_commit_pipeline: [FirstPipe::class, SecondPipe::class] |
user_schema.yml:
3. How to Create a Custom Pipe
Creating a new transformation step is now incredibly simple:-
Create a New Pipe Class: Create a new class, for example in
app/Services/Etl/Pipelines/. This class must implement theApp\Services\Etl\Pipelines\PreCommitPipeinterface, which requires a singlehandlemethod. -
Implement the Logic: Inside the
handlemethod, perform your transformations on the$datacollection. Crucially, you must callreturn $next($data);at the end to pass the modified data to the next pipe in the sequence.
app/Services/Etl/Pipelines/FormatUserNamePipe.php
- Add the Pipe to Your Schema: Simply add the new class to the
pre_commit_pipelinearray in your.ymlfile.
4. Developer Impact Summary
CommitImportJobis a Generic Runner: The core job is now completely agnostic of business logic. It simply reads thepre_commit_pipelinearray and executes it.- Maximum Extensibility: Adding new functionality no longer requires modifying the core service. You only need to create a new, self-contained pipe class and add it to the schema.
- Centralized Configuration: All logic for a specific import is now fully described within its schema file, making the system easier to understand and maintain.
- Frontend Options are still Used: UI options from the
EtlImportModal(likeupsertandupsert_field) are still passed to theCommitImportJob. The job uses these options to correctly configure pipes that require arguments (like theUpsertPipe).
Bahasa Indonesia
1. Konsep
Daripada memiliki logika yang di-hardcode di dalamCommitImportJob (misalnya, if (opsi === 'convert_id')), Anda sekarang dapat menentukan urutan kelas “pipe” di dalam file skema Anda. Setiap batch data yang diimpor akan dilewatkan melalui setiap kelas dalam urutan ini sebelum akhirnya disimpan ke database.
Pola yang kuat ini memungkinkan transformasi data yang kompleks, kustom, dan dapat digunakan kembali (seperti memformat nama, menghitung nilai, atau validasi terhadap sistem lain) untuk didefinisikan per skema tanpa perlu menyentuh kode inti layanan sama sekali.
2. Pembaruan Skema
Sebuah kunci baru yang wajib diisi,pre_commit_pipeline, telah ditambahkan ke file skema. Kunci ini harus berupa array yang berisi nama kelas yang fully-qualified.
| Key | Deskripsi | Contoh |
|---|---|---|
pre_commit_pipeline | Wajib Diisi. Array berurutan berisi kelas-kelas pipe yang akan dilewati data sebelum disimpan. | pre_commit_pipeline: [FirstPipe::class, SecondPipe::class] |
user_schema.yml:
3. Cara Membuat Pipe Kustom
Membuat langkah transformasi baru sekarang sangat sederhana:-
Buat Kelas Pipe Baru: Buat sebuah kelas baru, misalnya di
app/Services/Etl/Pipelines/. Kelas ini wajib mengimplementasikan interfaceApp\Services\Etl\Pipelines\PreCommitPipe, yang memerlukan satu methodhandle. -
Implementasikan Logika: Di dalam method
handle, lakukan transformasi Anda pada collection$data. Yang terpenting, Anda harus memanggilreturn $next($data);di akhir untuk meneruskan data yang telah dimodifikasi ke pipe berikutnya dalam urutan.
app/Services/Etl/Pipelines/FormatUserNamePipe.php
- Tambahkan Pipe ke Skema Anda: Cukup tambahkan kelas baru tersebut ke dalam array
pre_commit_pipelinedi file.ymlAnda.
4. Ringkasan Dampak bagi Developer
CommitImportJobMenjadi Runner Generik: Job inti sekarang sepenuhnya agnostik terhadap logika bisnis. Job ini hanya membaca arraypre_commit_pipelinedan menjalankannya.- Ekstensibilitas Maksimal: Menambahkan fungsionalitas baru tidak lagi memerlukan modifikasi pada layanan inti. Anda hanya perlu membuat kelas pipe baru yang mandiri dan menambahkannya ke skema.
- Konfigurasi Terpusat: Semua logika untuk proses impor tertentu sekarang sepenuhnya dijelaskan di dalam file skema-nya, membuat sistem lebih mudah dipahami dan dipelihara.
- Opsi Frontend Tetap Digunakan: Opsi UI dari
EtlImportModal(sepertiupsertdanupsert_field) tetap diteruskan keCommitImportJob. Job ini menggunakan opsi tersebut untuk mengkonfigurasi pipe yang memerlukan argumen (sepertiUpsertPipe) dengan benar.

