2016-02-27 23:35:12 +00:00
|
|
|
<?php
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2016-02-27 23:35:12 +00:00
|
|
|
namespace Pterodactyl\Models;
|
|
|
|
|
2020-02-08 23:23:08 +00:00
|
|
|
use Illuminate\Container\Container;
|
2017-09-17 04:10:00 +00:00
|
|
|
use Znck\Eloquent\Traits\BelongsToThrough;
|
2020-02-08 23:23:08 +00:00
|
|
|
use Pterodactyl\Contracts\Extensions\HashidsInterface;
|
2016-02-27 23:35:12 +00:00
|
|
|
|
2020-02-08 23:23:08 +00:00
|
|
|
/**
|
2021-01-28 04:52:11 +00:00
|
|
|
* @property int $id
|
|
|
|
* @property int $schedule_id
|
|
|
|
* @property int $sequence_id
|
|
|
|
* @property string $action
|
|
|
|
* @property string $payload
|
|
|
|
* @property int $time_offset
|
|
|
|
* @property bool $is_queued
|
2021-05-01 17:44:40 +00:00
|
|
|
* @property bool $continue_on_failure
|
2021-01-28 04:52:11 +00:00
|
|
|
* @property \Carbon\Carbon $created_at
|
|
|
|
* @property \Carbon\Carbon $updated_at
|
|
|
|
* @property string $hashid
|
2020-02-08 23:23:08 +00:00
|
|
|
* @property \Pterodactyl\Models\Schedule $schedule
|
2021-01-28 04:52:11 +00:00
|
|
|
* @property \Pterodactyl\Models\Server $server
|
2020-02-08 23:23:08 +00:00
|
|
|
*/
|
2020-04-04 06:22:35 +00:00
|
|
|
class Task extends Model
|
2016-02-27 23:35:12 +00:00
|
|
|
{
|
2019-09-05 04:00:34 +00:00
|
|
|
use BelongsToThrough;
|
2017-09-10 04:55:21 +00:00
|
|
|
|
2018-01-26 03:26:06 +00:00
|
|
|
/**
|
|
|
|
* The resource name for this model when it is transformed into an
|
|
|
|
* API representation using fractal.
|
|
|
|
*/
|
2021-01-23 20:33:34 +00:00
|
|
|
public const RESOURCE_NAME = 'schedule_task';
|
2018-01-26 03:26:06 +00:00
|
|
|
|
2021-05-01 17:44:40 +00:00
|
|
|
/**
|
|
|
|
* The default actions that can exist for a task in Pterodactyl.
|
|
|
|
*/
|
|
|
|
public const ACTION_POWER = 'power';
|
|
|
|
public const ACTION_COMMAND = 'command';
|
|
|
|
public const ACTION_BACKUP = 'backup';
|
|
|
|
|
2016-02-27 23:35:12 +00:00
|
|
|
/**
|
|
|
|
* The table associated with the model.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $table = 'tasks';
|
|
|
|
|
|
|
|
/**
|
2017-09-13 04:45:19 +00:00
|
|
|
* Relationships to be updated when this model is updated.
|
2016-02-27 23:35:12 +00:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-09-13 04:45:19 +00:00
|
|
|
protected $touches = ['schedule'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fields that are mass assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $fillable = [
|
|
|
|
'schedule_id',
|
2017-09-14 02:46:43 +00:00
|
|
|
'sequence_id',
|
2017-09-13 04:45:19 +00:00
|
|
|
'action',
|
|
|
|
'payload',
|
|
|
|
'time_offset',
|
|
|
|
'is_queued',
|
2021-05-01 17:44:40 +00:00
|
|
|
'continue_on_failure',
|
2017-09-13 04:45:19 +00:00
|
|
|
];
|
2016-02-27 23:35:12 +00:00
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
|
|
|
* Cast values to correct type.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
|
|
|
'id' => 'integer',
|
2017-09-13 04:45:19 +00:00
|
|
|
'schedule_id' => 'integer',
|
2017-09-14 02:46:43 +00:00
|
|
|
'sequence_id' => 'integer',
|
2017-09-13 04:45:19 +00:00
|
|
|
'time_offset' => 'integer',
|
|
|
|
'is_queued' => 'boolean',
|
2021-05-01 17:44:40 +00:00
|
|
|
'continue_on_failure' => 'boolean',
|
2017-03-19 23:36:50 +00:00
|
|
|
];
|
2016-02-27 23:35:12 +00:00
|
|
|
|
2017-09-10 04:55:21 +00:00
|
|
|
/**
|
|
|
|
* Default attributes when creating a new model.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $attributes = [
|
2020-03-19 05:28:32 +00:00
|
|
|
'time_offset' => 0,
|
2017-09-13 04:45:19 +00:00
|
|
|
'is_queued' => false,
|
2021-05-01 17:44:40 +00:00
|
|
|
'continue_on_failure' => false,
|
2017-09-10 04:55:21 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2019-09-05 05:19:57 +00:00
|
|
|
public static $validationRules = [
|
|
|
|
'schedule_id' => 'required|numeric|exists:schedules,id',
|
|
|
|
'sequence_id' => 'required|numeric|min:1',
|
|
|
|
'action' => 'required|string',
|
2020-06-19 04:00:04 +00:00
|
|
|
'payload' => 'required_unless:action,backup|string',
|
2019-09-05 05:19:57 +00:00
|
|
|
'time_offset' => 'required|numeric|between:0,900',
|
2017-09-13 04:45:19 +00:00
|
|
|
'is_queued' => 'boolean',
|
2021-05-01 17:44:40 +00:00
|
|
|
'continue_on_failure' => 'boolean',
|
2017-09-10 04:55:21 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a hashid encoded string to represent the ID of the task.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getHashidAttribute()
|
|
|
|
{
|
2020-02-08 23:23:08 +00:00
|
|
|
return Container::getInstance()->make(HashidsInterface::class)->encode($this->id);
|
2017-09-10 04:55:21 +00:00
|
|
|
}
|
|
|
|
|
2017-04-15 17:52:43 +00:00
|
|
|
/**
|
2017-09-13 04:45:19 +00:00
|
|
|
* Return the schedule that a task belongs to.
|
2017-04-15 17:52:43 +00:00
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
2017-09-13 04:45:19 +00:00
|
|
|
public function schedule()
|
2017-04-15 17:52:43 +00:00
|
|
|
{
|
2017-09-13 04:45:19 +00:00
|
|
|
return $this->belongsTo(Schedule::class);
|
2017-04-15 17:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-09-13 04:45:19 +00:00
|
|
|
* Return the server a task is assigned to, acts as a belongsToThrough.
|
2017-04-15 17:52:43 +00:00
|
|
|
*
|
2017-09-17 04:10:00 +00:00
|
|
|
* @return \Znck\Eloquent\Relations\BelongsToThrough
|
2021-01-23 20:33:34 +00:00
|
|
|
*
|
2017-09-17 04:10:00 +00:00
|
|
|
* @throws \Exception
|
2017-04-15 17:52:43 +00:00
|
|
|
*/
|
2017-09-13 04:45:19 +00:00
|
|
|
public function server()
|
2017-09-10 04:55:21 +00:00
|
|
|
{
|
2017-09-17 04:10:00 +00:00
|
|
|
return $this->belongsToThrough(Server::class, Schedule::class);
|
2017-09-10 04:55:21 +00:00
|
|
|
}
|
2016-02-27 23:35:12 +00:00
|
|
|
}
|