From 77cc7b2c76fb4ea04cffd9496e366fc668b1a4e3 Mon Sep 17 00:00:00 2001 From: f4ilji Date: Sun, 24 Nov 2024 14:55:12 +0500 Subject: [PATCH] Changes --- .../Commands/TransferPostsToNewTable.php | 19 ++++ app/Jobs/ImportApiDataPost.php | 107 ++++++++++++++++++ app/Providers/EventServiceProvider.php | 9 -- resources/js/Components/ClientPost.vue | 4 +- 4 files changed, 129 insertions(+), 10 deletions(-) create mode 100644 app/Console/Commands/TransferPostsToNewTable.php create mode 100644 app/Jobs/ImportApiDataPost.php diff --git a/app/Console/Commands/TransferPostsToNewTable.php b/app/Console/Commands/TransferPostsToNewTable.php new file mode 100644 index 0000000..974a6ea --- /dev/null +++ b/app/Console/Commands/TransferPostsToNewTable.php @@ -0,0 +1,19 @@ +object(); + + foreach ($response as $item) { + try { + $postResponse = Http::get('https://crawdad-fresh-bream.ngrok-free.app/api/posts/' . $item->ID)->object(); + + // Проверка на наличие данных + if (!isset($postResponse->post)) { + Log::error('Post data not found for ID: ' . $item->ID); + continue; + } + + $postData = $postResponse->post; + $images = $postResponse->images ?? []; // Обработка отсутствия изображений + + // Обработка изображения + $imagePaths = []; + foreach ($images as $image) { + $imagePaths[] = 'upload/' . $image->SUBDIR . '/' . $image->FILE_NAME; + } + + $content = strip_tags($postData->DETAIL_TEXT, ''); + $contentData = [ + [ + 'type' => 'paragraph', + 'data' => [ + 'content' => $content, + ], + ], + ]; + + $slug = $this->generateSlug($postData->NAME); + + // Создание нового поста + Post::create([ + 'id' => $postData->ID, + 'title' => $postData->NAME, + 'slug' => $slug, + 'preview_text' => strip_tags($postData->PREVIEW_TEXT), + 'authors' => array('Без автора'), + 'content' => $contentData, // Преобразуем в JSON + 'status' => 'published', + 'images' => $imagePaths, + 'search_data' => $content, // Преобразуем в JSON + 'reading_time' => 2, + 'user_id' => 1, + 'publish_at' => $postData->DATE_CREATE, + 'created_at' => $postData->DATE_CREATE, + 'updated_at' => $postData->DATE_CREATE, + ]); + } catch (\Exception $e) { + Log::error('Error importing post ID: ' . $item->ID . ' - ' . $e->getMessage()); + } + } + } catch (\Exception $e) { + Log::error('Error fetching posts: ' . $e->getMessage()); + } + } + + private function generateSlug($name) + { + $slug = Str::slug($name); + $originalSlug = $slug; + $count = 1; + + while (Post::where('slug', $slug)->exists()) { + $slug = $originalSlug . '-' . $count; + $count++; + } + + return $slug; + } + +} diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index b150479..eeb249a 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -8,9 +8,6 @@ use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Event; -use Laravel\Fortify\Events\TwoFactorAuthenticationChallenged; -use Laravel\Fortify\Events\TwoFactorAuthenticationEnabled; -use Vormkracht10\TwoFactorAuth\Listeners\SendTwoFactorCodeListener; class EventServiceProvider extends ServiceProvider { @@ -23,12 +20,6 @@ class EventServiceProvider extends ServiceProvider Registered::class => [ SendEmailVerificationNotification::class, ], - TwoFactorAuthenticationChallenged::class => [ - SendTwoFactorCodeListener::class, - ], - TwoFactorAuthenticationEnabled::class => [ - SendTwoFactorCodeListener::class, - ], ]; /** diff --git a/resources/js/Components/ClientPost.vue b/resources/js/Components/ClientPost.vue index fc5c398..0a20c63 100644 --- a/resources/js/Components/ClientPost.vue +++ b/resources/js/Components/ClientPost.vue @@ -63,7 +63,9 @@ >
- {{ textLimit(post.authors[0], 20) }} + + {{ textLimit(post.authors[0], 20) }} +