Skip to content

Commit

Permalink
initial language detection
Browse files Browse the repository at this point in the history
  • Loading branch information
antedebaas committed Nov 19, 2024
1 parent ca82efa commit c4d099d
Show file tree
Hide file tree
Showing 14 changed files with 308 additions and 46 deletions.
12 changes: 3 additions & 9 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,12 @@
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration

###> symfony/framework-bundle ###
APP_ENV=prod
APP_ENV=dev
APP_SECRET=d0d5f19dc666c3ac9c1a51ccc3902dd8
###< symfony/framework-bundle ###

###> doctrine/doctrine-bundle ###
DATABASE_URL="sqlite:///%kernel.project_dir%/var/data/database.sqlite"
###< doctrine/doctrine-bundle ###

###> symfony/mailer ###
MAILER_DSN=null://null
###< symfony/mailer ###

MAINTENANCE="false"

MAILBOX_CONNECTION=
MAILBOX_USERNAME=
Expand Down
55 changes: 28 additions & 27 deletions composer.lock

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

11 changes: 10 additions & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ services:

# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
App\EventListener\MaintenanceListener:
tags:
- { name: kernel.event_listener, event: kernel.request }

App\EventListener\KernelExceptionListener:
tags:
- { name: kernel.event_listener, event: kernel.exception, method: onKernelException }
- { name: kernel.event_listener, event: kernel.exception, method: onKernelException }

App\EventSubscriber\LocaleSubscriber:
arguments: ['%kernel.default_locale%']

App\EventSubscriber\UserLocaleSubscriber:
31 changes: 31 additions & 0 deletions migrations/mysql/Version20241119191121.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20241119191121 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE users ADD language VARCHAR(2) NOT NULL DEFAULT \'en\'');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE users DROP language');
}
}
31 changes: 31 additions & 0 deletions migrations/postgresql/Version20241119191004.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20241119191004 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE users ADD language VARCHAR(2) NOT NULL DEFAULT \'en\'');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE users DROP language');
}
}
36 changes: 36 additions & 0 deletions migrations/sqlite/Version20241115143427.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20241115143427 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE users ADD COLUMN language VARCHAR(2) NOT NULL DEFAULT \'en\'');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TEMPORARY TABLE __temp__users AS SELECT id, email, roles, password, is_verified, first_name, last_name FROM users');
$this->addSql('DROP TABLE users');
$this->addSql('CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, email VARCHAR(180) NOT NULL, roles CLOB NOT NULL, password VARCHAR(255) NOT NULL, is_verified BOOLEAN NOT NULL, first_name VARCHAR(255) DEFAULT NULL, last_name VARCHAR(255) DEFAULT NULL)');
$this->addSql('INSERT INTO users (id, email, roles, password, is_verified, first_name, last_name) SELECT id, email, roles, password, is_verified, first_name, last_name FROM __temp__users');
$this->addSql('DROP TABLE __temp__users');
$this->addSql('CREATE UNIQUE INDEX UNIQ_1483A5E9E7927C74 ON users (email)');
}
}
10 changes: 10 additions & 0 deletions src/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;

use Doctrine\ORM\EntityManagerInterface;
Expand Down Expand Up @@ -83,4 +84,13 @@ public function index(): Response
'logs' => $logs,
]);
}

#[Route('/version', name: 'app_version')]
public function version(): JsonResponse
{
return new JsonResponse([
'success' => true,
'version' => '1.22.4'
]);
}
}
3 changes: 3 additions & 0 deletions src/Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public function login(AuthenticationUtils $authenticationUtils): Response
if ($this->getUser()) {
return $this->redirectToRoute('app_dashboard');
}
if (!file_exists(dirname(__FILE__).'/../../.env.local')) {
return $this->redirectToRoute('app_setup');
}


// get the login error if there is one
Expand Down
15 changes: 15 additions & 0 deletions src/Entity/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class Users implements UserInterface, PasswordAuthenticatedUserInterface
#[ORM\Column(length: 255, nullable: true)]
private ?string $last_name = null;

#[ORM\Column(length: 2)]
private ?string $language = 'null';

public function __construct()
{
$this->domains = new ArrayCollection();
Expand Down Expand Up @@ -177,4 +180,16 @@ public function setLastName(?string $last_name): static

return $this;
}

public function getLanguage(): ?string
{
return $this->language;
}

public function setLanguage(string $language): static
{
$this->language = $language;

return $this;
}
}
Loading

0 comments on commit c4d099d

Please sign in to comment.