ikinci temizlik tamamlandı
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
# PDF Upload ve Senkronizasyon Entegrasyon Rehberi / PDF Upload and Synchronization Integration Guide
|
||||
|
||||
Bu rehber, herhangi bir modüle PDF dosya yükleme özelliği ve otomatik veritabanı eşleştirme (sync) altyapısının nasıl ekleneceğini açıklar.
|
||||
This guide explains how to add PDF file upload functionality and automatic database synchronization infrastructure to any module.
|
||||
|
||||
## Genel Bakış / Overview
|
||||
|
||||
Sistem, yüklenen PDF dosyalarını isimlendirme kurallarına göre veritabanındaki kayıtlarla otomatik olarak eşleştirir. İşlem 4 ana adımdan oluşur:
|
||||
The system automatically matches uploaded PDF files with database records based on naming conventions. The process consists of 4 main steps:
|
||||
|
||||
1. **Database Migration**: `download` sütununun eklenmesi.
|
||||
2. **Module View**: Arayüze yükleme butonu ve indirme linkinin eklenmesi.
|
||||
3. **Upload Handler**: Dosya yüklendiğinde çalışacak tetikleyicinin (trigger) tanımlanması.
|
||||
4. **Sync Script**: Dosya adı ile veritabanı kaydını eşleştiren mantığın kurulması.
|
||||
|
||||
---
|
||||
|
||||
## Adım 1: Veritabanı Migration / Database Migration
|
||||
|
||||
İlgili modülün tablosuna `download` sütunu eklenmelidir.
|
||||
Add a `download` column to the module's table.
|
||||
|
||||
```bash
|
||||
php artisan make:migration add_download_to_itps_table --table=i_t_p_s
|
||||
```
|
||||
|
||||
```php
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('i_t_p_s', function (Blueprint $table) {
|
||||
$table->string('download')->nullable();
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
## Adım 2: Modül Arayüzü / Module View
|
||||
|
||||
`resources/views/admin/type/{module}.blade.php` dosyasını düzenleyin.
|
||||
Edit the module's blade file.
|
||||
|
||||
### a. Sütun Tanımı / Column Definition
|
||||
`$relationDatas` dizisine `download` alanını ekleyin.
|
||||
Add the `download` field to `$relationDatas`.
|
||||
|
||||
```php
|
||||
$relationDatas = [
|
||||
'download' => [
|
||||
'type' => 'link-search',
|
||||
'html' => '<i class="fa fa-pdf"></i>'
|
||||
],
|
||||
// ...
|
||||
];
|
||||
```
|
||||
|
||||
### b. Blok Grubu / Block Group
|
||||
`$blockGroup` dizisinde uygun yere (genellikle 'General Info') ekleyin.
|
||||
Add to `$blockGroup` array.
|
||||
|
||||
### c. Yükleme Ayarları / Upload Configuration
|
||||
Dosyanın en altına, PHP bloğunun içine yükleme ayarlarını ekleyin.
|
||||
Add upload settings inside the PHP block.
|
||||
|
||||
```php
|
||||
$firstUploadFolder = '004_QA/000_ITP/'; // Hedef klasör / Target folder
|
||||
$firstUploadTitle = 'Upload PDF';
|
||||
$uploadPermissionKey = 'itp_upload_permission';
|
||||
```
|
||||
|
||||
### d. Include Upload Component
|
||||
Sayfanın HTML kısmına upload bileşenini dahil edin.
|
||||
Include the upload component in the HTML section.
|
||||
|
||||
```php
|
||||
<div class="content">
|
||||
<div class="row">
|
||||
@include("admin.type.document.upload") <!-- Add this line -->
|
||||
@include("components.blocks.module-block")
|
||||
</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
## Adım 3: Yükleme İşleyicisi / Upload Handler
|
||||
|
||||
`resources/views/admin-ajax/document-upload.blade.php` dosyasını açın ve modülünüz için bir koşul ekleyin.
|
||||
Open `document-upload.blade.php` and add a condition for your module.
|
||||
|
||||
```php
|
||||
if ($tableName == "i_t_p_s") { // Tablo adı / Table name
|
||||
?>
|
||||
@include("cron.pdf-db-itp-sync", [
|
||||
"fileName" => $onlyFileName
|
||||
])
|
||||
<?php
|
||||
}
|
||||
```
|
||||
|
||||
## Adım 4: Senkronizasyon Betiği / Sync Script
|
||||
|
||||
`resources/views/cron/pdf-db-{module}-sync.blade.php` dosyasını oluşturun. Bu dosya eşleştirme mantığını içerir.
|
||||
Create the sync script file. This file contains the matching logic.
|
||||
|
||||
**Örnek / Example (ITP):**
|
||||
|
||||
```php
|
||||
<?php
|
||||
$table = "i_t_p_s";
|
||||
$mainPath = "004_QA/000_ITP";
|
||||
$nullDownload = db($table);
|
||||
|
||||
// Tek dosya yüklendiğinde filtreleme / Filtering when single file uploaded
|
||||
if(isset($fileName)) {
|
||||
// Eşleşecek sütun (örn: itp_no) / Matching column (e.g. itp_no)
|
||||
$nullDownload = $nullDownload->where("itp_no", $fileName);
|
||||
$commitSize = 1;
|
||||
}
|
||||
|
||||
$nullDownload = $nullDownload->get();
|
||||
|
||||
DB::beginTransaction();
|
||||
// ... (Standart döngü ve update işlemi / Standard loop and update process)
|
||||
// Detaylar için mevcut sync dosyalarına bakınız / See existing sync files for details
|
||||
?>
|
||||
```
|
||||
|
||||
## İpuçları / Tips
|
||||
|
||||
- **Wildcard Matching**: Dosya adlarında `/` veya boşluk gibi karakterler farklılık gösterebilir. Sync scriptinde `str_replace` kullanarak bunları `*` ile değiştirmek eşleştirme başarısını artırır.
|
||||
- **Permission**: `uploadPermissionKey` tanımlamayı unutmayın, aksi halde yetki hatası alabilirsiniz.
|
||||
|
||||
Reference in New Issue
Block a user