-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_production_nutrition_status.php
More file actions
104 lines (85 loc) · 3.11 KB
/
Copy pathcheck_production_nutrition_status.php
File metadata and controls
104 lines (85 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/**
* Quick check for nutrition_status population
* Run this on cPanel to check if nutrition_status needs to be populated
*/
// Tự động tìm đường dẫn đúng cho autoload.php
$autoloadPaths = [
__DIR__.'/vendor/autoload.php', // Nếu script ở root
__DIR__.'/../vendor/autoload.php', // Nếu script ở public
__DIR__.'/../../vendor/autoload.php', // Nếu script ở public/subfolder
];
$autoloadFound = false;
foreach ($autoloadPaths as $path) {
if (file_exists($path)) {
require $path;
$autoloadFound = true;
break;
}
}
if (!$autoloadFound) {
die("ERROR: Không tìm thấy vendor/autoload.php\nVui lòng chạy script từ thư mục root của project (cùng cấp với folder vendor)\n");
}
// Tự động tìm đường dẫn cho bootstrap/app.php
$bootstrapPaths = [
__DIR__.'/bootstrap/app.php',
__DIR__.'/../bootstrap/app.php',
];
$bootstrapFound = false;
foreach ($bootstrapPaths as $path) {
if (file_exists($path)) {
$app = require_once $path;
$bootstrapFound = true;
break;
}
}
if (!$bootstrapFound) {
die("ERROR: Không tìm thấy bootstrap/app.php\n");
}
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();
use App\Models\History;
use Illuminate\Support\Facades\DB;
// Set headers nếu chạy qua web
if (php_sapi_name() !== 'cli') {
header('Content-Type: text/plain; charset=utf-8');
}
echo "=== Kiểm tra dữ liệu nutrition_status trên server ===\n\n";
// Tổng số record
$total = History::count();
echo "Tổng số record: $total\n\n";
// Kiểm tra nutrition_status
$withStatus = History::whereNotNull('nutrition_status')
->where('nutrition_status', '!=', '')
->count();
$emptyStatus = $total - $withStatus;
echo "Record CÓ nutrition_status: $withStatus\n";
echo "Record CHƯA CÓ nutrition_status: $emptyStatus\n\n";
if ($emptyStatus > 0) {
echo "⚠️ CẢNH BÁO: Có $emptyStatus records chưa có nutrition_status!\n";
echo "Cần chạy script populate_nutrition_status.php để cập nhật.\n\n";
// Mẫu 5 record chưa có nutrition_status
echo "=== MẪU 5 RECORD CHƯA CÓ nutrition_status ===\n";
$samples = History::where(function($q) {
$q->whereNull('nutrition_status')
->orWhere('nutrition_status', '');
})->limit(5)->get(['id', 'uid', 'age', 'created_at']);
foreach ($samples as $s) {
echo "ID: {$s->id} | UID: {$s->uid} | Tuổi: {$s->age} tháng | Tạo: {$s->created_at}\n";
}
} else {
echo "✅ Tất cả records đã có nutrition_status!\n\n";
// Thống kê phân bố
echo "=== PHÂN BỐ NUTRITION_STATUS ===\n";
$stats = DB::table('history')
->select('nutrition_status', DB::raw('count(*) as count'))
->whereNotNull('nutrition_status')
->where('nutrition_status', '!=', '')
->groupBy('nutrition_status')
->orderBy('count', 'desc')
->get();
foreach ($stats as $stat) {
echo "{$stat->nutrition_status}: {$stat->count} records\n";
}
}
echo "\n=== HOÀN TẤT ===\n";