Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2555788
ResourceJob.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
ResourceJob.php
View Options
<?php
namespace
App\Jobs
;
/**
* The abstract \App\Jobs\ResourceJob implements the logic needed for all dispatchable Jobs related to
* \App\Resource objects.
*
* ```php
* $job = new \App\Jobs\Resource\CreateJob($resourceId);
* $job->handle();
* ```
*/
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
* compared to a serialized version of the complete \App\Resource object.
*
* @var int
*/
protected
$resourceId
;
/**
* The \App\Resource email property, for legibility in the queue management.
*
* @var string
*/
protected
$resourceEmail
;
/**
* Create a new job instance.
*
* @param int $resourceId The ID for the resource to process.
* @param array $properties Old values of the resource properties on update
*
* @return void
*/
public
function
__construct
(
int
$resourceId
,
array
$properties
=
[])
{
$this
->
resourceId
=
$resourceId
;
$this
->
properties
=
$properties
;
$resource
=
$this
->
getResource
();
if
(
$resource
)
{
$this
->
resourceEmail
=
$resource
->
email
;
}
}
/**
* Get the \App\Resource entry associated with this job.
*
* @return \App\Resource|null
*
* @throws \Exception
*/
protected
function
getResource
()
{
$resource
=
\App\Resource
::
withTrashed
()->
find
(
$this
->
resourceId
);
if
(!
$resource
)
{
// The record might not exist yet in case of a db replication environment
// This will release the job and delay another attempt for 5 seconds
if
(
$this
instanceof
Resource\CreateJob
)
{
$this
->
release
(
5
);
return
null
;
}
$this
->
fail
(
new
\Exception
(
"Resource {$this->resourceId} could not be found in the database."
));
}
return
$resource
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Feb 27, 2:44 PM (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
446941
Default Alt Text
ResourceJob.php (2 KB)
Attached To
Mode
R2 kolab
Attached
Detach File
Event Timeline
Log In to Comment