Changeset View
Changeset View
Standalone View
Standalone View
src/app/Jobs/ResourceJob.php
<?php | <?php | ||||
namespace App\Jobs; | namespace App\Jobs; | ||||
/** | /** | ||||
* The abstract \App\Jobs\ResourceJob implements the logic needed for all dispatchable Jobs related to | * The abstract \App\Jobs\ResourceJob implements the logic needed for all dispatchable Jobs related to | ||||
* \App\Resource objects. | * \App\Resource objects. | ||||
* | * | ||||
* ```php | * ```php | ||||
* $job = new \App\Jobs\Resource\CreateJob($resourceId); | * $job = new \App\Jobs\Resource\CreateJob($resourceId); | ||||
* $job->handle(); | * $job->handle(); | ||||
* ``` | * ``` | ||||
*/ | */ | ||||
abstract class ResourceJob extends CommonJob | abstract class ResourceJob extends CommonJob | ||||
{ | { | ||||
/** | /** | ||||
* Old values of the resource properties on update (key -> value) | |||||
* | |||||
* @var array | |||||
*/ | |||||
protected $properties = []; | |||||
/** | |||||
* The ID for the \App\Resource. This is the shortest globally unique identifier and saves Redis space | * The ID for the \App\Resource. This is the shortest globally unique identifier and saves Redis space | ||||
* compared to a serialized version of the complete \App\Resource object. | * compared to a serialized version of the complete \App\Resource object. | ||||
* | * | ||||
* @var int | * @var int | ||||
*/ | */ | ||||
protected $resourceId; | protected $resourceId; | ||||
/** | /** | ||||
* The \App\Resource email property, for legibility in the queue management. | * The \App\Resource email property, for legibility in the queue management. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
protected $resourceEmail; | protected $resourceEmail; | ||||
/** | /** | ||||
* Create a new job instance. | * Create a new job instance. | ||||
* | * | ||||
* @param int $resourceId The ID for the resource to process. | * @param int $resourceId The ID for the resource to process. | ||||
* @param array $properties Old values of the resource properties on update | |||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function __construct(int $resourceId) | public function __construct(int $resourceId, array $properties = []) | ||||
{ | { | ||||
$this->resourceId = $resourceId; | $this->resourceId = $resourceId; | ||||
$this->properties = $properties; | |||||
$resource = $this->getResource(); | $resource = $this->getResource(); | ||||
if ($resource) { | if ($resource) { | ||||
$this->resourceEmail = $resource->email; | $this->resourceEmail = $resource->email; | ||||
} | } | ||||
} | } | ||||
Show All 25 Lines |