added pointer interfaces for jobs
This commit is contained in:
@ -3,67 +3,45 @@
|
||||
namespace App\Jobs\Setting;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Interfaces\Job\ShouldUpdate;
|
||||
use App\Models\Setting\Category;
|
||||
|
||||
class UpdateCategory extends Job
|
||||
class UpdateCategory extends Job implements ShouldUpdate
|
||||
{
|
||||
protected $category;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $category
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($category, $request)
|
||||
{
|
||||
$this->category = $category;
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Category
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): Category
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
\DB::transaction(function () {
|
||||
$this->category->update($this->request->all());
|
||||
$this->model->update($this->request->all());
|
||||
});
|
||||
|
||||
return $this->category;
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this action is applicable.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function authorize()
|
||||
public function authorize(): void
|
||||
{
|
||||
if (!$relationships = $this->getRelationships()) {
|
||||
if (! $relationships = $this->getRelationships()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->request->has('type') && ($this->request->get('type') != $this->category->type)) {
|
||||
if ($this->request->has('type') && ($this->request->get('type') != $this->model->type)) {
|
||||
$message = trans('messages.error.change_type', ['text' => implode(', ', $relationships)]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
|
||||
if (!$this->request->get('enabled')) {
|
||||
$message = trans('messages.warning.disabled', ['name' => $this->category->name, 'text' => implode(', ', $relationships)]);
|
||||
if (! $this->request->get('enabled')) {
|
||||
$message = trans('messages.warning.disabled', ['name' => $this->model->name, 'text' => implode(', ', $relationships)]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getRelationships()
|
||||
public function getRelationships(): array
|
||||
{
|
||||
$rels = [
|
||||
'items' => 'items',
|
||||
@ -72,6 +50,6 @@ class UpdateCategory extends Job
|
||||
'transactions' => 'transactions',
|
||||
];
|
||||
|
||||
return $this->countRelationships($this->category, $rels);
|
||||
return $this->countRelationships($this->model, $rels);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user