first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-06-08 17:09:23 -04:00
commit df3a033196
17887 changed files with 8637778 additions and 0 deletions
+119
View File
@@ -0,0 +1,119 @@
<?php
declare(strict_types=1);
/**
* @file classes/job/traits/Attributes.php
*
* Copyright (c) 2014-2022 Simon Fraser University
* Copyright (c) 2000-2022 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class Attributes
*
* @brief Attributes trait for Jobs model
*/
namespace PKP\job\traits;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Date;
/**
* Those attributes become from payload array
*/
trait Attributes
{
/**
* Return the job's display name value
*
*/
public function getDisplayNameAttribute(): ?string
{
if (!$this->payload['displayName']) {
return null;
}
return $this->payload['displayName'];
}
/**
* Return the job's max tries value
*
*/
public function getMaxTriesAttribute(): ?string
{
if (!$this->payload['maxTries']) {
return null;
}
return $this->payload['maxTries'];
}
/**
* Return the job's backoff value
*
*/
public function getBackoffAttribute(): ?string
{
if (!$this->payload['backoff']) {
return null;
}
return $this->payload['backoff'];
}
/**
* Return the job's timeout value
*
*/
public function getTimeoutAttribute(): ?string
{
if (!$this->payload['timeout']) {
return null;
}
return $this->payload['timeout'];
}
/**
* Return the job's timeout at value
*
*/
public function getTimeoutAtAttribute(): ?string
{
if (!$this->payload['timeout_at']) {
return null;
}
$obj = new Carbon($this->payload['timeout_at']);
return Date::instance($obj);
}
/**
* Return the job's command name value
*
*/
public function getCommandNameAttribute(): ?string
{
if (!$this->payload['data']['commandName']) {
return null;
}
return $this->payload['data']['commandName'];
}
/**
* Return the job's command value
*
*/
public function getCommandAttribute(): array
{
if (!$this->payload['data']['command']) {
return [];
}
return (array) unserialize($this->payload['data']['command']);
}
}
@@ -0,0 +1,86 @@
<?php
declare(strict_types=1);
/**
* @file classes/job/traits/JobResource.php
*
* Copyright (c) 2014-2022 Simon Fraser University
* Copyright (c) 2000-2022 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class JobResource
*
* @brief JobResource trait
*/
namespace PKP\job\traits;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use PKP\core\PKPRequest;
trait JobResource
{
protected string $dateFormat = 'Y-m-d G:i:s T Z';
public static function toResourceArray(Model $modelInstance): array
{
return (new static($modelInstance))->toArray(app()->get(PKPRequest::class));
}
public function getResource(): mixed
{
return $this->resource;
}
public function getCreatedAt(): string
{
if (!isset($this->getResource()->created_at)) {
return '-';
}
return $this->formatDate($this->getResource()->created_at);
}
public function getReservedAt(): string
{
if (!isset($this->getResource()->reserved_at)) {
return '-';
}
return $this->formatDate($this->getResource()->reserved_at);
}
public function getAvailableAt(): string
{
if (!isset($this->getResource()->available_at)) {
return '-';
}
return $this->formatDate($this->getResource()->available_at);
}
public function getFailedAt(): string
{
if (!isset($this->getResource()->failed_at)) {
return '-';
}
return $this->formatDate($this->getResource()->failed_at);
}
public function getJobName(): ?string
{
if (!isset($this->getResource()->payload)) {
return '-';
}
return $this->getResource()->payload['displayName'] ?? '-';
}
protected function formatDate(Carbon $date): string
{
return $date->format($this->dateFormat);
}
}