-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add job for attaching context to contents (#2918)
- Loading branch information
1 parent
02ac244
commit 3bab59e
Showing
7 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
sourcecode/hub/app/Http/Requests/AttachContextToContentsRequest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Requests; | ||
|
||
use App\Models\Context; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Validation\Rule; | ||
|
||
class AttachContextToContentsRequest extends FormRequest | ||
{ | ||
/** | ||
* @return array<mixed> | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'context' => ['required', Rule::exists(Context::class, 'id')], | ||
]; | ||
} | ||
|
||
public function getContext(): Context | ||
{ | ||
return Context::where('id', $this->validated('context'))->firstOrFail(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Models\Content; | ||
use App\Models\Context; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class AttachContextToContents | ||
{ | ||
use Dispatchable; | ||
use Queueable; | ||
use SerializesModels; | ||
|
||
public function __construct(private readonly Context $context) {} | ||
|
||
public function handle(): void | ||
{ | ||
Content::lazy()->each(function (Content $content) { | ||
$content->contexts()->syncWithoutDetaching([$this->context]); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
sourcecode/hub/resources/views/admin/contexts/attach-to-contents.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<x-layout> | ||
<x-slot:title>{{ trans('messages.attach-context-to-contents') }}</x-slot:title> | ||
|
||
<p class="alert alert-danger">{{ trans('messages.attach-context-to-contents-warning') }}</p> | ||
|
||
<x-form action="" method="POST"> | ||
<x-form.field | ||
name="context" | ||
type="select" | ||
emptyOption | ||
required | ||
:label="trans('messages.context')" | ||
:options="$available_contexts" | ||
/> | ||
|
||
<x-form.button class="btn btn-primary">{{ trans('messages.start-job') }}</x-form.button> | ||
</x-form> | ||
</x-layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters