feat: add initial database schema migration for project core tables
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
|
||||
|
||||
<?php
|
||||
$email = post("email");
|
||||
$password = post("password");
|
||||
if (Auth::attempt(array('email' => $email, 'password' => $password))){
|
||||
// echo "Kullanıcı girişiniz başarılı. \n";
|
||||
} else {
|
||||
|
||||
print2($_POST);
|
||||
echo "Kullanıcı adı veya şifreniz yanlış. Lütfen tekrar deneyiniz. \n";
|
||||
exit();
|
||||
}
|
||||
if(getisset("route")) {
|
||||
$route = get("route");
|
||||
?>
|
||||
@if(View::exists("api.$route"))
|
||||
@include("api.$route")
|
||||
@else
|
||||
Geçerli bir yönlendirici bulunamadı
|
||||
@endif
|
||||
<?php
|
||||
} ?>
|
||||
@@ -1,93 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
set_time_limit(-1);
|
||||
ini_set('max_execution_time', -1);
|
||||
$cronjobDocumentsPeriod = setting('cron_job_period');
|
||||
$oneMinuteAgo = Carbon::now()->subMinutes($cronjobDocumentsPeriod);
|
||||
$take = setting('cron_job_batch_process_count');
|
||||
$saat = date("H:i");
|
||||
|
||||
if(!getesit("type","")) {
|
||||
Cache::forget("cronjobDocuments");
|
||||
}
|
||||
|
||||
if(!getisset("type"))
|
||||
{
|
||||
exit();
|
||||
}
|
||||
if($saat == "00:00")
|
||||
{
|
||||
Cache::forget("cronjob");
|
||||
dump("forget cronjobDocuments");
|
||||
}
|
||||
|
||||
if(!Cache::has("cronjobDocuments")) {
|
||||
$start = new Carbon(simdi());
|
||||
|
||||
Cache::put("cronjobDocuments", simdi());
|
||||
|
||||
Log::debug("🟢📂 cron document start: " . simdi());
|
||||
|
||||
$allFiles = glob(base_path() . '/resources/views/cron-documents/*.blade.php');
|
||||
$total = count($allFiles);
|
||||
$count = 0;
|
||||
|
||||
try {
|
||||
?>
|
||||
@if(!getesit("type",""))
|
||||
@includeIf('cron-documents.' . get("type"))
|
||||
@else
|
||||
@foreach ($allFiles as $file)
|
||||
|
||||
<?php
|
||||
|
||||
$description = $file;
|
||||
$description = str_replace(".blade.php", "", $description);
|
||||
|
||||
Cache::put("cronjob_document_progress", [
|
||||
'total' => $total,
|
||||
'count' => $count,
|
||||
'progress' => round($count * 100 / $total),
|
||||
'description' => $description,
|
||||
'start' => simdi()
|
||||
|
||||
]);
|
||||
|
||||
$count++;
|
||||
?>
|
||||
|
||||
@include('cron-documents.' . basename(str_replace('.blade.php', '', $file)))
|
||||
@endforeach
|
||||
@endif
|
||||
<?php
|
||||
} catch (\Throwable $th) {
|
||||
//throw $th;
|
||||
dump($th);
|
||||
Log::error("cron documents");
|
||||
Log::error($th->getMessage());
|
||||
Cache::forget("cronjobDocuments");
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
<?php
|
||||
$end = new Carbon(simdi());
|
||||
|
||||
Cache::put("cronjob_document_progress", [
|
||||
'total' => $total,
|
||||
'count' => $total,
|
||||
'progress' => 100,
|
||||
'description' => "finish " . simdi() . " " . $start->diff($end)->format('%H:%I:%S')
|
||||
|
||||
]);
|
||||
|
||||
Log::debug("🔴📂 cron document finish: " . simdi());
|
||||
Log::debug("⏰📂 süre: " . $start->diff($end)->format('%H:%I:%S'));
|
||||
Cache::forget("cronjobDocuments");
|
||||
|
||||
} else {
|
||||
dump("Çalışan bir cron var onun bitmesini bekliyorum");
|
||||
Log::debug("Çalışan bir cron documents var onun bitmesini bekliyorum");
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
<?php
|
||||
if(!Cache::has("register-creator-cronjob")) {
|
||||
|
||||
Cache::put("register-creator-cronjob", simdi());
|
||||
$queue = Cache::get("register-creator-queue");
|
||||
if(!is_null($queue)) {
|
||||
|
||||
dump("Register Creator başladı");
|
||||
foreach($queue AS $queueId => &$data) {
|
||||
try {
|
||||
$_POST = $data;
|
||||
?>
|
||||
@include("admin-ajax.pdf.register-creator")
|
||||
<?php
|
||||
$subject = "$queueId Register Creator Job Completed!";
|
||||
$body = "Dear {$data['user']->name} {$data['user']->surname},
|
||||
$queueId register creator job has been completed.
|
||||
";
|
||||
|
||||
|
||||
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
$subject = "$queueId Register Creator Job Not Completed!";
|
||||
$body = "Dear {$data['user']->name} {$data['user']->surname},
|
||||
$queueId register creator job not completed. Error detail there 👇
|
||||
{$th->getMessage()}
|
||||
";
|
||||
Log::error($body);
|
||||
dump($body);
|
||||
}
|
||||
|
||||
|
||||
mailSend($data['user']->email, $subject, $body);
|
||||
|
||||
|
||||
|
||||
$lastQueue = Cache::get("register-creator-queue");
|
||||
unset($lastQueue[$queueId]);
|
||||
Cache::put("register-creator-queue", $lastQueue);
|
||||
|
||||
|
||||
}
|
||||
//dump("Register Creator bitti");
|
||||
} else {
|
||||
//dump("Register Creator işi yok bekliyorum...");
|
||||
}
|
||||
|
||||
|
||||
Cache::forget("register-creator-cronjob");
|
||||
|
||||
|
||||
} else {
|
||||
dump("Register Creator Job çalışıyor bitmesini bekliyorum");
|
||||
dump(Cache::get("register-creator-cronjob"));
|
||||
}
|
||||
|
||||
|
||||
if(!Cache::has("tp-creator-cronjob")) {
|
||||
|
||||
Cache::put("tp-creator-cronjob", simdi());
|
||||
$queue = Cache::get("tp-creator-queue");
|
||||
if(!is_null($queue)) {
|
||||
|
||||
dump("Register Creator başladı");
|
||||
foreach($queue AS $queueId => &$data) {
|
||||
try {
|
||||
$_POST = $data;
|
||||
?>
|
||||
@include("admin-ajax.pdf.tp-register-creator")
|
||||
<?php
|
||||
$subject = "$queueId Register Creator Job Completed!";
|
||||
$body = "Dear {$data['user']->name} {$data['user']->surname},
|
||||
$queueId register creator job has been completed.
|
||||
";
|
||||
|
||||
|
||||
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
$subject = "$queueId Register Creator Job Not Completed!";
|
||||
$body = "Dear {$data['user']->name} {$data['user']->surname},
|
||||
$queueId register creator job not completed. Error detail there 👇
|
||||
{$th->getMessage()}
|
||||
";
|
||||
Log::error($body);
|
||||
dump($body);
|
||||
}
|
||||
|
||||
|
||||
mailSend($data['user']->email, $subject, $body);
|
||||
|
||||
|
||||
|
||||
$lastQueue = Cache::get("tp-creator-queue");
|
||||
unset($lastQueue[$queueId]);
|
||||
Cache::put("tp-creator-queue", $lastQueue);
|
||||
|
||||
|
||||
}
|
||||
dump("Register Creator bitti");
|
||||
} else {
|
||||
dump("Register Creator işi yok bekliyorum...");
|
||||
}
|
||||
|
||||
|
||||
Cache::forget("tp-creator-cronjob");
|
||||
|
||||
|
||||
} else {
|
||||
dump("Register Creator Job çalışıyor bitmesini bekliyorum");
|
||||
dump(Cache::get("tp-creator-cronjob"));
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@@ -1,373 +0,0 @@
|
||||
<?php
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
// Memory ve execution limitleri
|
||||
$maxExecutionTime = 60; // 60 saniye
|
||||
$maxMemoryLimit = 256 * 1024 * 1024; // 256 MB memory limit
|
||||
$startTime = time();
|
||||
$initialMemory = memory_get_usage(true);
|
||||
|
||||
// Memory limit ayarla
|
||||
ini_set('memory_limit', '256M');
|
||||
ini_set('max_execution_time', $maxExecutionTime);
|
||||
|
||||
Log::debug("=== CRON REPORT BUILDER QUEUE STARTED ===");
|
||||
Log::debug("Timestamp: " . date('Y-m-d H:i:s'));
|
||||
Log::debug("Initial memory usage: " . round($initialMemory / 1024 / 1024, 2) . " MB");
|
||||
Log::debug("Memory limit set to: " . round($maxMemoryLimit / 1024 / 1024, 2) . " MB");
|
||||
|
||||
// Memory kontrol fonksiyonu
|
||||
function checkMemoryLimit($startMemory, $maxLimit) {
|
||||
$currentMemory = memory_get_usage(true);
|
||||
$memoryUsed = $currentMemory - $startMemory;
|
||||
$memoryPercentage = ($memoryUsed / $maxLimit) * 100;
|
||||
|
||||
Log::debug("Memory usage: " . round($currentMemory / 1024 / 1024, 2) . " MB");
|
||||
Log::debug("Memory used since start: " . round($memoryUsed / 1024 / 1024, 2) . " MB");
|
||||
Log::debug("Memory usage percentage: " . round($memoryPercentage, 2) . "%");
|
||||
|
||||
if ($memoryUsed > $maxLimit) {
|
||||
Log::debug("⚠ CRITICAL: Memory limit exceeded! Stopping execution.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($memoryPercentage > 80) {
|
||||
Log::debug("⚠ WARNING: Memory usage is high (" . round($memoryPercentage, 2) . "%)");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Database bağlantısını yenileme fonksiyonu
|
||||
function refreshDatabaseConnection() {
|
||||
try {
|
||||
DB::disconnect();
|
||||
DB::reconnect();
|
||||
Log::debug("🔄 Database connection refreshed");
|
||||
} catch (Exception $e) {
|
||||
Log::debug("❌ Failed to refresh database connection: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Memory temizleme fonksiyonu
|
||||
function cleanupMemory() {
|
||||
// Tüm değişkenleri temizle
|
||||
unset($GLOBALS['_POST']);
|
||||
unset($GLOBALS['_GET']);
|
||||
unset($GLOBALS['_REQUEST']);
|
||||
|
||||
// Garbage collection'ı zorla
|
||||
gc_collect_cycles();
|
||||
|
||||
// Memory kullanımını kontrol et
|
||||
$currentMemory = memory_get_usage(true);
|
||||
Log::debug("🧹 Memory cleanup completed. Current usage: " . round($currentMemory / 1024 / 1024, 2) . " MB");
|
||||
}
|
||||
|
||||
// İlk database bağlantısını kur
|
||||
refreshDatabaseConnection();
|
||||
|
||||
$documentTemplates = DB::table("document_templates")->where("y", "1")->orderByRaw('RAND()')->get();
|
||||
Log::debug("Total document templates found: " . $documentTemplates->count());
|
||||
|
||||
// Her template için progress takibi
|
||||
$templateProgress = [];
|
||||
foreach ($documentTemplates as $documentTemplate) {
|
||||
$templateId = $documentTemplate->id;
|
||||
$cacheKey = "cron_report_builder_template_{$templateId}";
|
||||
$progressCacheKey = "cron_report_builder_progress_{$templateId}";
|
||||
|
||||
$lastProcessedIndex = (int)setting($cacheKey, false, "0");
|
||||
$progressJson = setting($progressCacheKey, false, '{"processed_count":0,"error_count":0,"success_count":0,"total_records":0}');
|
||||
$progress = json_decode($progressJson, true);
|
||||
|
||||
$templateProgress[$templateId] = [
|
||||
'cacheKey' => $cacheKey,
|
||||
'progressCacheKey' => $progressCacheKey,
|
||||
'lastProcessedIndex' => $lastProcessedIndex,
|
||||
'progress' => $progress
|
||||
];
|
||||
}
|
||||
|
||||
$maxRecordsPerRun = 1; // Her çalıştırmada her template için maksimum 1 kayıt işle (azaltıldı)
|
||||
$totalProcessedInThisRun = 0;
|
||||
$databaseRefreshCounter = 0;
|
||||
|
||||
// Ana döngü - template'ler arasında dönüşümlü olarak ilerle
|
||||
while (true) {
|
||||
// Maksimum çalışma süresini kontrol et
|
||||
if ((time() - $startTime) >= $maxExecutionTime) {
|
||||
Log::debug("⚠ Maximum execution time ({$maxExecutionTime}s) reached. Stopping execution.");
|
||||
break;
|
||||
}
|
||||
|
||||
// Memory kontrolü
|
||||
if (!checkMemoryLimit($initialMemory, $maxMemoryLimit)) {
|
||||
break;
|
||||
}
|
||||
|
||||
$activeTemplates = 0;
|
||||
|
||||
// Her template için bir kayıt işle
|
||||
foreach ($documentTemplates as $documentTemplate) {
|
||||
$templateId = $documentTemplate->id;
|
||||
|
||||
// Bu template için progress bilgilerini al
|
||||
$progressInfo = $templateProgress[$templateId];
|
||||
$cacheKey = $progressInfo['cacheKey'];
|
||||
$progressCacheKey = $progressInfo['progressCacheKey'];
|
||||
$lastProcessedIndex = $progressInfo['lastProcessedIndex'];
|
||||
$progress = $progressInfo['progress'];
|
||||
|
||||
Log::debug("--- Processing Template ID: {$templateId} ---");
|
||||
Log::debug("Template Name: " . ($documentTemplate->title ?? 'N/A'));
|
||||
|
||||
$fields = json_decode($documentTemplate->fields);
|
||||
|
||||
if(isset($fields->editorMaster)) {
|
||||
Log::debug("✓ Editor Master SQL found");
|
||||
|
||||
if(isset($fields->multipleMode)) {
|
||||
Log::debug("⚠ Multiple Mode detected - skipping this template");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Master query'yi çalıştır - Database bağlantısını kontrol et
|
||||
try {
|
||||
// Log::debug("Executing Master SQL: " . $fields->editorMaster);
|
||||
$resultMaster = DB::select($fields->editorMaster);
|
||||
// Log::debug("Master query returned " . count($resultMaster) . " records");
|
||||
} catch (Exception $e) {
|
||||
Log::debug("❌ Database error in master query: " . $e->getMessage());
|
||||
refreshDatabaseConnection();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Total records'u güncelle (ilk kez çalıştırılıyorsa)
|
||||
if ($progress['total_records'] == 0) {
|
||||
$progress['total_records'] = count($resultMaster);
|
||||
$templateProgress[$templateId]['progress'] = $progress;
|
||||
}
|
||||
|
||||
// Bu template tamamlanmış mı kontrol et
|
||||
if ($lastProcessedIndex >= count($resultMaster)) {
|
||||
Log::debug("🎉 Template ID: {$templateId} already completed!");
|
||||
unset($resultMaster);
|
||||
continue;
|
||||
}
|
||||
|
||||
$activeTemplates++;
|
||||
|
||||
if(isset($fields->editorDetail) && !empty($resultMaster)) {
|
||||
Log::debug("✓ Editor Detail SQL found and master results exist");
|
||||
|
||||
// Bu template için kaç kayıt işleyeceğimizi hesapla
|
||||
$recordsToProcess = min($maxRecordsPerRun, count($resultMaster) - $lastProcessedIndex);
|
||||
Log::debug("📈 Processing {$recordsToProcess} records for template {$templateId}");
|
||||
|
||||
$processedCount = $progress['processed_count'];
|
||||
$errorCount = $progress['error_count'];
|
||||
$successCount = $progress['success_count'];
|
||||
|
||||
// Bu template için kayıtları işle
|
||||
for($i = 0; $i < $recordsToProcess; $i++) {
|
||||
$index = $lastProcessedIndex + $i;
|
||||
|
||||
// Maksimum çalışma süresini kontrol et
|
||||
if ((time() - $startTime) >= $maxExecutionTime) {
|
||||
Log::debug("⚠ Maximum execution time reached. Saving progress and stopping.");
|
||||
// İlerlemeyi kaydet
|
||||
setting_put($cacheKey, $index);
|
||||
setting_put($progressCacheKey, json_encode([
|
||||
'processed_count' => $processedCount,
|
||||
'error_count' => $errorCount,
|
||||
'success_count' => $successCount,
|
||||
'total_records' => $progress['total_records']
|
||||
]));
|
||||
break 3; // Tüm döngülerden çık
|
||||
}
|
||||
|
||||
// Memory kontrolü
|
||||
if (!checkMemoryLimit($initialMemory, $maxMemoryLimit)) {
|
||||
Log::debug("⚠ Memory limit reached. Saving progress and stopping.");
|
||||
setting_put($cacheKey, $index);
|
||||
setting_put($progressCacheKey, json_encode([
|
||||
'processed_count' => $processedCount,
|
||||
'error_count' => $errorCount,
|
||||
'success_count' => $successCount,
|
||||
'total_records' => $progress['total_records']
|
||||
]));
|
||||
break 3;
|
||||
}
|
||||
|
||||
$rowData = $resultMaster[$index];
|
||||
Log::debug("--- Processing Record " . ($index + 1) . " (Template: {$templateId}) ---");
|
||||
|
||||
// Convert object to array if needed
|
||||
$rowDataArray = is_object($rowData) ? (array)$rowData : $rowData;
|
||||
|
||||
// Prepare POST data for the report generator
|
||||
$_POST = [
|
||||
'sqlCodeMaster' => $fields->editorMaster,
|
||||
'sqlCodeDetail' => $fields->editorDetail ?? "",
|
||||
'templateRowNo' => $fields->templateRowNo ?? 25,
|
||||
'documentId' => $documentTemplate->id,
|
||||
'fileNameTemplate' => $fields->fileNameTemplate ?? 'report_{line_number}',
|
||||
'rowData' => $rowDataArray,
|
||||
'isMultipleMode' => isset($fields->isMultipleMode) ? $fields->isMultipleMode : false,
|
||||
'repeatedRows' => isset($fields->repeatedRows) ? json_encode($fields->repeatedRows) : json_encode([]),
|
||||
'isSingleMode' => isset($fields->isSingleMode) ? $fields->isSingleMode : true,
|
||||
'repeatRowCheckbox' => isset($fields->repeatRowCheckbox) ? $fields->repeatRowCheckbox : false,
|
||||
'repeatedTableCount' => isset($fields->repeatedTableCount) ? $fields->repeatedTableCount : 1
|
||||
];
|
||||
|
||||
$recordStartTime = microtime(true);
|
||||
|
||||
try {
|
||||
// Render the report-builder-pdf-generator view directly
|
||||
Log::debug("📄 Rendering report-builder-pdf-generator view...");
|
||||
$response = view('admin-ajax.report-builder-pdf-generator')->render();
|
||||
|
||||
$recordEndTime = microtime(true);
|
||||
$executionTime = round(($recordEndTime - $recordStartTime) * 1000, 2);
|
||||
|
||||
Log::debug("✅ Response generated successfully");
|
||||
Log::debug("⏱️ Execution time: {$executionTime}ms");
|
||||
|
||||
// Increment counters after successful processing
|
||||
$processedCount++;
|
||||
$successCount++;
|
||||
$totalProcessedInThisRun++;
|
||||
|
||||
} catch (Exception $e) {
|
||||
$recordEndTime = microtime(true);
|
||||
$executionTime = round(($recordEndTime - $recordStartTime) * 1000, 2);
|
||||
|
||||
Log::debug("❌ Error processing row: " . $e->getMessage());
|
||||
Log::debug("⏱️ Execution time before error: {$executionTime}ms");
|
||||
|
||||
$errorCount++;
|
||||
$totalProcessedInThisRun++;
|
||||
}
|
||||
|
||||
// Progress'i güncelle
|
||||
$lastProcessedIndex = $index + 1;
|
||||
$templateProgress[$templateId]['lastProcessedIndex'] = $lastProcessedIndex;
|
||||
$templateProgress[$templateId]['progress']['processed_count'] = $processedCount;
|
||||
$templateProgress[$templateId]['progress']['error_count'] = $errorCount;
|
||||
$templateProgress[$templateId]['progress']['success_count'] = $successCount;
|
||||
|
||||
// Setting'e kaydet
|
||||
setting_put($cacheKey, $lastProcessedIndex);
|
||||
setting_put($progressCacheKey, json_encode([
|
||||
'processed_count' => $processedCount,
|
||||
'error_count' => $errorCount,
|
||||
'success_count' => $successCount,
|
||||
'total_records' => $progress['total_records']
|
||||
]));
|
||||
|
||||
// Gelişmiş bellek temizliği
|
||||
unset($rowData, $rowDataArray, $response, $recordStartTime, $recordEndTime, $executionTime);
|
||||
cleanupMemory();
|
||||
|
||||
// Her 5 işlemde bir database bağlantısını yenile
|
||||
$databaseRefreshCounter++;
|
||||
if ($databaseRefreshCounter >= 5) {
|
||||
refreshDatabaseConnection();
|
||||
$databaseRefreshCounter = 0;
|
||||
}
|
||||
|
||||
// Add a small delay to prevent overwhelming the server
|
||||
Log::debug("⏳ Waiting 2 seconds before next record...");
|
||||
sleep(2);
|
||||
}
|
||||
/*
|
||||
Log::debug("--- Template ID: {$templateId} Round Complete ---");
|
||||
Log::debug("Current Statistics:");
|
||||
Log::debug(" - Total records in master query: " . count($resultMaster));
|
||||
Log::debug(" - Successfully processed: {$successCount}");
|
||||
Log::debug(" - Failed to process: {$errorCount}");
|
||||
Log::debug(" - Current index: {$lastProcessedIndex}");
|
||||
*/
|
||||
|
||||
} else {
|
||||
if(!isset($fields->editorDetail)) {
|
||||
Log::debug("❌ Editor Detail SQL not found");
|
||||
}
|
||||
if(empty($resultMaster)) {
|
||||
Log::debug("❌ Master query returned no results");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Log::debug("❌ Editor Master SQL not found");
|
||||
}
|
||||
|
||||
// Template işlemi sonrası memory temizliği
|
||||
unset($fields, $resultMaster);
|
||||
cleanupMemory();
|
||||
}
|
||||
|
||||
// Eğer hiç aktif template kalmadıysa döngüden çık
|
||||
if ($activeTemplates == 0) {
|
||||
Log::debug("🎉 All templates completed!");
|
||||
break;
|
||||
}
|
||||
|
||||
Log::debug("🔄 Completed one round for all templates. Total processed in this run: {$totalProcessedInThisRun}");
|
||||
Log::debug("⏳ Waiting 5 seconds before next round...");
|
||||
sleep(5);
|
||||
}
|
||||
|
||||
$totalExecutionTime = time() - $startTime;
|
||||
$finalMemory = memory_get_usage(true);
|
||||
$peakMemory = memory_get_peak_usage(true);
|
||||
|
||||
Log::debug("=== CRON REPORT BUILDER QUEUE COMPLETED ===");
|
||||
Log::debug("Total execution time: {$totalExecutionTime} seconds");
|
||||
Log::debug("Final memory usage: " . round($finalMemory / 1024 / 1024, 2) . " MB");
|
||||
Log::debug("Peak memory usage: " . round($peakMemory / 1024 / 1024, 2) . " MB");
|
||||
Log::debug("Final timestamp: " . date('Y-m-d H:i:s'));
|
||||
|
||||
// Tüm işlemler bittikten sonra sadece başladığınız template'in progress'ini yenile
|
||||
if ($activeTemplates == 0) {
|
||||
Log::debug("🔄 All templates completed. Resetting progress for next cycle...");
|
||||
|
||||
// Sadece bu çalıştırmada işlem yapılan template'lerin progress'ini sıfırla
|
||||
foreach ($templateProgress as $templateId => $progressInfo) {
|
||||
$cacheKey = $progressInfo['cacheKey'];
|
||||
$progressCacheKey = $progressInfo['progressCacheKey'];
|
||||
|
||||
// Eğer bu template'de işlem yapıldıysa (lastProcessedIndex > 0) progress'i sıfırla
|
||||
if ($progressInfo['lastProcessedIndex'] > 0) {
|
||||
Log::debug("🔄 Resetting progress for Template ID: {$templateId}");
|
||||
setting_put($cacheKey, 0); // İndeksi sıfırla
|
||||
setting_put($progressCacheKey, json_encode([
|
||||
'processed_count' => 0,
|
||||
'error_count' => 0,
|
||||
'success_count' => 0,
|
||||
'total_records' => 0
|
||||
]));
|
||||
} else {
|
||||
Log::debug("⏸️ Skipping progress reset for Template ID: {$templateId} (no processing done)");
|
||||
}
|
||||
}
|
||||
|
||||
Log::debug("✅ Progress reset completed for processed templates only");
|
||||
}
|
||||
|
||||
// Genel ilerleme bilgisini setting'e kaydet
|
||||
$overallProgress = [
|
||||
'last_run' => date('Y-m-d H:i:s'),
|
||||
'execution_time' => $totalExecutionTime,
|
||||
'final_memory_mb' => round($finalMemory / 1024 / 1024, 2),
|
||||
'peak_memory_mb' => round($peakMemory / 1024 / 1024, 2),
|
||||
'status' => ($totalExecutionTime >= $maxExecutionTime) ? 'timeout' : 'completed',
|
||||
'total_processed_in_run' => $totalProcessedInThisRun
|
||||
];
|
||||
setting_put('cron_report_builder_overall_progress', json_encode($overallProgress));
|
||||
|
||||
// Final cleanup
|
||||
cleanupMemory();
|
||||
refreshDatabaseConnection();
|
||||
?>
|
||||
@@ -1,271 +0,0 @@
|
||||
@if(!getisset("type"))
|
||||
<?php
|
||||
$result = Artisan::call('schedule:run');
|
||||
dump("Schedule run: $result");
|
||||
?>
|
||||
@include("cron-register-creator")
|
||||
<?php
|
||||
// Check if current time is within night shift hours (20:00 to 07:00)
|
||||
$currentHour = (int) date("H");
|
||||
$isNightShift = ($currentHour >= 20 || $currentHour < 7);
|
||||
|
||||
if ($isNightShift) {
|
||||
dump("Night shift");
|
||||
} else {
|
||||
dump("Day shift");
|
||||
}
|
||||
?>
|
||||
@if($isNightShift)
|
||||
@include("cron-report-builder-queue")
|
||||
@endif
|
||||
@endif
|
||||
<?php
|
||||
ini_set('memory_limit', '8G');
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
set_time_limit(-1);
|
||||
ini_set('max_execution_time', -1);
|
||||
|
||||
|
||||
|
||||
$adminMail = env("ADMIN_MAIL");
|
||||
|
||||
// Regular cron jobs working time
|
||||
$workingTime = [
|
||||
// '12:00',
|
||||
// '12:00',
|
||||
'23:00',
|
||||
'02:00',
|
||||
//'10:30',
|
||||
];
|
||||
|
||||
// Cache-blade cron jobs working time - separate schedule
|
||||
$cacheWorkingTime = [
|
||||
'06:00',
|
||||
'09:00',
|
||||
'12:00',
|
||||
'15:00',
|
||||
'18:00',
|
||||
'21:00',
|
||||
'00:00',
|
||||
'03:00',
|
||||
];
|
||||
|
||||
$cronJobPeriod = setting('cron_job_period');
|
||||
$oneMinuteAgo = Carbon::now()->subMinutes($cronJobPeriod);
|
||||
$take = setting('cron_job_batch_process_count');
|
||||
$saat = date("H:i");
|
||||
$dakika = (int) date("i");
|
||||
$period = 30;
|
||||
$kalan = $dakika % $period;
|
||||
|
||||
$commitSize = 250;
|
||||
|
||||
// Determine whether to process cache files or regular files based on current time
|
||||
$isCacheTime = in_array($saat, $cacheWorkingTime);
|
||||
$isRegularTime = in_array($saat, $workingTime);
|
||||
|
||||
if(!getisset("type"))
|
||||
{
|
||||
// Only allow the script to run at specified times
|
||||
if (getisset("cache")) {
|
||||
// If cache parameter is explicitly provided, use it to override time-based decision
|
||||
$runCacheFiles = get("cache") == 1;
|
||||
|
||||
if ($runCacheFiles && !$isCacheTime) {
|
||||
dump($saat);
|
||||
dump($cacheWorkingTime);
|
||||
dump("Cache Working Time Out");
|
||||
exit();
|
||||
} else if (!$runCacheFiles && !$isRegularTime) {
|
||||
dump($saat);
|
||||
dump($workingTime);
|
||||
dump("Working Time Out");
|
||||
exit();
|
||||
}
|
||||
} else {
|
||||
// No cache parameter - automatically decide based on current time
|
||||
if (!$isCacheTime && !$isRegularTime) {
|
||||
dump($saat);
|
||||
dump("Working Time Out - Not in any scheduled time");
|
||||
dump("Regular times: " . implode(", ", $workingTime));
|
||||
dump("Cache times: " . implode(", ", $cacheWorkingTime));
|
||||
exit();
|
||||
}
|
||||
// If both cache and regular time overlap, cache takes precedence
|
||||
}
|
||||
}
|
||||
|
||||
Cache::forget("cronjob");
|
||||
|
||||
|
||||
if(!getesit("type","")) {
|
||||
Cache::forget("cronjob");
|
||||
}
|
||||
|
||||
if($saat == "11:00")
|
||||
{
|
||||
Cache::forget("cronjob");
|
||||
dump("forget cronjob");
|
||||
}
|
||||
|
||||
if(!Cache::has("cronjob")) {
|
||||
// if($kalan == 0) {
|
||||
$start = new Carbon(simdi());
|
||||
|
||||
Cache::put("cronjob", simdi());
|
||||
|
||||
Log::debug("🟢 cron start: " . simdi());
|
||||
|
||||
// Get all blade files from cron directory
|
||||
$allFiles = glob(base_path() . '/resources/views/cron/*.blade.php');
|
||||
|
||||
// Separate cache-blade files from other files
|
||||
$cacheFiles = [];
|
||||
$regularFiles = [];
|
||||
|
||||
foreach($allFiles as $file) {
|
||||
$basename = basename($file);
|
||||
if(strpos($basename, 'cache-blade') === 0) {
|
||||
$cacheFiles[] = $file;
|
||||
} else {
|
||||
$regularFiles[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
// Determine which files to process based on request or time
|
||||
$filesToProcess = [];
|
||||
|
||||
if(getisset("type")) {
|
||||
// If specific type is requested, include only that file
|
||||
$filesToProcess = $allFiles;
|
||||
} else if(getisset("cache")) {
|
||||
// If cache parameter is explicitly provided
|
||||
$runCacheFiles = get("cache") == 1;
|
||||
if($runCacheFiles) {
|
||||
$filesToProcess = $cacheFiles;
|
||||
Log::debug("Processing only cache-blade files (explicit): " . count($cacheFiles));
|
||||
} else {
|
||||
$filesToProcess = $regularFiles;
|
||||
Log::debug("Processing regular cron files (explicit): " . count($regularFiles));
|
||||
}
|
||||
} else {
|
||||
// Auto determine based on current time
|
||||
// If both time ranges overlap, cache takes precedence
|
||||
if($isCacheTime) {
|
||||
$filesToProcess = $cacheFiles;
|
||||
Log::debug("Processing cache-blade files (auto time-based): " . count($cacheFiles));
|
||||
} else if($isRegularTime) {
|
||||
$filesToProcess = $regularFiles;
|
||||
Log::debug("Processing regular cron files (auto time-based): " . count($regularFiles));
|
||||
} else {
|
||||
// This shouldn't happen due to earlier check, but just in case
|
||||
$filesToProcess = [];
|
||||
Log::debug("No files to process - not in any scheduled time");
|
||||
}
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
$total = count($filesToProcess);
|
||||
?>
|
||||
@if(!getesit("type",""))
|
||||
@includeIf('cron.' . get("type"))
|
||||
@else
|
||||
@foreach ($filesToProcess as $file)
|
||||
<?php
|
||||
//ob_start();
|
||||
$description = basename($file);
|
||||
$description = str_replace(".blade.php", "", $description);
|
||||
|
||||
Log::info($file);
|
||||
|
||||
Cache::put("cronjob_progress", [
|
||||
'total' => $total,
|
||||
'count' => $count,
|
||||
'progress' => round($count * 100 / $total),
|
||||
'description' => $description,
|
||||
'start' => simdi()
|
||||
|
||||
]);
|
||||
|
||||
$count++;
|
||||
try {
|
||||
?>
|
||||
@include('cron.' . basename(str_replace('.blade.php', '', $file)))
|
||||
<?php
|
||||
} catch (\Throwable $th) {
|
||||
Log::error("cron");
|
||||
Log::error($th->getMessage());
|
||||
Cache::forget("cronjob");
|
||||
dump($th);
|
||||
mailSend($adminMail, env("APP_NAME")." Cron Job Error", $th->getMessage());
|
||||
}
|
||||
?>
|
||||
|
||||
<?php
|
||||
// ob_end_clean();
|
||||
//gc_collect_cycles();
|
||||
?>
|
||||
@endforeach
|
||||
@endif
|
||||
<?php
|
||||
|
||||
|
||||
$end = new Carbon(simdi());
|
||||
|
||||
if(!getisset("type")) {
|
||||
Cache::put("cronjob_progress", [
|
||||
'total' => $total,
|
||||
'count' => $total,
|
||||
'progress' => 100,
|
||||
'start' => simdi(),
|
||||
'description' => "finish " . simdi() . " " . $start->diff($end)->format('%H:%I:%S')
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Log::debug("🔴 cron finish: " . simdi());
|
||||
Log::debug("⏰ süre: " . $start->diff($end)->format('%H:%I:%S'));
|
||||
Cache::forget("cronjob");
|
||||
//.. mailSend($adminMail, env("APP_NAME")." Cron Job Finished", "Cron Job Finished");
|
||||
/*
|
||||
} else {
|
||||
// dump($period - $kalan);
|
||||
dump("Cron ". $period - $kalan ." dakika sonra çalışacak");
|
||||
}
|
||||
*/
|
||||
|
||||
?>
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
} else {
|
||||
$runControlAttempt = Cache::get("cronJobRunControlAttempt");
|
||||
|
||||
if(is_null($runControlAttempt))
|
||||
{
|
||||
$runControlAttempt = 0;
|
||||
}
|
||||
|
||||
$runControlAttempt++;
|
||||
|
||||
Cache::put("cronJobRunControlAttempt", $runControlAttempt);
|
||||
|
||||
if($runControlAttempt == 100)
|
||||
{
|
||||
|
||||
Cache::forget("cronjob");
|
||||
Cache::forget("cronJobRunControlAttempt");
|
||||
Log::debug("Cron job 100 dakikadır çalışıyor. Tekrar başlatılacak...");
|
||||
}
|
||||
|
||||
dump("cronJobRunControlAttempt $runControlAttempt");
|
||||
dump("Çalışan bir cron var onun bitmesini bekliyorum");
|
||||
Log::debug("Çalışan bir cron var onun bitmesini bekliyorum");
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
<?php
|
||||
// Admin authentication check
|
||||
$providedPassword = request('password');
|
||||
$isAdmin = false;
|
||||
|
||||
// Check if user is admin and password is correct
|
||||
if (auth()->check() && auth()->user()->level === 'Admin') {
|
||||
// Check if provided password matches the admin user's password in database
|
||||
if (Hash::check($providedPassword, auth()->user()->password)) {
|
||||
$isAdmin = true;
|
||||
} else {
|
||||
echo "❌ Admin password is incorrect!";
|
||||
exit();
|
||||
}
|
||||
} else {
|
||||
echo "❌ Admin privileges required to access this page!";
|
||||
exit();
|
||||
}
|
||||
|
||||
// Only proceed if admin authentication is successful
|
||||
if (!$isAdmin) {
|
||||
echo "❌ Authorization error!";
|
||||
exit();
|
||||
}
|
||||
|
||||
// Set execution settings
|
||||
ini_set('memory_limit', '8G');
|
||||
set_time_limit(-1);
|
||||
ini_set('max_execution_time', -1);
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
$adminMail = env("ADMIN_MAIL");
|
||||
$start = new Carbon(simdi());
|
||||
|
||||
Log::debug("🟢 Important Job start: " . simdi());
|
||||
|
||||
// Get all blade files from important-job directory
|
||||
$allFiles = glob(base_path() . '/resources/views/important-job/*.blade.php');
|
||||
$count = 0;
|
||||
$total = count($allFiles);
|
||||
|
||||
if ($total == 0) {
|
||||
echo "❌ No files found in important-job folder!";
|
||||
exit();
|
||||
}
|
||||
|
||||
echo "📁 Total $total files will be processed...<br><br>";
|
||||
?>
|
||||
|
||||
@php
|
||||
$count = 0;
|
||||
@endphp
|
||||
|
||||
@foreach($allFiles as $file)
|
||||
@php
|
||||
$description = basename($file, '.blade.php');
|
||||
$count++;
|
||||
echo "🔄 Processing ($count/$total): $description<br>";
|
||||
Log::info("Processing: $file");
|
||||
try {
|
||||
@endphp
|
||||
|
||||
@includeIf('important-job.' . $description)
|
||||
|
||||
@php
|
||||
echo "✅ Success: $description<br>";
|
||||
} catch (\Throwable $th) {
|
||||
Log::error("Important Job Error in $description");
|
||||
Log::error($th->getMessage());
|
||||
echo "❌ Error ($description): " . $th->getMessage() . "<br>";
|
||||
if ($adminMail) {
|
||||
mailSend($adminMail, env("APP_NAME")." Important Job Error",
|
||||
"File: $description\nError: " . $th->getMessage());
|
||||
}
|
||||
}
|
||||
echo "<br>";
|
||||
@endphp
|
||||
@endforeach
|
||||
|
||||
<?php
|
||||
$end = new Carbon(simdi());
|
||||
$duration = $start->diff($end)->format('%H:%I:%S');
|
||||
|
||||
echo "🎉 All operations completed!<br>";
|
||||
echo "⏱️ Total duration: $duration<br>";
|
||||
|
||||
Log::debug("🔴 Important Job finish: " . simdi());
|
||||
Log::debug("⏰ Duration: $duration");
|
||||
|
||||
// Send completion email to admin
|
||||
if ($adminMail) {
|
||||
mailSend($adminMail, env("APP_NAME")." Important Job Completed",
|
||||
"Total $total files processed.\nDuration: $duration");
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
@extends('admin.master')
|
||||
@section("title", get("title"))
|
||||
<?php $type = get("type");
|
||||
$id = "summary";
|
||||
?>
|
||||
|
||||
@section('content')
|
||||
@if(Hash::check($type, get("hash")))
|
||||
@includeIf("admin.type.$type")
|
||||
@endif
|
||||
@endsection
|
||||
@@ -1 +0,0 @@
|
||||
@includeCache("mail-link-content")
|
||||
Reference in New Issue
Block a user