From b9c3358f7fb0ef44637b0c8bbf0b5fbb8ebabe32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sun, 6 Jul 2025 22:15:48 +0200 Subject: [PATCH] Use a doctrine entity for storing the settings --- config/packages/settings.yaml | 8 ++++- migrations/Version20250706201121.php | 49 ++++++++++++++++++++++++++++ src/Entity/SettingsEntry.php | 35 ++++++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 migrations/Version20250706201121.php create mode 100644 src/Entity/SettingsEntry.php diff --git a/config/packages/settings.yaml b/config/packages/settings.yaml index 6b47cba3..05e21636 100644 --- a/config/packages/settings.yaml +++ b/config/packages/settings.yaml @@ -1,2 +1,8 @@ jbtronics_settings: - default_storage_adapter: Jbtronics\SettingsBundle\Storage\PHPFileStorageAdapter \ No newline at end of file + default_storage_adapter: Jbtronics\SettingsBundle\Storage\ORMStorageAdapter + + cache: + default_cacheable: true + + orm_storage: + default_entity_class: App\Entity\SettingsEntry \ No newline at end of file diff --git a/migrations/Version20250706201121.php b/migrations/Version20250706201121.php new file mode 100644 index 00000000..b7563978 --- /dev/null +++ b/migrations/Version20250706201121.php @@ -0,0 +1,49 @@ +addSql('CREATE TABLE settings_entry (`key` VARCHAR(255) NOT NULL, `data` JSON DEFAULT NULL, id INT AUTO_INCREMENT NOT NULL, UNIQUE INDEX UNIQ_93F8DB394E645A7E (`key`), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci`'); + + } + + public function mySQLDown(Schema $schema): void + { + $this->addSql('DROP TABLE settings_entry'); + } + + public function sqLiteUp(Schema $schema): void + { + $this->addSql('CREATE TABLE settings_entry ("key" VARCHAR(255) NOT NULL, "data" CLOB DEFAULT NULL, id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_93F8DB39F48571EB ON settings_entry ("key")'); + } + + public function sqLiteDown(Schema $schema): void + { + $this->addSql('DROP TABLE settings_entry'); + } + + public function postgreSQLUp(Schema $schema): void + { + $this->addSql('CREATE TABLE settings_entry ("key" VARCHAR(255) NOT NULL, "data" JSON DEFAULT NULL, id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_93F8DB39F48571EB ON settings_entry ("key")'); + } + + public function postgreSQLDown(Schema $schema): void + { + $this->addSql('DROP TABLE settings_entry'); + } +} diff --git a/src/Entity/SettingsEntry.php b/src/Entity/SettingsEntry.php new file mode 100644 index 00000000..488de1d1 --- /dev/null +++ b/src/Entity/SettingsEntry.php @@ -0,0 +1,35 @@ +. + */ + +declare(strict_types=1); + + +namespace App\Entity; + +use Doctrine\DBAL\Types\Types; +use Jbtronics\SettingsBundle\Entity\AbstractSettingsORMEntry; +use Doctrine\ORM\Mapping as ORM; + +#[ORM\Entity] +class SettingsEntry extends AbstractSettingsORMEntry +{ + #[ORM\Id, ORM\GeneratedValue, ORM\Column(type: Types::INTEGER)] + protected int $id; +} \ No newline at end of file