From 96e50506a17a40b53a0af50441f24a4c784c75f7 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Wed, 25 Jan 2017 16:37:01 -0500 Subject: [PATCH] Move notification email of server created into the event listener --- app/Notifications/ServerCreated.php | 14 +++++++------- app/Observers/ServerObserver.php | 13 +++++++++++++ app/Repositories/ServerRepository.php | 11 ----------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/app/Notifications/ServerCreated.php b/app/Notifications/ServerCreated.php index a8e8b59f0..a867e26c7 100644 --- a/app/Notifications/ServerCreated.php +++ b/app/Notifications/ServerCreated.php @@ -66,12 +66,12 @@ class ServerCreated extends Notification implements ShouldQueue public function toMail($notifiable) { return (new MailMessage) - ->line('A new server as been assigned to your account.') - ->line('Server Name: ' . $this->server->name) - ->line('Memory: ' . $this->server->memory . ' MB') - ->line('Node: ' . $this->server->node) - ->line('Type: ' . $this->server->service . ' - ' . $this->server->option) - ->action('Peel Off the Protective Wrap', route('server.index', $this->server->uuidShort)) - ->line('Please let us know if you have any additional questions or concerns!'); + ->line('A new server as been assigned to your account.') + ->line('Server Name: ' . $this->server->name) + ->line('Memory: ' . $this->server->memory . ' MB') + ->line('Node: ' . $this->server->node) + ->line('Type: ' . $this->server->service . ' - ' . $this->server->option) + ->action('Peel Off the Protective Wrap', route('server.index', $this->server->uuidShort)) + ->line('Please let us know if you have any additional questions or concerns!'); } } diff --git a/app/Observers/ServerObserver.php b/app/Observers/ServerObserver.php index 82c403a8a..ed6246ed4 100644 --- a/app/Observers/ServerObserver.php +++ b/app/Observers/ServerObserver.php @@ -26,9 +26,11 @@ namespace Pterodactyl\Observers; use Carbon; use Pterodactyl\Events; +use Pterodactyl\Models\User; use Pterodactyl\Models\Server; use Pterodactyl\Jobs\DeleteServer; use Pterodactyl\Jobs\SuspendServer; +use Pterodactyl\Notifications\ServerCreated; use Illuminate\Foundation\Bus\DispatchesJobs; class ServerObserver @@ -55,6 +57,17 @@ class ServerObserver public function created(Server $server) { event(new Events\Server\Created($server)); + + // Queue Notification Email + $user = User::findOrFail($server->owner); + $user->notify((new ServerCreated([ + 'name' => $server->name, + 'memory' => $server->memory, + 'node' => $node->name, + 'service' => $service->name, + 'option' => $option->name, + 'uuidShort' => $server->uuidShort, + ]))); } /** diff --git a/app/Repositories/ServerRepository.php b/app/Repositories/ServerRepository.php index 9e16de31e..324e1f47d 100644 --- a/app/Repositories/ServerRepository.php +++ b/app/Repositories/ServerRepository.php @@ -32,7 +32,6 @@ use Pterodactyl\Models; use Pterodactyl\Services\UuidService; use Pterodactyl\Services\DeploymentService; use Pterodactyl\Exceptions\DisplayException; -use Pterodactyl\Notifications\ServerCreated; use Pterodactyl\Exceptions\DisplayValidationException; class ServerRepository @@ -300,16 +299,6 @@ class ServerRepository ]); } - // Queue Notification Email - $user->notify((new ServerCreated([ - 'name' => $server->name, - 'memory' => $server->memory, - 'node' => $node->name, - 'service' => $service->name, - 'option' => $option->name, - 'uuidShort' => $server->uuidShort, - ]))); - $client = Models\Node::guzzleRequest($node->id); $client->request('POST', '/servers', [ 'headers' => [