Initial implementation of new task mgmt system 👮
This commit is contained in:
parent
f157c06d04
commit
bab28dbc85
31 changed files with 1535 additions and 132 deletions
|
@ -24,10 +24,16 @@
|
|||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
use Sofa\Eloquence\Eloquence;
|
||||
use Sofa\Eloquence\Validable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Sofa\Eloquence\Contracts\CleansAttributes;
|
||||
use Sofa\Eloquence\Contracts\Validable as ValidableContract;
|
||||
|
||||
class Task extends Model
|
||||
class Task extends Model implements CleansAttributes, ValidableContract
|
||||
{
|
||||
use Eloquence, Validable;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
|
@ -55,6 +61,53 @@ class Task extends Model
|
|||
'active' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Default attributes when creating a new model.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'parent_task_id' => null,
|
||||
'chain_order' => null,
|
||||
'active' => true,
|
||||
'day_of_week' => '*',
|
||||
'day_of_month' => '*',
|
||||
'hour' => '*',
|
||||
'minute' => '*',
|
||||
'chain_delay' => null,
|
||||
'queued' => false,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $applicationRules = [
|
||||
'server_id' => 'required',
|
||||
'action' => 'required',
|
||||
'data' => 'required',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $dataIntegrityRules = [
|
||||
'name' => 'nullable|string|max:255',
|
||||
'parent_task_id' => 'nullable|numeric|exists:tasks,id',
|
||||
'chain_order' => 'nullable|numeric|min:1',
|
||||
'server_id' => 'numeric|exists:servers,id',
|
||||
'active' => 'boolean',
|
||||
'action' => 'string',
|
||||
'data' => 'string',
|
||||
'queued' => 'boolean',
|
||||
'day_of_month' => 'string',
|
||||
'day_of_week' => 'string',
|
||||
'hour' => 'string',
|
||||
'minute' => 'string',
|
||||
'chain_delay' => 'nullable|numeric|between:1,900',
|
||||
'last_run' => 'nullable|timestamp',
|
||||
'next_run' => 'nullable|timestamp',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
|
@ -62,6 +115,16 @@ class Task extends Model
|
|||
*/
|
||||
protected $dates = ['last_run', 'next_run', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* Return a hashid encoded string to represent the ID of the task.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHashidAttribute()
|
||||
{
|
||||
return app()->make('hashids')->encode($this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server associated with a task.
|
||||
*
|
||||
|
@ -81,4 +144,14 @@ class Task extends Model
|
|||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return chained tasks for a parent task.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function chained()
|
||||
{
|
||||
return $this->hasMany(self::class, 'parent_task_id')->orderBy('chain_order', 'asc');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue