Skip to content

Commit

Permalink
Replace every with helper
Browse files Browse the repository at this point in the history
  • Loading branch information
RMartinOscar committed Feb 11, 2025
1 parent 617cec7 commit 87d8ed6
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 55 deletions.
20 changes: 10 additions & 10 deletions app/Console/Commands/Environment/DatabaseSettingsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function handle(): int
);

if ($this->variables['DB_CONNECTION'] === 'mysql') {
$this->output->note(__('commands.database_settings.DB_HOST_note'));
$this->output->note(trans('commands.database_settings.DB_HOST_note'));
$this->variables['DB_HOST'] = $this->option('host') ?? $this->ask(
'Database Host',
config('database.connections.mysql.host', '127.0.0.1')
Expand All @@ -73,7 +73,7 @@ public function handle(): int
config('database.connections.mysql.database', 'panel')
);

$this->output->note(__('commands.database_settings.DB_USERNAME_note'));
$this->output->note(trans('commands.database_settings.DB_USERNAME_note'));
$this->variables['DB_USERNAME'] = $this->option('username') ?? $this->ask(
'Database Username',
config('database.connections.mysql.username', 'pelican')
Expand All @@ -82,7 +82,7 @@ public function handle(): int
$askForMySQLPassword = true;
if (!empty(config('database.connections.mysql.password')) && $this->input->isInteractive()) {
$this->variables['DB_PASSWORD'] = config('database.connections.mysql.password');
$askForMySQLPassword = $this->confirm(__('commands.database_settings.DB_PASSWORD_note'));
$askForMySQLPassword = $this->confirm(trans('commands.database_settings.DB_PASSWORD_note'));
}

if ($askForMySQLPassword) {
Expand All @@ -106,9 +106,9 @@ public function handle(): int
$this->database->connection('_panel_command_test')->getPdo();
} catch (\PDOException $exception) {
$this->output->error(sprintf('Unable to connect to the MySQL server using the provided credentials. The error returned was "%s".', $exception->getMessage()));
$this->output->error(__('commands.database_settings.DB_error_2'));
$this->output->error(trans('commands.database_settings.DB_error_2'));

if ($this->confirm(__('commands.database_settings.go_back'))) {
if ($this->confirm(trans('commands.database_settings.go_back'))) {
$this->database->disconnect('_panel_command_test');

return $this->handle();
Expand All @@ -117,7 +117,7 @@ public function handle(): int
return 1;
}
} elseif ($this->variables['DB_CONNECTION'] === 'mariadb') {
$this->output->note(__('commands.database_settings.DB_HOST_note'));
$this->output->note(trans('commands.database_settings.DB_HOST_note'));
$this->variables['DB_HOST'] = $this->option('host') ?? $this->ask(
'Database Host',
config('database.connections.mariadb.host', '127.0.0.1')
Expand All @@ -133,7 +133,7 @@ public function handle(): int
config('database.connections.mariadb.database', 'panel')
);

$this->output->note(__('commands.database_settings.DB_USERNAME_note'));
$this->output->note(trans('commands.database_settings.DB_USERNAME_note'));
$this->variables['DB_USERNAME'] = $this->option('username') ?? $this->ask(
'Database Username',
config('database.connections.mariadb.username', 'pelican')
Expand All @@ -142,7 +142,7 @@ public function handle(): int
$askForMariaDBPassword = true;
if (!empty(config('database.connections.mariadb.password')) && $this->input->isInteractive()) {
$this->variables['DB_PASSWORD'] = config('database.connections.mariadb.password');
$askForMariaDBPassword = $this->confirm(__('commands.database_settings.DB_PASSWORD_note'));
$askForMariaDBPassword = $this->confirm(trans('commands.database_settings.DB_PASSWORD_note'));
}

if ($askForMariaDBPassword) {
Expand All @@ -166,9 +166,9 @@ public function handle(): int
$this->database->connection('_panel_command_test')->getPdo();
} catch (\PDOException $exception) {
$this->output->error(sprintf('Unable to connect to the MariaDB server using the provided credentials. The error returned was "%s".', $exception->getMessage()));
$this->output->error(__('commands.database_settings.DB_error_2'));
$this->output->error(trans('commands.database_settings.DB_error_2'));

if ($this->confirm(__('commands.database_settings.go_back'))) {
if ($this->confirm(trans('commands.database_settings.go_back'))) {
$this->database->disconnect('_panel_command_test');

return $this->handle();
Expand Down
38 changes: 19 additions & 19 deletions app/Console/Commands/Node/MakeNodeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,31 @@ public function __construct(private NodeCreationService $creationService)
*/
public function handle(): void
{
$data['name'] = $this->option('name') ?? $this->ask(__('commands.make_node.name'));
$data['description'] = $this->option('description') ?? $this->ask(__('commands.make_node.description'));
$data['name'] = $this->option('name') ?? $this->ask(trans('commands.make_node.name'));
$data['description'] = $this->option('description') ?? $this->ask(trans('commands.make_node.description'));
$data['scheme'] = $this->option('scheme') ?? $this->anticipate(
__('commands.make_node.scheme'),
trans('commands.make_node.scheme'),
['https', 'http'],
'https'
);

$data['fqdn'] = $this->option('fqdn') ?? $this->ask(__('commands.make_node.fqdn'));
$data['public'] = $this->option('public') ?? $this->confirm(__('commands.make_node.public'), true);
$data['behind_proxy'] = $this->option('proxy') ?? $this->confirm(__('commands.make_node.behind_proxy'));
$data['maintenance_mode'] = $this->option('maintenance') ?? $this->confirm(__('commands.make_node.maintenance_mode'));
$data['memory'] = $this->option('maxMemory') ?? $this->ask(__('commands.make_node.memory'), '0');
$data['memory_overallocate'] = $this->option('overallocateMemory') ?? $this->ask(__('commands.make_node.memory_overallocate'), '-1');
$data['disk'] = $this->option('maxDisk') ?? $this->ask(__('commands.make_node.disk'), '0');
$data['disk_overallocate'] = $this->option('overallocateDisk') ?? $this->ask(__('commands.make_node.disk_overallocate'), '-1');
$data['cpu'] = $this->option('maxCpu') ?? $this->ask(__('commands.make_node.cpu'), '0');
$data['cpu_overallocate'] = $this->option('overallocateCpu') ?? $this->ask(__('commands.make_node.cpu_overallocate'), '-1');
$data['upload_size'] = $this->option('uploadSize') ?? $this->ask(__('commands.make_node.upload_size'), '256');
$data['daemon_listen'] = $this->option('daemonListeningPort') ?? $this->ask(__('commands.make_node.daemonListen'), '8080');
$data['daemon_sftp'] = $this->option('daemonSFTPPort') ?? $this->ask(__('commands.make_node.daemonSFTP'), '2022');
$data['daemon_sftp_alias'] = $this->option('daemonSFTPAlias') ?? $this->ask(__('commands.make_node.daemonSFTPAlias'), '');
$data['daemon_base'] = $this->option('daemonBase') ?? $this->ask(__('commands.make_node.daemonBase'), '/var/lib/pelican/volumes');
$data['fqdn'] = $this->option('fqdn') ?? $this->ask(trans('commands.make_node.fqdn'));
$data['public'] = $this->option('public') ?? $this->confirm(trans('commands.make_node.public'), true);
$data['behind_proxy'] = $this->option('proxy') ?? $this->confirm(trans('commands.make_node.behind_proxy'));
$data['maintenance_mode'] = $this->option('maintenance') ?? $this->confirm(trans('commands.make_node.maintenance_mode'));
$data['memory'] = $this->option('maxMemory') ?? $this->ask(trans('commands.make_node.memory'), '0');
$data['memory_overallocate'] = $this->option('overallocateMemory') ?? $this->ask(trans('commands.make_node.memory_overallocate'), '-1');
$data['disk'] = $this->option('maxDisk') ?? $this->ask(trans('commands.make_node.disk'), '0');
$data['disk_overallocate'] = $this->option('overallocateDisk') ?? $this->ask(trans('commands.make_node.disk_overallocate'), '-1');
$data['cpu'] = $this->option('maxCpu') ?? $this->ask(trans('commands.make_node.cpu'), '0');
$data['cpu_overallocate'] = $this->option('overallocateCpu') ?? $this->ask(trans('commands.make_node.cpu_overallocate'), '-1');
$data['upload_size'] = $this->option('uploadSize') ?? $this->ask(trans('commands.make_node.upload_size'), '256');
$data['daemon_listen'] = $this->option('daemonListeningPort') ?? $this->ask(trans('commands.make_node.daemonListen'), '8080');
$data['daemon_sftp'] = $this->option('daemonSFTPPort') ?? $this->ask(trans('commands.make_node.daemonSFTP'), '2022');
$data['daemon_sftp_alias'] = $this->option('daemonSFTPAlias') ?? $this->ask(trans('commands.make_node.daemonSFTPAlias'), '');
$data['daemon_base'] = $this->option('daemonBase') ?? $this->ask(trans('commands.make_node.daemonBase'), '/var/lib/pelican/volumes');

$node = $this->creationService->handle($data);
$this->line(__('commands.make_node.success', ['name' => $data['name'], 'id' => $node->id]));
$this->line(trans('commands.make_node.success', ['name' => $data['name'], 'id' => $node->id]));
}
}
4 changes: 2 additions & 2 deletions app/Console/Commands/Node/NodeConfigurationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public function handle(): int

/** @var \App\Models\Node $node */
$node = Node::query()->where($column, $this->argument('node'))->firstOr(function () {
$this->error(__('commands.node_config.error_not_exist'));
$this->error(trans('commands.node_config.error_not_exist'));

exit(1);
});

$format = $this->option('format');
if (!in_array($format, ['yaml', 'yml', 'json'])) {
$this->error(__('commands.node_config.error_invalid_format'));
$this->error(trans('commands.node_config.error_invalid_format'));

return 1;
}
Expand Down
6 changes: 3 additions & 3 deletions app/Console/Commands/Overrides/KeyGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class KeyGenerateCommand extends BaseKeyGenerateCommand
public function handle(): void
{
if (!empty(config('app.key')) && $this->input->isInteractive()) {
$this->output->warning(__('commands.key_generate.error_already_exist'));
if (!$this->confirm(__('commands.key_generate.understand'))) {
$this->output->warning(trans('commands.key_generate.error_already_exist'));
if (!$this->confirm(trans('commands.key_generate.understand'))) {
return;
}

if (!$this->confirm(__('commands.key_generate.continue'))) {
if (!$this->confirm(trans('commands.key_generate.continue'))) {
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/Schedule/ProcessRunnableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function handle(ProcessScheduleService $processScheduleService): int
->get();

if ($schedules->count() < 1) {
$this->line(__('commands.schedule.process.no_tasks'));
$this->line(trans('commands.schedule.process.no_tasks'));

return 0;
}
Expand Down Expand Up @@ -64,7 +64,7 @@ protected function processSchedule(ProcessScheduleService $processScheduleServic
} catch (Throwable $exception) {
logger()->error($exception, ['schedule_id' => $schedule->id]);

$this->error(__('commands.schedule.process.no_tasks') . " #$schedule->id: " . $exception->getMessage());
$this->error(trans('commands.schedule.process.no_tasks') . " #$schedule->id: " . $exception->getMessage());
}
}
}
20 changes: 10 additions & 10 deletions app/Console/Commands/UpgradeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,26 @@ public function handle(): void
{
$skipDownload = $this->option('skip-download');
if (!$skipDownload) {
$this->output->warning(__('commands.upgrade.integrity'));
$this->output->comment(__('commands.upgrade.source_url'));
$this->output->warning(trans('commands.upgrade.integrity'));
$this->output->comment(trans('commands.upgrade.source_url'));
$this->line($this->getUrl());
}

$user = 'www-data';
$group = 'www-data';
if ($this->input->isInteractive()) {
if (!$skipDownload) {
$skipDownload = !$this->confirm(__('commands.upgrade.skipDownload'), true);
$skipDownload = !$this->confirm(trans('commands.upgrade.skipDownload'), true);
}

if (is_null($this->option('user'))) {
$userDetails = function_exists('posix_getpwuid') ? posix_getpwuid(fileowner('public')) : [];
$user = $userDetails['name'] ?? 'www-data';

$message = __('commands.upgrade.webserver_user', ['user' => $user]);
$message = trans('commands.upgrade.webserver_user', ['user' => $user]);
if (!$this->confirm($message, true)) {
$user = $this->anticipate(
__('commands.upgrade.name_webserver'),
trans('commands.upgrade.name_webserver'),
[
'www-data',
'nginx',
Expand All @@ -67,10 +67,10 @@ public function handle(): void
$groupDetails = function_exists('posix_getgrgid') ? posix_getgrgid(filegroup('public')) : [];
$group = $groupDetails['name'] ?? 'www-data';

$message = __('commands.upgrade.group_webserver', ['group' => $user]);
$message = trans('commands.upgrade.group_webserver', ['group' => $user]);
if (!$this->confirm($message, true)) {
$group = $this->anticipate(
__('commands.upgrade.group_webserver_question'),
trans('commands.upgrade.group_webserver_question'),
[
'www-data',
'nginx',
Expand All @@ -80,8 +80,8 @@ public function handle(): void
}
}

if (!$this->confirm(__('commands.upgrade.are_your_sure'))) {
$this->warn(__('commands.upgrade.terminated'));
if (!$this->confirm(trans('commands.upgrade.are_your_sure'))) {
$this->warn(trans('commands.upgrade.terminated'));

return;
}
Expand Down Expand Up @@ -171,7 +171,7 @@ public function handle(): void
});

$this->newLine(2);
$this->info(__('commands.upgrade.success'));
$this->info(trans('commands.upgrade.success'));
}

protected function withProgress(ProgressBar $bar, \Closure $callback): void
Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Pages/Auth/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function throwFailureValidationException(): never
$this->dispatch('reset-captcha');

throw ValidationException::withMessages([
'data.login' => __('filament-panels::pages/auth/login.messages.failed'),
'data.login' => trans('filament-panels::pages/auth/login.messages.failed'),
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function table(Table $table): Table
})
->hintAction(
Action::make('edit')
->label(__('filament-actions::edit.single.label'))
->label(trans('filament-actions::edit.single.label'))
->icon('tabler-edit')
->visible(fn (ActivityLog $activityLog) => $activityLog->actor instanceof User && auth()->user()->can('update user'))
->url(fn (ActivityLog $activityLog) => EditUser::getUrl(['record' => $activityLog->actor], panel: 'admin'))
Expand Down
4 changes: 2 additions & 2 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ protected static function booted(): void
});

static::deleting(function (self $user) {
throw_if($user->servers()->count() > 0, new DisplayException(__('admin/user.exceptions.user_has_servers')));
throw_if($user->servers()->count() > 0, new DisplayException(trans('admin/user.exceptions.user_has_servers')));

throw_if(request()->user()?->id === $user->id, new DisplayException(__('admin/user.exceptions.user_is_self')));
throw_if(request()->user()?->id === $user->id, new DisplayException(trans('admin/user.exceptions.user_is_self')));
});
}

Expand Down
10 changes: 5 additions & 5 deletions app/Traits/Commands/RequestRedisSettingsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ trait RequestRedisSettingsTrait
{
protected function requestRedisSettings(): void
{
$this->output->note(__('commands.appsettings.redis.note'));
$this->output->note(trans('commands.appsettings.redis.note'));
$this->variables['REDIS_HOST'] = $this->option('redis-host') ?? $this->ask(
'Redis Host',
config('database.redis.default.host')
Expand All @@ -17,21 +17,21 @@ protected function requestRedisSettings(): void

if (!empty(config('database.redis.default.user'))) {
$this->variables['REDIS_USERNAME'] = config('database.redis.default.user');
$askForRedisUser = $this->confirm(__('commands.appsettings.redis.confirm', ['field' => 'user']));
$askForRedisUser = $this->confirm(trans('commands.appsettings.redis.confirm', ['field' => 'user']));
}
if (!empty(config('database.redis.default.password'))) {
$this->variables['REDIS_PASSWORD'] = config('database.redis.default.password');
$askForRedisPassword = $this->confirm(__('commands.appsettings.redis.confirm', ['field' => 'password']));
$askForRedisPassword = $this->confirm(trans('commands.appsettings.redis.confirm', ['field' => 'password']));
}

if ($askForRedisUser) {
$this->output->comment(__('commands.appsettings.redis.comment'));
$this->output->comment(trans('commands.appsettings.redis.comment'));
$this->variables['REDIS_USERNAME'] = $this->option('redis-user') ?? $this->output->askHidden(
'Redis User'
);
}
if ($askForRedisPassword) {
$this->output->comment(__('commands.appsettings.redis.comment'));
$this->output->comment(trans('commands.appsettings.redis.comment'));
$this->variables['REDIS_PASSWORD'] = $this->option('redis-pass') ?? $this->output->askHidden(
'Redis Password'
);
Expand Down

0 comments on commit 87d8ed6

Please sign in to comment.