A lot of things

This commit is contained in:
2026-06-16 16:21:43 +02:00
parent 4f9f6c63b3
commit 7e1e26f20b
126 changed files with 7917 additions and 204 deletions

View File

@@ -4,9 +4,11 @@ namespace App\Services;
use App\Exceptions\SubmissionException;
use App\Helpers\EntryHelpers;
use App\Helpers\PlayOnlineHelpers;
use App\Helpers\XenForoHelpers;
use App\Http\Requests\StoreEntryRequest;
use App\Jobs\CreateXenForoCommentsThread;
use App\Jobs\DeleteFile;
use App\Models\Author;
use App\Models\Category;
use App\Models\Entry;
@@ -76,8 +78,12 @@ class SubmissionsService {
'error' => null,
'uuid' => $uuid,
'state' => $file->state,
'can_be_online_patched' => EntryHelpers::enableOnlinePatcherBasedOnExtension($file['filename']),
'meta_online_patcher' => $file->online_patcher,
'meta_secondary_online_patcher' => $file->secondary_online_patcher,
'meta_play_online' => $file->playOnlineSetting()->exists() ? true : false,
'meta_play_online_core' => $file->playOnlineSetting()->exists() ? $file->playOnlineSetting->core : '',
'meta_play_online_threads' => $file->playOnlineSetting()->exists() ? $file->playOnlineSetting->threads : false,
];
$file = Cache::get("uploaded_file_{$uuid}");
@@ -92,8 +98,12 @@ class SubmissionsService {
'error' => null,
'uuid' => $uuid,
'state' => $file['state'],
'can_be_online_patched' => EntryHelpers::enableOnlinePatcherBasedOnExtension($file['filename']),
'meta_online_patcher' => false,
'meta_secondary_online_patcher' => false,
'meta_play_online' => false,
'meta_play_online_core' => null,
'meta_play_online_threads' => false
];
return null;
@@ -298,15 +308,20 @@ class SubmissionsService {
foreach ( $uuidData ?? [] as $uuid ) {
$fileData = Cache::pull("uploaded_file_{$uuid}");
if( !$fileData )
throw new SubmissionException( "File {$uuid} has expired. Please delete all your files and retry. If it's an edition, delete all your new files and retry." );
throw new SubmissionException( "File {$uuid} has expired. Please delete all your files and retry. If it's an edition, delete all the new files and retry." );
$onlinePatcher = (bool)($metadataArray[$uuid]['online_patcher'] ?? false);
if( !$onlinePatcher )
$onlinePatcher = EntryHelpers::enableOnlinePatcherBasedOnExtension( $fileData['filename'] );
if( section_must_be( [ 'romhacks', 'translations' ], $entry->type ) ) {
$onlinePatcher = (bool)($metadataArray[$uuid]['online_patcher'] ?? false);
if (!$onlinePatcher)
$onlinePatcher = EntryHelpers::enableOnlinePatcherBasedOnExtension($fileData['filename']);
$secondaryOnlinePatcher = (bool)($metadataArray[$uuid]['secondary_online_patcher'] ?? false);
$secondaryOnlinePatcher = (bool)($metadataArray[$uuid]['secondary_online_patcher'] ?? false);
} else {
$onlinePatcher = false;
$secondaryOnlinePatcher = false;
}
EntryFile::create([
$file = EntryFile::create([
'entry_id' => $entry->id,
'file_uuid' => $uuid,
'filename' => $fileData['filename'],
@@ -319,6 +334,26 @@ class SubmissionsService {
'secondary_online_patcher' => $secondaryOnlinePatcher,
]);
if( section_must_be( ['romhacks', 'translations', 'homebrew'], $entry->type ) ) {
$playOnline = (bool)($metadataArray[$uuid]['play_online'] ?? false);
$playOnlineCore = $metadataArray[$uuid]['play_online_core'] ?? null;
$playOnlineThreads = (bool)($metadataArray[$uuid]['play_online_threads'] ?? false);
if (!$playOnline && $entry->getRealPlatform()?->play_online_core !== null) {
$playOnline = true;
$playOnlineCore = $entry->getRealPlatform()?->play_online_core;
}
if ($playOnline) {
$file->playOnlineSetting()->updateOrCreate(
['file_id' => $file->id],
[
'core' => $playOnlineCore,
'threads' => $playOnlineThreads,
]
);
}
}
}
}
@@ -452,9 +487,10 @@ class SubmissionsService {
private function Step12a_PrepareGalleryImages( Entry $entry ): void
{
foreach ( $this->request->input('gallery', [] ) ?? [] as $imagePath ) {
foreach ( $this->request->input('gallery', [] ) ?? [] as $i => $imagePath ) {
$entry->gallery()->create([
'image' => $imagePath,
'order' => $i
]);
}
}
@@ -556,6 +592,10 @@ class SubmissionsService {
if( \Auth::user()->can('moderate', $this->entry) ){
$fields['staff_comment'] = $this->request->input('staff_comment');
$fields['featured'] = $this->request->input('featured') ?? false;
if( $fields['featured'] == true && $this->entry->featured_at === null )
$fields['featured_at'] = now();
if( $fields['featured'] == false )
$fields['featured_at'] = null;
$fields['comments_thread_id'] = $this->request->input('comments_thread_id');
}
@@ -666,6 +706,10 @@ class SubmissionsService {
$needDeletion = array_diff( $existingUuids, $requestUuids );
if( !empty( $needDeletion ) ){
$userId = \Auth::user()->user_id;
EntryFile::where('entry_id', $entryId)->whereIn('file_uuid', $needDeletion)->get()->each( function ( $f ) use ( $userId ) {
DeleteFile::dispatch( $f->filepath, $f->filename, $userId);
});
EntryFile::where('entry_id', $entryId)->whereIn('file_uuid', $needDeletion)->delete();
}
@@ -680,15 +724,45 @@ class SubmissionsService {
foreach( $stateMap as $uuid => $state ){
$onlinePatcher = (bool)($metadataArray[$uuid]['online_patcher'] ?? false);
$secondaryOnlinePatcher = (bool)($metadataArray[$uuid]['secondary_online_patcher'] ?? false);
if( section_must_be( ['romhacks', 'translations'], $this->entry->type ) ) {
$onlinePatcher = (bool)($metadataArray[$uuid]['online_patcher'] ?? false);
$secondaryOnlinePatcher = (bool)($metadataArray[$uuid]['secondary_online_patcher'] ?? false);
} else {
$onlinePatcher = false;
$secondaryOnlinePatcher = false;
}
EntryFile::where('file_uuid', $uuid)->where('entry_id', $entryId)->where('state', '!=', 'archived')
->update([
'state' => $state,
'online_patcher' => $onlinePatcher,
'secondary_online_patcher' => $secondaryOnlinePatcher,
]);
$entryFile = EntryFile::where('file_uuid', $uuid)->where('entry_id', $entryId)->where('state', '!=', 'archived')->first();
if( !$entryFile )
continue;
$entryFile->update([
'state' => $state,
'online_patcher' => $onlinePatcher,
'secondary_online_patcher' => $secondaryOnlinePatcher,
]);
if( section_must_be( ['romhacks', 'translations', 'homebrew'], $this->entry->type ) ) {
$playOnline = (bool)($metadataArray[$uuid]['play_online'] ?? false);
$playOnlineCore = $metadataArray[$uuid]['play_online_core'] ?? null;
$playOnlineThreads = (bool)($metadataArray[$uuid]['play_online_threads'] ?? false);
if ($playOnline) {
if ($playOnlineCore === null || !in_array($playOnlineCore, PlayOnlineHelpers::getCoreLists()))
$playOnlineCore = $this->entry->getRealPlatform()->play_online_core ? $this->entry->getRealPlatform()->play_online_core : 'nes';
$entryFile->playOnlineSetting()->updateOrCreate(
['file_id' => $entryFile->id],
[
'core' => $playOnlineCore,
'threads' => $playOnlineThreads,
]
);
} else {
$entryFile->playOnlineSetting()->delete();
}
}
}
}
@@ -860,6 +934,10 @@ class SubmissionsService {
]);
}
foreach ( $requestGallery as $i => $imagePath ){
$this->entry->gallery()->where('image', $imagePath )->update(['order' => $i]);
}
return [ 'addition' => $images, 'deletion' => $needDeletion ];
}