2016-02-28 00:35:12 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Pterodactyl - Panel
|
2017-01-24 23:57:08 +01:00
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
2016-02-28 00:35:12 +01:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
2016-12-07 23:46:38 +01:00
|
|
|
|
2016-02-28 00:35:12 +01:00
|
|
|
namespace Pterodactyl\Models;
|
|
|
|
|
2017-09-10 06:55:21 +02:00
|
|
|
use Sofa\Eloquence\Eloquence;
|
|
|
|
use Sofa\Eloquence\Validable;
|
2016-02-28 00:35:12 +01:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2017-09-10 06:55:21 +02:00
|
|
|
use Sofa\Eloquence\Contracts\CleansAttributes;
|
|
|
|
use Sofa\Eloquence\Contracts\Validable as ValidableContract;
|
2016-02-28 00:35:12 +01:00
|
|
|
|
2017-09-10 06:55:21 +02:00
|
|
|
class Task extends Model implements CleansAttributes, ValidableContract
|
2016-02-28 00:35:12 +01:00
|
|
|
{
|
2017-09-10 06:55:21 +02:00
|
|
|
use Eloquence, Validable;
|
|
|
|
|
2016-02-28 00:35:12 +01:00
|
|
|
/**
|
|
|
|
* The table associated with the model.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $table = 'tasks';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fields that are not mass assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $guarded = ['id', 'created_at', 'updated_at'];
|
|
|
|
|
2017-03-20 00:36:50 +01:00
|
|
|
/**
|
|
|
|
* Cast values to correct type.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
|
|
|
'id' => 'integer',
|
2017-04-15 19:52:43 +02:00
|
|
|
'user_id' => 'integer',
|
|
|
|
'server_id' => 'integer',
|
|
|
|
'queued' => 'boolean',
|
|
|
|
'active' => 'boolean',
|
2017-03-20 00:36:50 +01:00
|
|
|
];
|
2016-02-28 00:35:12 +01:00
|
|
|
|
2017-09-10 06:55:21 +02:00
|
|
|
/**
|
|
|
|
* 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',
|
|
|
|
];
|
|
|
|
|
2016-12-07 23:46:38 +01:00
|
|
|
/**
|
2016-02-28 00:35:12 +01:00
|
|
|
* The attributes that should be mutated to dates.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $dates = ['last_run', 'next_run', 'created_at', 'updated_at'];
|
2017-04-15 19:52:43 +02:00
|
|
|
|
2017-09-10 06:55:21 +02:00
|
|
|
/**
|
|
|
|
* Return a hashid encoded string to represent the ID of the task.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getHashidAttribute()
|
|
|
|
{
|
|
|
|
return app()->make('hashids')->encode($this->id);
|
|
|
|
}
|
|
|
|
|
2017-04-15 19:52:43 +02:00
|
|
|
/**
|
|
|
|
* Gets the server associated with a task.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
|
|
|
public function server()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Server::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the user associated with a task.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
|
|
|
public function user()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
}
|
2017-09-10 06:55:21 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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');
|
|
|
|
}
|
2016-02-28 00:35:12 +01:00
|
|
|
}
|