2022-05-19 00:32:40 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2022-05-23 01:08:08 +02:00
|
|
|
use App\Services\TaskScheduler\TaskSchedulerService;
|
2022-05-19 00:32:40 +02:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property boolean paused
|
|
|
|
* @property boolean archived
|
|
|
|
* @property \Carbon\Carbon|mixed start_from
|
|
|
|
* @property string repeat_every
|
|
|
|
* @property \Carbon\Carbon|mixed scheduled_run
|
|
|
|
*/
|
|
|
|
class Scheduler extends Model
|
|
|
|
{
|
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
'start_from',
|
|
|
|
'paused',
|
|
|
|
'archived',
|
|
|
|
'repeat_every',
|
|
|
|
'scheduled_run',
|
|
|
|
];
|
2022-05-23 01:08:08 +02:00
|
|
|
protected $appends = ['linked_job'];
|
|
|
|
|
2022-05-19 00:32:40 +02:00
|
|
|
const DAILY = 'DAY';
|
|
|
|
const WEEKLY = 'WEEK';
|
|
|
|
const MONTHLY = 'MONTH';
|
|
|
|
const QUARTERLY = '3MONTHS';
|
|
|
|
const ANNUALLY = 'YEAR';
|
|
|
|
|
2022-05-23 01:08:08 +02:00
|
|
|
public function getLinkedJobAttribute()
|
|
|
|
{
|
|
|
|
return $this->job ?? [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Service entry points.
|
|
|
|
*/
|
|
|
|
public function service(): TaskSchedulerService
|
|
|
|
{
|
|
|
|
return new TaskSchedulerService($this);
|
|
|
|
}
|
|
|
|
|
2022-05-19 00:32:40 +02:00
|
|
|
public function job(): \Illuminate\Database\Eloquent\Relations\HasOne
|
|
|
|
{
|
|
|
|
return $this->hasOne(ScheduledJob::class, 'scheduler_id', 'id');
|
|
|
|
}
|
|
|
|
}
|