-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-post-suggestions.php
More file actions
80 lines (68 loc) · 2.6 KB
/
check-post-suggestions.php
File metadata and controls
80 lines (68 loc) · 2.6 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
<?php
/**
* Diagnostic script to check post suggestions
* Access: https://wegenius.fahmidsroadmap.com/check-post-suggestions.php
*/
require __DIR__ . '/vendor/autoload.php';
$app = require_once __DIR__ . '/bootstrap/app.php';
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();
use App\Models\WordPressPost;
use App\Models\ArticleAnalysis;
use App\Models\AiSuggestion;
header('Content-Type: application/json');
try {
$postId = 3;
$post = WordPressPost::with([
'articleAnalyses' => function ($query) {
$query->latest()->limit(1);
},
'suggestions' => function ($query) {
$query->orderBy('status')->orderBy('created_at', 'desc');
}
])->find($postId);
if (!$post) {
echo json_encode(['error' => 'Post not found'], JSON_PRETTY_PRINT);
exit;
}
$latestAnalysis = $post->articleAnalyses->first();
$suggestionsData = $post->suggestions->map(function ($suggestion) {
// Decode and format suggested content for display
$suggestedContent = $suggestion->suggested_content;
if (is_string($suggestedContent)) {
$decoded = json_decode($suggestedContent, true);
if (is_array($decoded)) {
$suggestedContent = $decoded;
}
}
return [
'id' => $suggestion->id,
'type' => $suggestion->type,
'section' => $suggestion->section,
'position' => $suggestion->position,
'original_content' => $suggestion->original_content,
'suggested_content' => $suggestedContent,
'suggested_content_raw' => $suggestion->suggested_content,
'explanation' => $suggestion->explanation,
'meta_data' => $suggestion->meta_data,
'status' => $suggestion->status,
'implemented_at' => $suggestion->implemented_at?->format('M d, Y H:i'),
'created_at' => $suggestion->created_at->format('M d, Y H:i'),
];
});
echo json_encode([
'post_id' => $postId,
'post_title' => $post->title,
'analysis' => [
'id' => $latestAnalysis?->id,
'status' => $latestAnalysis?->status,
'overall_score' => $latestAnalysis?->overall_score,
],
'suggestions_count' => $suggestionsData->count(),
'suggestions' => $suggestionsData->toArray(),
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
} catch (\Exception $e) {
echo json_encode([
'error' => $e->getMessage(),
'trace' => $e->getTraceAsString()
], JSON_PRETTY_PRINT);
}