Revert "rector: arrrrr"

This reverts commit 16c0cd10d8.
This commit is contained in:
Andras Bacsai
2025-01-07 15:31:43 +01:00
parent da07b4fdcf
commit 1fe4dd722b
349 changed files with 3689 additions and 4184 deletions

View File

@@ -3,7 +3,6 @@
namespace App\Console\Commands;
use App\Models\User;
use Exception;
use Illuminate\Console\Command;
class AdminRemoveUser extends Command
@@ -47,7 +46,7 @@ class AdminRemoveUser extends Command
$team->delete();
}
$user->delete();
} catch (Exception $e) {
} catch (\Exception $e) {
$this->error('Failed to remove user.');
$this->error($e->getMessage());

View File

@@ -15,7 +15,7 @@ class CheckApplicationDeploymentQueue extends Command
public function handle()
{
$seconds = $this->option('seconds');
$deployments = ApplicationDeploymentQueue::query()->whereIn('status', [
$deployments = ApplicationDeploymentQueue::whereIn('status', [
ApplicationDeploymentStatus::IN_PROGRESS,
ApplicationDeploymentStatus::QUEUED,
])->where('created_at', '<=', now()->subSeconds($seconds))->get();
@@ -40,11 +40,11 @@ class CheckApplicationDeploymentQueue extends Command
}
}
private function cancelDeployment(ApplicationDeploymentQueue $applicationDeploymentQueue)
private function cancelDeployment(ApplicationDeploymentQueue $deployment)
{
$applicationDeploymentQueue->update(['status' => ApplicationDeploymentStatus::FAILED]);
if ($applicationDeploymentQueue->server?->isFunctional()) {
remote_process(['docker rm -f '.$applicationDeploymentQueue->deployment_uuid], $applicationDeploymentQueue->server, false);
$deployment->update(['status' => ApplicationDeploymentStatus::FAILED]);
if ($deployment->server?->isFunctional()) {
remote_process(['docker rm -f '.$deployment->deployment_uuid], $deployment->server, false);
}
}
}

View File

@@ -3,7 +3,6 @@
namespace App\Console\Commands;
use App\Models\ApplicationDeploymentQueue;
use App\Models\Server;
use Illuminate\Console\Command;
class CleanupApplicationDeploymentQueue extends Command
@@ -15,9 +14,9 @@ class CleanupApplicationDeploymentQueue extends Command
public function handle()
{
$team_id = $this->option('team-id');
$servers = Server::query()->where('team_id', $team_id)->get();
$servers = \App\Models\Server::where('team_id', $team_id)->get();
foreach ($servers as $server) {
$deployments = ApplicationDeploymentQueue::query()->whereIn('status', ['in_progress', 'queued'])->where('server_id', $server->id)->get();
$deployments = ApplicationDeploymentQueue::whereIn('status', ['in_progress', 'queued'])->where('server_id', $server->id)->get();
foreach ($deployments as $deployment) {
$deployment->update(['status' => 'failed']);
instant_remote_process(['docker rm -f '.$deployment->deployment_uuid], $server, false);

View File

@@ -18,14 +18,19 @@ class CleanupDatabase extends Command
} else {
echo "Running database cleanup in dry-run mode...\n";
}
$keep_days = isCloud() ? $this->option('keep-days') ?? 60 : $this->option('keep-days') ?? 60;
if (isCloud()) {
// Later on we can increase this to 180 days or dynamically set
$keep_days = $this->option('keep-days') ?? 60;
} else {
$keep_days = $this->option('keep-days') ?? 60;
}
echo "Keep days: $keep_days\n";
// Cleanup failed jobs table
$builder = DB::table('failed_jobs')->where('failed_at', '<', now()->subDays(1));
$count = $builder->count();
$failed_jobs = DB::table('failed_jobs')->where('failed_at', '<', now()->subDays(1));
$count = $failed_jobs->count();
echo "Delete $count entries from failed_jobs.\n";
if ($this->option('yes')) {
$builder->delete();
$failed_jobs->delete();
}
// Cleanup sessions table

View File

@@ -21,7 +21,6 @@ use App\Models\StandaloneMysql;
use App\Models\StandalonePostgresql;
use App\Models\StandaloneRedis;
use Illuminate\Console\Command;
use Throwable;
class CleanupStuckedResources extends Command
{
@@ -43,18 +42,18 @@ class CleanupStuckedResources extends Command
foreach ($servers as $server) {
CleanupHelperContainersJob::dispatch($server);
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in cleaning stucked resources: {$e->getMessage()}\n";
}
try {
$applicationsDeploymentQueue = ApplicationDeploymentQueue::query()->get();
$applicationsDeploymentQueue = ApplicationDeploymentQueue::get();
foreach ($applicationsDeploymentQueue as $applicationDeploymentQueue) {
if (is_null($applicationDeploymentQueue->application)) {
echo "Deleting stuck application deployment queue: {$applicationDeploymentQueue->id}\n";
$applicationDeploymentQueue->delete();
}
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in cleaning stuck application deployment queue: {$e->getMessage()}\n";
}
try {
@@ -63,18 +62,18 @@ class CleanupStuckedResources extends Command
echo "Deleting stuck application: {$application->name}\n";
$application->forceDelete();
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in cleaning stuck application: {$e->getMessage()}\n";
}
try {
$applicationsPreviews = ApplicationPreview::query()->get();
$applicationsPreviews = ApplicationPreview::get();
foreach ($applicationsPreviews as $applicationPreview) {
if (! data_get($applicationPreview, 'application')) {
echo "Deleting stuck application preview: {$applicationPreview->uuid}\n";
$applicationPreview->delete();
}
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in cleaning stuck application: {$e->getMessage()}\n";
}
try {
@@ -83,16 +82,16 @@ class CleanupStuckedResources extends Command
echo "Deleting stuck postgresql: {$postgresql->name}\n";
$postgresql->forceDelete();
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in cleaning stuck postgresql: {$e->getMessage()}\n";
}
try {
$redis = StandaloneRedis::withTrashed()->whereNotNull('deleted_at')->get();
foreach ($redis as $redi) {
echo "Deleting stuck redis: {$redi->name}\n";
$redi->forceDelete();
foreach ($redis as $redis) {
echo "Deleting stuck redis: {$redis->name}\n";
$redis->forceDelete();
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in cleaning stuck redis: {$e->getMessage()}\n";
}
try {
@@ -101,7 +100,7 @@ class CleanupStuckedResources extends Command
echo "Deleting stuck keydb: {$keydb->name}\n";
$keydb->forceDelete();
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in cleaning stuck keydb: {$e->getMessage()}\n";
}
try {
@@ -110,7 +109,7 @@ class CleanupStuckedResources extends Command
echo "Deleting stuck dragonfly: {$dragonfly->name}\n";
$dragonfly->forceDelete();
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in cleaning stuck dragonfly: {$e->getMessage()}\n";
}
try {
@@ -119,7 +118,7 @@ class CleanupStuckedResources extends Command
echo "Deleting stuck clickhouse: {$clickhouse->name}\n";
$clickhouse->forceDelete();
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in cleaning stuck clickhouse: {$e->getMessage()}\n";
}
try {
@@ -128,7 +127,7 @@ class CleanupStuckedResources extends Command
echo "Deleting stuck mongodb: {$mongodb->name}\n";
$mongodb->forceDelete();
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in cleaning stuck mongodb: {$e->getMessage()}\n";
}
try {
@@ -137,7 +136,7 @@ class CleanupStuckedResources extends Command
echo "Deleting stuck mysql: {$mysql->name}\n";
$mysql->forceDelete();
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in cleaning stuck mysql: {$e->getMessage()}\n";
}
try {
@@ -146,7 +145,7 @@ class CleanupStuckedResources extends Command
echo "Deleting stuck mariadb: {$mariadb->name}\n";
$mariadb->forceDelete();
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in cleaning stuck mariadb: {$e->getMessage()}\n";
}
try {
@@ -155,7 +154,7 @@ class CleanupStuckedResources extends Command
echo "Deleting stuck service: {$service->name}\n";
$service->forceDelete();
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in cleaning stuck service: {$e->getMessage()}\n";
}
try {
@@ -164,7 +163,7 @@ class CleanupStuckedResources extends Command
echo "Deleting stuck serviceapp: {$serviceApp->name}\n";
$serviceApp->forceDelete();
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in cleaning stuck serviceapp: {$e->getMessage()}\n";
}
try {
@@ -173,7 +172,7 @@ class CleanupStuckedResources extends Command
echo "Deleting stuck serviceapp: {$serviceDb->name}\n";
$serviceDb->forceDelete();
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in cleaning stuck serviceapp: {$e->getMessage()}\n";
}
try {
@@ -184,7 +183,7 @@ class CleanupStuckedResources extends Command
$scheduled_task->delete();
}
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in cleaning stuck scheduledtasks: {$e->getMessage()}\n";
}
@@ -196,7 +195,7 @@ class CleanupStuckedResources extends Command
$scheduled_backup->delete();
}
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in cleaning stuck scheduledbackups: {$e->getMessage()}\n";
}
@@ -223,7 +222,7 @@ class CleanupStuckedResources extends Command
continue;
}
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in application: {$e->getMessage()}\n";
}
try {
@@ -248,32 +247,32 @@ class CleanupStuckedResources extends Command
continue;
}
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in postgresql: {$e->getMessage()}\n";
}
try {
$redis = StandaloneRedis::all();
foreach ($redis as $redi) {
if (! data_get($redi, 'environment')) {
echo 'Redis without environment: '.$redi->name.'\n';
$redi->forceDelete();
foreach ($redis as $redis) {
if (! data_get($redis, 'environment')) {
echo 'Redis without environment: '.$redis->name.'\n';
$redis->forceDelete();
continue;
}
if (! $redi->destination()) {
echo 'Redis without destination: '.$redi->name.'\n';
$redi->forceDelete();
if (! $redis->destination()) {
echo 'Redis without destination: '.$redis->name.'\n';
$redis->forceDelete();
continue;
}
if (! data_get($redi, 'destination.server')) {
echo 'Redis without server: '.$redi->name.'\n';
$redi->forceDelete();
if (! data_get($redis, 'destination.server')) {
echo 'Redis without server: '.$redis->name.'\n';
$redis->forceDelete();
continue;
}
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in redis: {$e->getMessage()}\n";
}
@@ -299,7 +298,7 @@ class CleanupStuckedResources extends Command
continue;
}
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in mongodb: {$e->getMessage()}\n";
}
@@ -325,7 +324,7 @@ class CleanupStuckedResources extends Command
continue;
}
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in mysql: {$e->getMessage()}\n";
}
@@ -351,7 +350,7 @@ class CleanupStuckedResources extends Command
continue;
}
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in mariadb: {$e->getMessage()}\n";
}
@@ -377,33 +376,33 @@ class CleanupStuckedResources extends Command
continue;
}
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in service: {$e->getMessage()}\n";
}
try {
$serviceApplications = ServiceApplication::all();
foreach ($serviceApplications as $serviceApplication) {
if (! data_get($serviceApplication, 'service')) {
echo 'ServiceApplication without service: '.$serviceApplication->name.'\n';
$serviceApplication->forceDelete();
foreach ($serviceApplications as $service) {
if (! data_get($service, 'service')) {
echo 'ServiceApplication without service: '.$service->name.'\n';
$service->forceDelete();
continue;
}
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in serviceApplications: {$e->getMessage()}\n";
}
try {
$serviceDatabases = ServiceDatabase::all();
foreach ($serviceDatabases as $serviceDatabase) {
if (! data_get($serviceDatabase, 'service')) {
echo 'ServiceDatabase without service: '.$serviceDatabase->name.'\n';
$serviceDatabase->forceDelete();
foreach ($serviceDatabases as $service) {
if (! data_get($service, 'service')) {
echo 'ServiceDatabase without service: '.$service->name.'\n';
$service->forceDelete();
continue;
}
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in ServiceDatabases: {$e->getMessage()}\n";
}
}

View File

@@ -14,7 +14,7 @@ class CleanupUnreachableServers extends Command
public function handle()
{
echo "Running unreachable server cleanup...\n";
$servers = Server::query()->where('unreachable_count', 3)->where('unreachable_notification_sent', true)->where('updated_at', '<', now()->subDays(7))->get();
$servers = Server::where('unreachable_count', 3)->where('unreachable_notification_sent', true)->where('updated_at', '<', now()->subDays(7))->get();
if ($servers->count() > 0) {
foreach ($servers as $server) {
echo "Cleanup unreachable server ($server->id) with name $server->name";

View File

@@ -4,7 +4,6 @@ namespace App\Console\Commands;
use App\Models\Team;
use Illuminate\Console\Command;
use Stripe\StripeClient;
class CloudCheckSubscription extends Command
{
@@ -27,19 +26,19 @@ class CloudCheckSubscription extends Command
*/
public function handle()
{
$stripeClient = new StripeClient(config('subscription.stripe_api_key'));
$activeSubscribers = Team::query()->whereRelation('subscription', 'stripe_invoice_paid', true)->get();
foreach ($activeSubscribers as $activeSubscriber) {
$stripeSubscriptionId = $activeSubscriber->subscription->stripe_subscription_id;
$stripeInvoicePaid = $activeSubscriber->subscription->stripe_invoice_paid;
$stripeCustomerId = $activeSubscriber->subscription->stripe_customer_id;
$stripe = new \Stripe\StripeClient(config('subscription.stripe_api_key'));
$activeSubscribers = Team::whereRelation('subscription', 'stripe_invoice_paid', true)->get();
foreach ($activeSubscribers as $team) {
$stripeSubscriptionId = $team->subscription->stripe_subscription_id;
$stripeInvoicePaid = $team->subscription->stripe_invoice_paid;
$stripeCustomerId = $team->subscription->stripe_customer_id;
if (! $stripeSubscriptionId) {
echo "Team {$activeSubscriber->id} has no subscription, but invoice status is: {$stripeInvoicePaid}\n";
echo "Team {$team->id} has no subscription, but invoice status is: {$stripeInvoicePaid}\n";
echo "Link on Stripe: https://dashboard.stripe.com/customers/{$stripeCustomerId}\n";
continue;
}
$subscription = $stripeClient->subscriptions->retrieve($stripeSubscriptionId);
$subscription = $stripe->subscriptions->retrieve($stripeSubscriptionId);
if ($subscription->status === 'active') {
continue;
}

View File

@@ -4,9 +4,7 @@ namespace App\Console\Commands;
use App\Events\ServerReachabilityChanged;
use App\Models\Team;
use Exception;
use Illuminate\Console\Command;
use Stripe\StripeClient;
class CloudCleanupSubscriptions extends Command
{
@@ -23,7 +21,7 @@ class CloudCleanupSubscriptions extends Command
return;
}
$this->info('Cleaning up subcriptions teams');
$stripeClient = new StripeClient(config('subscription.stripe_api_key'));
$stripe = new \Stripe\StripeClient(config('subscription.stripe_api_key'));
$teams = Team::all()->filter(function ($team) {
return $team->id !== 0;
@@ -49,33 +47,34 @@ class CloudCleanupSubscriptions extends Command
$this->disableServers($team);
continue;
}
$subscription = $stripeClient->subscriptions->retrieve(data_get($team, 'subscription.stripe_subscription_id'), []);
$status = data_get($subscription, 'status');
if ($status === 'active' || $status === 'past_due') {
$team->subscription->update([
'stripe_invoice_paid' => true,
'stripe_trial_already_ended' => false,
]);
continue;
}
$this->info('Subscription status: '.$status);
$this->info('Subscription id: '.data_get($team, 'subscription.stripe_subscription_id'));
$confirm = $this->confirm('Do you want to cancel the subscription?', true);
if (! $confirm) {
$this->info("Skipping team {$team->id}");
} else {
$this->info("Cancelling subscription for team {$team->id}");
$team->subscription->update([
'stripe_invoice_paid' => false,
'stripe_trial_already_ended' => false,
'stripe_subscription_id' => null,
]);
$this->disableServers($team);
$subscription = $stripe->subscriptions->retrieve(data_get($team, 'subscription.stripe_subscription_id'), []);
$status = data_get($subscription, 'status');
if ($status === 'active' || $status === 'past_due') {
$team->subscription->update([
'stripe_invoice_paid' => true,
'stripe_trial_already_ended' => false,
]);
continue;
}
$this->info('Subscription status: '.$status);
$this->info('Subscription id: '.data_get($team, 'subscription.stripe_subscription_id'));
$confirm = $this->confirm('Do you want to cancel the subscription?', true);
if (! $confirm) {
$this->info("Skipping team {$team->id}");
} else {
$this->info("Cancelling subscription for team {$team->id}");
$team->subscription->update([
'stripe_invoice_paid' => false,
'stripe_trial_already_ended' => false,
'stripe_subscription_id' => null,
]);
$this->disableServers($team);
}
}
}
} catch (Exception $e) {
} catch (\Exception $e) {
$this->error($e->getMessage());
return;

View File

@@ -33,7 +33,7 @@ class Dev extends Command
// Generate OpenAPI documentation
echo "Generating OpenAPI documentation.\n";
// https://github.com/OAI/OpenAPI-Specification/releases
$processResult = Process::run([
$process = Process::run([
'/var/www/html/vendor/bin/openapi',
'app',
'-o',
@@ -41,11 +41,11 @@ class Dev extends Command
'--version',
'3.1.0',
]);
$error = $processResult->errorOutput();
$error = $process->errorOutput();
$error = preg_replace('/^.*an object literal,.*$/m', '', $error);
$error = preg_replace('/^\h*\v+/m', '', $error);
echo $error;
echo $processResult->output();
echo $process->output();
// Convert YAML to JSON
$yaml = file_get_contents('openapi.yaml');
$json = json_encode(Yaml::parse($yaml), JSON_PRETTY_PRINT);
@@ -69,7 +69,7 @@ class Dev extends Command
}
// Seed database if it's empty
$settings = InstanceSettings::query()->find(0);
$settings = InstanceSettings::find(0);
if (! $settings) {
echo "Initializing instance, seeding database.\n";
Artisan::call('migrate --seed');

View File

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

View File

@@ -16,7 +16,8 @@ class Horizon extends Command
$this->info('Horizon is enabled on this server.');
$this->call('horizon');
exit(0);
} else {
exit(0);
}
exit(0);
}
}

View File

@@ -15,7 +15,6 @@ use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Http;
use Throwable;
class Init extends Command
{
@@ -23,7 +22,7 @@ class Init extends Command
protected $description = 'Cleanup instance related stuffs';
public $servers;
public $servers = null;
public function handle()
{
@@ -36,7 +35,8 @@ class Init extends Command
}
$this->servers = Server::all();
if (! isCloud()) {
if (isCloud()) {
} else {
$this->send_alive_signal();
get_public_ips();
}
@@ -61,14 +61,14 @@ class Init extends Command
try {
$this->pullHelperImage();
} catch (Throwable $e) {
} catch (\Throwable $e) {
//
}
if (isCloud()) {
try {
$this->pullTemplatesFromCDN();
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Could not pull templates from CDN: {$e->getMessage()}\n";
}
}
@@ -76,13 +76,13 @@ class Init extends Command
if (! isCloud()) {
try {
$this->pullTemplatesFromCDN();
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Could not pull templates from CDN: {$e->getMessage()}\n";
}
try {
$localhost = $this->servers->where('id', 0)->first();
$localhost->setupDynamicProxyConfiguration();
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Could not setup dynamic configuration: {$e->getMessage()}\n";
}
$settings = instanceSettings();
@@ -119,8 +119,8 @@ class Init extends Command
private function update_user_emails()
{
try {
User::query()->whereRaw('email ~ \'[A-Z]\'')->get()->each(fn (User $user) => $user->update(['email' => strtolower($user->email)]));
} catch (Throwable $e) {
User::whereRaw('email ~ \'[A-Z]\'')->get()->each(fn (User $user) => $user->update(['email' => strtolower($user->email)]));
} catch (\Throwable $e) {
echo "Error in updating user emails: {$e->getMessage()}\n";
}
}
@@ -128,8 +128,8 @@ class Init extends Command
private function update_traefik_labels()
{
try {
Server::query()->where('proxy->type', 'TRAEFIK_V2')->update(['proxy->type' => 'TRAEFIK']);
} catch (Throwable $e) {
Server::where('proxy->type', 'TRAEFIK_V2')->update(['proxy->type' => 'TRAEFIK']);
} catch (\Throwable $e) {
echo "Error in updating traefik labels: {$e->getMessage()}\n";
}
}
@@ -149,12 +149,10 @@ class Init extends Command
return instant_remote_process([
"rm -f $file",
], $server, false);
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in cleaning up unnecessary dynamic proxy configuration: {$e->getMessage()}\n";
}
}
return null;
}
private function cleanup_unused_network_from_coolify_proxy()
@@ -170,19 +168,19 @@ class Init extends Command
['networks' => $networks, 'allNetworks' => $allNetworks] = collectDockerNetworksByServer($server);
$removeNetworks = $allNetworks->diff($networks);
$commands = collect();
foreach ($removeNetworks as $removeNetwork) {
$out = instant_remote_process(["docker network inspect -f json {$removeNetwork} | jq '.[].Containers | if . == {} then null else . end'"], $server, false);
if ($out === null || $out === '' || $out === '0') {
$commands->push("docker network disconnect {$removeNetwork} coolify-proxy >/dev/null 2>&1 || true");
$commands->push("docker network rm {$removeNetwork} >/dev/null 2>&1 || true");
foreach ($removeNetworks as $network) {
$out = instant_remote_process(["docker network inspect -f json $network | jq '.[].Containers | if . == {} then null else . end'"], $server, false);
if (empty($out)) {
$commands->push("docker network disconnect $network coolify-proxy >/dev/null 2>&1 || true");
$commands->push("docker network rm $network >/dev/null 2>&1 || true");
} else {
$data = collect(json_decode($out, true));
if ($data->count() === 1) {
// If only coolify-proxy itself is connected to that network (it should not be possible, but who knows)
$isCoolifyProxyItself = data_get($data->first(), 'Name') === 'coolify-proxy';
if ($isCoolifyProxyItself) {
$commands->push("docker network disconnect {$removeNetwork} coolify-proxy >/dev/null 2>&1 || true");
$commands->push("docker network rm {$removeNetwork} >/dev/null 2>&1 || true");
$commands->push("docker network disconnect $network coolify-proxy >/dev/null 2>&1 || true");
$commands->push("docker network rm $network >/dev/null 2>&1 || true");
}
}
}
@@ -190,7 +188,7 @@ class Init extends Command
if ($commands->isNotEmpty()) {
remote_process(command: $commands, type: ActivityTypes::INLINE->value, server: $server, ignore_errors: false);
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in cleaning up unused networks from coolify proxy: {$e->getMessage()}\n";
}
}
@@ -204,20 +202,20 @@ class Init extends Command
if ($database && $database->trashed()) {
echo "Restoring coolify db backup\n";
$database->restore();
$scheduledBackup = ScheduledDatabaseBackup::query()->find(0);
$scheduledBackup = ScheduledDatabaseBackup::find(0);
if (! $scheduledBackup) {
ScheduledDatabaseBackup::query()->create([
ScheduledDatabaseBackup::create([
'id' => 0,
'enabled' => true,
'save_s3' => false,
'frequency' => '0 0 * * *',
'database_id' => $database->id,
'database_type' => StandalonePostgresql::class,
'database_type' => \App\Models\StandalonePostgresql::class,
'team_id' => 0,
]);
}
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in restoring coolify db backup: {$e->getMessage()}\n";
}
}
@@ -236,7 +234,7 @@ class Init extends Command
}
try {
Http::get("https://undead.coolify.io/v4/alive?appId=$id&version=$version");
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in sending live signal: {$e->getMessage()}\n";
}
}
@@ -248,12 +246,12 @@ class Init extends Command
if (isCloud()) {
return;
}
$queued_inprogress_deployments = ApplicationDeploymentQueue::query()->whereIn('status', [ApplicationDeploymentStatus::IN_PROGRESS->value, ApplicationDeploymentStatus::QUEUED->value])->get();
foreach ($queued_inprogress_deployments as $queued_inprogress_deployment) {
$queued_inprogress_deployment->status = ApplicationDeploymentStatus::FAILED->value;
$queued_inprogress_deployment->save();
$queued_inprogress_deployments = ApplicationDeploymentQueue::whereIn('status', [ApplicationDeploymentStatus::IN_PROGRESS->value, ApplicationDeploymentStatus::QUEUED->value])->get();
foreach ($queued_inprogress_deployments as $deployment) {
$deployment->status = ApplicationDeploymentStatus::FAILED->value;
$deployment->save();
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error: {$e->getMessage()}\n";
}
}

View File

@@ -16,8 +16,9 @@ class Migration extends Command
$this->info('Migration is enabled on this server.');
$this->call('migrate', ['--force' => true, '--isolated' => true]);
exit(0);
} else {
$this->info('Migration is disabled on this server.');
exit(0);
}
$this->info('Migration is disabled on this server.');
exit(0);
}
}

View File

@@ -16,7 +16,7 @@ class OpenApi extends Command
// Generate OpenAPI documentation
echo "Generating OpenAPI documentation.\n";
// https://github.com/OAI/OpenAPI-Specification/releases
$processResult = Process::run([
$process = Process::run([
'/var/www/html/vendor/bin/openapi',
'app',
'-o',
@@ -24,10 +24,10 @@ class OpenApi extends Command
'--version',
'3.1.0',
]);
$error = $processResult->errorOutput();
$error = $process->errorOutput();
$error = preg_replace('/^.*an object literal,.*$/m', '', $error);
$error = preg_replace('/^\h*\v+/m', '', $error);
echo $error;
echo $processResult->output();
echo $process->output();
}
}

View File

@@ -3,7 +3,6 @@
namespace App\Console\Commands;
use App\Models\User;
use Exception;
use Illuminate\Console\Command;
class RootChangeEmail extends Command
@@ -32,9 +31,9 @@ class RootChangeEmail extends Command
$email = $this->ask('Give me a new email for root user');
$this->info('Updating root email...');
try {
User::query()->find(0)->update(['email' => $email]);
User::find(0)->update(['email' => $email]);
$this->info('Root user\'s email updated successfully.');
} catch (Exception $e) {
} catch (\Exception $e) {
$this->error('Failed to update root user\'s email.');
return;

View File

@@ -3,7 +3,6 @@
namespace App\Console\Commands;
use App\Models\User;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash;
@@ -33,16 +32,16 @@ class RootResetPassword extends Command
$this->info('You are about to reset the root password.');
$password = password('Give me a new password for root user: ');
$passwordAgain = password('Again');
if ($password !== $passwordAgain) {
if ($password != $passwordAgain) {
$this->error('Passwords do not match.');
return;
}
$this->info('Updating root password...');
try {
User::query()->find(0)->update(['password' => Hash::make($password)]);
User::find(0)->update(['password' => Hash::make($password)]);
$this->info('Root password updated successfully.');
} catch (Exception $e) {
} catch (\Exception $e) {
$this->error('Failed to update root password.');
return;

View File

@@ -16,7 +16,8 @@ class Scheduler extends Command
$this->info('Scheduler is enabled on this server.');
$this->call('schedule:work');
exit(0);
} else {
exit(0);
}
exit(0);
}
}

View File

@@ -16,8 +16,9 @@ class Seeder extends Command
$this->info('Seeder is enabled on this server.');
$this->call('db:seed', ['--class' => 'ProductionSeeder', '--force' => true]);
exit(0);
} else {
$this->info('Seeder is disabled on this server.');
exit(0);
}
$this->info('Seeder is disabled on this server.');
exit(0);
}
}

View File

@@ -62,8 +62,8 @@ class ServicesDelete extends Command
options: $servers->pluck('name', 'id')->sortKeys(),
);
foreach ($serversToDelete as $serverToDelete) {
$toDelete = $servers->where('id', $serverToDelete)->first();
foreach ($serversToDelete as $server) {
$toDelete = $servers->where('id', $server)->first();
if ($toDelete) {
$this->info($toDelete);
$confirmed = confirm('Are you sure you want to delete all selected resources?');
@@ -88,8 +88,8 @@ class ServicesDelete extends Command
$applications->pluck('name', 'id')->sortKeys(),
);
foreach ($applicationsToDelete as $applicationToDelete) {
$toDelete = $applications->where('id', $applicationToDelete)->first();
foreach ($applicationsToDelete as $application) {
$toDelete = $applications->where('id', $application)->first();
if ($toDelete) {
$this->info($toDelete);
$confirmed = confirm('Are you sure you want to delete all selected resources? ');
@@ -114,8 +114,8 @@ class ServicesDelete extends Command
$databases->pluck('name', 'id')->sortKeys(),
);
foreach ($databasesToDelete as $databaseToDelete) {
$toDelete = $databases->where('id', $databaseToDelete)->first();
foreach ($databasesToDelete as $database) {
$toDelete = $databases->where('id', $database)->first();
if ($toDelete) {
$this->info($toDelete);
$confirmed = confirm('Are you sure you want to delete all selected resources?');
@@ -140,8 +140,8 @@ class ServicesDelete extends Command
$services->pluck('name', 'id')->sortKeys(),
);
foreach ($servicesToDelete as $serviceToDelete) {
$toDelete = $services->where('id', $serviceToDelete)->first();
foreach ($servicesToDelete as $service) {
$toDelete = $services->where('id', $service)->first();
if ($toDelete) {
$this->info($toDelete);
$confirmed = confirm('Are you sure you want to delete all selected resources?');

View File

@@ -45,7 +45,7 @@ class ServicesGenerate extends Command
$data = collect(explode(PHP_EOL, $content))->mapWithKeys(function ($line): array {
preg_match('/^#(?<key>.*):(?<value>.*)$/U', $line, $m);
return $m !== [] ? [trim($m['key']) => trim($m['value'])] : [];
return $m ? [trim($m['key']) => trim($m['value'])] : [];
});
if (str($data->get('ignore'))->toBoolean()) {

View File

@@ -6,7 +6,6 @@ use Illuminate\Console\Command;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Http\Client\Pool;
use Illuminate\Support\Facades\Http;
use Throwable;
use function Laravel\Prompts\confirm;
@@ -115,8 +114,7 @@ class SyncBunny extends Command
$this->info('Service template uploaded & purged...');
return;
}
if ($only_version) {
} elseif ($only_version) {
if ($nightly) {
$this->info('About to sync NIGHLTY versions.json to BunnyCDN.');
} else {
@@ -125,6 +123,7 @@ class SyncBunny extends Command
$file = file_get_contents($versions_location);
$json = json_decode($file, true);
$actual_version = data_get($json, 'coolify.v4.version');
$confirmed = confirm("Are you sure you want to sync to {$actual_version}?");
if (! $confirmed) {
return;
@@ -153,7 +152,7 @@ class SyncBunny extends Command
$pool->purge("$bunny_cdn/$bunny_cdn_path/$install_script"),
]);
$this->info('All files uploaded & purged...');
} catch (Throwable $e) {
} catch (\Throwable $e) {
$this->error('Error: '.$e->getMessage());
}
}