Changes
This commit is contained in:
@@ -29,6 +29,7 @@ use DateTime;
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use Inertia\Inertia;
|
use Inertia\Inertia;
|
||||||
|
|
||||||
@@ -36,6 +37,7 @@ class MainController extends Controller
|
|||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
|
|
||||||
$admissionCampaign = $this->getAdmissionCampaign();
|
$admissionCampaign = $this->getAdmissionCampaign();
|
||||||
$educations = $this->getEducationsData();
|
$educations = $this->getEducationsData();
|
||||||
$sliders = $this->getActiveSliders();
|
$sliders = $this->getActiveSliders();
|
||||||
|
|||||||
@@ -31,28 +31,45 @@ class ImportApiDataPost implements ShouldQueue
|
|||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
// Получаем первую страницу данных
|
||||||
$response = Http::get('https://crawdad-fresh-bream.ngrok-free.app/api/posts')->object();
|
$response = Http::get('https://crawdad-fresh-bream.ngrok-free.app/api/posts')->object();
|
||||||
|
$last_page = $response->last_page;
|
||||||
|
Log::info('Last page: ' . $last_page);
|
||||||
|
|
||||||
|
// Проходим по всем страницам
|
||||||
|
for ($page = 1; $page <= $last_page; $page++) {
|
||||||
|
$response = Http::get("https://crawdad-fresh-bream.ngrok-free.app/api/posts?page=$page")->object();
|
||||||
|
$results = $response->data;
|
||||||
|
|
||||||
|
// Обрабатываем каждую запись
|
||||||
|
foreach ($results as $post) {
|
||||||
|
Log::info('Processing post ID: ' . $post->ID);
|
||||||
|
|
||||||
foreach ($response as $item) {
|
|
||||||
try {
|
try {
|
||||||
$postResponse = Http::get('https://crawdad-fresh-bream.ngrok-free.app/api/posts/' . $item->ID)->object();
|
// Получаем массив изображений
|
||||||
|
$images = $post->images ?? []; // Обработка отсутствия изображений
|
||||||
// Проверка на наличие данных
|
|
||||||
if (!isset($postResponse->post)) {
|
|
||||||
Log::error('Post data not found for ID: ' . $item->ID);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$postData = $postResponse->post;
|
|
||||||
$images = $postResponse->images ?? []; // Обработка отсутствия изображений
|
|
||||||
|
|
||||||
// Обработка изображения
|
|
||||||
$imagePaths = [];
|
$imagePaths = [];
|
||||||
|
|
||||||
|
// Проверяем, есть ли изображения
|
||||||
|
if (empty($images)) {
|
||||||
|
Log::warning('No images found for post ID: ' . $post->ID);
|
||||||
|
} else {
|
||||||
|
// Проходимся по массиву изображений
|
||||||
foreach ($images as $image) {
|
foreach ($images as $image) {
|
||||||
|
// Проверяем наличие необходимых свойств
|
||||||
|
if (isset($image->SUBDIR) && isset($image->FILE_NAME)) {
|
||||||
$imagePaths[] = 'upload/' . $image->SUBDIR . '/' . $image->FILE_NAME;
|
$imagePaths[] = 'upload/' . $image->SUBDIR . '/' . $image->FILE_NAME;
|
||||||
|
} else {
|
||||||
|
Log::warning('Image data is incomplete for post ID: ' . $post->ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = strip_tags($postData->DETAIL_TEXT, '<a>');
|
// Логируем пути к изображениям для отладки
|
||||||
|
Log::info('Image paths for post ID ' . $post->ID . ': ' . json_encode($imagePaths));
|
||||||
|
|
||||||
|
// Обработка контента поста
|
||||||
|
$content = strip_tags($post->DETAIL_TEXT, '<a>');
|
||||||
$contentData = [
|
$contentData = [
|
||||||
[
|
[
|
||||||
'type' => 'paragraph',
|
'type' => 'paragraph',
|
||||||
@@ -62,27 +79,29 @@ class ImportApiDataPost implements ShouldQueue
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$slug = $this->generateSlug($postData->NAME);
|
// Генерация уникального slug
|
||||||
|
$slug = $this->generateSlug($post->NAME);
|
||||||
|
|
||||||
// Создание нового поста
|
// Создание нового поста
|
||||||
Post::create([
|
Post::create([
|
||||||
'id' => $postData->ID,
|
'id' => $post->ID,
|
||||||
'title' => $postData->NAME,
|
'title' => $post->NAME,
|
||||||
'slug' => $slug,
|
'slug' => $slug,
|
||||||
'preview_text' => strip_tags($postData->PREVIEW_TEXT),
|
'preview_text' => strip_tags($post->PREVIEW_TEXT),
|
||||||
'authors' => array('Без автора'),
|
'authors' => ['Без автора'],
|
||||||
'content' => $contentData, // Преобразуем в JSON
|
'content' => $contentData, // Преобразуем в JSON
|
||||||
'status' => 'published',
|
'status' => 'published',
|
||||||
'images' => $imagePaths,
|
'images' => $imagePaths, // Сохраняем пути к изображениям
|
||||||
'search_data' => $content, // Преобразуем в JSON
|
'search_data' => $content, // Преобразуем в JSON
|
||||||
'reading_time' => 2,
|
'reading_time' => 2,
|
||||||
'user_id' => 1,
|
'user_id' => 1,
|
||||||
'publish_at' => $postData->DATE_CREATE,
|
'publish_at' => $post->DATE_CREATE,
|
||||||
'created_at' => $postData->DATE_CREATE,
|
'created_at' => $post->DATE_CREATE,
|
||||||
'updated_at' => $postData->DATE_CREATE,
|
'updated_at' => $post->DATE_CREATE,
|
||||||
]);
|
]);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::error('Error importing post ID: ' . $item->ID . ' - ' . $e->getMessage());
|
Log::error('Error importing post ID: ' . $post->ID . ' - ' . $e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user