Skip to content

Commit

Permalink
Use the schema of the selected database when running the 'ImportTrans…
Browse files Browse the repository at this point in the history
…lationsCommand'.
  • Loading branch information
caswd committed Jun 27, 2024
1 parent a41424d commit fb159f6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Console/Commands/ImportTranslationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Outhebox\TranslationsUI\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Database\Schema\Builder as SchemaBuilder;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -50,7 +51,7 @@ public function handle(): void

protected function importLanguages(): void
{
if (! Schema::hasTable('ltu_languages') || Language::count() === 0) {
if (! $this->getSchema()->hasTable('ltu_languages') || Language::count() === 0) {
if ($this->confirm('The ltu_languages table does not exist or is empty, would you like to install the default languages?', true)) {
$this->call('db:seed', ['--class' => LanguagesTableSeeder::class]);
} else {
Expand All @@ -63,13 +64,18 @@ protected function importLanguages(): void

protected function truncateTables(): void
{
Schema::withoutForeignKeyConstraints(function () {
$this->getSchema()->withoutForeignKeyConstraints(function () {
Phrase::truncate();
Translation::truncate();
TranslationFile::truncate();
});
}

protected function getSchema(): SchemaBuilder
{
return Schema::connection(config('translations.database_connection'));
}

public function createOrGetSourceLanguage(): Translation
{
$language = Language::where('code', config('translations.source_language'))->first();
Expand Down

0 comments on commit fb159f6

Please sign in to comment.