Skip to content

Commit 6536878

Browse files
committed
Changing model events to use observer classes
1 parent cf4b731 commit 6536878

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+925
-654
lines changed

Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@ coverage: ##@tests Test Coverage HTML
9696
--html storage/app/tmp/coverage/ --clover storage/app/tmp/coverage.xml
9797
@rm storage/app/tmp/*.cov
9898

99-
phpunit-fast: ##@tests Unit Tests - Excluding slow model tests which touch the database
100-
@echo "${GREEN}Fast unit tests${RESET}"
101-
@php vendor/bin/phpunit --no-coverage --testsuite "Unit Tests" --exclude-group slow
102-
10399
phpunit: ##@tests Unit Tests
104100
@echo "${GREEN}Unit tests${RESET}"
105101
@php vendor/bin/phpunit --no-coverage --testsuite "Unit Tests"
@@ -109,7 +105,7 @@ integration: ##@tests Integration Tests
109105
@php vendor/bin/phpunit --no-coverage --testsuite "Integration Tests"
110106

111107
quicktest: ##@shortcuts Runs fast tests; these exclude PHPMD, slow unit tests, integration & dusk tests
112-
quicktest: install-dev lint phpcs phpdoc-check phpcpd phpunit-fast
108+
quicktest: install-dev lint phpcs phpdoc-check phpcpd
113109

114110
test: ##@shortcuts Runs most tests; but excludes integration & dusk tests
115111
test: install-dev lint phpcs phpdoc-check phpunit phpcpd phpmd phpstan

app/Channel.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Illuminate\Database\Eloquent\Model;
66
use Illuminate\Database\Eloquent\SoftDeletes;
77
use Illuminate\Notifications\Notifiable;
8-
use REBELinBLUE\Deployer\Notifications\System\NewTestNotification;
98
use REBELinBLUE\Deployer\Traits\BroadcastChanges;
109

1110
/**
@@ -67,20 +66,6 @@ public function project()
6766
return $this->belongsTo(Project::class);
6867
}
6968

70-
/**
71-
* Override the boot method to bind model event listeners.
72-
*/
73-
public static function boot()
74-
{
75-
parent::boot();
76-
77-
// When the notification has been saved queue a test
78-
static::saved(function (Channel $model) {
79-
// FIXME: Change to use an event listener
80-
$model->notify(new NewTestNotification(app('translator')));
81-
});
82-
}
83-
8469
/**
8570
* Returns the email address to send the notification to.
8671
*

app/CheckUrl.php

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@
44

55
use Illuminate\Database\Eloquent\Model;
66
use Illuminate\Database\Eloquent\SoftDeletes;
7-
use Illuminate\Foundation\Bus\DispatchesJobs;
8-
use REBELinBLUE\Deployer\Events\UrlDown;
9-
use REBELinBLUE\Deployer\Events\UrlUp;
10-
use REBELinBLUE\Deployer\Jobs\RequestProjectCheckUrl;
117
use REBELinBLUE\Deployer\Traits\BroadcastChanges;
128

139
/**
1410
* The application's url store for health check.
1511
*/
1612
class CheckUrl extends Model
1713
{
18-
use SoftDeletes, BroadcastChanges, DispatchesJobs;
14+
use SoftDeletes, BroadcastChanges;
1915

2016
const ONLINE = 0;
2117
const UNTESTED = 1;
@@ -55,21 +51,6 @@ class CheckUrl extends Model
5551
*/
5652
protected $dates = ['last_seen'];
5753

58-
/**
59-
* Override the boot method to bind model event listeners.
60-
*/
61-
public static function boot()
62-
{
63-
parent::boot();
64-
65-
// When saving the model, if the URL has changed we need to test it
66-
static::saved(function (CheckUrl $model) {
67-
if ($model->status === self::UNTESTED) {
68-
$model->dispatch(new RequestProjectCheckUrl(collect([$model])));
69-
}
70-
});
71-
}
72-
7354
/**
7455
* Define a mutator to set the status to untested if the URL changes.
7556
*
@@ -92,17 +73,9 @@ public function setUrlAttribute($value)
9273
*/
9374
public function online()
9475
{
95-
$isCurrentlyHealthy = ($this->status === self::UNTESTED || $this->isHealthy());
96-
9776
$this->status = self::ONLINE;
9877
$this->missed = 0;
9978
$this->last_seen = $this->freshTimestamp();
100-
101-
if (!$isCurrentlyHealthy) {
102-
event(new UrlUp($this));
103-
}
104-
105-
return $this->save();
10679
}
10780

10881
/**
@@ -112,12 +85,8 @@ public function online()
11285
*/
11386
public function offline()
11487
{
115-
$this->status = self::OFFLINE;
116-
$this->missed = $this->missed + 1;
117-
118-
event(new UrlDown($this));
119-
120-
return $this->save();
88+
$this->status = self::OFFLINE;
89+
$this->missed = $this->missed + 1;
12190
}
12291

12392
/**

app/Deployment.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public static function boot()
7878
{
7979
parent::boot();
8080

81+
// FIXME: Change to use the trait
8182
static::saved(function (Deployment $model) {
8283
event(new ModelChanged($model, 'deployment'));
8384
});

app/Listeners/ClearJwt.php renamed to app/Events/Listeners/ClearJwt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace REBELinBLUE\Deployer\Listeners;
3+
namespace REBELinBLUE\Deployer\Events\Listeners;
44

55
use Illuminate\Session\Store;
66

app/Listeners/CreateJwt.php renamed to app/Events/Listeners/CreateJwt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace REBELinBLUE\Deployer\Listeners;
3+
namespace REBELinBLUE\Deployer\Events\Listeners;
44

55
use Carbon\Carbon;
66
use Illuminate\Auth\Events\Login;

app/Listeners/SendCheckUrlNotification.php renamed to app/Events/Listeners/SendCheckUrlNotifications.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace REBELinBLUE\Deployer\Listeners;
3+
namespace REBELinBLUE\Deployer\Events\Listeners;
44

55
use Illuminate\Contracts\Translation\Translator;
66
use REBELinBLUE\Deployer\Events\UrlChanged;
@@ -10,7 +10,7 @@
1010
/**
1111
* Event handler class for URL notifications.
1212
**/
13-
class SendCheckUrlNotification
13+
class SendCheckUrlNotifications
1414
{
1515
/**
1616
* @var Translator

app/Listeners/SendDeploymentNotifications.php renamed to app/Events/Listeners/SendDeploymentNotifications.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace REBELinBLUE\Deployer\Listeners;
3+
namespace REBELinBLUE\Deployer\Events\Listeners;
44

55
use Illuminate\Contracts\Translation\Translator;
66
use REBELinBLUE\Deployer\Events\DeploymentFinished;
@@ -41,6 +41,7 @@ public function handle(DeploymentFinished $event)
4141

4242
$notification = DeploymentFailed::class;
4343
$event = 'deployment_failure';
44+
4445
if ($deployment->isSuccessful()) {
4546
$notification = DeploymentSucceeded::class;
4647
$event = 'deployment_success';

app/Listeners/SendEmailChangeConfirmation.php renamed to app/Events/Listeners/SendEmailChangeConfirmation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace REBELinBLUE\Deployer\Listeners;
3+
namespace REBELinBLUE\Deployer\Events\Listeners;
44

55
use Illuminate\Contracts\Translation\Translator;
66
use REBELinBLUE\Deployer\Events\EmailChangeRequested;

app/Listeners/SendHeartbeatNotification.php renamed to app/Events/Listeners/SendHeartbeatNotifications.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace REBELinBLUE\Deployer\Listeners;
3+
namespace REBELinBLUE\Deployer\Events\Listeners;
44

55
use Illuminate\Contracts\Translation\Translator;
66
use REBELinBLUE\Deployer\Events\HeartbeatChanged;
@@ -10,7 +10,7 @@
1010
/**
1111
* Event handler class for heartbeat notifications.
1212
**/
13-
class SendHeartbeatNotification
13+
class SendHeartbeatNotifications
1414
{
1515
/**
1616
* @var Translator
@@ -36,6 +36,7 @@ public function handle(HeartbeatChanged $event)
3636

3737
$notification = HeartbeatRecovered::class;
3838
$event = 'heartbeat_recovered';
39+
3940
if (!$heartbeat->isHealthy()) {
4041
$notification = HeartbeatMissing::class;
4142
$event = 'heartbeat_missing';

0 commit comments

Comments
 (0)