rector: arrrrr

This commit is contained in:
Andras Bacsai
2025-01-07 14:52:08 +01:00
parent c702ebff6d
commit 16c0cd10d8
349 changed files with 4204 additions and 3712 deletions

View File

@@ -12,7 +12,6 @@ use App\Notifications\Application\DeploymentFailed;
use App\Notifications\Application\DeploymentSuccess;
use App\Notifications\Application\StatusChanged;
use App\Notifications\Database\BackupFailed;
use App\Notifications\Database\BackupSuccess;
use App\Notifications\Test;
use Exception;
use Illuminate\Console\Command;
@@ -43,7 +42,7 @@ class Emails extends Command
/**
* Execute the console command.
*/
private ?MailMessage $mail = null;
private ?MailMessage $mailMessage = null;
private ?string $email = null;
@@ -69,15 +68,13 @@ class Emails extends Command
$emailsGathered = ['realusers-before-trial', 'realusers-server-lost-connection'];
if (isDev()) {
$this->email = 'test@example.com';
} else {
if (! in_array($type, $emailsGathered)) {
$this->email = text('Email Address to send to:');
}
} elseif (! in_array($type, $emailsGathered)) {
$this->email = text('Email Address to send to:');
}
set_transanctional_email_settings();
$this->mail = new MailMessage;
$this->mail->subject('Test Email');
$this->mailMessage = new MailMessage;
$this->mailMessage->subject('Test Email');
switch ($type) {
case 'updates':
$teams = Team::all();
@@ -102,18 +99,18 @@ class Emails extends Command
$confirmed = confirm('Are you sure?');
if ($confirmed) {
foreach ($emails as $email) {
$this->mail = new MailMessage;
$this->mail->subject('One-click Services, Docker Compose support');
$this->mailMessage = new MailMessage;
$this->mailMessage->subject('One-click Services, Docker Compose support');
$unsubscribeUrl = route('unsubscribe.marketing.emails', [
'token' => encrypt($email),
]);
$this->mail->view('emails.updates', ['unsubscribeUrl' => $unsubscribeUrl]);
$this->mailMessage->view('emails.updates', ['unsubscribeUrl' => $unsubscribeUrl]);
$this->sendEmail($email);
}
}
break;
case 'emails-test':
$this->mail = (new Test)->toMail();
$this->mailMessage = (new Test)->toMail();
$this->sendEmail();
break;
case 'application-deployment-success-daily':
@@ -123,41 +120,41 @@ class Emails extends Command
if ($deployments->isEmpty()) {
continue;
}
$this->mail = (new DeploymentSuccess($application, 'test'))->toMail();
$this->mailMessage = (new DeploymentSuccess($application, 'test'))->toMail();
$this->sendEmail();
}
break;
case 'application-deployment-success':
$application = Application::all()->first();
$this->mail = (new DeploymentSuccess($application, 'test'))->toMail();
$this->mailMessage = (new DeploymentSuccess($application, 'test'))->toMail();
$this->sendEmail();
break;
case 'application-deployment-failed':
$application = Application::all()->first();
$preview = ApplicationPreview::all()->first();
if (! $preview) {
$preview = ApplicationPreview::create([
$preview = ApplicationPreview::query()->create([
'application_id' => $application->id,
'pull_request_id' => 1,
'pull_request_html_url' => 'http://example.com',
'fqdn' => $application->fqdn,
]);
}
$this->mail = (new DeploymentFailed($application, 'test'))->toMail();
$this->mailMessage = (new DeploymentFailed($application, 'test'))->toMail();
$this->sendEmail();
$this->mail = (new DeploymentFailed($application, 'test', $preview))->toMail();
$this->mailMessage = (new DeploymentFailed($application, 'test', $preview))->toMail();
$this->sendEmail();
break;
case 'application-status-changed':
$application = Application::all()->first();
$this->mail = (new StatusChanged($application))->toMail();
$this->mailMessage = (new StatusChanged($application))->toMail();
$this->sendEmail();
break;
case 'backup-failed':
$backup = ScheduledDatabaseBackup::all()->first();
$db = StandalonePostgresql::all()->first();
if (! $backup) {
$backup = ScheduledDatabaseBackup::create([
$backup = ScheduledDatabaseBackup::query()->create([
'enabled' => true,
'frequency' => 'daily',
'save_s3' => false,
@@ -167,14 +164,14 @@ class Emails extends Command
]);
}
$output = 'Because of an error, the backup of the database '.$db->name.' failed.';
$this->mail = (new BackupFailed($backup, $db, $output))->toMail();
$this->mailMessage = (new BackupFailed($backup, $db, $output))->toMail();
$this->sendEmail();
break;
case 'backup-success':
$backup = ScheduledDatabaseBackup::all()->first();
$db = StandalonePostgresql::all()->first();
if (! $backup) {
$backup = ScheduledDatabaseBackup::create([
$backup = ScheduledDatabaseBackup::query()->create([
'enabled' => true,
'frequency' => 'daily',
'save_s3' => false,
@@ -183,7 +180,7 @@ class Emails extends Command
'team_id' => 0,
]);
}
//$this->mail = (new BackupSuccess($backup->frequency, $db->name))->toMail();
// $this->mail = (new BackupSuccess($backup->frequency, $db->name))->toMail();
$this->sendEmail();
break;
// case 'invitation-link':
@@ -201,10 +198,10 @@ class Emails extends Command
// $this->sendEmail();
// break;
case 'realusers-before-trial':
$this->mail = new MailMessage;
$this->mail->view('emails.before-trial-conversion');
$this->mail->subject('Trial period has been added for all subscription plans.');
$teams = Team::doesntHave('subscription')->where('id', '!=', 0)->get();
$this->mailMessage = new MailMessage;
$this->mailMessage->view('emails.before-trial-conversion');
$this->mailMessage->subject('Trial period has been added for all subscription plans.');
$teams = Team::query()->doesntHave('subscription')->where('id', '!=', 0)->get();
if (! $teams || $teams->isEmpty()) {
echo 'No teams found.'.PHP_EOL;
@@ -232,7 +229,7 @@ class Emails extends Command
break;
case 'realusers-server-lost-connection':
$serverId = text('Server Id');
$server = Server::find($serverId);
$server = Server::query()->find($serverId);
if (! $server) {
throw new Exception('Server not found');
}
@@ -247,13 +244,13 @@ class Emails extends Command
foreach ($admins as $admin) {
$this->info($admin);
}
$this->mail = new MailMessage;
$this->mail->view('emails.server-lost-connection', [
$this->mailMessage = new MailMessage;
$this->mailMessage->view('emails.server-lost-connection', [
'name' => $server->name,
]);
$this->mail->subject('Action required: Server '.$server->name.' lost connection.');
foreach ($admins as $email) {
$this->sendEmail($email);
$this->mailMessage->subject('Action required: Server '.$server->name.' lost connection.');
foreach ($admins as $admin) {
$this->sendEmail($admin);
}
break;
}
@@ -269,8 +266,8 @@ class Emails extends Command
[],
fn (Message $message) => $message
->to($this->email)
->subject($this->mail->subject)
->html((string) $this->mail->render())
->subject($this->mailMessage->subject)
->html((string) $this->mailMessage->render())
);
$this->info("Email sent to $this->email successfully. 📧");
}