Skip to content

Commit 96e5050

Browse files
committed
Move notification email of server created into the event listener
1 parent b8271cf commit 96e5050

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

app/Notifications/ServerCreated.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ public function via($notifiable)
6666
public function toMail($notifiable)
6767
{
6868
return (new MailMessage)
69-
->line('A new server as been assigned to your account.')
70-
->line('Server Name: ' . $this->server->name)
71-
->line('Memory: ' . $this->server->memory . ' MB')
72-
->line('Node: ' . $this->server->node)
73-
->line('Type: ' . $this->server->service . ' - ' . $this->server->option)
74-
->action('Peel Off the Protective Wrap', route('server.index', $this->server->uuidShort))
75-
->line('Please let us know if you have any additional questions or concerns!');
69+
->line('A new server as been assigned to your account.')
70+
->line('Server Name: ' . $this->server->name)
71+
->line('Memory: ' . $this->server->memory . ' MB')
72+
->line('Node: ' . $this->server->node)
73+
->line('Type: ' . $this->server->service . ' - ' . $this->server->option)
74+
->action('Peel Off the Protective Wrap', route('server.index', $this->server->uuidShort))
75+
->line('Please let us know if you have any additional questions or concerns!');
7676
}
7777
}

app/Observers/ServerObserver.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626

2727
use Carbon;
2828
use Pterodactyl\Events;
29+
use Pterodactyl\Models\User;
2930
use Pterodactyl\Models\Server;
3031
use Pterodactyl\Jobs\DeleteServer;
3132
use Pterodactyl\Jobs\SuspendServer;
33+
use Pterodactyl\Notifications\ServerCreated;
3234
use Illuminate\Foundation\Bus\DispatchesJobs;
3335

3436
class ServerObserver
@@ -55,6 +57,17 @@ public function creating(Server $server)
5557
public function created(Server $server)
5658
{
5759
event(new Events\Server\Created($server));
60+
61+
// Queue Notification Email
62+
$user = User::findOrFail($server->owner);
63+
$user->notify((new ServerCreated([
64+
'name' => $server->name,
65+
'memory' => $server->memory,
66+
'node' => $node->name,
67+
'service' => $service->name,
68+
'option' => $option->name,
69+
'uuidShort' => $server->uuidShort,
70+
])));
5871
}
5972

6073
/**

app/Repositories/ServerRepository.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
use Pterodactyl\Services\UuidService;
3333
use Pterodactyl\Services\DeploymentService;
3434
use Pterodactyl\Exceptions\DisplayException;
35-
use Pterodactyl\Notifications\ServerCreated;
3635
use Pterodactyl\Exceptions\DisplayValidationException;
3736

3837
class ServerRepository
@@ -300,16 +299,6 @@ public function create(array $data)
300299
]);
301300
}
302301

303-
// Queue Notification Email
304-
$user->notify((new ServerCreated([
305-
'name' => $server->name,
306-
'memory' => $server->memory,
307-
'node' => $node->name,
308-
'service' => $service->name,
309-
'option' => $option->name,
310-
'uuidShort' => $server->uuidShort,
311-
])));
312-
313302
$client = Models\Node::guzzleRequest($node->id);
314303
$client->request('POST', '/servers', [
315304
'headers' => [

0 commit comments

Comments
 (0)