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));
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ use Pterodactyl\Exceptions\Http\Server\ServerStateConflictException;
|
|||
* @property int $backup_limit
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @property \Illuminate\Support\Carbon|null $installed_at
|
||||
* @property \Illuminate\Database\Eloquent\Collection|\Pterodactyl\Models\ActivityLog[] $activity
|
||||
* @property int|null $activity_count
|
||||
* @property \Pterodactyl\Models\Allocation|null $allocation
|
||||
|
@ -128,6 +129,7 @@ class Server extends Model
|
|||
protected $attributes = [
|
||||
'status' => self::STATUS_INSTALLING,
|
||||
'oom_disabled' => true,
|
||||
'installed_at' => null,
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -142,14 +144,14 @@ class Server extends Model
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dates = [self::CREATED_AT, self::UPDATED_AT, 'deleted_at'];
|
||||
protected $dates = [self::CREATED_AT, self::UPDATED_AT, 'deleted_at', 'installed_at'];
|
||||
|
||||
/**
|
||||
* Fields that are not mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = ['id', self::CREATED_AT, self::UPDATED_AT, 'deleted_at'];
|
||||
protected $guarded = ['id', self::CREATED_AT, self::UPDATED_AT, 'deleted_at', 'installed_at'];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
|
|
|
@ -205,4 +205,18 @@ return [
|
|||
'assets' => [
|
||||
'use_hash' => env('PTERODACTYL_USE_ASSET_HASH', false),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Email Notification Settings
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This section controls what notifications are sent to users.
|
||||
*/
|
||||
'email' => [
|
||||
// Should an email be sent to a server owner once their server has completed it's first install process?
|
||||
'send_install_notification' => env('PTERODACTYL_SEND_INSTALL_NOTIFICATION', true),
|
||||
// Should an email be sent to a server owner whenever their server is reinstalled?
|
||||
'send_reinstall_notification' => env('PTERODACTYL_SEND_REINSTALL_NOTIFICATION', true),
|
||||
],
|
||||
];
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddInstalledAtColumnToServersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('servers', function (Blueprint $table) {
|
||||
$table->timestamp('installed_at')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('servers', function (Blueprint $table) {
|
||||
$table->dropColumn('installed_at');
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue