2016-02-27 23:35:12 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Pterodactyl - Panel
|
2017-01-24 22:57:08 +00:00
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
2016-02-27 23:35:12 +00: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 22:46:38 +00:00
|
|
|
|
2016-02-27 23:35:12 +00:00
|
|
|
namespace Pterodactyl\Models;
|
|
|
|
|
2017-09-10 04:55:21 +00:00
|
|
|
use Sofa\Eloquence\Eloquence;
|
|
|
|
use Sofa\Eloquence\Validable;
|
2016-02-27 23:35:12 +00:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2017-09-10 04:55:21 +00:00
|
|
|
use Sofa\Eloquence\Contracts\CleansAttributes;
|
|
|
|
use Sofa\Eloquence\Contracts\Validable as ValidableContract;
|
2016-02-27 23:35:12 +00:00
|
|
|
|
2017-09-10 04:55:21 +00:00
|
|
|
class Task extends Model implements CleansAttributes, ValidableContract
|
2016-02-27 23:35:12 +00:00
|
|
|
{
|
2017-09-10 04:55:21 +00:00
|
|
|
use Eloquence, Validable;
|
|
|
|
|
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',
|
|
|
|
'squence_id',
|
|
|
|
'action',
|
|
|
|
'payload',
|
|
|
|
'time_offset',
|
|
|
|
'is_queued',
|
|
|
|
];
|
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',
|
|
|
|
'squence_id' => 'integer',
|
|
|
|
'time_offset' => 'integer',
|
|
|
|
'is_queued' => '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 = [
|
2017-09-13 04:45:19 +00:00
|
|
|
'is_queued' => false,
|
2017-09-10 04:55:21 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected static $applicationRules = [
|
2017-09-13 04:45:19 +00:00
|
|
|
'schedule_id' => 'required',
|
|
|
|
'squence_id' => 'required',
|
2017-09-10 04:55:21 +00:00
|
|
|
'action' => 'required',
|
2017-09-13 04:45:19 +00:00
|
|
|
'payload' => 'required',
|
|
|
|
'time_offset' => 'required',
|
2017-09-10 04:55:21 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected static $dataIntegrityRules = [
|
2017-09-13 04:45:19 +00:00
|
|
|
'schedule_id' => 'numeric|exists:schedules,id',
|
|
|
|
'squence_id' => 'numeric|min:1',
|
2017-09-10 04:55:21 +00:00
|
|
|
'action' => 'string',
|
2017-09-13 04:45:19 +00:00
|
|
|
'payload' => 'string',
|
|
|
|
'time_offset' => 'numeric|between:0,900',
|
|
|
|
'is_queued' => '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()
|
|
|
|
{
|
|
|
|
return app()->make('hashids')->encode($this->id);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
2017-09-13 04:45:19 +00:00
|
|
|
public function server()
|
2017-09-10 04:55:21 +00:00
|
|
|
{
|
2017-09-13 04:45:19 +00:00
|
|
|
if ($schedule = $this->schedule) {
|
|
|
|
return $schedule->server();
|
|
|
|
} else {
|
|
|
|
throw new \InvalidArgumentException('Instance of Task must have an associated Schedule in the database.');
|
|
|
|
}
|
2017-09-10 04:55:21 +00:00
|
|
|
}
|
2016-02-27 23:35:12 +00:00
|
|
|
}
|