Skip to content

Commit b9c3358

Browse files
committed
Use a doctrine entity for storing the settings
1 parent 2f2f4b2 commit b9c3358

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

config/packages/settings.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
jbtronics_settings:
2-
default_storage_adapter: Jbtronics\SettingsBundle\Storage\PHPFileStorageAdapter
2+
default_storage_adapter: Jbtronics\SettingsBundle\Storage\ORMStorageAdapter
3+
4+
cache:
5+
default_cacheable: true
6+
7+
orm_storage:
8+
default_entity_class: App\Entity\SettingsEntry
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DoctrineMigrations;
6+
7+
use App\Migration\AbstractMultiPlatformMigration;
8+
use Doctrine\DBAL\Schema\Schema;
9+
10+
final class Version20250706201121 extends AbstractMultiPlatformMigration
11+
{
12+
public function getDescription(): string
13+
{
14+
return 'Add settings_entry table for storing settings';
15+
}
16+
17+
public function mySQLUp(Schema $schema): void
18+
{
19+
$this->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`');
20+
21+
}
22+
23+
public function mySQLDown(Schema $schema): void
24+
{
25+
$this->addSql('DROP TABLE settings_entry');
26+
}
27+
28+
public function sqLiteUp(Schema $schema): void
29+
{
30+
$this->addSql('CREATE TABLE settings_entry ("key" VARCHAR(255) NOT NULL, "data" CLOB DEFAULT NULL, id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)');
31+
$this->addSql('CREATE UNIQUE INDEX UNIQ_93F8DB39F48571EB ON settings_entry ("key")');
32+
}
33+
34+
public function sqLiteDown(Schema $schema): void
35+
{
36+
$this->addSql('DROP TABLE settings_entry');
37+
}
38+
39+
public function postgreSQLUp(Schema $schema): void
40+
{
41+
$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))');
42+
$this->addSql('CREATE UNIQUE INDEX UNIQ_93F8DB39F48571EB ON settings_entry ("key")');
43+
}
44+
45+
public function postgreSQLDown(Schema $schema): void
46+
{
47+
$this->addSql('DROP TABLE settings_entry');
48+
}
49+
}

src/Entity/SettingsEntry.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/*
3+
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
4+
*
5+
* Copyright (C) 2019 - 2025 Jan Böhmer (https://github.com/jbtronics)
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Affero General Public License as published
9+
* by the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
24+
namespace App\Entity;
25+
26+
use Doctrine\DBAL\Types\Types;
27+
use Jbtronics\SettingsBundle\Entity\AbstractSettingsORMEntry;
28+
use Doctrine\ORM\Mapping as ORM;
29+
30+
#[ORM\Entity]
31+
class SettingsEntry extends AbstractSettingsORMEntry
32+
{
33+
#[ORM\Id, ORM\GeneratedValue, ORM\Column(type: Types::INTEGER)]
34+
protected int $id;
35+
}

0 commit comments

Comments
 (0)