Some checks failed
Tests / PHP 8.1 (push) Has been cancelled
Tests / PHP 8.2 (push) Has been cancelled
Tests / PHP 8.3 (push) Has been cancelled
53 lines
1.8 KiB
PHP
53 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs\Common;
|
|
|
|
use App\Abstracts\Job;
|
|
use App\Events\Common\ItemUpdated;
|
|
use App\Events\Common\ItemUpdating;
|
|
use App\Interfaces\Job\ShouldUpdate;
|
|
use App\Jobs\Common\CreateItemTaxes;
|
|
use App\Models\Common\Item;
|
|
|
|
class UpdateItem extends Job implements ShouldUpdate
|
|
{
|
|
public function handle(): Item
|
|
{
|
|
// Security: strip HTML tags from name to prevent stored XSS in delete
|
|
// confirmation modal (CVE-2026-11942). Defense-in-depth alongside e()
|
|
// output encoding in DeleteLink/DeleteButton getMessage().
|
|
if ($this->request->has('name')) {
|
|
$this->request->merge([
|
|
'name' => strip_tags($this->request->get('name')),
|
|
]);
|
|
}
|
|
|
|
event(new ItemUpdating($this->model, $this->request));
|
|
|
|
\DB::transaction(function () {
|
|
$this->model->update($this->request->all());
|
|
|
|
// Upload picture
|
|
if ($this->request->file('picture')) {
|
|
$this->deleteMediaModel($this->model, 'picture', $this->request);
|
|
|
|
$media = $this->getMedia($this->request->file('picture'), 'items');
|
|
|
|
$this->model->attachMedia($media, 'picture');
|
|
} elseif ($this->request->isNotApi() && ! $this->request->file('picture') && $this->model->picture) {
|
|
$this->deleteMediaModel($this->model, 'picture', $this->request);
|
|
} elseif ($this->request->isApi() && $this->request->has('remove_picture') && $this->model->picture) {
|
|
$this->deleteMediaModel($this->model, 'picture', $this->request);
|
|
}
|
|
|
|
$this->deleteRelationships($this->model, ['taxes']);
|
|
|
|
$this->dispatch(new CreateItemTaxes($this->model, $this->request));
|
|
});
|
|
|
|
event(new ItemUpdated($this->model, $this->request));
|
|
|
|
return $this->model;
|
|
}
|
|
}
|