Move notification email of server created into the event listener

This commit is contained in:
Dane Everitt 2017-01-25 16:37:01 -05:00
parent b8271cf8f6
commit 96e50506a1
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 20 additions and 18 deletions

View file

@ -66,12 +66,12 @@ class ServerCreated extends Notification implements ShouldQueue
public function toMail($notifiable) public function toMail($notifiable)
{ {
return (new MailMessage) return (new MailMessage)
->line('A new server as been assigned to your account.') ->line('A new server as been assigned to your account.')
->line('Server Name: ' . $this->server->name) ->line('Server Name: ' . $this->server->name)
->line('Memory: ' . $this->server->memory . ' MB') ->line('Memory: ' . $this->server->memory . ' MB')
->line('Node: ' . $this->server->node) ->line('Node: ' . $this->server->node)
->line('Type: ' . $this->server->service . ' - ' . $this->server->option) ->line('Type: ' . $this->server->service . ' - ' . $this->server->option)
->action('Peel Off the Protective Wrap', route('server.index', $this->server->uuidShort)) ->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('Please let us know if you have any additional questions or concerns!');
} }
} }

View file

@ -26,9 +26,11 @@ namespace Pterodactyl\Observers;
use Carbon; use Carbon;
use Pterodactyl\Events; use Pterodactyl\Events;
use Pterodactyl\Models\User;
use Pterodactyl\Models\Server; use Pterodactyl\Models\Server;
use Pterodactyl\Jobs\DeleteServer; use Pterodactyl\Jobs\DeleteServer;
use Pterodactyl\Jobs\SuspendServer; use Pterodactyl\Jobs\SuspendServer;
use Pterodactyl\Notifications\ServerCreated;
use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Bus\DispatchesJobs;
class ServerObserver class ServerObserver
@ -55,6 +57,17 @@ class ServerObserver
public function created(Server $server) public function created(Server $server)
{ {
event(new Events\Server\Created($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,
])));
} }
/** /**

View file

@ -32,7 +32,6 @@ use Pterodactyl\Models;
use Pterodactyl\Services\UuidService; use Pterodactyl\Services\UuidService;
use Pterodactyl\Services\DeploymentService; use Pterodactyl\Services\DeploymentService;
use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Notifications\ServerCreated;
use Pterodactyl\Exceptions\DisplayValidationException; use Pterodactyl\Exceptions\DisplayValidationException;
class ServerRepository 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 = Models\Node::guzzleRequest($node->id);
$client->request('POST', '/servers', [ $client->request('POST', '/servers', [
'headers' => [ 'headers' => [