server: add configuration for install notifications (#4331)
* server: track `installed_at`, only send install notification on first install * server: add configuration for install notifications
This commit is contained in:
parent
23124c9b08
commit
8e1a21563e
4 changed files with 59 additions and 6 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Pterodactyl\Models\Server;
|
||||
|
@ -40,7 +41,7 @@ class ServerInstallController extends Controller
|
|||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function index(Request $request, string $uuid)
|
||||
public function index(Request $request, string $uuid): JsonResponse
|
||||
{
|
||||
$server = $this->repository->getByUuid($uuid);
|
||||
$egg = $server->egg;
|
||||
|
@ -60,7 +61,7 @@ class ServerInstallController extends Controller
|
|||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
*/
|
||||
public function store(InstallationDataRequest $request, string $uuid)
|
||||
public function store(InstallationDataRequest $request, string $uuid): JsonResponse
|
||||
{
|
||||
$server = $this->repository->getByUuid($uuid);
|
||||
|
||||
|
@ -69,10 +70,14 @@ class ServerInstallController extends Controller
|
|||
$status = Server::STATUS_SUSPENDED;
|
||||
}
|
||||
|
||||
$this->repository->update($server->id, ['status' => $status], true, true);
|
||||
$this->repository->update($server->id, ['status' => $status, 'installed_at' => CarbonImmutable::now()], true, true);
|
||||
|
||||
// If the server successfully installed, fire installed event.
|
||||
if ($status === null) {
|
||||
// This logic allows individually disabling install and reinstall notifications separately.
|
||||
$isInitialInstall = is_null($server->installed_at);
|
||||
if ($isInitialInstall && config()->get('pterodactyl.email.send_install_notification', true)) {
|
||||
$this->eventDispatcher->dispatch(new ServerInstalled($server));
|
||||
} elseif (! $isInitialInstall && config()->get('pterodactyl.email.send_reinstall_notification', true)) {
|
||||
$this->eventDispatcher->dispatch(new ServerInstalled($server));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue