Skip to content

Commit

Permalink
Fixed scopeWithProgress to work with pg_sql
Browse files Browse the repository at this point in the history
  • Loading branch information
lyalls-marc committed Oct 30, 2024
1 parent 4db0efb commit eeae018
Show file tree
Hide file tree
Showing 8 changed files with 877 additions and 939 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration
return new class extends Migration
{
public function getConnection()
{
Expand Down
28 changes: 26 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Http/Controllers/PhraseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function edit(Translation $translation, Phrase $phrase): RedirectResponse
'google' => [
'id' => 'google',
'engine' => 'Google Translate',
'value' => (new GoogleTranslate())->preserveParameters()
'value' => (new GoogleTranslate)->preserveParameters()
->setSource($phrase->source->translation->language->code)
->setTarget($translation->language->code)
->translate($phrase->source->value),
Expand Down
4 changes: 1 addition & 3 deletions src/Mail/InviteCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ class InviteCreated extends Mailable
{
use Queueable, SerializesModels;

public function __construct(public Invite $invite)
{
}
public function __construct(public Invite $invite) {}

public function build(): static
{
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function scopeIsSource($query): void
public function scopeWithProgress($query): void
{
$query->addSelect([
'progress' => Phrase::selectRaw('COUNT(CASE WHEN value IS NOT NULL THEN 1 END) / COUNT(*) * 100')
'progress' => Phrase::selectRaw('AVG(CASE WHEN value IS NOT NULL THEN 1 ELSE 0 END) * 100')
->whereColumn('ltu_phrases.translation_id', 'ltu_translations.id')
->limit(1),
])->withCasts([
Expand Down
5 changes: 2 additions & 3 deletions src/TranslationsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ class TranslationsManager
{
public function __construct(
protected Filesystem $filesystem
) {
}
) {}

public function getLocales(): array
{
Expand Down Expand Up @@ -118,7 +117,7 @@ public function download(): ?string
try {
$this->export(download: true);

$zip = new ZipArchive();
$zip = new ZipArchive;

$zipPath = storage_path('app/lang.zip');
$zip->open($zipPath, ZipArchive::CREATE | ZipArchive::OVERWRITE);
Expand Down
12 changes: 6 additions & 6 deletions tests/TranslationsManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// Create nested folder structure
createPhpLanguageFile('en/book/create.php', []);

$translationsManager = new TranslationsManager(new Filesystem());
$translationsManager = new TranslationsManager(new Filesystem);
$locales = $translationsManager->getLocales();

expect($locales)->toBe(['de', 'en', 'fr']);
Expand Down Expand Up @@ -55,7 +55,7 @@

Config::set('translations.exclude_files', ['validation.php', 'book/excluded.php']);
Config::set('translations.source_language', 'en');
$filesystem = new Filesystem();
$filesystem = new Filesystem;

$translationsManager = new TranslationsManager($filesystem);
$translations = $translationsManager->getTranslations('en');
Expand Down Expand Up @@ -91,7 +91,7 @@

Config::set('translations.exclude_files', ['*.php']);
Config::set('translations.source_language', 'en');
$filesystem = new Filesystem();
$filesystem = new Filesystem;

$translationsManager = new TranslationsManager($filesystem);
$translations = $translationsManager->getTranslations('en');
Expand All @@ -106,7 +106,7 @@
});

test('export creates a new translation file with the correct content', function () {
$filesystem = new Filesystem();
$filesystem = new Filesystem;
createDirectoryIfNotExits(lang_path('en/auth.php'));
// Update to include nested folder
createDirectoryIfNotExits(lang_path('en/book/create.php'));
Expand Down Expand Up @@ -164,7 +164,7 @@
// Update to include nested folder
createPhpLanguageFile('en/book/create.php', ['nested' => 'Nested :attribute must be accepted.']);

$filesystem = new Filesystem();
$filesystem = new Filesystem;

$translation = Translation::factory()
->has(Phrase::factory()
Expand Down Expand Up @@ -207,7 +207,7 @@

// Update to include nested folder
createJsonLanguageFile('en/book/create.json', ['nested' => 'Nested test']);
$filesystem = new Filesystem();
$filesystem = new Filesystem;

$translation = Translation::factory()
->has(Phrase::factory()
Expand Down
Loading

0 comments on commit eeae018

Please sign in to comment.