mirror of
https://github.com/CachetHQ/Cachet.git
synced 2025-01-17 13:38:20 +01:00
Cleanup models
This commit is contained in:
parent
a14c28b287
commit
a442708062
@ -1,11 +1,14 @@
|
||||
<?php
|
||||
|
||||
use CachetHQ\Cachet\Transformers\ComponentTransformer;
|
||||
use Dingo\Api\Transformer\TransformableInterface;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingTrait;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
class Component extends Eloquent implements \Dingo\Api\Transformer\TransformableInterface
|
||||
class Component extends Model implements TransformableInterface
|
||||
{
|
||||
use ValidatingTrait;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingTrait;
|
||||
use SoftDeletingTrait, ValidatingTrait;
|
||||
|
||||
protected $rules = [
|
||||
'user_id' => 'integer|required',
|
||||
@ -14,20 +17,12 @@ class Component extends Eloquent implements \Dingo\Api\Transformer\Transformable
|
||||
'link' => 'url',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
'status',
|
||||
'user_id',
|
||||
'tags',
|
||||
'link',
|
||||
'order',
|
||||
];
|
||||
protected $fillable = ['name', 'description', 'status', 'user_id', 'tags', 'link', 'order'];
|
||||
|
||||
/**
|
||||
* Lookup all of the incidents reported on the component.
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Relations
|
||||
* @return \Illuminate\Database\Eloquent\Relations
|
||||
*/
|
||||
public function incidents()
|
||||
{
|
||||
@ -37,10 +32,10 @@ class Component extends Eloquent implements \Dingo\Api\Transformer\Transformable
|
||||
/**
|
||||
* Finds all components by status.
|
||||
*
|
||||
* @param Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param int $status
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Builder
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeStatus($query, $status)
|
||||
{
|
||||
@ -50,10 +45,10 @@ class Component extends Eloquent implements \Dingo\Api\Transformer\Transformable
|
||||
/**
|
||||
* Finds all components which don't have the given status.
|
||||
*
|
||||
* @param Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param int $status
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Builder
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeNotStatus($query, $status)
|
||||
{
|
||||
@ -73,10 +68,10 @@ class Component extends Eloquent implements \Dingo\Api\Transformer\Transformable
|
||||
/**
|
||||
* Get the transformer instance.
|
||||
*
|
||||
* @return ComponentTransformer
|
||||
* @return \CachetHQ\Cachet\Transformers\ComponentTransformer
|
||||
*/
|
||||
public function getTransformer()
|
||||
{
|
||||
return new CachetHQ\Cachet\Transformers\ComponentTransformer();
|
||||
return new ComponentTransformer();
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
<?php
|
||||
|
||||
use CachetHQ\Cachet\Transformers\IncidentTransformer;
|
||||
use Dingo\Api\Transformer\TransformableInterface;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingTrait;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
class Incident extends Eloquent implements TransformableInterface
|
||||
class Incident extends Model implements TransformableInterface
|
||||
{
|
||||
use SoftDeletingTrait, ValidatingTrait;
|
||||
|
||||
@ -74,7 +76,7 @@ class Incident extends Eloquent implements TransformableInterface
|
||||
*/
|
||||
public function getTransformer()
|
||||
{
|
||||
return new CachetHQ\Cachet\Transformers\IncidentTransformer();
|
||||
return new IncidentTransformer();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
class IncidentTemplate extends Eloquent
|
||||
class IncidentTemplate extends Model
|
||||
{
|
||||
use ValidatingTrait;
|
||||
|
||||
@ -11,10 +12,7 @@ class IncidentTemplate extends Eloquent
|
||||
'template' => 'required',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'template',
|
||||
];
|
||||
protected $fillable = ['name', 'template'];
|
||||
|
||||
/**
|
||||
* Overrides the models boot method.
|
||||
|
@ -1,8 +1,11 @@
|
||||
<?php
|
||||
|
||||
use CachetHQ\Cachet\Transformers\MetricTransformer;
|
||||
use Dingo\Api\Transformer\TransformableInterface;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
class Metric extends Eloquent implements \Dingo\Api\Transformer\TransformableInterface
|
||||
class Metric extends Model implements TransformableInterface
|
||||
{
|
||||
use ValidatingTrait;
|
||||
|
||||
@ -17,7 +20,7 @@ class Metric extends Eloquent implements \Dingo\Api\Transformer\TransformableInt
|
||||
/**
|
||||
* Metrics contain many metric points.
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Builder
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function points()
|
||||
{
|
||||
@ -37,10 +40,10 @@ class Metric extends Eloquent implements \Dingo\Api\Transformer\TransformableInt
|
||||
/**
|
||||
* Get the transformer instance.
|
||||
*
|
||||
* @return CachetHQ\Cachet\Transformers\MetricTransformer
|
||||
* @return \CachetHQ\Cachet\Transformers\MetricTransformer
|
||||
*/
|
||||
public function getTransformer()
|
||||
{
|
||||
return new CachetHQ\Cachet\Transformers\MetricTransformer();
|
||||
return new MetricTransformer();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
class MetricPoint extends Eloquent
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MetricPoint extends Model
|
||||
{
|
||||
/**
|
||||
* A metric point belongs to a metric unit.
|
||||
|
@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
class Service extends Eloquent
|
||||
class Service extends Model
|
||||
{
|
||||
use ValidatingTrait;
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
class Setting extends Eloquent
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Setting extends Model
|
||||
{
|
||||
protected $fillable = ['name', 'value'];
|
||||
|
||||
@ -20,7 +22,7 @@ class Setting extends Eloquent
|
||||
// First try finding the setting in the database.
|
||||
try {
|
||||
$setting = self::whereName($settingName)->first()->value;
|
||||
} catch (\ErrorException $e) {
|
||||
} catch (ErrorException $e) {
|
||||
// If we don't have a setting, check the env (fallback for original version)
|
||||
if ($checkEnv) {
|
||||
if (!($setting = getenv(strtoupper($settingName)))) {
|
||||
@ -39,14 +41,12 @@ class Setting extends Eloquent
|
||||
*
|
||||
* @param string $setting
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function unknownSettingException($setting)
|
||||
{
|
||||
throw new \Exception(
|
||||
sprintf('Unknown setting %s', $setting)
|
||||
);
|
||||
throw new Exception(sprintf('Unknown setting %s', $setting));
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Eloquent\SoftDeletingTrait;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
class Subscriber extends Eloquent
|
||||
class Subscriber extends Model
|
||||
{
|
||||
use ValidatingTrait;
|
||||
use SoftDeletingTrait;
|
||||
use SoftDeletingTrait, ValidatingTrait;
|
||||
|
||||
protected $rules = [
|
||||
'email' => 'required|email',
|
||||
|
@ -4,8 +4,10 @@ use Illuminate\Auth\Reminders\RemindableInterface;
|
||||
use Illuminate\Auth\Reminders\RemindableTrait;
|
||||
use Illuminate\Auth\UserInterface;
|
||||
use Illuminate\Auth\UserTrait;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class User extends Eloquent implements UserInterface, RemindableInterface
|
||||
class User extends Model implements UserInterface, RemindableInterface
|
||||
{
|
||||
use UserTrait, RemindableTrait;
|
||||
|
||||
@ -33,7 +35,7 @@ class User extends Eloquent implements UserInterface, RemindableInterface
|
||||
/**
|
||||
* Hash any password being inserted by default.
|
||||
*
|
||||
* @param string @password
|
||||
* @param string $password
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -51,10 +53,6 @@ class User extends Eloquent implements UserInterface, RemindableInterface
|
||||
*/
|
||||
public function getGravatarAttribute($size = 200)
|
||||
{
|
||||
return sprintf(
|
||||
'https://www.gravatar.com/avatar/%s?size=%d',
|
||||
md5($this->email),
|
||||
$size
|
||||
);
|
||||
return sprintf('https://www.gravatar.com/avatar/%s?size=%d', md5($this->email), $size);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,10 @@
|
||||
<?php
|
||||
|
||||
class WebHook extends Eloquent
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
|
||||
class WebHook extends Model
|
||||
{
|
||||
// Request Methods.
|
||||
const HEAD = 0;
|
||||
@ -13,7 +17,7 @@ class WebHook extends Eloquent
|
||||
/**
|
||||
* Returns all responses for a WebHook.
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Builder
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function response()
|
||||
{
|
||||
@ -23,9 +27,9 @@ class WebHook extends Eloquent
|
||||
/**
|
||||
* Returns all active hooks.
|
||||
*
|
||||
* @param Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Builder
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeActive($query)
|
||||
{
|
||||
@ -35,7 +39,7 @@ class WebHook extends Eloquent
|
||||
/**
|
||||
* Setups a Ping event that is fired upon a web hook.
|
||||
*
|
||||
* @return array result of the ping
|
||||
* @return object
|
||||
*/
|
||||
public function ping()
|
||||
{
|
||||
@ -54,7 +58,7 @@ class WebHook extends Eloquent
|
||||
{
|
||||
$startTime = microtime(true);
|
||||
|
||||
$client = new \GuzzleHttp\Client();
|
||||
$client = new Client();
|
||||
$request = $client->createRequest($this->requestMethod, $this->endpoint, [
|
||||
'headers' => [
|
||||
'X-Cachet-Event' => $eventType,
|
||||
@ -64,7 +68,7 @@ class WebHook extends Eloquent
|
||||
|
||||
try {
|
||||
$response = $client->send($request);
|
||||
} catch (\GuzzleHttp\Exception\ClientException $e) {
|
||||
} catch (ClientException $e) {
|
||||
// Do nothing with the exception, we want it.
|
||||
$response = $e->getResponse();
|
||||
}
|
||||
@ -88,7 +92,7 @@ class WebHook extends Eloquent
|
||||
/**
|
||||
* Returns a human readable request type name.
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return string HEAD, GET, POST, DELETE, PATCH, PUT etc
|
||||
*/
|
||||
@ -98,29 +102,19 @@ class WebHook extends Eloquent
|
||||
|
||||
switch ($this->request_type) {
|
||||
case self::HEAD:
|
||||
$requestMethod = 'HEAD';
|
||||
break;
|
||||
return 'HEAD';
|
||||
case self::GET:
|
||||
$requestMethod = 'GET';
|
||||
break;
|
||||
return 'GET';
|
||||
case self::POST:
|
||||
$requestMethod = 'POST';
|
||||
break;
|
||||
return 'POST';
|
||||
case self::PATCH:
|
||||
$requestMethod = 'PATCH';
|
||||
break;
|
||||
return 'PATCH';
|
||||
case self::PUT:
|
||||
$requestMethod = 'PUT';
|
||||
break;
|
||||
return 'PUT';
|
||||
case self::DELETE:
|
||||
$requestMethod = 'DELETE';
|
||||
break;
|
||||
|
||||
return 'DELETE';
|
||||
default:
|
||||
throw new Exception('Unknown request type value: '.$this->request_type);
|
||||
break;
|
||||
}
|
||||
|
||||
return $requestMethod;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
<?php
|
||||
|
||||
class WebHookResponse extends Eloquent
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebHookResponse extends Model
|
||||
{
|
||||
/**
|
||||
* Returns the hook that a response belongs to.
|
||||
*
|
||||
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function hook()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user