100 lines
2.6 KiB
PHP
100 lines
2.6 KiB
PHP
<?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");
|
|
}
|
|
?>
|
|
|