Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move meta relation into trait #3478

Merged
merged 1 commit into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions app/Models/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace CachetHQ\Cachet\Models;

use AltThree\Validator\ValidatingTrait;
use CachetHQ\Cachet\Models\Traits\HasMeta;
use CachetHQ\Cachet\Models\Traits\HasTags;
use CachetHQ\Cachet\Models\Traits\SearchableTrait;
use CachetHQ\Cachet\Models\Traits\SortableTrait;
Expand All @@ -23,7 +24,12 @@

class Component extends Model implements HasPresenter
{
use HasTags, SearchableTrait, SoftDeletes, SortableTrait, ValidatingTrait;
use HasTags,
HasMeta,
SearchableTrait,
SoftDeletes,
SortableTrait,
ValidatingTrait;

/**
* List of attributes that have default values.
Expand Down Expand Up @@ -134,16 +140,6 @@ public function incidents()
return $this->hasMany(Incident::class, 'component_id', 'id');
}

/**
* Get the meta relation.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function meta()
{
return $this->morphMany(Meta::class, 'meta');
}

/**
* Finds all components by status.
*
Expand Down
18 changes: 7 additions & 11 deletions app/Models/Incident.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace CachetHQ\Cachet\Models;

use AltThree\Validator\ValidatingTrait;
use CachetHQ\Cachet\Models\Traits\HasMeta;
use CachetHQ\Cachet\Models\Traits\HasTags;
use CachetHQ\Cachet\Models\Traits\SearchableTrait;
use CachetHQ\Cachet\Models\Traits\SortableTrait;
Expand All @@ -30,7 +31,12 @@
*/
class Incident extends Model implements HasPresenter
{
use HasTags, SearchableTrait, SoftDeletes, SortableTrait, ValidatingTrait;
use HasMeta,
HasTags,
SearchableTrait,
SoftDeletes,
SortableTrait,
ValidatingTrait;

/**
* Status for incident being investigated.
Expand Down Expand Up @@ -181,16 +187,6 @@ public function component()
return $this->belongsTo(Component::class, 'component_id', 'id');
}

/**
* Get all of the meta relation.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function meta()
{
return $this->morphMany(Meta::class, 'meta');
}

/**
* Get the updates relation.
*
Expand Down
15 changes: 4 additions & 11 deletions app/Models/Metric.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use AltThree\Validator\ValidatingTrait;
use AltThree\Validator\ValidationException;
use CachetHQ\Cachet\Models\Traits\HasMeta;
use CachetHQ\Cachet\Models\Traits\SortableTrait;
use CachetHQ\Cachet\Presenters\MetricPresenter;
use Illuminate\Database\Eloquent\Builder;
Expand All @@ -22,7 +23,9 @@

class Metric extends Model implements HasPresenter
{
use SortableTrait, ValidatingTrait;
use HasMeta,
SortableTrait,
ValidatingTrait;

/**
* The calculation type of sum.
Expand Down Expand Up @@ -165,16 +168,6 @@ public static function boot()
});
}

/**
* Get the meta relation.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function meta()
{
return $this->morphMany(Meta::class, 'meta');
}

/**
* Get the points relation.
*
Expand Down
17 changes: 6 additions & 11 deletions app/Models/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace CachetHQ\Cachet\Models;

use AltThree\Validator\ValidatingTrait;
use CachetHQ\Cachet\Models\Traits\HasMeta;
use CachetHQ\Cachet\Models\Traits\SearchableTrait;
use CachetHQ\Cachet\Models\Traits\SortableTrait;
use CachetHQ\Cachet\Presenters\SchedulePresenter;
Expand All @@ -28,7 +29,11 @@
*/
class Schedule extends Model implements HasPresenter
{
use SearchableTrait, SoftDeletes, SortableTrait, ValidatingTrait;
use HasMeta,
SearchableTrait,
SoftDeletes,
SortableTrait,
ValidatingTrait;

/**
* The upcoming status.
Expand Down Expand Up @@ -143,16 +148,6 @@ public function components()
return $this->hasMany(ScheduleComponent::class);
}

/**
* Get the meta relation.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function meta()
{
return $this->morphMany(Meta::class, 'meta');
}

/**
* Scope schedules that are in progress.
*
Expand Down
15 changes: 4 additions & 11 deletions app/Models/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace CachetHQ\Cachet\Models;

use AltThree\Validator\ValidatingTrait;
use CachetHQ\Cachet\Models\Traits\HasMeta;
use CachetHQ\Cachet\Presenters\SubscriberPresenter;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -28,7 +29,9 @@
*/
class Subscriber extends Model implements HasPresenter
{
use Notifiable, ValidatingTrait;
use HasMeta,
Notifiable,
ValidatingTrait;

/**
* The attributes that should be casted to native types.
Expand Down Expand Up @@ -91,16 +94,6 @@ public static function boot()
});
}

/**
* Get the meta relation.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function meta()
{
return $this->morphMany(Meta::class, 'meta');
}

/**
* Get the subscriptions relation.
*
Expand Down
32 changes: 32 additions & 0 deletions app/Models/Traits/HasMeta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CachetHQ\Cachet\Models\Traits;

use CachetHQ\Cachet\Models\Meta;

/**
* This is the has meta trait.
*
* @author James Brooks <[email protected]>
*/
trait HasMeta
{
/**
* Get the meta relation.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function meta()
{
return $this->morphMany(Meta::class, 'meta');
}
}