Migration complete

This commit is contained in:
2026-06-23 19:24:38 +02:00
parent 279160c1cb
commit 64b26ef059
126 changed files with 8121 additions and 221 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Services;
use App\Models\Entry;
use App\Models\EntryReview;
use App\Models\News;
use App\View\Components\EntryCard;
use Illuminate\Support\Carbon;
@@ -17,9 +18,10 @@ class ActivityService
private const CACHE_MESSAGES = 300; // seconds.
private const CACHE_THREADS = 300; // seconds.
private const CACHE_CLUBS = 300; // seconds.
private const CACHE_REVIEWS = 300; // seconds.
private const ITEMS_PER_TYPE = 15;
public function getActivities( array $activities = [ 'entries', 'news', 'messages', 'threads', 'clubs' ] ): Collection
public function getActivities( array $activities = [ 'entries', 'news', 'messages', 'threads', 'clubs', 'reviews' ] ): Collection
{
$c = collect();
if( in_array( 'entries', $activities ) ) {
@@ -37,6 +39,9 @@ class ActivityService
if( in_array( 'clubs', $activities ) ) {
$c = $c->merge($this->getClubs());
}
if( in_array( 'reviews', $activities ) ) {
$c = $c->merge($this->getReviews());
}
return $c->sortByDesc('date')
->values()
@@ -135,6 +140,23 @@ class ActivityService
];
}
private function formatReview( EntryReview $review ): array
{
return [
'type' => 'review',
'title' => $review->title,
'url' => $review->entry()->exists() ? route('entries.show', ['section' => $review->entry->type, 'entry' => $review->entry]) : '',
'image' => null,
'date' => $review->created_at->timestamp,
'author' => null,
'user_id' => $review->user_id,
'badge' => 'Review',
'badge_class' => 'review',
'excerpt' => $review->description ? \Str::limit(strip_tags($review->description), 80) : null,
'meta' => $review->entry()->exists() ? ( $review->entry->complete_title ?? $review->entry->title ) : null,
];
}
private function getEntries(): array
{
return Cache::remember('activity_entries', self::CACHE_ENTRIES, function() {
@@ -220,4 +242,16 @@ class ActivityService
->toArray();
});
}
private function getReviews(): array
{
return Cache::remember('activity_reviews', self::CACHE_REVIEWS, function() {
return EntryReview::with(['entry'])
->latest('created_at')
->limit(self::ITEMS_PER_TYPE)
->get()
->map($this->formatReview(...))
->toArray();
});
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace App\Services;
use App\Helpers\EntryHelpers;
use App\Models\Entry;
use App\Models\EntryReview;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class ReviewsService
{
private ?Request $request = null;
private ?Entry $entry = null;
private ?EntryReview $entryReview = null;
/**
* @throws \Throwable
*/
public function storeReview(Request $request, Entry $entry)
{
// Step 1: Prepare fields.
$this->request = $request;
$this->entry = $entry;
$user_id = \Auth::user()->user_id;
$review = DB::transaction(function () use ($user_id) {
$fields = [
'entry_id' => $this->entry->id,
'title' => $this->request->input('title'),
'rating'=> $this->request->input('rating'),
'description' => $this->request->input('description'),
'user_id' => $user_id,
];
$review = EntryReview::create($fields);
return $review;
});
return $review;
}
}

View File

@@ -201,7 +201,7 @@ class SubmissionsService {
$this->Step11_SaveLanguages( $entry );
// STEP 11.5 : Save Categories
if( section_must_be( 'utilities', $this->section ) ) {
if( section_must_be( ['utilities', 'documents'], $this->section ) ) {
$this->Step11_5_SaveCategories($entry);
}
@@ -605,6 +605,9 @@ class SubmissionsService {
if( $fields['featured'] == false )
$fields['featured_at'] = null;
$fields['comments_thread_id'] = $this->request->input('comments_thread_id');
$refresh_created_at = $this->request->input('refresh_created_at') ?? false;
if( $refresh_created_at )
$fields['created_at'] = now();
}
$this->entry->update( $fields );
@@ -631,7 +634,7 @@ class SubmissionsService {
$this->eStep10_UpdateLanguages();
// STEP 10.5 : Update categories
if( section_must_be( 'utilities', $this->section ) )
if( section_must_be( ['utilities', 'documents'], $this->section ) )
$this->eStep10_5_UpdateCategories();
// STEP 11: Prepare new gallery images and prepare deletion of others ones.

View File

@@ -24,7 +24,7 @@ class XenforoApiService {
*/
private function get(string $endpoint, ?int $customUserId = null ): mixed
{
$response = Http::withHeaders([
$response = Http::timeout(30)->withHeaders([
'XF-Api-Key' => $this->apiKey,
'XF-Api-User' => $customUserId ?? $this->superUserId,
])->get("{$this->apiUrl}/{$endpoint}");
@@ -37,7 +37,7 @@ class XenforoApiService {
private function post(string $endpoint, ?int $customUserId = null, array $data = [] ): mixed
{
$response = Http::withHeaders([
$response = Http::timeout(30)->withHeaders([
'XF-Api-Key' => $this->apiKey,
'XF-Api-User' => $customUserId ?? $this->superUserId,
])->post("{$this->apiUrl}/{$endpoint}", $data);
@@ -50,7 +50,7 @@ class XenforoApiService {
private function delete(string $endpoint, ?int $customUserId = null, array $data = [] ): mixed
{
$response = Http::withHeaders([
$response = Http::timeout(30)->withHeaders([
'XF-Api-Key' => $this->apiKey,
'XF-Api-User' => $customUserId ?? $this->superUserId,
])->delete("{$this->apiUrl}/{$endpoint}", $data);
@@ -75,7 +75,7 @@ class XenforoApiService {
public function markAllNotificationsRead(int $userId): void
{
Cache::forget("xf_alerts_{$userId}");
$this->post("alerts/marl-all", $userId );
$this->post("alerts/mark-all", $userId );
}
public function getConversations(int $userId): mixed
@@ -87,8 +87,9 @@ class XenforoApiService {
public function createConversation( array $userIdList, string $title, string $message, bool $conversationOpen, bool $openInvite ): bool
{
$response = $this->post("conversations", data: ['recipient_ids' => $userIdList, 'title' => $title, 'message' => $message, 'open_invite' => $openInvite, 'conversation_open' => $conversationOpen] );
$response = $this->post("conversations",
data: ['recipient_ids' => $userIdList, 'title' => $title, 'message' => $message, 'open_invite' => $openInvite, 'conversation_open' => $conversationOpen]
);
return $response['success'] ?? false;
}
@@ -152,4 +153,13 @@ class XenforoApiService {
return (bool) $this->post("threads/{$threadId}/undelete" );
}
public function _migrateUser(array $data): array
{
$response = $this->post("migrate/user", data: $data );
if( !$response || !$response['success'] )
return [false,false];
return [ $response['user_id'] ?? false, $response['password_set'] ?? false ];
}
}