Club System
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Services;
|
||||
|
||||
use App\Exceptions\SubmissionException;
|
||||
use App\Helpers\EntryHelpers;
|
||||
use App\Helpers\XenForoHelpers;
|
||||
use App\Http\Requests\StoreEntryRequest;
|
||||
use App\Jobs\CreateXenForoCommentsThread;
|
||||
use App\Models\Author;
|
||||
@@ -70,7 +71,8 @@ class SubmissionsService {
|
||||
'currentChunk' => 0,
|
||||
'done' => true,
|
||||
'error' => null,
|
||||
'uuid' => $uuid
|
||||
'uuid' => $uuid,
|
||||
'state' => $file->state
|
||||
];
|
||||
|
||||
$file = Cache::get("uploaded_file_{$uuid}");
|
||||
@@ -83,7 +85,8 @@ class SubmissionsService {
|
||||
'currentChunk' => 0,
|
||||
'done' => true,
|
||||
'error' => null,
|
||||
'uuid' => $uuid
|
||||
'uuid' => $uuid,
|
||||
'state' => $file['state']
|
||||
];
|
||||
|
||||
return null;
|
||||
@@ -105,7 +108,7 @@ class SubmissionsService {
|
||||
|
||||
$this->request = $request;
|
||||
$this->section = $section;
|
||||
$user_id = 0; // TODO: Replace that.
|
||||
$user_id = \Auth::user()->user_id;
|
||||
|
||||
$entry = DB::transaction(function () use ( $user_id ) {
|
||||
|
||||
@@ -184,6 +187,9 @@ class SubmissionsService {
|
||||
// Step 13: Try to create the comments section.
|
||||
$this->Step13_CreateCommentsThread( $entry );
|
||||
|
||||
// Step 14: Refresh XF count.
|
||||
XenForoHelpers::updateEntriesCount( $entry->user_id );
|
||||
|
||||
return $entry;
|
||||
|
||||
}
|
||||
@@ -417,7 +423,14 @@ class SubmissionsService {
|
||||
$this->request = $request;
|
||||
$this->section = $section;
|
||||
$this->entry = $entry;
|
||||
$user_id = 0; // TODO: Replace that.
|
||||
|
||||
if( \Auth::user()->can('moderate', $entry) ){
|
||||
$user_id = $this->request->input('owner_user_id');
|
||||
$oldUserId = $this->entry->user_id;
|
||||
} else {
|
||||
$user_id = \Auth::user()->user_id;
|
||||
$oldUserId = null;
|
||||
}
|
||||
|
||||
$oldMainImage = $entry->main_image;
|
||||
$galleryPaths = [];
|
||||
@@ -465,6 +478,11 @@ class SubmissionsService {
|
||||
'user_id' => $user_id,
|
||||
'complete_title' => $completeTitle,
|
||||
];
|
||||
|
||||
if( \Auth::user()->can('moderate', $this->entry) ){
|
||||
$fields['staff_comment'] = $this->request->input('staff_comment');
|
||||
}
|
||||
|
||||
$this->entry->update( $fields );
|
||||
|
||||
// STEP 6: Update entry files.
|
||||
@@ -500,6 +518,11 @@ class SubmissionsService {
|
||||
// STEP 11 : Update gallery storage.
|
||||
$this->eStep11c_UpdateGalleryImages( $galleryPaths );
|
||||
|
||||
// STEP 12: Refresh XF count.
|
||||
if( $oldUserId )
|
||||
XenForoHelpers::updateEntriesCount( $oldUserId );
|
||||
XenForoHelpers::updateEntriesCount( $entry->user_id );
|
||||
|
||||
return $entry;
|
||||
}
|
||||
|
||||
@@ -540,6 +563,7 @@ class SubmissionsService {
|
||||
private function eStep6_UpdateEntryFiles(int $entryId ): void
|
||||
{
|
||||
$requestUuids = $this->request->input('files_uuid', []);
|
||||
$requestStates = $this->request->input('files_state', []);
|
||||
$existingUuids = EntryFile::where( 'entry_id', $entryId )->pluck('file_uuid')->toArray();
|
||||
|
||||
$needDeletion = array_diff( $existingUuids, $requestUuids );
|
||||
@@ -552,6 +576,11 @@ class SubmissionsService {
|
||||
if( !empty( $needAddition ) ){
|
||||
$this->Step7_SaveEntryFiles( $this->entry->id, $needAddition ); // Same code.
|
||||
}
|
||||
|
||||
$stateMap = array_combine( $requestUuids, $requestStates );
|
||||
foreach( $stateMap as $uuid => $state ){
|
||||
EntryFile::where('file_uuid', $uuid)->where('entry_id', $entryId)->where('state', '!=', 'archived')->update(['state' => $state]);
|
||||
}
|
||||
}
|
||||
|
||||
private function eStep7_UpdateHashes(int $entryId): void
|
||||
|
||||
Reference in New Issue
Block a user