mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Merge branch 'master' into settings-bundle
This commit is contained in:
commit
3e657a7cac
305 changed files with 7543 additions and 4274 deletions
4
.env
4
.env
|
@ -23,6 +23,10 @@ DATABASE_MYSQL_USE_SSL_CA=0
|
||||||
# Only do this, if you know what you are doing!
|
# Only do this, if you know what you are doing!
|
||||||
DATABASE_MYSQL_SSL_VERIFY_CERT=1
|
DATABASE_MYSQL_SSL_VERIFY_CERT=1
|
||||||
|
|
||||||
|
# Emulate natural sorting of strings even on databases that do not support it (like SQLite, MySQL or MariaDB < 10.7)
|
||||||
|
# This can be slow on big databases and might have some problems and quirks, so use it with caution
|
||||||
|
DATABASE_EMULATE_NATURAL_SORT=0
|
||||||
|
|
||||||
###################################################################################
|
###################################################################################
|
||||||
# General settings
|
# General settings
|
||||||
###################################################################################
|
###################################################################################
|
||||||
|
|
2
.github/workflows/docker_build.yml
vendored
2
.github/workflows/docker_build.yml
vendored
|
@ -65,7 +65,7 @@ jobs:
|
||||||
|
|
||||||
-
|
-
|
||||||
name: Build and push
|
name: Build and push
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||||
|
|
2
.github/workflows/docker_frankenphp.yml
vendored
2
.github/workflows/docker_frankenphp.yml
vendored
|
@ -65,7 +65,7 @@ jobs:
|
||||||
|
|
||||||
-
|
-
|
||||||
name: Build and push
|
name: Build and push
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: Dockerfile-frankenphp
|
file: Dockerfile-frankenphp
|
||||||
|
|
33
.github/workflows/tests.yml
vendored
33
.github/workflows/tests.yml
vendored
|
@ -16,9 +16,10 @@ jobs:
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
php-versions: [ '8.1', '8.2', '8.3' ]
|
php-versions: [ '8.1', '8.2', '8.3' ]
|
||||||
db-type: [ 'mysql', 'sqlite' ]
|
db-type: [ 'mysql', 'sqlite', 'postgres' ]
|
||||||
|
|
||||||
env:
|
env:
|
||||||
# Note that we set DATABASE URL later based on our db-type matrix value
|
# Note that we set DATABASE URL later based on our db-type matrix value
|
||||||
|
@ -30,13 +31,17 @@ jobs:
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set Database env for MySQL
|
- name: Set Database env for MySQL
|
||||||
run: echo "DATABASE_URL=mysql://root:root@127.0.0.1:3306/test" >> $GITHUB_ENV
|
run: echo "DATABASE_URL=mysql://root:root@127.0.0.1:3306/partdb?serverVersion=8.0.35" >> $GITHUB_ENV
|
||||||
if: matrix.db-type == 'mysql'
|
if: matrix.db-type == 'mysql'
|
||||||
|
|
||||||
- name: Set Database env for SQLite
|
- name: Set Database env for SQLite
|
||||||
run: echo "DATABASE_URL="sqlite:///%kernel.project_dir%/var/app_test.db"" >> $GITHUB_ENV
|
run: echo "DATABASE_URL="sqlite:///%kernel.project_dir%/var/app_test.db"" >> $GITHUB_ENV
|
||||||
if: matrix.db-type == 'sqlite'
|
if: matrix.db-type == 'sqlite'
|
||||||
|
|
||||||
|
- name: Set Database env for PostgreSQL
|
||||||
|
run: echo "DATABASE_URL=postgresql://postgres:postgres @127.0.0.1:5432/partdb?serverVersion=14&charset=utf8" >> $GITHUB_ENV
|
||||||
|
if: matrix.db-type == 'postgres'
|
||||||
|
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
@ -50,8 +55,17 @@ jobs:
|
||||||
|
|
||||||
- name: Start MySQL
|
- name: Start MySQL
|
||||||
run: sudo systemctl start mysql.service
|
run: sudo systemctl start mysql.service
|
||||||
|
if: matrix.db-type == 'mysql'
|
||||||
|
|
||||||
#- name: Setup MySQL
|
# Replace the scram-sha-256 with trust for host connections, to avoid password authentication
|
||||||
|
- name: Start PostgreSQL
|
||||||
|
run: |
|
||||||
|
sudo sed -i 's/^\(host.*all.*all.*\)scram-sha-256/\1trust/' /etc/postgresql/14/main/pg_hba.conf
|
||||||
|
sudo systemctl start postgresql.service
|
||||||
|
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
|
||||||
|
if: matrix.db-type == 'postgres'
|
||||||
|
|
||||||
|
#- name: Setup MySQL
|
||||||
# uses: mirromutth/mysql-action@v1.1
|
# uses: mirromutth/mysql-action@v1.1
|
||||||
# with:
|
# with:
|
||||||
# mysql version: 5.7
|
# mysql version: 5.7
|
||||||
|
@ -99,12 +113,7 @@ jobs:
|
||||||
|
|
||||||
- name: Create DB
|
- name: Create DB
|
||||||
run: php bin/console --env test doctrine:database:create --if-not-exists -n
|
run: php bin/console --env test doctrine:database:create --if-not-exists -n
|
||||||
if: matrix.db-type == 'mysql'
|
if: matrix.db-type == 'mysql' || matrix.db-type == 'postgres'
|
||||||
|
|
||||||
# Checkinf for existance is not supported for sqlite, so do it without it
|
|
||||||
- name: Create DB
|
|
||||||
run: php bin/console --env test doctrine:database:create -n
|
|
||||||
if: matrix.db-type == 'sqlite'
|
|
||||||
|
|
||||||
- name: Do migrations
|
- name: Do migrations
|
||||||
run: php bin/console --env test doctrine:migrations:migrate -n
|
run: php bin/console --env test doctrine:migrations:migrate -n
|
||||||
|
@ -135,11 +144,11 @@ jobs:
|
||||||
- name: Test check-requirements command
|
- name: Test check-requirements command
|
||||||
run: php bin/console partdb:check-requirements -n
|
run: php bin/console partdb:check-requirements -n
|
||||||
|
|
||||||
|
- name: Test partdb:backup command
|
||||||
|
run: php bin/console partdb:backup -n --full /tmp/test_backup.zip
|
||||||
|
|
||||||
- name: Test legacy Part-DB import
|
- name: Test legacy Part-DB import
|
||||||
run: bash .github/assets/legacy_import/test_legacy_import.sh
|
run: bash .github/assets/legacy_import/test_legacy_import.sh
|
||||||
if: matrix.db-type == 'mysql' && matrix.php-versions == '8.2'
|
if: matrix.db-type == 'mysql' && matrix.php-versions == '8.2'
|
||||||
env:
|
env:
|
||||||
DATABASE_URL: mysql://root:root@localhost:3306/legacy_db
|
DATABASE_URL: mysql://root:root@localhost:3306/legacy_db
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ for the first time.
|
||||||
* Event log: Track what changes happen to your inventory, track which user does what. Revert your parts to older
|
* Event log: Track what changes happen to your inventory, track which user does what. Revert your parts to older
|
||||||
versions.
|
versions.
|
||||||
* Responsive design: You can use Part-DB on your PC, your tablet, and your smartphone using the same interface.
|
* Responsive design: You can use Part-DB on your PC, your tablet, and your smartphone using the same interface.
|
||||||
* MySQL and SQLite are supported as database backends
|
* MySQL, SQLite and PostgreSQL are supported as database backends
|
||||||
* Support for rich text descriptions and comments in parts
|
* Support for rich text descriptions and comments in parts
|
||||||
* Support for multiple currencies and automatic update of exchange rates supported
|
* Support for multiple currencies and automatic update of exchange rates supported
|
||||||
* Powerful search and filter function, including parametric search (search for parts according to some specifications)
|
* Powerful search and filter function, including parametric search (search for parts according to some specifications)
|
||||||
|
@ -74,10 +74,10 @@ Part-DB is also used by small companies and universities for managing their inve
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
* A **web server** (like Apache2 or nginx) that is capable of
|
* A **web server** (like Apache2 or nginx) that is capable of
|
||||||
running [Symfony 5](https://symfony.com/doc/current/reference/requirements.html),
|
running [Symfony 6](https://symfony.com/doc/current/reference/requirements.html),
|
||||||
this includes a minimum PHP version of **PHP 8.1**
|
this includes a minimum PHP version of **PHP 8.1**
|
||||||
* A **MySQL** (at least 5.7) /**MariaDB** (at least 10.2.2) database server if you do not want to use SQLite.
|
* A **MySQL** (at least 5.7) /**MariaDB** (at least 10.4) database server, or **PostgreSQL** 10+ if you do not want to use SQLite.
|
||||||
* Shell access to your server is highly suggested!
|
* Shell access to your server is highly recommended!
|
||||||
* For building the client-side assets **yarn** and **nodejs** (>= 18.0) is needed.
|
* For building the client-side assets **yarn** and **nodejs** (>= 18.0) is needed.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
1.12.0
|
1.13.1
|
||||||
|
|
|
@ -88,5 +88,8 @@ export default class extends Controller {
|
||||||
} else {
|
} else {
|
||||||
this.hideSidebar();
|
this.hideSidebar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Hide the tootip on the button
|
||||||
|
this._toggle_button.blur();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,18 +10,18 @@
|
||||||
"ext-intl": "*",
|
"ext-intl": "*",
|
||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"ext-mbstring": "*",
|
"ext-mbstring": "*",
|
||||||
"api-platform/core": "3.2.*",
|
"amphp/http-client": "^5.1",
|
||||||
|
"api-platform/core": "^3.1",
|
||||||
"beberlei/doctrineextensions": "^1.2",
|
"beberlei/doctrineextensions": "^1.2",
|
||||||
"brick/math": "0.12.1 as 0.11.0",
|
"brick/math": "0.12.1 as 0.11.0",
|
||||||
"composer/ca-bundle": "^1.3",
|
"composer/ca-bundle": "^1.3",
|
||||||
"composer/package-versions-deprecated": "^1.11.99.5",
|
"composer/package-versions-deprecated": "^1.11.99.5",
|
||||||
"doctrine/annotations": "1.14.3",
|
|
||||||
"doctrine/data-fixtures": "^1.6.6",
|
"doctrine/data-fixtures": "^1.6.6",
|
||||||
"doctrine/dbal": "^3.4.6",
|
"doctrine/dbal": "^4.0.0",
|
||||||
"doctrine/doctrine-bundle": "^2.0",
|
"doctrine/doctrine-bundle": "^2.0",
|
||||||
"doctrine/doctrine-migrations-bundle": "^3.0",
|
"doctrine/doctrine-migrations-bundle": "^3.0",
|
||||||
"doctrine/orm": "^2.16",
|
"doctrine/orm": "^3.2.0",
|
||||||
"dompdf/dompdf": "dev-master#c9cf4be933e2406a51990bd4eb9e70612e790cc0 as v2.0.4",
|
"dompdf/dompdf": "^v3.0.0",
|
||||||
"erusev/parsedown": "^1.7",
|
"erusev/parsedown": "^1.7",
|
||||||
"florianv/swap": "^4.0",
|
"florianv/swap": "^4.0",
|
||||||
"florianv/swap-bundle": "dev-master",
|
"florianv/swap-bundle": "dev-master",
|
||||||
|
@ -105,8 +105,7 @@
|
||||||
"phpstan/phpstan-strict-rules": "^1.5",
|
"phpstan/phpstan-strict-rules": "^1.5",
|
||||||
"phpstan/phpstan-symfony": "^1.1.7",
|
"phpstan/phpstan-symfony": "^1.1.7",
|
||||||
"phpunit/phpunit": "^9.5",
|
"phpunit/phpunit": "^9.5",
|
||||||
"psalm/plugin-symfony": "^v5.0.1",
|
"rector/rector": "^1.1.1",
|
||||||
"rector/rector": "^0.18.0",
|
|
||||||
"roave/security-advisories": "dev-latest",
|
"roave/security-advisories": "dev-latest",
|
||||||
"symfony/browser-kit": "6.4.*",
|
"symfony/browser-kit": "6.4.*",
|
||||||
"symfony/css-selector": "6.4.*",
|
"symfony/css-selector": "6.4.*",
|
||||||
|
@ -115,8 +114,7 @@
|
||||||
"symfony/phpunit-bridge": "6.4.*",
|
"symfony/phpunit-bridge": "6.4.*",
|
||||||
"symfony/stopwatch": "6.4.*",
|
"symfony/stopwatch": "6.4.*",
|
||||||
"symfony/web-profiler-bundle": "6.4.*",
|
"symfony/web-profiler-bundle": "6.4.*",
|
||||||
"symplify/easy-coding-standard": "^12.0",
|
"symplify/easy-coding-standard": "^12.0"
|
||||||
"vimeo/psalm": "^5.6.0"
|
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"ext-bcmath": "Used to improve price calculation performance",
|
"ext-bcmath": "Used to improve price calculation performance",
|
||||||
|
|
4002
composer.lock
generated
4002
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -33,4 +33,5 @@ api_platform:
|
||||||
pagination_client_items_per_page: true # Allow clients to override the default items per page
|
pagination_client_items_per_page: true # Allow clients to override the default items per page
|
||||||
|
|
||||||
keep_legacy_inflector: false
|
keep_legacy_inflector: false
|
||||||
event_listeners_backward_compatibility_layer: false
|
# Need to be true, or some tests will fail
|
||||||
|
use_symfony_listeners: true
|
|
@ -9,15 +9,26 @@ doctrine:
|
||||||
# either here or in the DATABASE_URL env var (see .env file)
|
# either here or in the DATABASE_URL env var (see .env file)
|
||||||
|
|
||||||
types:
|
types:
|
||||||
|
# UTC datetimes
|
||||||
datetime:
|
datetime:
|
||||||
class: App\Doctrine\Types\UTCDateTimeType
|
class: App\Doctrine\Types\UTCDateTimeType
|
||||||
date:
|
date:
|
||||||
class: App\Doctrine\Types\UTCDateTimeType
|
class: App\Doctrine\Types\UTCDateTimeType
|
||||||
|
|
||||||
|
datetime_immutable:
|
||||||
|
class: App\Doctrine\Types\UTCDateTimeImmutableType
|
||||||
|
date_immutable:
|
||||||
|
class: App\Doctrine\Types\UTCDateTimeImmutableType
|
||||||
|
|
||||||
big_decimal:
|
big_decimal:
|
||||||
class: App\Doctrine\Types\BigDecimalType
|
class: App\Doctrine\Types\BigDecimalType
|
||||||
tinyint:
|
tinyint:
|
||||||
class: App\Doctrine\Types\TinyIntType
|
class: App\Doctrine\Types\TinyIntType
|
||||||
|
|
||||||
|
# This was removed in doctrine/orm 4.0 but we need it for the WebauthnKey entity
|
||||||
|
array:
|
||||||
|
class: App\Doctrine\Types\ArrayType
|
||||||
|
|
||||||
schema_filter: ~^(?!internal)~
|
schema_filter: ~^(?!internal)~
|
||||||
# Only enable this when needed
|
# Only enable this when needed
|
||||||
profiling_collect_backtrace: false
|
profiling_collect_backtrace: false
|
||||||
|
@ -29,6 +40,8 @@ doctrine:
|
||||||
validate_xml_mapping: true
|
validate_xml_mapping: true
|
||||||
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
|
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
|
||||||
auto_mapping: true
|
auto_mapping: true
|
||||||
|
controller_resolver:
|
||||||
|
auto_mapping: true
|
||||||
mappings:
|
mappings:
|
||||||
App:
|
App:
|
||||||
type: attribute
|
type: attribute
|
||||||
|
@ -39,10 +52,11 @@ doctrine:
|
||||||
|
|
||||||
dql:
|
dql:
|
||||||
string_functions:
|
string_functions:
|
||||||
regexp: DoctrineExtensions\Query\Mysql\Regexp
|
regexp: App\Doctrine\Functions\Regexp
|
||||||
ifnull: DoctrineExtensions\Query\Mysql\IfNull
|
|
||||||
field: DoctrineExtensions\Query\Mysql\Field
|
field: DoctrineExtensions\Query\Mysql\Field
|
||||||
field2: App\Doctrine\Functions\Field2
|
field2: App\Doctrine\Functions\Field2
|
||||||
|
natsort: App\Doctrine\Functions\Natsort
|
||||||
|
array_position: App\Doctrine\Functions\ArrayPosition
|
||||||
|
|
||||||
when@test:
|
when@test:
|
||||||
doctrine:
|
doctrine:
|
||||||
|
|
|
@ -17,6 +17,8 @@ parameters:
|
||||||
|
|
||||||
partdb.default_uri: '%env(string:DEFAULT_URI)%' # The default URI to use for the Part-DB instance (e.g. https://part-db.example.com/). This is used for generating links in emails
|
partdb.default_uri: '%env(string:DEFAULT_URI)%' # The default URI to use for the Part-DB instance (e.g. https://part-db.example.com/). This is used for generating links in emails
|
||||||
|
|
||||||
|
partdb.db.emulate_natural_sort: '%env(bool:DATABASE_EMULATE_NATURAL_SORT)%' # If this is set to true, natural sorting is emulated on platforms that do not support it natively. This can be slow on large datasets.
|
||||||
|
|
||||||
######################################################################################################################
|
######################################################################################################################
|
||||||
# Users and Privacy
|
# Users and Privacy
|
||||||
######################################################################################################################
|
######################################################################################################################
|
||||||
|
@ -137,3 +139,5 @@ parameters:
|
||||||
env(SAML_ROLE_MAPPING): '{}'
|
env(SAML_ROLE_MAPPING): '{}'
|
||||||
|
|
||||||
env(EDA_KICAD_CATEGORY_DEPTH): 0
|
env(EDA_KICAD_CATEGORY_DEPTH): 0
|
||||||
|
|
||||||
|
env(DATABASE_EMULATE_NATURAL_SORT): 0
|
||||||
|
|
|
@ -75,14 +75,6 @@ services:
|
||||||
# Only the event classes specified here are saved to DB (set to []) to log all events
|
# Only the event classes specified here are saved to DB (set to []) to log all events
|
||||||
$whitelist: []
|
$whitelist: []
|
||||||
|
|
||||||
App\EventSubscriber\LogSystem\EventLoggerSubscriber:
|
|
||||||
tags:
|
|
||||||
- { name: 'doctrine.event_subscriber' }
|
|
||||||
|
|
||||||
App\EventSubscriber\LogSystem\LogDBMigrationSubscriber:
|
|
||||||
tags:
|
|
||||||
- { name: 'doctrine.event_subscriber' }
|
|
||||||
|
|
||||||
App\Services\Attachments\AttachmentSubmitHandler:
|
App\Services\Attachments\AttachmentSubmitHandler:
|
||||||
arguments:
|
arguments:
|
||||||
$mimeTypes: '@mime_types'
|
$mimeTypes: '@mime_types'
|
||||||
|
|
|
@ -40,6 +40,9 @@ options listed, see `.env` file for the full list of possible env variables.
|
||||||
* `DATABASE_MYSQL_USE_SSL_CA`: If this value is set to `1` or `true` and a MySQL connection is used, then the connection
|
* `DATABASE_MYSQL_USE_SSL_CA`: If this value is set to `1` or `true` and a MySQL connection is used, then the connection
|
||||||
is encrypted by SSL/TLS and the server certificate is verified against the system CA certificates or the CA certificate
|
is encrypted by SSL/TLS and the server certificate is verified against the system CA certificates or the CA certificate
|
||||||
bundled with Part-DB. Set `DATABASE_MYSQL_SSL_VERIFY_CERT` if you want to accept all certificates.
|
bundled with Part-DB. Set `DATABASE_MYSQL_SSL_VERIFY_CERT` if you want to accept all certificates.
|
||||||
|
* `DATABASE_EMULATE_NATURAL_SORT` (default 0): If set to 1, Part-DB will emulate natural sorting, even if the database
|
||||||
|
does not support it natively. However this is much slower than the native sorting, and contain bugs or quirks, so use
|
||||||
|
it only, if you have to.
|
||||||
* `DEFAULT_LANG`: The default language to use server-wide (when no language is explicitly specified by a user or via
|
* `DEFAULT_LANG`: The default language to use server-wide (when no language is explicitly specified by a user or via
|
||||||
language chooser). Must be something like `en`, `de`, `fr`, etc.
|
language chooser). Must be something like `en`, `de`, `fr`, etc.
|
||||||
* `DEFAULT_TIMEZONE`: The default timezone to use globally, when a user has no timezone specified. Must be something
|
* `DEFAULT_TIMEZONE`: The default timezone to use globally, when a user has no timezone specified. Must be something
|
||||||
|
|
|
@ -41,7 +41,7 @@ It is installed on a web server and so can be accessed with any browser without
|
||||||
* Event log: Track what changes happens to your inventory, track which user does what. Revert your parts to older
|
* Event log: Track what changes happens to your inventory, track which user does what. Revert your parts to older
|
||||||
versions.
|
versions.
|
||||||
* Responsive design: You can use Part-DB on your PC, your tablet and your smartphone using the same interface.
|
* Responsive design: You can use Part-DB on your PC, your tablet and your smartphone using the same interface.
|
||||||
* MySQL and SQLite supported as database backends
|
* MySQL, SQLite and PostgreSQL are supported as database backends
|
||||||
* Support for rich text descriptions and comments in parts
|
* Support for rich text descriptions and comments in parts
|
||||||
* Support for multiple currencies and automatic update of exchange rates supported
|
* Support for multiple currencies and automatic update of exchange rates supported
|
||||||
* Powerful search and filter function, including parametric search (search for parts according to some specifications)
|
* Powerful search and filter function, including parametric search (search for parts according to some specifications)
|
||||||
|
|
|
@ -7,10 +7,18 @@ nav_order: 1
|
||||||
|
|
||||||
# Choosing database: SQLite or MySQL
|
# Choosing database: SQLite or MySQL
|
||||||
|
|
||||||
Part-DB saves its data in a [relational (SQL) database](https://en.wikipedia.org/wiki/Relational_database). Part-DB
|
Part-DB saves its data in a [relational (SQL) database](https://en.wikipedia.org/wiki/Relational_database).
|
||||||
supports either the use of [SQLite](https://www.sqlite.org/index.html)
|
|
||||||
or [MySQL](https://www.mysql.com/) / [MariaDB](https://mariadb.org/) (which are mostly the same, except for some minor
|
For this multiple database types are supported, currently these are:
|
||||||
differences).
|
|
||||||
|
* [SQLite](https://www.sqlite.org/index.html)
|
||||||
|
* [MySQL](https://www.mysql.com/) / [MariaDB](https://mariadb.org/) (which are mostly the same, except for some minor
|
||||||
|
differences)
|
||||||
|
* [PostgreSQL](https://www.postgresql.org/)
|
||||||
|
|
||||||
|
All these database types allow for the same basic functionality and allow Part-DB to run. However, there are some minor
|
||||||
|
differences between them, which might be important for you. Therefore the pros and cons of the different database types
|
||||||
|
are listed here.
|
||||||
|
|
||||||
{: .important }
|
{: .important }
|
||||||
You have to choose between the database types before you start using Part-DB and **you can not change it (easily) after
|
You have to choose between the database types before you start using Part-DB and **you can not change it (easily) after
|
||||||
|
@ -18,29 +26,157 @@ you have started creating data**. So you should choose the database type for you
|
||||||
|
|
||||||
## Comparison
|
## Comparison
|
||||||
|
|
||||||
**SQLite** is the default database type which is configured out of the box. All data is saved in a single file (
|
### SQLite
|
||||||
normally `var/app.db` in the Part-DB folder) and no additional installation or configuration besides Part-DB is needed.
|
|
||||||
To use **MySQL/MariaDB** as database, you have to install and configure the MySQL server, configure it and create a
|
|
||||||
database and user for Part-DB, which needs some additional work. When using docker you need an additional docker
|
|
||||||
container, and volume for the data
|
|
||||||
|
|
||||||
When using **SQLite** The database can be backuped easily by just copying the SQLite file to a safe place. Ideally, the *
|
#### Pros
|
||||||
*MySQL** database has to be dumped to a SQL file (using `mysqldump`). The `console partdb:backup` command can do this
|
|
||||||
automatically
|
|
||||||
|
|
||||||
However, SQLite does not support certain operations like regex search, which has to be emulated by PHP and therefore is
|
* **Easy to use**: No additional installation or configuration is needed, just start Part-DB and it will work out of the box
|
||||||
pretty slow compared to the same operation at MySQL. In the future, there might be features that may only be available, when
|
* **Easy backup**: Just copy the SQLite file to a safe place, and you have a backup, which you can restore by copying it
|
||||||
using MySQL. Also, SQLite has limitations in comparisons and sorting of Unicode characters, which might lead to unexpected
|
back. No need to work with SQL dumps
|
||||||
behavior when using non-ASCII characters in your data. For example `µ` (micro sign) is not seen as equal to `μ(greek minuscule mu),
|
|
||||||
therefore searching for `µ` (micro sign) will not find parts containing `μ` (mu) and vice versa. In MySQL identical-looking characters are seen as equal, which is more intuitive in most cases.
|
|
||||||
|
|
||||||
In general MySQL might perform better for big Part-DB instances with many entries, lots of users and high activity, than
|
#### Cons
|
||||||
SQLite.
|
|
||||||
|
|
||||||
## Conclusion and Suggestion
|
* **Performance**: SQLite is not as fast as MySQL or PostgreSQL, especially when using complex queries or many users.
|
||||||
|
* **Emulated RegEx search**: SQLite does not support RegEx search natively. Part-DB can emulate it, however that is pretty slow.
|
||||||
|
* **Emualted natural sorting**: SQLite does not support natural sorting natively. Part-DB can emulate it, but it is pretty slow.
|
||||||
|
* **Limitations with Unicode**: SQLite has limitations in comparisons and sorting of Unicode characters, which might lead to
|
||||||
|
unexpected behavior when using non-ASCII characters in your data. For example `µ` (micro sign) is not seen as equal to
|
||||||
|
`μ` (greek minuscule mu), therefore searching for `µ` (micro sign) will not find parts containing `μ` (mu) and vice versa.
|
||||||
|
The other databases behave more intuitive in this case.
|
||||||
|
* **No advanced features**: SQLite do no support many of the advanced features of MySQL or PostgreSQL, which might be utilized
|
||||||
|
in future versions of Part-DB
|
||||||
|
|
||||||
|
|
||||||
|
### MySQL/MariaDB
|
||||||
|
|
||||||
|
**If possible, it is recommended to use MariaDB 10.7+ (instead of MySQL), as it supports natural sorting of columns natively.**
|
||||||
|
|
||||||
|
#### Pros
|
||||||
|
|
||||||
|
* **Performance**: Compared to SQLite, MySQL/MariaDB will probably perform better, especially in large databases with many
|
||||||
|
users and high activity.
|
||||||
|
* **Natural Sorting**: MariaDB 10.7+ supports natural sorting of columns. On other databases it has to be emulated, which is pretty
|
||||||
|
slow.
|
||||||
|
* **Native RegEx search**: MySQL supports RegEx search natively, which is faster than emulating it in PHP.
|
||||||
|
* **Advanced features**: MySQL/MariaDB supports many advanced features, which might be utilized in future versions of Part-DB.
|
||||||
|
* **Full Unicode support**: MySQL/MariaDB has better support for Unicode characters, which makes it more intuitive to use
|
||||||
|
non-ASCII characters in your data.
|
||||||
|
|
||||||
|
#### Cons
|
||||||
|
|
||||||
|
* **Additional installation and configuration**: You have to install and configure the MySQL server, create a database and
|
||||||
|
user for Part-DB, which needs some additional work compared to SQLite.
|
||||||
|
* **Backup**: The MySQL database has to be dumped to a SQL file (using `mysqldump`). The `console partdb:backup` command can automate this.
|
||||||
|
|
||||||
|
|
||||||
|
### PostgreSQL
|
||||||
|
|
||||||
|
#### Pros
|
||||||
|
* **Performance**: PostgreSQL is known for its performance, especially in large databases with many users and high activity.
|
||||||
|
* **Advanced features**: PostgreSQL supports many advanced features, which might be utilized in future versions of Part-DB.
|
||||||
|
* **Full Unicode support**: PostgreSQL has better support for Unicode characters, which makes it more intuitive to use
|
||||||
|
non-ASCII characters in your data.
|
||||||
|
* **Native RegEx search**: PostgreSQL supports RegEx search natively, which is faster than emulating it in PHP.
|
||||||
|
* **Native Natural Sorting**: PostgreSQL supports natural sorting of columns natively in all versions and in general the support for it
|
||||||
|
is better than on MariaDB.
|
||||||
|
* **Support of transactional DDL**: PostgreSQL supports transactional DDL, which means that if you encounter a problem during a schema change,
|
||||||
|
the database will automatically rollback the changes. On MySQL/MariaDB you have to manually rollback the changes, by restoring from a database backup.
|
||||||
|
|
||||||
|
#### Cons
|
||||||
|
* **New backend**: The support of postgresql is new, and it was not tested as much as the other backends. There might be some bugs caused by this.
|
||||||
|
* **Additional installation and configuration**: You have to install and configure the PostgreSQL server, create a database and
|
||||||
|
user for Part-DB, which needs some additional work compared to SQLite.
|
||||||
|
* **Backup**: The PostgreSQL database has to be dumped to a SQL file (using `pg_dump`). The `console partdb:backup` command can automate this.
|
||||||
|
|
||||||
|
|
||||||
|
## Recommendation
|
||||||
|
|
||||||
When you are a hobbyist and use Part-DB for your own small inventory management with only you as user (or maybe sometimes
|
When you are a hobbyist and use Part-DB for your own small inventory management with only you as user (or maybe sometimes
|
||||||
a few other people), then the easy-to-use SQLite database will be fine.
|
a few other people), then the easy-to-use SQLite database will be fine, as long as you can live with the limitations, stated above.
|
||||||
|
However using MariaDB (or PostgreSQL), has no disadvantages in that situation (besides the initial setup requirements), so you might
|
||||||
|
want to use it, to be prepared for future use cases.
|
||||||
|
|
||||||
When you are planning to have a very big database, with a lot of entries and many users which regularly (and
|
When you are planning to have a very big database, with a lot of entries and many users which regularly using Part-DB, then you should
|
||||||
concurrently) using Part-DB you should maybe use MySQL as this will scale better.
|
use MariaDB or PostgreSQL, as they will perform better in that situation and allow for more advanced features.
|
||||||
|
If you should use MariaDB or PostgreSQL depends on your personal preference and what you already have installed on your servers and
|
||||||
|
what you are familiar with.
|
||||||
|
|
||||||
|
## Using the different databases
|
||||||
|
|
||||||
|
The only difference in using the different databases, is a different value in the `DATABASE_URL` environment variable in the `.env.local` file
|
||||||
|
or in the `DATABASE_URL` environment variable in your server or container configuration. It has the shape of a URL, where the scheme (the part before `://`)
|
||||||
|
is the database type, and the rest is connection information.
|
||||||
|
|
||||||
|
**The env var format below is for the `env.local` file. It might work differently for other env configuration. E.g. in a docker-compose file you have to remove the quotes!**
|
||||||
|
|
||||||
|
### SQLite
|
||||||
|
|
||||||
|
```shell
|
||||||
|
DATABASE_URL="sqlite:///%kernel.project_dir%/var/app.db"
|
||||||
|
```
|
||||||
|
|
||||||
|
Here you just need to configure the path to the SQLite file, which is created by Part-DB when performing the database migrations.
|
||||||
|
The `%kernel.project_dir%` is a placeholder for the path to the project directory, which is replaced by the actual path by Symfony, so that you do not
|
||||||
|
need to specify the path manually. In the example the database will be created as `app.db` in the `var` directory of your Part-DB installation folder.
|
||||||
|
|
||||||
|
### MySQL/MariaDB
|
||||||
|
|
||||||
|
```shell
|
||||||
|
DATABASE_URL="mysql://user:password@127.0.0.1:3306/database?serverVersion=8.0.37"
|
||||||
|
```
|
||||||
|
|
||||||
|
Here you have to replace `user`, `password` and `database` with the credentials of the MySQL/MariaDB user and the database name you want to use.
|
||||||
|
The host (here 127.0.0.1) and port should also be specified according to your MySQL/MariaDB server configuration.
|
||||||
|
|
||||||
|
In the `serverVersion` parameter you can specify the version of the MySQL/MariaDB server you are using, in the way the server returns it
|
||||||
|
(e.g. `8.0.37` for MySQL and `10.4.14-MariaDB`). If you do not know it, you can leave the default value.
|
||||||
|
|
||||||
|
If you want to use a unix socket for the connection instead of a TCP connnection, you can specify the socket path in the `unix_socket` parameter.
|
||||||
|
```shell
|
||||||
|
DATABASE_URL="mysql://user:password@localhost/database?serverVersion=8.0.37&unix_socket=/var/run/mysqld/mysqld.sock"
|
||||||
|
```
|
||||||
|
|
||||||
|
### PostgreSQL
|
||||||
|
|
||||||
|
```shell
|
||||||
|
DATABASE_URL="postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=12.19&charset=utf8"
|
||||||
|
```
|
||||||
|
|
||||||
|
Here you have to replace `db_user`, `db_password` and `db_name` with the credentials of the PostgreSQL user and the database name you want to use.
|
||||||
|
The host (here 127.0.0.1) and port should also be specified according to your PostgreSQL server configuration.
|
||||||
|
|
||||||
|
In the `serverVersion` parameter you can specify the version of the PostgreSQL server you are using, in the way the server returns it
|
||||||
|
(e.g. `12.19 (Debian 12.19-1.pgdg120+1)`). If you do not know it, you can leave the default value.
|
||||||
|
|
||||||
|
The `charset` parameter specify the character set of the database. It should be set to `utf8` to ensure that all characters are stored correctly.
|
||||||
|
|
||||||
|
If you want to use a unix socket for the connection instead of a TCP connnection, you can specify the socket path in the `unix_socket` parameter.
|
||||||
|
```shell
|
||||||
|
DATABASE_URL="postgresql://db_user:db_password@localhost/db_name?serverVersion=12.19&charset=utf8&unix_socket=/var/run/postgresql/.s.PGSQL.5432"
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Natural Sorting
|
||||||
|
|
||||||
|
Natural sorting is the sorting of strings in a way that numbers are sorted by their numerical value, not by their ASCII value.
|
||||||
|
|
||||||
|
For example in the classical binary sorting the string `DIP-4`, `DIP-8`, `DIP-16`, `DIP-28` would be sorted as following:
|
||||||
|
|
||||||
|
* `DIP-16`
|
||||||
|
* `DIP-28`
|
||||||
|
* `DIP-4`
|
||||||
|
* `DIP-8`
|
||||||
|
|
||||||
|
In natural sorting, it would be sorted as:
|
||||||
|
|
||||||
|
* `DIP-4`
|
||||||
|
* `DIP-8`
|
||||||
|
* `DIP-16`
|
||||||
|
* `DIP-28`
|
||||||
|
|
||||||
|
Part-DB can sort names in part tables and tree views naturally. PostgreSQL and MariaDB 10.7+ support natural sorting natively,
|
||||||
|
and it is automatically used if available.
|
||||||
|
|
||||||
|
For SQLite and MySQL < 10.7 it has to be emulated if wanted, which is pretty slow. Therefore it has to be explicity enabled by setting the
|
||||||
|
`DATABASE_EMULATE_NATURAL_SORT` environment variable to `1`. If it is 0 the classical binary sorting is used, on these databases. The emulations
|
||||||
|
might have some quirks and issues, so it is recommended to use a database which supports natural sorting natively, if you want to use it.
|
||||||
|
|
|
@ -235,4 +235,14 @@ EOD;
|
||||||
{
|
{
|
||||||
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
|
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -380,4 +380,14 @@ final class Version20190902140506 extends AbstractMultiPlatformMigration
|
||||||
{
|
{
|
||||||
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
|
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,4 +88,14 @@ final class Version20190913141126 extends AbstractMultiPlatformMigration
|
||||||
{
|
{
|
||||||
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
|
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,4 +179,14 @@ final class Version20190924113252 extends AbstractMultiPlatformMigration
|
||||||
{
|
{
|
||||||
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
|
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,4 +65,14 @@ final class Version20191214153125 extends AbstractMultiPlatformMigration
|
||||||
{
|
{
|
||||||
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
|
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,4 +68,14 @@ final class Version20200126191823 extends AbstractMultiPlatformMigration
|
||||||
{
|
{
|
||||||
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
|
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,4 +56,14 @@ final class Version20200311204104 extends AbstractMultiPlatformMigration
|
||||||
{
|
{
|
||||||
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
|
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,4 +42,14 @@ final class Version20200409130946 extends AbstractMultiPlatformMigration
|
||||||
{
|
{
|
||||||
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
|
$this->warnIf(true, "Migration not needed for SQLite. Skipping...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,4 +163,14 @@ EOD;
|
||||||
$this->addSql('DROP TABLE u2f_keys');
|
$this->addSql('DROP TABLE u2f_keys');
|
||||||
$this->addSql('DROP TABLE "users"');
|
$this->addSql('DROP TABLE "users"');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -535,4 +535,14 @@ final class Version20220925162725 extends AbstractMultiPlatformMigration
|
||||||
$this->addSql('CREATE INDEX IDX_1483A5E938248176 ON "users" (currency_id)');
|
$this->addSql('CREATE INDEX IDX_1483A5E938248176 ON "users" (currency_id)');
|
||||||
$this->addSql('CREATE INDEX IDX_1483A5E96DEDCEC2 ON "users" (id_preview_attachement)');
|
$this->addSql('CREATE INDEX IDX_1483A5E96DEDCEC2 ON "users" (id_preview_attachement)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,4 +47,14 @@ final class Version20221003212851 extends AbstractMultiPlatformMigration
|
||||||
{
|
{
|
||||||
$this->addSql('DROP TABLE webauthn_keys');
|
$this->addSql('DROP TABLE webauthn_keys');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,24 +4,20 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace DoctrineMigrations;
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
use App\Entity\UserSystem\PermissionData;
|
|
||||||
use App\Migration\AbstractMultiPlatformMigration;
|
use App\Migration\AbstractMultiPlatformMigration;
|
||||||
use App\Security\Interfaces\HasPermissionsInterface;
|
use App\Migration\WithPermPresetsTrait;
|
||||||
use App\Services\UserSystem\PermissionPresetsHelper;
|
use App\Services\UserSystem\PermissionPresetsHelper;
|
||||||
use Doctrine\DBAL\Connection;
|
use Doctrine\DBAL\Connection;
|
||||||
use Doctrine\DBAL\Schema\Schema;
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
use Doctrine\Migrations\AbstractMigration;
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Auto-generated Migration: Please modify to your needs!
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
*/
|
*/
|
||||||
final class Version20221114193325 extends AbstractMultiPlatformMigration implements ContainerAwareInterface
|
final class Version20221114193325 extends AbstractMultiPlatformMigration implements ContainerAwareInterface
|
||||||
{
|
{
|
||||||
private ?ContainerInterface $container = null;
|
use WithPermPresetsTrait;
|
||||||
private ?PermissionPresetsHelper $permission_presets_helper = null;
|
|
||||||
|
|
||||||
public function __construct(Connection $connection, LoggerInterface $logger)
|
public function __construct(Connection $connection, LoggerInterface $logger)
|
||||||
{
|
{
|
||||||
|
@ -33,34 +29,6 @@ final class Version20221114193325 extends AbstractMultiPlatformMigration impleme
|
||||||
return 'Update the permission system to the new system. Please note that all permissions will be reset!';
|
return 'Update the permission system to the new system. Please note that all permissions will be reset!';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getJSONPermDataFromPreset(string $preset): string
|
|
||||||
{
|
|
||||||
if ($this->permission_presets_helper === null) {
|
|
||||||
throw new \RuntimeException('PermissionPresetsHelper not set! There seems to be some issue with the dependency injection!');
|
|
||||||
}
|
|
||||||
|
|
||||||
//Create a virtual user on which we can apply the preset
|
|
||||||
$user = new class implements HasPermissionsInterface {
|
|
||||||
|
|
||||||
public PermissionData $perm_data;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->perm_data = new PermissionData();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getPermissions(): PermissionData
|
|
||||||
{
|
|
||||||
return $this->perm_data;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//Apply the preset to the virtual user
|
|
||||||
$this->permission_presets_helper->applyPreset($user, $preset);
|
|
||||||
|
|
||||||
//And return the json data
|
|
||||||
return json_encode($user->getPermissions());
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addDataMigrationAndWarning(): void
|
private function addDataMigrationAndWarning(): void
|
||||||
{
|
{
|
||||||
|
@ -164,11 +132,15 @@ final class Version20221114193325 extends AbstractMultiPlatformMigration impleme
|
||||||
$this->addSql('CREATE INDEX user_idx_username ON "users" (name)');
|
$this->addSql('CREATE INDEX user_idx_username ON "users" (name)');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setContainer(ContainerInterface $container = null)
|
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
{
|
{
|
||||||
if ($container) {
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
$this->container = $container;
|
}
|
||||||
$this->permission_presets_helper = $container->get(PermissionPresetsHelper::class);
|
|
||||||
}
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,4 +55,14 @@ final class Version20221204004815 extends AbstractMultiPlatformMigration
|
||||||
$this->addSql('CREATE INDEX parts_idx_datet_name_last_id_needs ON "parts" (datetime_added, name, last_modified, id, needs_review)');
|
$this->addSql('CREATE INDEX parts_idx_datet_name_last_id_needs ON "parts" (datetime_added, name, last_modified, id, needs_review)');
|
||||||
$this->addSql('CREATE INDEX parts_idx_name ON "parts" (name)');
|
$this->addSql('CREATE INDEX parts_idx_name ON "parts" (name)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,15 @@ final class Version20221216224745 extends AbstractMultiPlatformMigration
|
||||||
$this->addSql('CREATE INDEX log_idx_type ON log (type)');
|
$this->addSql('CREATE INDEX log_idx_type ON log (type)');
|
||||||
$this->addSql('CREATE INDEX log_idx_type_target ON log (type, target_type, target_id)');
|
$this->addSql('CREATE INDEX log_idx_type_target ON log (type, target_type, target_id)');
|
||||||
$this->addSql('CREATE INDEX log_idx_datetime ON log (datetime)');
|
$this->addSql('CREATE INDEX log_idx_datetime ON log (datetime)');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -320,4 +320,14 @@ final class Version20230108165410 extends AbstractMultiPlatformMigration
|
||||||
$this->addSql('ALTER TABLE projects RENAME TO devices');
|
$this->addSql('ALTER TABLE projects RENAME TO devices');
|
||||||
$this->addSql('ALTER TABLE project_bom_entries RENAME TO device_parts');
|
$this->addSql('ALTER TABLE project_bom_entries RENAME TO device_parts');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -521,4 +521,14 @@ final class Version20230219225340 extends AbstractMultiPlatformMigration
|
||||||
$this->addSql('CREATE INDEX IDX_799FD143A76ED395 ON webauthn_keys (user_id)');
|
$this->addSql('CREATE INDEX IDX_799FD143A76ED395 ON webauthn_keys (user_id)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,4 +37,14 @@ final class Version20230220221024 extends AbstractMultiPlatformMigration
|
||||||
{
|
{
|
||||||
$this->addSql('ALTER TABLE `users` DROP saml_user');
|
$this->addSql('ALTER TABLE `users` DROP saml_user');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -297,4 +297,14 @@ final class Version20230402170923 extends AbstractMultiPlatformMigration
|
||||||
$this->addSql('DROP TABLE __temp__webauthn_keys');
|
$this->addSql('DROP TABLE __temp__webauthn_keys');
|
||||||
$this->addSql('CREATE INDEX IDX_799FD143A76ED395 ON webauthn_keys (user_id)');
|
$this->addSql('CREATE INDEX IDX_799FD143A76ED395 ON webauthn_keys (user_id)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,4 +49,14 @@ final class Version20230408170059 extends AbstractMultiPlatformMigration
|
||||||
$this->addSql('CREATE INDEX IDX_1483A5E9EA7100A1 ON "users" (id_preview_attachment)');
|
$this->addSql('CREATE INDEX IDX_1483A5E9EA7100A1 ON "users" (id_preview_attachment)');
|
||||||
$this->addSql('CREATE INDEX user_idx_username ON "users" (name)');
|
$this->addSql('CREATE INDEX user_idx_username ON "users" (name)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -434,4 +434,14 @@ final class Version20230408213957 extends AbstractMultiPlatformMigration
|
||||||
$this->addSql('DROP TABLE __temp__webauthn_keys');
|
$this->addSql('DROP TABLE __temp__webauthn_keys');
|
||||||
$this->addSql('CREATE INDEX IDX_799FD143A76ED395 ON webauthn_keys (user_id)');
|
$this->addSql('CREATE INDEX IDX_799FD143A76ED395 ON webauthn_keys (user_id)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,4 +45,14 @@ final class Version20230417211732 extends AbstractMultiPlatformMigration
|
||||||
{
|
{
|
||||||
//As we done nothing, we don't need to implement this method.
|
//As we done nothing, we don't need to implement this method.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,4 +62,14 @@ final class Version20230528000149 extends AbstractMultiPlatformMigration
|
||||||
$this->addSql('DROP TABLE __temp__webauthn_keys');
|
$this->addSql('DROP TABLE __temp__webauthn_keys');
|
||||||
$this->addSql('CREATE INDEX IDX_799FD143A76ED395 ON webauthn_keys (user_id)');
|
$this->addSql('CREATE INDEX IDX_799FD143A76ED395 ON webauthn_keys (user_id)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -348,4 +348,14 @@ final class Version20230716184033 extends AbstractMultiPlatformMigration
|
||||||
$this->addSql('DROP TABLE __temp__webauthn_keys');
|
$this->addSql('DROP TABLE __temp__webauthn_keys');
|
||||||
$this->addSql('CREATE INDEX IDX_799FD143A76ED395 ON webauthn_keys (user_id)');
|
$this->addSql('CREATE INDEX IDX_799FD143A76ED395 ON webauthn_keys (user_id)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,4 +99,14 @@ final class Version20230730131708 extends AbstractMultiPlatformMigration
|
||||||
$this->addSql('CREATE INDEX parts_idx_name ON "parts" (name)');
|
$this->addSql('CREATE INDEX parts_idx_name ON "parts" (name)');
|
||||||
$this->addSql('CREATE INDEX parts_idx_ipn ON "parts" (ipn)');
|
$this->addSql('CREATE INDEX parts_idx_ipn ON "parts" (ipn)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,4 +41,14 @@ final class Version20230816213201 extends AbstractMultiPlatformMigration
|
||||||
{
|
{
|
||||||
$this->addSql('DROP TABLE api_tokens');
|
$this->addSql('DROP TABLE api_tokens');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,4 +68,14 @@ final class Version20231114223101 extends AbstractMultiPlatformMigration
|
||||||
$this->addSql('CREATE INDEX part_lots_idx_instock_un_expiration_id_part ON part_lots (instock_unknown, expiration_date, id_part)');
|
$this->addSql('CREATE INDEX part_lots_idx_instock_un_expiration_id_part ON part_lots (instock_unknown, expiration_date, id_part)');
|
||||||
$this->addSql('CREATE INDEX part_lots_idx_needs_refill ON part_lots (needs_refill)');
|
$this->addSql('CREATE INDEX part_lots_idx_needs_refill ON part_lots (needs_refill)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,4 +85,14 @@ final class Version20231130180903 extends AbstractMultiPlatformMigration
|
||||||
$this->addSql('CREATE INDEX parts_idx_name ON "parts" (name)');
|
$this->addSql('CREATE INDEX parts_idx_name ON "parts" (name)');
|
||||||
$this->addSql('CREATE INDEX parts_idx_ipn ON "parts" (ipn)');
|
$this->addSql('CREATE INDEX parts_idx_ipn ON "parts" (ipn)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,4 +62,14 @@ final class Version20240427222442 extends AbstractMultiPlatformMigration
|
||||||
$this->addSql('DROP TABLE __temp__webauthn_keys');
|
$this->addSql('DROP TABLE __temp__webauthn_keys');
|
||||||
$this->addSql('CREATE INDEX IDX_799FD143A76ED395 ON webauthn_keys (user_id)');
|
$this->addSql('CREATE INDEX IDX_799FD143A76ED395 ON webauthn_keys (user_id)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->warnIf(true, "Migration not needed for Postgres. Skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
653
migrations/Version20240606203053.php
Normal file
653
migrations/Version20240606203053.php
Normal file
|
@ -0,0 +1,653 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use App\Migration\AbstractMultiPlatformMigration;
|
||||||
|
use App\Migration\WithPermPresetsTrait;
|
||||||
|
use App\Services\UserSystem\PermissionPresetsHelper;
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20240606203053 extends AbstractMultiPlatformMigration implements ContainerAwareInterface
|
||||||
|
{
|
||||||
|
use WithPermPresetsTrait;
|
||||||
|
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Initial schema for Postgres and apply changes to MySQL and SQLite caused by the doctrine upgrade';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
//Create a collation for natural sorting
|
||||||
|
$this->addSql("CREATE COLLATION numeric (provider = icu, locale = 'en-u-kn-true');");
|
||||||
|
|
||||||
|
$this->addSql('CREATE TABLE api_tokens (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, valid_until TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, token VARCHAR(68) NOT NULL, level SMALLINT NOT NULL, last_time_used TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, user_id INT DEFAULT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_2CAD560E5F37A13B ON api_tokens (token)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_2CAD560EA76ED395 ON api_tokens (user_id)');
|
||||||
|
$this->addSql('CREATE TABLE "attachment_types" (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, comment TEXT NOT NULL, not_selectable BOOLEAN NOT NULL, alternative_names TEXT DEFAULT NULL, filetype_filter TEXT NOT NULL, parent_id INT DEFAULT NULL, id_preview_attachment INT DEFAULT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_EFAED719727ACA70 ON "attachment_types" (parent_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_EFAED719EA7100A1 ON "attachment_types" (id_preview_attachment)');
|
||||||
|
$this->addSql('CREATE INDEX attachment_types_idx_name ON "attachment_types" (name)');
|
||||||
|
$this->addSql('CREATE INDEX attachment_types_idx_parent_name ON "attachment_types" (parent_id, name)');
|
||||||
|
$this->addSql('CREATE TABLE "attachments" (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, original_filename VARCHAR(255) DEFAULT NULL, path VARCHAR(255) NOT NULL, show_in_table BOOLEAN NOT NULL, type_id INT NOT NULL, class_name VARCHAR(255) NOT NULL, element_id INT NOT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_47C4FAD6C54C8C93 ON "attachments" (type_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_47C4FAD61F1F2A24 ON "attachments" (element_id)');
|
||||||
|
$this->addSql('CREATE INDEX attachments_idx_id_element_id_class_name ON "attachments" (id, element_id, class_name)');
|
||||||
|
$this->addSql('CREATE INDEX attachments_idx_class_name_id ON "attachments" (class_name, id)');
|
||||||
|
$this->addSql('CREATE INDEX attachment_name_idx ON "attachments" (name)');
|
||||||
|
$this->addSql('CREATE INDEX attachment_element_idx ON "attachments" (class_name, element_id)');
|
||||||
|
$this->addSql('CREATE TABLE "categories" (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, comment TEXT NOT NULL, not_selectable BOOLEAN NOT NULL, alternative_names TEXT DEFAULT NULL, partname_hint TEXT NOT NULL, partname_regex TEXT NOT NULL, disable_footprints BOOLEAN NOT NULL, disable_manufacturers BOOLEAN NOT NULL, disable_autodatasheets BOOLEAN NOT NULL, disable_properties BOOLEAN NOT NULL, default_description TEXT NOT NULL, default_comment TEXT NOT NULL, eda_info_reference_prefix VARCHAR(255) DEFAULT NULL, eda_info_invisible BOOLEAN DEFAULT NULL, eda_info_exclude_from_bom BOOLEAN DEFAULT NULL, eda_info_exclude_from_board BOOLEAN DEFAULT NULL, eda_info_exclude_from_sim BOOLEAN DEFAULT NULL, eda_info_kicad_symbol VARCHAR(255) DEFAULT NULL, parent_id INT DEFAULT NULL, id_preview_attachment INT DEFAULT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_3AF34668727ACA70 ON "categories" (parent_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_3AF34668EA7100A1 ON "categories" (id_preview_attachment)');
|
||||||
|
$this->addSql('CREATE INDEX category_idx_name ON "categories" (name)');
|
||||||
|
$this->addSql('CREATE INDEX category_idx_parent_name ON "categories" (parent_id, name)');
|
||||||
|
$this->addSql('CREATE TABLE currencies (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, comment TEXT NOT NULL, not_selectable BOOLEAN NOT NULL, alternative_names TEXT DEFAULT NULL, exchange_rate NUMERIC(11, 5) DEFAULT NULL, iso_code VARCHAR(255) NOT NULL, parent_id INT DEFAULT NULL, id_preview_attachment INT DEFAULT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_37C44693727ACA70 ON currencies (parent_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_37C44693EA7100A1 ON currencies (id_preview_attachment)');
|
||||||
|
$this->addSql('CREATE INDEX currency_idx_name ON currencies (name)');
|
||||||
|
$this->addSql('CREATE INDEX currency_idx_parent_name ON currencies (parent_id, name)');
|
||||||
|
$this->addSql('CREATE TABLE "footprints" (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, comment TEXT NOT NULL, not_selectable BOOLEAN NOT NULL, alternative_names TEXT DEFAULT NULL, eda_info_kicad_footprint VARCHAR(255) DEFAULT NULL, parent_id INT DEFAULT NULL, id_preview_attachment INT DEFAULT NULL, id_footprint_3d INT DEFAULT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_A34D68A2727ACA70 ON "footprints" (parent_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_A34D68A2EA7100A1 ON "footprints" (id_preview_attachment)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_A34D68A232A38C34 ON "footprints" (id_footprint_3d)');
|
||||||
|
$this->addSql('CREATE INDEX footprint_idx_name ON "footprints" (name)');
|
||||||
|
$this->addSql('CREATE INDEX footprint_idx_parent_name ON "footprints" (parent_id, name)');
|
||||||
|
$this->addSql('CREATE TABLE "groups" (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, comment TEXT NOT NULL, not_selectable BOOLEAN NOT NULL, alternative_names TEXT DEFAULT NULL, enforce_2fa BOOLEAN NOT NULL, permissions_data JSON NOT NULL, parent_id INT DEFAULT NULL, id_preview_attachment INT DEFAULT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_F06D3970727ACA70 ON "groups" (parent_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_F06D3970EA7100A1 ON "groups" (id_preview_attachment)');
|
||||||
|
$this->addSql('CREATE INDEX group_idx_name ON "groups" (name)');
|
||||||
|
$this->addSql('CREATE INDEX group_idx_parent_name ON "groups" (parent_id, name)');
|
||||||
|
$this->addSql('CREATE TABLE label_profiles (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, comment TEXT NOT NULL, show_in_dropdown BOOLEAN NOT NULL, options_width DOUBLE PRECISION NOT NULL, options_height DOUBLE PRECISION NOT NULL, options_barcode_type VARCHAR(255) NOT NULL, options_picture_type VARCHAR(255) NOT NULL, options_supported_element VARCHAR(255) NOT NULL, options_additional_css TEXT NOT NULL, options_lines_mode VARCHAR(255) NOT NULL, options_lines TEXT NOT NULL, id_preview_attachment INT DEFAULT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_C93E9CF5EA7100A1 ON label_profiles (id_preview_attachment)');
|
||||||
|
$this->addSql('CREATE TABLE log (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, username VARCHAR(255) NOT NULL, datetime TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, level SMALLINT NOT NULL, target_id INT NOT NULL, target_type SMALLINT NOT NULL, extra JSON NOT NULL, id_user INT DEFAULT NULL, type SMALLINT NOT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_8F3F68C56B3CA4B ON log (id_user)');
|
||||||
|
$this->addSql('CREATE INDEX log_idx_type ON log (type)');
|
||||||
|
$this->addSql('CREATE INDEX log_idx_type_target ON log (type, target_type, target_id)');
|
||||||
|
$this->addSql('CREATE INDEX log_idx_datetime ON log (datetime)');
|
||||||
|
$this->addSql('CREATE TABLE "manufacturers" (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, comment TEXT NOT NULL, not_selectable BOOLEAN NOT NULL, alternative_names TEXT DEFAULT NULL, address VARCHAR(255) NOT NULL, phone_number VARCHAR(255) NOT NULL, fax_number VARCHAR(255) NOT NULL, email_address VARCHAR(255) NOT NULL, website VARCHAR(255) NOT NULL, auto_product_url VARCHAR(255) NOT NULL, parent_id INT DEFAULT NULL, id_preview_attachment INT DEFAULT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_94565B12727ACA70 ON "manufacturers" (parent_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_94565B12EA7100A1 ON "manufacturers" (id_preview_attachment)');
|
||||||
|
$this->addSql('CREATE INDEX manufacturer_name ON "manufacturers" (name)');
|
||||||
|
$this->addSql('CREATE INDEX manufacturer_idx_parent_name ON "manufacturers" (parent_id, name)');
|
||||||
|
$this->addSql('CREATE TABLE "measurement_units" (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, comment TEXT NOT NULL, not_selectable BOOLEAN NOT NULL, alternative_names TEXT DEFAULT NULL, unit VARCHAR(255) DEFAULT NULL, is_integer BOOLEAN NOT NULL, use_si_prefix BOOLEAN NOT NULL, parent_id INT DEFAULT NULL, id_preview_attachment INT DEFAULT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_F5AF83CF727ACA70 ON "measurement_units" (parent_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_F5AF83CFEA7100A1 ON "measurement_units" (id_preview_attachment)');
|
||||||
|
$this->addSql('CREATE INDEX unit_idx_name ON "measurement_units" (name)');
|
||||||
|
$this->addSql('CREATE INDEX unit_idx_parent_name ON "measurement_units" (parent_id, name)');
|
||||||
|
$this->addSql('CREATE TABLE oauth_tokens (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, token TEXT DEFAULT NULL, expires_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, refresh_token TEXT DEFAULT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE UNIQUE INDEX oauth_tokens_unique_name ON oauth_tokens (name)');
|
||||||
|
$this->addSql('CREATE TABLE "orderdetails" (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, supplierpartnr VARCHAR(255) NOT NULL, obsolete BOOLEAN NOT NULL, supplier_product_url TEXT NOT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, part_id INT NOT NULL, id_supplier INT DEFAULT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_489AFCDC4CE34BEC ON "orderdetails" (part_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_489AFCDCCBF180EB ON "orderdetails" (id_supplier)');
|
||||||
|
$this->addSql('CREATE INDEX orderdetails_supplier_part_nr ON "orderdetails" (supplierpartnr)');
|
||||||
|
$this->addSql('CREATE TABLE parameters (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, symbol VARCHAR(255) NOT NULL, value_min DOUBLE PRECISION DEFAULT NULL, value_typical DOUBLE PRECISION DEFAULT NULL, value_max DOUBLE PRECISION DEFAULT NULL, unit VARCHAR(255) NOT NULL, value_text VARCHAR(255) NOT NULL, param_group VARCHAR(255) NOT NULL, type SMALLINT NOT NULL, element_id INT NOT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_69348FE1F1F2A24 ON parameters (element_id)');
|
||||||
|
$this->addSql('CREATE INDEX parameter_name_idx ON parameters (name)');
|
||||||
|
$this->addSql('CREATE INDEX parameter_group_idx ON parameters (param_group)');
|
||||||
|
$this->addSql('CREATE INDEX parameter_type_element_idx ON parameters (type, element_id)');
|
||||||
|
$this->addSql('CREATE TABLE part_association (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, type SMALLINT NOT NULL, other_type VARCHAR(255) DEFAULT NULL, comment TEXT DEFAULT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, owner_id INT NOT NULL, other_id INT NOT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_61B952E07E3C61F9 ON part_association (owner_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_61B952E0998D9879 ON part_association (other_id)');
|
||||||
|
$this->addSql('CREATE TABLE part_lots (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, description TEXT NOT NULL, comment TEXT NOT NULL, expiration_date TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, instock_unknown BOOLEAN NOT NULL, amount DOUBLE PRECISION NOT NULL, needs_refill BOOLEAN NOT NULL, vendor_barcode VARCHAR(255) DEFAULT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, id_store_location INT DEFAULT NULL, id_part INT NOT NULL, id_owner INT DEFAULT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_EBC8F9435D8F4B37 ON part_lots (id_store_location)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_EBC8F943C22F6CC4 ON part_lots (id_part)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_EBC8F94321E5A74C ON part_lots (id_owner)');
|
||||||
|
$this->addSql('CREATE INDEX part_lots_idx_instock_un_expiration_id_part ON part_lots (instock_unknown, expiration_date, id_part)');
|
||||||
|
$this->addSql('CREATE INDEX part_lots_idx_needs_refill ON part_lots (needs_refill)');
|
||||||
|
$this->addSql('CREATE INDEX part_lots_idx_barcode ON part_lots (vendor_barcode)');
|
||||||
|
$this->addSql('CREATE TABLE "parts" (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, needs_review BOOLEAN NOT NULL, tags TEXT NOT NULL, mass DOUBLE PRECISION DEFAULT NULL, ipn VARCHAR(100) DEFAULT NULL, description TEXT NOT NULL, comment TEXT NOT NULL, visible BOOLEAN NOT NULL, favorite BOOLEAN NOT NULL, minamount DOUBLE PRECISION NOT NULL, manufacturer_product_url TEXT NOT NULL, manufacturer_product_number VARCHAR(255) NOT NULL, manufacturing_status VARCHAR(255) DEFAULT NULL, order_quantity INT NOT NULL, manual_order BOOLEAN NOT NULL, provider_reference_provider_key VARCHAR(255) DEFAULT NULL, provider_reference_provider_id VARCHAR(255) DEFAULT NULL, provider_reference_provider_url VARCHAR(255) DEFAULT NULL, provider_reference_last_updated TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, eda_info_reference_prefix VARCHAR(255) DEFAULT NULL, eda_info_value VARCHAR(255) DEFAULT NULL, eda_info_invisible BOOLEAN DEFAULT NULL, eda_info_exclude_from_bom BOOLEAN DEFAULT NULL, eda_info_exclude_from_board BOOLEAN DEFAULT NULL, eda_info_exclude_from_sim BOOLEAN DEFAULT NULL, eda_info_kicad_symbol VARCHAR(255) DEFAULT NULL, eda_info_kicad_footprint VARCHAR(255) DEFAULT NULL, id_preview_attachment INT DEFAULT NULL, id_category INT NOT NULL, id_footprint INT DEFAULT NULL, id_part_unit INT DEFAULT NULL, id_manufacturer INT DEFAULT NULL, order_orderdetails_id INT DEFAULT NULL, built_project_id INT DEFAULT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_6940A7FE3D721C14 ON "parts" (ipn)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_6940A7FEEA7100A1 ON "parts" (id_preview_attachment)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_6940A7FE5697F554 ON "parts" (id_category)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_6940A7FE7E371A10 ON "parts" (id_footprint)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_6940A7FE2626CEF9 ON "parts" (id_part_unit)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_6940A7FE1ECB93AE ON "parts" (id_manufacturer)');
|
||||||
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_6940A7FE81081E9B ON "parts" (order_orderdetails_id)');
|
||||||
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_6940A7FEE8AE70D9 ON "parts" (built_project_id)');
|
||||||
|
$this->addSql('CREATE INDEX parts_idx_datet_name_last_id_needs ON "parts" (datetime_added, name, last_modified, id, needs_review)');
|
||||||
|
$this->addSql('CREATE INDEX parts_idx_name ON "parts" (name)');
|
||||||
|
$this->addSql('CREATE INDEX parts_idx_ipn ON "parts" (ipn)');
|
||||||
|
$this->addSql('CREATE TABLE "pricedetails" (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, price NUMERIC(11, 5) NOT NULL, price_related_quantity DOUBLE PRECISION NOT NULL, min_discount_quantity DOUBLE PRECISION NOT NULL, manual_input BOOLEAN NOT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, id_currency INT DEFAULT NULL, orderdetails_id INT NOT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_C68C4459398D64AA ON "pricedetails" (id_currency)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_C68C44594A01DDC7 ON "pricedetails" (orderdetails_id)');
|
||||||
|
$this->addSql('CREATE INDEX pricedetails_idx_min_discount ON "pricedetails" (min_discount_quantity)');
|
||||||
|
$this->addSql('CREATE INDEX pricedetails_idx_min_discount_price_qty ON "pricedetails" (min_discount_quantity, price_related_quantity)');
|
||||||
|
$this->addSql('CREATE TABLE project_bom_entries (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, quantity DOUBLE PRECISION NOT NULL, mountnames TEXT NOT NULL, name VARCHAR(255) DEFAULT NULL, comment TEXT NOT NULL, price NUMERIC(11, 5) DEFAULT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, id_device INT DEFAULT NULL, id_part INT DEFAULT NULL, price_currency_id INT DEFAULT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_1AA2DD312F180363 ON project_bom_entries (id_device)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_1AA2DD31C22F6CC4 ON project_bom_entries (id_part)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_1AA2DD313FFDCD60 ON project_bom_entries (price_currency_id)');
|
||||||
|
$this->addSql('CREATE TABLE projects (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, comment TEXT NOT NULL, not_selectable BOOLEAN NOT NULL, alternative_names TEXT DEFAULT NULL, order_quantity INT NOT NULL, status VARCHAR(64) DEFAULT NULL, order_only_missing_parts BOOLEAN NOT NULL, description TEXT NOT NULL, parent_id INT DEFAULT NULL, id_preview_attachment INT DEFAULT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_5C93B3A4727ACA70 ON projects (parent_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_5C93B3A4EA7100A1 ON projects (id_preview_attachment)');
|
||||||
|
$this->addSql('CREATE TABLE "storelocations" (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, comment TEXT NOT NULL, not_selectable BOOLEAN NOT NULL, alternative_names TEXT DEFAULT NULL, is_full BOOLEAN NOT NULL, only_single_part BOOLEAN NOT NULL, limit_to_existing_parts BOOLEAN NOT NULL, part_owner_must_match BOOLEAN DEFAULT false NOT NULL, parent_id INT DEFAULT NULL, storage_type_id INT DEFAULT NULL, id_owner INT DEFAULT NULL, id_preview_attachment INT DEFAULT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_7517020727ACA70 ON "storelocations" (parent_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_7517020B270BFF1 ON "storelocations" (storage_type_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_751702021E5A74C ON "storelocations" (id_owner)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_7517020EA7100A1 ON "storelocations" (id_preview_attachment)');
|
||||||
|
$this->addSql('CREATE INDEX location_idx_name ON "storelocations" (name)');
|
||||||
|
$this->addSql('CREATE INDEX location_idx_parent_name ON "storelocations" (parent_id, name)');
|
||||||
|
$this->addSql('CREATE TABLE "suppliers" (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, comment TEXT NOT NULL, not_selectable BOOLEAN NOT NULL, alternative_names TEXT DEFAULT NULL, address VARCHAR(255) NOT NULL, phone_number VARCHAR(255) NOT NULL, fax_number VARCHAR(255) NOT NULL, email_address VARCHAR(255) NOT NULL, website VARCHAR(255) NOT NULL, auto_product_url VARCHAR(255) NOT NULL, shipping_costs NUMERIC(11, 5) DEFAULT NULL, parent_id INT DEFAULT NULL, default_currency_id INT DEFAULT NULL, id_preview_attachment INT DEFAULT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_AC28B95C727ACA70 ON "suppliers" (parent_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_AC28B95CECD792C0 ON "suppliers" (default_currency_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_AC28B95CEA7100A1 ON "suppliers" (id_preview_attachment)');
|
||||||
|
$this->addSql('CREATE INDEX supplier_idx_name ON "suppliers" (name)');
|
||||||
|
$this->addSql('CREATE INDEX supplier_idx_parent_name ON "suppliers" (parent_id, name)');
|
||||||
|
$this->addSql('CREATE TABLE u2f_keys (key_handle VARCHAR(128) NOT NULL, public_key VARCHAR(255) NOT NULL, certificate TEXT NOT NULL, counter VARCHAR(255) NOT NULL, id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, user_id INT DEFAULT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_4F4ADB4BA76ED395 ON u2f_keys (user_id)');
|
||||||
|
$this->addSql('CREATE UNIQUE INDEX user_unique ON u2f_keys (user_id, key_handle)');
|
||||||
|
$this->addSql('CREATE TABLE "users" (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, disabled BOOLEAN NOT NULL, config_theme VARCHAR(255) DEFAULT NULL, pw_reset_token VARCHAR(255) DEFAULT NULL, config_instock_comment_a TEXT NOT NULL, config_instock_comment_w TEXT NOT NULL, about_me TEXT NOT NULL, trusted_device_cookie_version INT NOT NULL, backup_codes JSON NOT NULL, google_authenticator_secret VARCHAR(255) DEFAULT NULL, config_timezone VARCHAR(255) DEFAULT NULL, config_language VARCHAR(255) DEFAULT NULL, email VARCHAR(255) DEFAULT NULL, show_email_on_profile BOOLEAN DEFAULT false NOT NULL, department VARCHAR(255) DEFAULT NULL, last_name VARCHAR(255) DEFAULT NULL, first_name VARCHAR(255) DEFAULT NULL, need_pw_change BOOLEAN NOT NULL, password VARCHAR(255) DEFAULT NULL, settings JSON NOT NULL, backup_codes_generation_date TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, pw_reset_expires TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, saml_user BOOLEAN NOT NULL, name VARCHAR(180) NOT NULL, permissions_data JSON NOT NULL, group_id INT DEFAULT NULL, id_preview_attachment INT DEFAULT NULL, currency_id INT DEFAULT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_1483A5E95E237E06 ON "users" (name)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_1483A5E9FE54D947 ON "users" (group_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_1483A5E9EA7100A1 ON "users" (id_preview_attachment)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_1483A5E938248176 ON "users" (currency_id)');
|
||||||
|
$this->addSql('CREATE INDEX user_idx_username ON "users" (name)');
|
||||||
|
$this->addSql('CREATE TABLE webauthn_keys (public_key_credential_id TEXT NOT NULL, type VARCHAR(255) NOT NULL, transports TEXT NOT NULL, attestation_type VARCHAR(255) NOT NULL, trust_path JSON NOT NULL, aaguid TEXT NOT NULL, credential_public_key TEXT NOT NULL, user_handle VARCHAR(255) NOT NULL, counter INT NOT NULL, other_ui TEXT DEFAULT NULL, backup_eligible BOOLEAN DEFAULT NULL, backup_status BOOLEAN DEFAULT NULL, uv_initialized BOOLEAN DEFAULT NULL, id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, last_time_used TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, last_modified TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, user_id INT DEFAULT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_799FD143A76ED395 ON webauthn_keys (user_id)');
|
||||||
|
$this->addSql('ALTER TABLE api_tokens ADD CONSTRAINT FK_2CAD560EA76ED395 FOREIGN KEY (user_id) REFERENCES "users" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "attachment_types" ADD CONSTRAINT FK_EFAED719727ACA70 FOREIGN KEY (parent_id) REFERENCES "attachment_types" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "attachment_types" ADD CONSTRAINT FK_EFAED719EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES "attachments" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "attachments" ADD CONSTRAINT FK_47C4FAD6C54C8C93 FOREIGN KEY (type_id) REFERENCES "attachment_types" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "categories" ADD CONSTRAINT FK_3AF34668727ACA70 FOREIGN KEY (parent_id) REFERENCES "categories" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "categories" ADD CONSTRAINT FK_3AF34668EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES "attachments" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE currencies ADD CONSTRAINT FK_37C44693727ACA70 FOREIGN KEY (parent_id) REFERENCES currencies (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE currencies ADD CONSTRAINT FK_37C44693EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES "attachments" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "footprints" ADD CONSTRAINT FK_A34D68A2727ACA70 FOREIGN KEY (parent_id) REFERENCES "footprints" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "footprints" ADD CONSTRAINT FK_A34D68A2EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES "attachments" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "footprints" ADD CONSTRAINT FK_A34D68A232A38C34 FOREIGN KEY (id_footprint_3d) REFERENCES "attachments" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "groups" ADD CONSTRAINT FK_F06D3970727ACA70 FOREIGN KEY (parent_id) REFERENCES "groups" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "groups" ADD CONSTRAINT FK_F06D3970EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES "attachments" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE label_profiles ADD CONSTRAINT FK_C93E9CF5EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES "attachments" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE log ADD CONSTRAINT FK_8F3F68C56B3CA4B FOREIGN KEY (id_user) REFERENCES "users" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "manufacturers" ADD CONSTRAINT FK_94565B12727ACA70 FOREIGN KEY (parent_id) REFERENCES "manufacturers" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "manufacturers" ADD CONSTRAINT FK_94565B12EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES "attachments" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "measurement_units" ADD CONSTRAINT FK_F5AF83CF727ACA70 FOREIGN KEY (parent_id) REFERENCES "measurement_units" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "measurement_units" ADD CONSTRAINT FK_F5AF83CFEA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES "attachments" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "orderdetails" ADD CONSTRAINT FK_489AFCDC4CE34BEC FOREIGN KEY (part_id) REFERENCES "parts" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "orderdetails" ADD CONSTRAINT FK_489AFCDCCBF180EB FOREIGN KEY (id_supplier) REFERENCES "suppliers" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE part_association ADD CONSTRAINT FK_61B952E07E3C61F9 FOREIGN KEY (owner_id) REFERENCES "parts" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE part_association ADD CONSTRAINT FK_61B952E0998D9879 FOREIGN KEY (other_id) REFERENCES "parts" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE part_lots ADD CONSTRAINT FK_EBC8F9435D8F4B37 FOREIGN KEY (id_store_location) REFERENCES "storelocations" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE part_lots ADD CONSTRAINT FK_EBC8F943C22F6CC4 FOREIGN KEY (id_part) REFERENCES "parts" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE part_lots ADD CONSTRAINT FK_EBC8F94321E5A74C FOREIGN KEY (id_owner) REFERENCES "users" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "parts" ADD CONSTRAINT FK_6940A7FEEA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES "attachments" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "parts" ADD CONSTRAINT FK_6940A7FE5697F554 FOREIGN KEY (id_category) REFERENCES "categories" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "parts" ADD CONSTRAINT FK_6940A7FE7E371A10 FOREIGN KEY (id_footprint) REFERENCES "footprints" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "parts" ADD CONSTRAINT FK_6940A7FE2626CEF9 FOREIGN KEY (id_part_unit) REFERENCES "measurement_units" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "parts" ADD CONSTRAINT FK_6940A7FE1ECB93AE FOREIGN KEY (id_manufacturer) REFERENCES "manufacturers" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "parts" ADD CONSTRAINT FK_6940A7FE81081E9B FOREIGN KEY (order_orderdetails_id) REFERENCES "orderdetails" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "parts" ADD CONSTRAINT FK_6940A7FEE8AE70D9 FOREIGN KEY (built_project_id) REFERENCES projects (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "pricedetails" ADD CONSTRAINT FK_C68C4459398D64AA FOREIGN KEY (id_currency) REFERENCES currencies (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "pricedetails" ADD CONSTRAINT FK_C68C44594A01DDC7 FOREIGN KEY (orderdetails_id) REFERENCES "orderdetails" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE project_bom_entries ADD CONSTRAINT FK_1AA2DD312F180363 FOREIGN KEY (id_device) REFERENCES projects (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE project_bom_entries ADD CONSTRAINT FK_1AA2DD31C22F6CC4 FOREIGN KEY (id_part) REFERENCES "parts" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE project_bom_entries ADD CONSTRAINT FK_1AA2DD313FFDCD60 FOREIGN KEY (price_currency_id) REFERENCES currencies (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE projects ADD CONSTRAINT FK_5C93B3A4727ACA70 FOREIGN KEY (parent_id) REFERENCES projects (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE projects ADD CONSTRAINT FK_5C93B3A4EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES "attachments" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "storelocations" ADD CONSTRAINT FK_7517020727ACA70 FOREIGN KEY (parent_id) REFERENCES "storelocations" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "storelocations" ADD CONSTRAINT FK_7517020B270BFF1 FOREIGN KEY (storage_type_id) REFERENCES "measurement_units" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "storelocations" ADD CONSTRAINT FK_751702021E5A74C FOREIGN KEY (id_owner) REFERENCES "users" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "storelocations" ADD CONSTRAINT FK_7517020EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES "attachments" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "suppliers" ADD CONSTRAINT FK_AC28B95C727ACA70 FOREIGN KEY (parent_id) REFERENCES "suppliers" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "suppliers" ADD CONSTRAINT FK_AC28B95CECD792C0 FOREIGN KEY (default_currency_id) REFERENCES currencies (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "suppliers" ADD CONSTRAINT FK_AC28B95CEA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES "attachments" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE u2f_keys ADD CONSTRAINT FK_4F4ADB4BA76ED395 FOREIGN KEY (user_id) REFERENCES "users" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "users" ADD CONSTRAINT FK_1483A5E9FE54D947 FOREIGN KEY (group_id) REFERENCES "groups" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "users" ADD CONSTRAINT FK_1483A5E9EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES "attachments" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE "users" ADD CONSTRAINT FK_1483A5E938248176 FOREIGN KEY (currency_id) REFERENCES currencies (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE webauthn_keys ADD CONSTRAINT FK_799FD143A76ED395 FOREIGN KEY (user_id) REFERENCES "users" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
|
||||||
|
//Create the initial groups and users
|
||||||
|
//Retrieve the json representations of the presets
|
||||||
|
$admin = $this->getJSONPermDataFromPreset(PermissionPresetsHelper::PRESET_ADMIN);
|
||||||
|
$editor = $this->getJSONPermDataFromPreset(PermissionPresetsHelper::PRESET_EDITOR);
|
||||||
|
$read_only = $this->getJSONPermDataFromPreset(PermissionPresetsHelper::PRESET_READ_ONLY);
|
||||||
|
|
||||||
|
|
||||||
|
$sql = <<<EOD
|
||||||
|
INSERT INTO "groups" ("id", "parent_id", "comment", "not_selectable", "name", "permissions_data", "enforce_2fa") VALUES
|
||||||
|
(1, NULL, 'Users of this group can do everything: Read, Write and Administrative actions.', FALSE, 'admins', '$admin', FALSE),
|
||||||
|
(2, NULL, 'Users of this group can only read informations, use tools, and do not have access to administrative tools.', FALSE, 'readonly', '$read_only', FALSE),
|
||||||
|
(3, NULL, 'Users of this group, can edit part informations, create new ones, etc. but are not allowed to use administrative tools. (But can read current configuration, and see Server status)', FALSE, 'users', '$editor', FALSE);
|
||||||
|
|
||||||
|
EOD;
|
||||||
|
$this->addSql($sql);
|
||||||
|
|
||||||
|
//Increase the sequence for the groups, to avoid conflicts later
|
||||||
|
$this->addSql('SELECT setval(\'groups_id_seq\', 4)');
|
||||||
|
|
||||||
|
|
||||||
|
$admin_pw = $this->getInitalAdminPW();
|
||||||
|
|
||||||
|
$sql = <<<EOD
|
||||||
|
INSERT INTO "users" ("id", "group_id", "name", "password", "need_pw_change", "first_name", "last_name", "department", "email",
|
||||||
|
"config_language", "config_timezone", "config_theme", "config_instock_comment_w", "config_instock_comment_a",
|
||||||
|
"currency_id", "settings", "disabled", "backup_codes", "trusted_device_cookie_version",
|
||||||
|
"permissions_data", "saml_user", "about_me"
|
||||||
|
) VALUES
|
||||||
|
(1, 2, 'anonymous', '', FALSE, '', '', '', '', NULL, NULL, NULL, '', '', NULL, '{}', FALSE, 'null', 0, 'null', FALSE, ''),
|
||||||
|
(2, 1, 'admin', '{$admin_pw}', TRUE, '', '', '', '', NULL, NULL, NULL, '', '', NULL, '{}', FALSE, 'null', 0, '{$admin}', FALSE, '')
|
||||||
|
EOD;
|
||||||
|
$this->addSql($sql);
|
||||||
|
|
||||||
|
//Increase the sequence for the users, to avoid conflicts later
|
||||||
|
$this->addSql('SELECT setval(\'users_id_seq\', 3)');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postgreSQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('CREATE SCHEMA public');
|
||||||
|
$this->addSql('ALTER TABLE api_tokens DROP CONSTRAINT FK_2CAD560EA76ED395');
|
||||||
|
$this->addSql('ALTER TABLE "attachment_types" DROP CONSTRAINT FK_EFAED719727ACA70');
|
||||||
|
$this->addSql('ALTER TABLE "attachment_types" DROP CONSTRAINT FK_EFAED719EA7100A1');
|
||||||
|
$this->addSql('ALTER TABLE "attachments" DROP CONSTRAINT FK_47C4FAD6C54C8C93');
|
||||||
|
$this->addSql('ALTER TABLE "categories" DROP CONSTRAINT FK_3AF34668727ACA70');
|
||||||
|
$this->addSql('ALTER TABLE "categories" DROP CONSTRAINT FK_3AF34668EA7100A1');
|
||||||
|
$this->addSql('ALTER TABLE currencies DROP CONSTRAINT FK_37C44693727ACA70');
|
||||||
|
$this->addSql('ALTER TABLE currencies DROP CONSTRAINT FK_37C44693EA7100A1');
|
||||||
|
$this->addSql('ALTER TABLE "footprints" DROP CONSTRAINT FK_A34D68A2727ACA70');
|
||||||
|
$this->addSql('ALTER TABLE "footprints" DROP CONSTRAINT FK_A34D68A2EA7100A1');
|
||||||
|
$this->addSql('ALTER TABLE "footprints" DROP CONSTRAINT FK_A34D68A232A38C34');
|
||||||
|
$this->addSql('ALTER TABLE "groups" DROP CONSTRAINT FK_F06D3970727ACA70');
|
||||||
|
$this->addSql('ALTER TABLE "groups" DROP CONSTRAINT FK_F06D3970EA7100A1');
|
||||||
|
$this->addSql('ALTER TABLE label_profiles DROP CONSTRAINT FK_C93E9CF5EA7100A1');
|
||||||
|
$this->addSql('ALTER TABLE log DROP CONSTRAINT FK_8F3F68C56B3CA4B');
|
||||||
|
$this->addSql('ALTER TABLE "manufacturers" DROP CONSTRAINT FK_94565B12727ACA70');
|
||||||
|
$this->addSql('ALTER TABLE "manufacturers" DROP CONSTRAINT FK_94565B12EA7100A1');
|
||||||
|
$this->addSql('ALTER TABLE "measurement_units" DROP CONSTRAINT FK_F5AF83CF727ACA70');
|
||||||
|
$this->addSql('ALTER TABLE "measurement_units" DROP CONSTRAINT FK_F5AF83CFEA7100A1');
|
||||||
|
$this->addSql('ALTER TABLE "orderdetails" DROP CONSTRAINT FK_489AFCDC4CE34BEC');
|
||||||
|
$this->addSql('ALTER TABLE "orderdetails" DROP CONSTRAINT FK_489AFCDCCBF180EB');
|
||||||
|
$this->addSql('ALTER TABLE part_association DROP CONSTRAINT FK_61B952E07E3C61F9');
|
||||||
|
$this->addSql('ALTER TABLE part_association DROP CONSTRAINT FK_61B952E0998D9879');
|
||||||
|
$this->addSql('ALTER TABLE part_lots DROP CONSTRAINT FK_EBC8F9435D8F4B37');
|
||||||
|
$this->addSql('ALTER TABLE part_lots DROP CONSTRAINT FK_EBC8F943C22F6CC4');
|
||||||
|
$this->addSql('ALTER TABLE part_lots DROP CONSTRAINT FK_EBC8F94321E5A74C');
|
||||||
|
$this->addSql('ALTER TABLE "parts" DROP CONSTRAINT FK_6940A7FEEA7100A1');
|
||||||
|
$this->addSql('ALTER TABLE "parts" DROP CONSTRAINT FK_6940A7FE5697F554');
|
||||||
|
$this->addSql('ALTER TABLE "parts" DROP CONSTRAINT FK_6940A7FE7E371A10');
|
||||||
|
$this->addSql('ALTER TABLE "parts" DROP CONSTRAINT FK_6940A7FE2626CEF9');
|
||||||
|
$this->addSql('ALTER TABLE "parts" DROP CONSTRAINT FK_6940A7FE1ECB93AE');
|
||||||
|
$this->addSql('ALTER TABLE "parts" DROP CONSTRAINT FK_6940A7FE81081E9B');
|
||||||
|
$this->addSql('ALTER TABLE "parts" DROP CONSTRAINT FK_6940A7FEE8AE70D9');
|
||||||
|
$this->addSql('ALTER TABLE "pricedetails" DROP CONSTRAINT FK_C68C4459398D64AA');
|
||||||
|
$this->addSql('ALTER TABLE "pricedetails" DROP CONSTRAINT FK_C68C44594A01DDC7');
|
||||||
|
$this->addSql('ALTER TABLE project_bom_entries DROP CONSTRAINT FK_1AA2DD312F180363');
|
||||||
|
$this->addSql('ALTER TABLE project_bom_entries DROP CONSTRAINT FK_1AA2DD31C22F6CC4');
|
||||||
|
$this->addSql('ALTER TABLE project_bom_entries DROP CONSTRAINT FK_1AA2DD313FFDCD60');
|
||||||
|
$this->addSql('ALTER TABLE projects DROP CONSTRAINT FK_5C93B3A4727ACA70');
|
||||||
|
$this->addSql('ALTER TABLE projects DROP CONSTRAINT FK_5C93B3A4EA7100A1');
|
||||||
|
$this->addSql('ALTER TABLE "storelocations" DROP CONSTRAINT FK_7517020727ACA70');
|
||||||
|
$this->addSql('ALTER TABLE "storelocations" DROP CONSTRAINT FK_7517020B270BFF1');
|
||||||
|
$this->addSql('ALTER TABLE "storelocations" DROP CONSTRAINT FK_751702021E5A74C');
|
||||||
|
$this->addSql('ALTER TABLE "storelocations" DROP CONSTRAINT FK_7517020EA7100A1');
|
||||||
|
$this->addSql('ALTER TABLE "suppliers" DROP CONSTRAINT FK_AC28B95C727ACA70');
|
||||||
|
$this->addSql('ALTER TABLE "suppliers" DROP CONSTRAINT FK_AC28B95CECD792C0');
|
||||||
|
$this->addSql('ALTER TABLE "suppliers" DROP CONSTRAINT FK_AC28B95CEA7100A1');
|
||||||
|
$this->addSql('ALTER TABLE u2f_keys DROP CONSTRAINT FK_4F4ADB4BA76ED395');
|
||||||
|
$this->addSql('ALTER TABLE "users" DROP CONSTRAINT FK_1483A5E9FE54D947');
|
||||||
|
$this->addSql('ALTER TABLE "users" DROP CONSTRAINT FK_1483A5E9EA7100A1');
|
||||||
|
$this->addSql('ALTER TABLE "users" DROP CONSTRAINT FK_1483A5E938248176');
|
||||||
|
$this->addSql('ALTER TABLE webauthn_keys DROP CONSTRAINT FK_799FD143A76ED395');
|
||||||
|
$this->addSql('DROP TABLE api_tokens');
|
||||||
|
$this->addSql('DROP TABLE "attachment_types"');
|
||||||
|
$this->addSql('DROP TABLE "attachments"');
|
||||||
|
$this->addSql('DROP TABLE "categories"');
|
||||||
|
$this->addSql('DROP TABLE currencies');
|
||||||
|
$this->addSql('DROP TABLE "footprints"');
|
||||||
|
$this->addSql('DROP TABLE "groups"');
|
||||||
|
$this->addSql('DROP TABLE label_profiles');
|
||||||
|
$this->addSql('DROP TABLE log');
|
||||||
|
$this->addSql('DROP TABLE "manufacturers"');
|
||||||
|
$this->addSql('DROP TABLE "measurement_units"');
|
||||||
|
$this->addSql('DROP TABLE oauth_tokens');
|
||||||
|
$this->addSql('DROP TABLE "orderdetails"');
|
||||||
|
$this->addSql('DROP TABLE parameters');
|
||||||
|
$this->addSql('DROP TABLE part_association');
|
||||||
|
$this->addSql('DROP TABLE part_lots');
|
||||||
|
$this->addSql('DROP TABLE "parts"');
|
||||||
|
$this->addSql('DROP TABLE "pricedetails"');
|
||||||
|
$this->addSql('DROP TABLE project_bom_entries');
|
||||||
|
$this->addSql('DROP TABLE projects');
|
||||||
|
$this->addSql('DROP TABLE "storelocations"');
|
||||||
|
$this->addSql('DROP TABLE "suppliers"');
|
||||||
|
$this->addSql('DROP TABLE u2f_keys');
|
||||||
|
$this->addSql('DROP TABLE "users"');
|
||||||
|
$this->addSql('DROP TABLE webauthn_keys');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function mySQLUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('ALTER TABLE currencies CHANGE exchange_rate exchange_rate NUMERIC(11, 5) DEFAULT NULL');
|
||||||
|
//Set empty JSON fields to "{}" to avoid issues with failing JSON validation
|
||||||
|
$this->addSql('UPDATE `groups` SET permissions_data = "{}" WHERE permissions_data = ""');
|
||||||
|
$this->addSql('ALTER TABLE `groups` CHANGE permissions_data permissions_data JSON NOT NULL');
|
||||||
|
//Set the empty JSON fields to "{}" to avoid issues with failing JSON validation
|
||||||
|
$this->addSql('UPDATE `log` SET extra = "{}" WHERE extra = ""');
|
||||||
|
$this->addSql('ALTER TABLE `log` CHANGE level level TINYINT NOT NULL, CHANGE extra extra JSON NOT NULL');
|
||||||
|
$this->addSql('ALTER TABLE oauth_tokens CHANGE expires_at expires_at DATETIME DEFAULT NULL');
|
||||||
|
$this->addSql('ALTER TABLE pricedetails CHANGE price price NUMERIC(11, 5) NOT NULL');
|
||||||
|
$this->addSql('ALTER TABLE project_bom_entries CHANGE price price NUMERIC(11, 5) DEFAULT NULL');
|
||||||
|
$this->addSql('ALTER TABLE suppliers CHANGE shipping_costs shipping_costs NUMERIC(11, 5) DEFAULT NULL');
|
||||||
|
//Set the empty JSON fields to "{}" to avoid issues with failing JSON validation
|
||||||
|
$this->addSql('UPDATE `users` SET settings = "{}" WHERE settings = ""');
|
||||||
|
$this->addSql('UPDATE `users` SET backup_codes = "{}" WHERE backup_codes = ""');
|
||||||
|
$this->addSql('UPDATE `users` SET permissions_data = "{}" WHERE permissions_data = ""');
|
||||||
|
$this->addSql('ALTER TABLE `users` CHANGE settings settings JSON NOT NULL, CHANGE backup_codes backup_codes JSON NOT NULL, CHANGE permissions_data permissions_data JSON NOT NULL');
|
||||||
|
$this->addSql('ALTER TABLE webauthn_keys CHANGE public_key_credential_id public_key_credential_id LONGTEXT NOT NULL, CHANGE transports transports LONGTEXT NOT NULL, CHANGE trust_path trust_path JSON NOT NULL, CHANGE aaguid aaguid TINYTEXT NOT NULL, CHANGE credential_public_key credential_public_key LONGTEXT NOT NULL, CHANGE other_ui other_ui LONGTEXT DEFAULT NULL, CHANGE last_time_used last_time_used DATETIME DEFAULT NULL');
|
||||||
|
|
||||||
|
// Add the natural sort emulation function to the database (based on this stackoverflow: https://stackoverflow.com/questions/153633/natural-sort-in-mysql/58154535#58154535)
|
||||||
|
$this->addSql(<<<EOD
|
||||||
|
CREATE DEFINER=CURRENT_USER FUNCTION `NatSortKey`(`s` VARCHAR(1000) CHARSET utf8mb4, `n` INT) RETURNS varchar(3500) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci
|
||||||
|
DETERMINISTIC
|
||||||
|
SQL SECURITY INVOKER
|
||||||
|
BEGIN
|
||||||
|
/****
|
||||||
|
Converts numbers in the input string s into a format such that sorting results in a nat-sort.
|
||||||
|
Numbers of up to 359 digits (before the decimal point, if one is present) are supported. Sort results are undefined if the input string contains numbers longer than this.
|
||||||
|
For n>0, only the first n numbers in the input string will be converted for nat-sort (so strings that differ only after the first n numbers will not nat-sort amongst themselves).
|
||||||
|
Total sort-ordering is preserved, i.e. if s1!=s2, then NatSortKey(s1,n)!=NatSortKey(s2,n), for any given n.
|
||||||
|
Numbers may contain ',' as a thousands separator, and '.' as a decimal point. To reverse these (as appropriate for some European locales), the code would require modification.
|
||||||
|
Numbers preceded by '+' sort with numbers not preceded with either a '+' or '-' sign.
|
||||||
|
Negative numbers (preceded with '-') sort before positive numbers, but are sorted in order of ascending absolute value (so -7 sorts BEFORE -1001).
|
||||||
|
Numbers with leading zeros sort after the same number with no (or fewer) leading zeros.
|
||||||
|
Decimal-part-only numbers (like .75) are recognised, provided the decimal point is not immediately preceded by either another '.', or by a letter-type character.
|
||||||
|
Numbers with thousand separators sort after the same number without them.
|
||||||
|
Thousand separators are only recognised in numbers with no leading zeros that don't immediately follow a ',', and when they format the number correctly.
|
||||||
|
(When not recognised as a thousand separator, a ',' will instead be treated as separating two distinct numbers).
|
||||||
|
Version-number-like sequences consisting of 3 or more numbers separated by '.' are treated as distinct entities, and each component number will be nat-sorted.
|
||||||
|
The entire entity will sort after any number beginning with the first component (so e.g. 10.2.1 sorts after both 10 and 10.995, but before 11)
|
||||||
|
Note that The first number component in an entity like this is also permitted to contain thousand separators.
|
||||||
|
|
||||||
|
To achieve this, numbers within the input string are prefixed and suffixed according to the following format:
|
||||||
|
- The number is prefixed by a 2-digit base-36 number representing its length, excluding leading zeros. If there is a decimal point, this length only includes the integer part of the number.
|
||||||
|
- A 3-character suffix is appended after the number (after the decimals if present).
|
||||||
|
- The first character is a space, or a '+' sign if the number was preceded by '+'. Any preceding '+' sign is also removed from the front of the number.
|
||||||
|
- This is followed by a 2-digit base-36 number that encodes the number of leading zeros and whether the number was expressed in comma-separated form (e.g. 1,000,000.25 vs 1000000.25)
|
||||||
|
- The value of this 2-digit number is: (number of leading zeros)*2 + (1 if comma-separated, 0 otherwise)
|
||||||
|
- For version number sequences, each component number has the prefix in front of it, and the separating dots are removed.
|
||||||
|
Then there is a single suffix that consists of a ' ' or '+' character, followed by a pair base-36 digits for each number component in the sequence.
|
||||||
|
|
||||||
|
e.g. here is how some simple sample strings get converted:
|
||||||
|
'Foo055' --> 'Foo0255 02'
|
||||||
|
'Absolute zero is around -273 centigrade' --> 'Absolute zero is around -03273 00 centigrade'
|
||||||
|
'The $1,000,000 prize' --> 'The $071000000 01 prize'
|
||||||
|
'+99.74 degrees' --> '0299.74+00 degrees'
|
||||||
|
'I have 0 apples' --> 'I have 00 02 apples'
|
||||||
|
'.5 is the same value as 0000.5000' --> '00.5 00 is the same value as 00.5000 08'
|
||||||
|
'MariaDB v10.3.0018' --> 'MariaDB v02100130218 000004'
|
||||||
|
|
||||||
|
The restriction to numbers of up to 359 digits comes from the fact that the first character of the base-36 prefix MUST be a decimal digit, and so the highest permitted prefix value is '9Z' or 359 decimal.
|
||||||
|
The code could be modified to handle longer numbers by increasing the size of (both) the prefix and suffix.
|
||||||
|
A higher base could also be used (by replacing CONV() with a custom function), provided that the collation you are using sorts the "digits" of the base in the correct order, starting with 0123456789.
|
||||||
|
However, while the maximum number length may be increased this way, note that the technique this function uses is NOT applicable where strings may contain numbers of unlimited length.
|
||||||
|
|
||||||
|
The function definition does not specify the charset or collation to be used for string-type parameters or variables: The default database charset & collation at the time the function is defined will be used.
|
||||||
|
This is to make the function code more portable. However, there are some important restrictions:
|
||||||
|
|
||||||
|
- Collation is important here only when comparing (or storing) the output value from this function, but it MUST order the characters " +0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" in that order for the natural sort to work.
|
||||||
|
This is true for most collations, but not all of them, e.g. in Lithuanian 'Y' comes before 'J' (according to Wikipedia).
|
||||||
|
To adapt the function to work with such collations, replace CONV() in the function code with a custom function that emits "digits" above 9 that are characters ordered according to the collation in use.
|
||||||
|
|
||||||
|
- For efficiency, the function code uses LENGTH() rather than CHAR_LENGTH() to measure the length of strings that consist only of digits 0-9, '.', and ',' characters.
|
||||||
|
This works for any single-byte charset, as well as any charset that maps standard ASCII characters to single bytes (such as utf8 or utf8mb4).
|
||||||
|
If using a charset that maps these characters to multiple bytes (such as, e.g. utf16 or utf32), you MUST replace all instances of LENGTH() in the function definition with CHAR_LENGTH()
|
||||||
|
|
||||||
|
Length of the output:
|
||||||
|
|
||||||
|
Each number converted adds 5 characters (2 prefix + 3 suffix) to the length of the string. n is the maximum count of numbers to convert;
|
||||||
|
This parameter is provided as a means to limit the maximum output length (to input length + 5*n).
|
||||||
|
If you do not require the total-ordering property, you could edit the code to use suffixes of 1 character (space or plus) only; this would reduce the maximum output length for any given n.
|
||||||
|
Since a string of length L has at most ((L+1) DIV 2) individual numbers in it (every 2nd character a digit), for n<=0 the maximum output length is (inputlength + 5*((inputlength+1) DIV 2))
|
||||||
|
So for the current input length of 100, the maximum output length is 350.
|
||||||
|
If changing the input length, the output length must be modified according to the above formula. The DECLARE statements for x,y,r, and suf must also be modified, as the code comments indicate.
|
||||||
|
****/
|
||||||
|
|
||||||
|
DECLARE x,y varchar(1000); # need to be same length as input s
|
||||||
|
DECLARE r varchar(3500) DEFAULT ''; # return value: needs to be same length as return type
|
||||||
|
DECLARE suf varchar(101); # suffix for a number or version string. Must be (((inputlength+1) DIV 2)*2 + 1) chars to support version strings (e.g. '1.2.33.5'), though it's usually just 3 chars. (Max version string e.g. 1.2. ... .5 has ((length of input + 1) DIV 2) numeric components)
|
||||||
|
DECLARE i,j,k int UNSIGNED;
|
||||||
|
IF n<=0 THEN SET n := -1; END IF; # n<=0 means "process all numbers"
|
||||||
|
LOOP
|
||||||
|
SET i := REGEXP_INSTR(s,'\\d'); # find position of next digit
|
||||||
|
IF i=0 OR n=0 THEN RETURN CONCAT(r,s); END IF; # no more numbers to process -> we're done
|
||||||
|
SET n := n-1, suf := ' ';
|
||||||
|
IF i>1 THEN
|
||||||
|
IF SUBSTRING(s,i-1,1)='.' AND (i=2 OR SUBSTRING(s,i-2,1) RLIKE '[^.\\p{L}\\p{N}\\p{M}\\x{608}\\x{200C}\\x{200D}\\x{2100}-\\x{214F}\\x{24B6}-\\x{24E9}\\x{1F130}-\\x{1F149}\\x{1F150}-\\x{1F169}\\x{1F170}-\\x{1F189}]') AND (SUBSTRING(s,i) NOT RLIKE '^\\d++\\.\\d') THEN SET i:=i-1; END IF; # Allow decimal number (but not version string) to begin with a '.', provided preceding char is neither another '.', nor a member of the unicode character classes: "Alphabetic", "Letter", "Block=Letterlike Symbols" "Number", "Mark", "Join_Control"
|
||||||
|
IF i>1 AND SUBSTRING(s,i-1,1)='+' THEN SET suf := '+', j := i-1; ELSE SET j := i; END IF; # move any preceding '+' into the suffix, so equal numbers with and without preceding "+" signs sort together
|
||||||
|
SET r := CONCAT(r,SUBSTRING(s,1,j-1)); SET s = SUBSTRING(s,i); # add everything before the number to r and strip it from the start of s; preceding '+' is dropped (not included in either r or s)
|
||||||
|
END IF;
|
||||||
|
SET x := REGEXP_SUBSTR(s,IF(SUBSTRING(s,1,1) IN ('0','.') OR (SUBSTRING(r,-1)=',' AND suf=' '),'^\\d*+(?:\\.\\d++)*','^(?:[1-9]\\d{0,2}(?:,\\d{3}(?!\\d))++|\\d++)(?:\\.\\d++)*+')); # capture the number + following decimals (including multiple consecutive '.<digits>' sequences)
|
||||||
|
SET s := SUBSTRING(s,CHAR_LENGTH(x)+1); # NOTE: CHAR_LENGTH() can be safely used instead of CHAR_LENGTH() here & below PROVIDED we're using a charset that represents digits, ',' and '.' characters using single bytes (e.g. latin1, utf8)
|
||||||
|
SET i := INSTR(x,'.');
|
||||||
|
IF i=0 THEN SET y := ''; ELSE SET y := SUBSTRING(x,i); SET x := SUBSTRING(x,1,i-1); END IF; # move any following decimals into y
|
||||||
|
SET i := CHAR_LENGTH(x);
|
||||||
|
SET x := REPLACE(x,',','');
|
||||||
|
SET j := CHAR_LENGTH(x);
|
||||||
|
SET x := TRIM(LEADING '0' FROM x); # strip leading zeros
|
||||||
|
SET k := CHAR_LENGTH(x);
|
||||||
|
SET suf := CONCAT(suf,LPAD(CONV(LEAST((j-k)*2,1294) + IF(i=j,0,1),10,36),2,'0')); # (j-k)*2 + IF(i=j,0,1) = (count of leading zeros)*2 + (1 if there are thousands-separators, 0 otherwise) Note the first term is bounded to <= base-36 'ZY' as it must fit within 2 characters
|
||||||
|
SET i := LOCATE('.',y,2);
|
||||||
|
IF i=0 THEN
|
||||||
|
SET r := CONCAT(r,LPAD(CONV(LEAST(k,359),10,36),2,'0'),x,y,suf); # k = count of digits in number, bounded to be <= '9Z' base-36
|
||||||
|
ELSE # encode a version number (like 3.12.707, etc)
|
||||||
|
SET r := CONCAT(r,LPAD(CONV(LEAST(k,359),10,36),2,'0'),x); # k = count of digits in number, bounded to be <= '9Z' base-36
|
||||||
|
WHILE CHAR_LENGTH(y)>0 AND n!=0 DO
|
||||||
|
IF i=0 THEN SET x := SUBSTRING(y,2); SET y := ''; ELSE SET x := SUBSTRING(y,2,i-2); SET y := SUBSTRING(y,i); SET i := LOCATE('.',y,2); END IF;
|
||||||
|
SET j := CHAR_LENGTH(x);
|
||||||
|
SET x := TRIM(LEADING '0' FROM x); # strip leading zeros
|
||||||
|
SET k := CHAR_LENGTH(x);
|
||||||
|
SET r := CONCAT(r,LPAD(CONV(LEAST(k,359),10,36),2,'0'),x); # k = count of digits in number, bounded to be <= '9Z' base-36
|
||||||
|
SET suf := CONCAT(suf,LPAD(CONV(LEAST((j-k)*2,1294),10,36),2,'0')); # (j-k)*2 = (count of leading zeros)*2, bounded to fit within 2 base-36 digits
|
||||||
|
SET n := n-1;
|
||||||
|
END WHILE;
|
||||||
|
SET r := CONCAT(r,y,suf);
|
||||||
|
END IF;
|
||||||
|
END LOOP;
|
||||||
|
END
|
||||||
|
EOD
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function mySQLDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('ALTER TABLE currencies CHANGE exchange_rate exchange_rate NUMERIC(11, 5) DEFAULT NULL COMMENT \'(DC2Type:big_decimal)\'');
|
||||||
|
$this->addSql('ALTER TABLE `groups` CHANGE permissions_data permissions_data LONGTEXT NOT NULL COMMENT \'(DC2Type:json)\'');
|
||||||
|
$this->addSql('ALTER TABLE log CHANGE level level TINYINT(1) NOT NULL COMMENT \'(DC2Type:tinyint)\', CHANGE extra extra LONGTEXT NOT NULL COMMENT \'(DC2Type:json)\'');
|
||||||
|
$this->addSql('ALTER TABLE oauth_tokens CHANGE expires_at expires_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\'');
|
||||||
|
$this->addSql('ALTER TABLE `pricedetails` CHANGE price price NUMERIC(11, 5) NOT NULL COMMENT \'(DC2Type:big_decimal)\'');
|
||||||
|
$this->addSql('ALTER TABLE project_bom_entries CHANGE price price NUMERIC(11, 5) DEFAULT NULL COMMENT \'(DC2Type:big_decimal)\'');
|
||||||
|
$this->addSql('ALTER TABLE `suppliers` CHANGE shipping_costs shipping_costs NUMERIC(11, 5) DEFAULT NULL COMMENT \'(DC2Type:big_decimal)\'');
|
||||||
|
$this->addSql('ALTER TABLE `users` CHANGE backup_codes backup_codes LONGTEXT NOT NULL COMMENT \'(DC2Type:json)\', CHANGE settings settings LONGTEXT NOT NULL COMMENT \'(DC2Type:json)\', CHANGE permissions_data permissions_data LONGTEXT NOT NULL COMMENT \'(DC2Type:json)\'');
|
||||||
|
$this->addSql('ALTER TABLE webauthn_keys CHANGE public_key_credential_id public_key_credential_id LONGTEXT NOT NULL COMMENT \'(DC2Type:base64)\', CHANGE transports transports LONGTEXT NOT NULL COMMENT \'(DC2Type:array)\', CHANGE trust_path trust_path LONGTEXT NOT NULL COMMENT \'(DC2Type:trust_path)\', CHANGE aaguid aaguid TINYTEXT NOT NULL COMMENT \'(DC2Type:aaguid)\', CHANGE credential_public_key credential_public_key LONGTEXT NOT NULL COMMENT \'(DC2Type:base64)\', CHANGE other_ui other_ui LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\', CHANGE last_time_used last_time_used DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\'');
|
||||||
|
|
||||||
|
//Drop custom function
|
||||||
|
$this->addSql('DROP FUNCTION IF EXISTS NatSortKey');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sqLiteUp(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__currencies AS SELECT id, parent_id, id_preview_attachment, exchange_rate, iso_code, comment, not_selectable, name, last_modified, datetime_added, alternative_names FROM currencies');
|
||||||
|
$this->addSql('DROP TABLE currencies');
|
||||||
|
$this->addSql('CREATE TABLE currencies (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, parent_id INTEGER DEFAULT NULL, id_preview_attachment INTEGER DEFAULT NULL, exchange_rate NUMERIC(11, 5) DEFAULT NULL, iso_code VARCHAR(255) NOT NULL, comment CLOB NOT NULL, not_selectable BOOLEAN NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, alternative_names CLOB DEFAULT NULL, CONSTRAINT FK_37C44693727ACA70 FOREIGN KEY (parent_id) REFERENCES currencies (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_37C44693EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES attachments (id) ON UPDATE NO ACTION ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||||
|
$this->addSql('INSERT INTO currencies (id, parent_id, id_preview_attachment, exchange_rate, iso_code, comment, not_selectable, name, last_modified, datetime_added, alternative_names) SELECT id, parent_id, id_preview_attachment, exchange_rate, iso_code, comment, not_selectable, name, last_modified, datetime_added, alternative_names FROM __temp__currencies');
|
||||||
|
$this->addSql('DROP TABLE __temp__currencies');
|
||||||
|
$this->addSql('CREATE INDEX IDX_37C44693EA7100A1 ON currencies (id_preview_attachment)');
|
||||||
|
$this->addSql('CREATE INDEX currency_idx_parent_name ON currencies (parent_id, name)');
|
||||||
|
$this->addSql('CREATE INDEX currency_idx_name ON currencies (name)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_37C44693727ACA70 ON currencies (parent_id)');
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__groups AS SELECT id, parent_id, id_preview_attachment, enforce_2fa, comment, not_selectable, name, last_modified, datetime_added, permissions_data, alternative_names FROM groups');
|
||||||
|
$this->addSql('DROP TABLE groups');
|
||||||
|
$this->addSql('CREATE TABLE groups (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, parent_id INTEGER DEFAULT NULL, id_preview_attachment INTEGER DEFAULT NULL, enforce_2fa BOOLEAN NOT NULL, comment CLOB NOT NULL, not_selectable BOOLEAN NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, permissions_data CLOB NOT NULL, alternative_names CLOB DEFAULT NULL, CONSTRAINT FK_F06D3970727ACA70 FOREIGN KEY (parent_id) REFERENCES groups (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_F06D3970EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES attachments (id) ON UPDATE NO ACTION ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||||
|
$this->addSql('INSERT INTO groups (id, parent_id, id_preview_attachment, enforce_2fa, comment, not_selectable, name, last_modified, datetime_added, permissions_data, alternative_names) SELECT id, parent_id, id_preview_attachment, enforce_2fa, comment, not_selectable, name, last_modified, datetime_added, permissions_data, alternative_names FROM __temp__groups');
|
||||||
|
$this->addSql('DROP TABLE __temp__groups');
|
||||||
|
$this->addSql('CREATE INDEX IDX_F06D3970EA7100A1 ON groups (id_preview_attachment)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_F06D3970727ACA70 ON groups (parent_id)');
|
||||||
|
$this->addSql('CREATE INDEX group_idx_name ON groups (name)');
|
||||||
|
$this->addSql('CREATE INDEX group_idx_parent_name ON groups (parent_id, name)');
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__log AS SELECT id, id_user, datetime, level, target_id, target_type, extra, type, username FROM log');
|
||||||
|
$this->addSql('DROP TABLE log');
|
||||||
|
$this->addSql('CREATE TABLE log (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, id_user INTEGER DEFAULT NULL, datetime DATETIME NOT NULL, level SMALLINT NOT NULL, target_id INTEGER NOT NULL, target_type SMALLINT NOT NULL, extra CLOB NOT NULL, type SMALLINT NOT NULL, username VARCHAR(255) NOT NULL, CONSTRAINT FK_8F3F68C56B3CA4B FOREIGN KEY (id_user) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||||
|
$this->addSql('INSERT INTO log (id, id_user, datetime, level, target_id, target_type, extra, type, username) SELECT id, id_user, datetime, level, target_id, target_type, extra, type, username FROM __temp__log');
|
||||||
|
$this->addSql('DROP TABLE __temp__log');
|
||||||
|
$this->addSql('CREATE INDEX IDX_8F3F68C56B3CA4B ON log (id_user)');
|
||||||
|
$this->addSql('CREATE INDEX log_idx_type ON log (type)');
|
||||||
|
$this->addSql('CREATE INDEX log_idx_type_target ON log (type, target_type, target_id)');
|
||||||
|
$this->addSql('CREATE INDEX log_idx_datetime ON log (datetime)');
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__oauth_tokens AS SELECT id, token, expires_at, refresh_token, name, last_modified, datetime_added FROM oauth_tokens');
|
||||||
|
$this->addSql('DROP TABLE oauth_tokens');
|
||||||
|
$this->addSql('CREATE TABLE oauth_tokens (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, token CLOB DEFAULT NULL, expires_at DATETIME DEFAULT NULL, refresh_token CLOB DEFAULT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL)');
|
||||||
|
$this->addSql('INSERT INTO oauth_tokens (id, token, expires_at, refresh_token, name, last_modified, datetime_added) SELECT id, token, expires_at, refresh_token, name, last_modified, datetime_added FROM __temp__oauth_tokens');
|
||||||
|
$this->addSql('DROP TABLE __temp__oauth_tokens');
|
||||||
|
$this->addSql('CREATE UNIQUE INDEX oauth_tokens_unique_name ON oauth_tokens (name)');
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__pricedetails AS SELECT id, id_currency, orderdetails_id, price, price_related_quantity, min_discount_quantity, manual_input, last_modified, datetime_added FROM pricedetails');
|
||||||
|
$this->addSql('DROP TABLE pricedetails');
|
||||||
|
$this->addSql('CREATE TABLE pricedetails (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, id_currency INTEGER DEFAULT NULL, orderdetails_id INTEGER NOT NULL, price NUMERIC(11, 5) NOT NULL, price_related_quantity DOUBLE PRECISION NOT NULL, min_discount_quantity DOUBLE PRECISION NOT NULL, manual_input BOOLEAN NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, CONSTRAINT FK_C68C4459398D64AA FOREIGN KEY (id_currency) REFERENCES currencies (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_C68C44594A01DDC7 FOREIGN KEY (orderdetails_id) REFERENCES orderdetails (id) ON UPDATE NO ACTION ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||||
|
$this->addSql('INSERT INTO pricedetails (id, id_currency, orderdetails_id, price, price_related_quantity, min_discount_quantity, manual_input, last_modified, datetime_added) SELECT id, id_currency, orderdetails_id, price, price_related_quantity, min_discount_quantity, manual_input, last_modified, datetime_added FROM __temp__pricedetails');
|
||||||
|
$this->addSql('DROP TABLE __temp__pricedetails');
|
||||||
|
$this->addSql('CREATE INDEX pricedetails_idx_min_discount_price_qty ON pricedetails (min_discount_quantity, price_related_quantity)');
|
||||||
|
$this->addSql('CREATE INDEX pricedetails_idx_min_discount ON pricedetails (min_discount_quantity)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_C68C4459398D64AA ON pricedetails (id_currency)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_C68C44594A01DDC7 ON pricedetails (orderdetails_id)');
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__project_bom_entries AS SELECT id, id_device, id_part, price_currency_id, quantity, mountnames, name, comment, price, last_modified, datetime_added FROM project_bom_entries');
|
||||||
|
$this->addSql('DROP TABLE project_bom_entries');
|
||||||
|
$this->addSql('CREATE TABLE project_bom_entries (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, id_device INTEGER DEFAULT NULL, id_part INTEGER DEFAULT NULL, price_currency_id INTEGER DEFAULT NULL, quantity DOUBLE PRECISION NOT NULL, mountnames CLOB NOT NULL, name VARCHAR(255) DEFAULT NULL, comment CLOB NOT NULL, price NUMERIC(11, 5) DEFAULT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, CONSTRAINT FK_AFC547992F180363 FOREIGN KEY (id_device) REFERENCES projects (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_AFC54799C22F6CC4 FOREIGN KEY (id_part) REFERENCES parts (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_1AA2DD313FFDCD60 FOREIGN KEY (price_currency_id) REFERENCES currencies (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||||
|
$this->addSql('INSERT INTO project_bom_entries (id, id_device, id_part, price_currency_id, quantity, mountnames, name, comment, price, last_modified, datetime_added) SELECT id, id_device, id_part, price_currency_id, quantity, mountnames, name, comment, price, last_modified, datetime_added FROM __temp__project_bom_entries');
|
||||||
|
$this->addSql('DROP TABLE __temp__project_bom_entries');
|
||||||
|
$this->addSql('CREATE INDEX IDX_1AA2DD313FFDCD60 ON project_bom_entries (price_currency_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_1AA2DD312F180363 ON project_bom_entries (id_device)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_1AA2DD31C22F6CC4 ON project_bom_entries (id_part)');
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__suppliers AS SELECT id, parent_id, default_currency_id, id_preview_attachment, shipping_costs, address, phone_number, fax_number, email_address, website, auto_product_url, comment, not_selectable, name, last_modified, datetime_added, alternative_names FROM suppliers');
|
||||||
|
$this->addSql('DROP TABLE suppliers');
|
||||||
|
$this->addSql('CREATE TABLE suppliers (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, parent_id INTEGER DEFAULT NULL, default_currency_id INTEGER DEFAULT NULL, id_preview_attachment INTEGER DEFAULT NULL, shipping_costs NUMERIC(11, 5) DEFAULT NULL, address VARCHAR(255) NOT NULL, phone_number VARCHAR(255) NOT NULL, fax_number VARCHAR(255) NOT NULL, email_address VARCHAR(255) NOT NULL, website VARCHAR(255) NOT NULL, auto_product_url VARCHAR(255) NOT NULL, comment CLOB NOT NULL, not_selectable BOOLEAN NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, alternative_names CLOB DEFAULT NULL, CONSTRAINT FK_AC28B95C727ACA70 FOREIGN KEY (parent_id) REFERENCES suppliers (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_AC28B95CECD792C0 FOREIGN KEY (default_currency_id) REFERENCES currencies (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_AC28B95CEA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES attachments (id) ON UPDATE NO ACTION ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||||
|
$this->addSql('INSERT INTO suppliers (id, parent_id, default_currency_id, id_preview_attachment, shipping_costs, address, phone_number, fax_number, email_address, website, auto_product_url, comment, not_selectable, name, last_modified, datetime_added, alternative_names) SELECT id, parent_id, default_currency_id, id_preview_attachment, shipping_costs, address, phone_number, fax_number, email_address, website, auto_product_url, comment, not_selectable, name, last_modified, datetime_added, alternative_names FROM __temp__suppliers');
|
||||||
|
$this->addSql('DROP TABLE __temp__suppliers');
|
||||||
|
$this->addSql('CREATE INDEX IDX_AC28B95CEA7100A1 ON suppliers (id_preview_attachment)');
|
||||||
|
$this->addSql('CREATE INDEX supplier_idx_parent_name ON suppliers (parent_id, name)');
|
||||||
|
$this->addSql('CREATE INDEX supplier_idx_name ON suppliers (name)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_AC28B95C727ACA70 ON suppliers (parent_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_AC28B95CECD792C0 ON suppliers (default_currency_id)');
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__users AS SELECT id, group_id, currency_id, id_preview_attachment, disabled, config_theme, pw_reset_token, config_instock_comment_a, config_instock_comment_w, trusted_device_cookie_version, backup_codes, google_authenticator_secret, config_timezone, config_language, email, department, last_name, first_name, need_pw_change, password, name, settings, backup_codes_generation_date, pw_reset_expires, last_modified, datetime_added, permissions_data, saml_user, about_me, show_email_on_profile FROM users');
|
||||||
|
$this->addSql('DROP TABLE users');
|
||||||
|
$this->addSql('CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, group_id INTEGER DEFAULT NULL, currency_id INTEGER DEFAULT NULL, id_preview_attachment INTEGER DEFAULT NULL, disabled BOOLEAN NOT NULL, config_theme VARCHAR(255) DEFAULT NULL, pw_reset_token VARCHAR(255) DEFAULT NULL, config_instock_comment_a CLOB NOT NULL, config_instock_comment_w CLOB NOT NULL, trusted_device_cookie_version INTEGER NOT NULL, backup_codes CLOB NOT NULL, google_authenticator_secret VARCHAR(255) DEFAULT NULL, config_timezone VARCHAR(255) DEFAULT NULL, config_language VARCHAR(255) DEFAULT NULL, email VARCHAR(255) DEFAULT NULL, department VARCHAR(255) DEFAULT NULL, last_name VARCHAR(255) DEFAULT NULL, first_name VARCHAR(255) DEFAULT NULL, need_pw_change BOOLEAN NOT NULL, password VARCHAR(255) DEFAULT NULL, name VARCHAR(180) NOT NULL, settings CLOB NOT NULL, backup_codes_generation_date DATETIME DEFAULT NULL, pw_reset_expires DATETIME DEFAULT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, permissions_data CLOB NOT NULL, saml_user BOOLEAN NOT NULL, about_me CLOB NOT NULL, show_email_on_profile BOOLEAN DEFAULT 0 NOT NULL, CONSTRAINT FK_1483A5E9FE54D947 FOREIGN KEY (group_id) REFERENCES groups (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_1483A5E938248176 FOREIGN KEY (currency_id) REFERENCES currencies (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_1483A5E9EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES attachments (id) ON UPDATE NO ACTION ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||||
|
$this->addSql('INSERT INTO users (id, group_id, currency_id, id_preview_attachment, disabled, config_theme, pw_reset_token, config_instock_comment_a, config_instock_comment_w, trusted_device_cookie_version, backup_codes, google_authenticator_secret, config_timezone, config_language, email, department, last_name, first_name, need_pw_change, password, name, settings, backup_codes_generation_date, pw_reset_expires, last_modified, datetime_added, permissions_data, saml_user, about_me, show_email_on_profile) SELECT id, group_id, currency_id, id_preview_attachment, disabled, config_theme, pw_reset_token, config_instock_comment_a, config_instock_comment_w, trusted_device_cookie_version, backup_codes, google_authenticator_secret, config_timezone, config_language, email, department, last_name, first_name, need_pw_change, password, name, settings, backup_codes_generation_date, pw_reset_expires, last_modified, datetime_added, permissions_data, saml_user, about_me, show_email_on_profile FROM __temp__users');
|
||||||
|
$this->addSql('DROP TABLE __temp__users');
|
||||||
|
$this->addSql('CREATE INDEX IDX_1483A5E9EA7100A1 ON users (id_preview_attachment)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_1483A5E938248176 ON users (currency_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_1483A5E9FE54D947 ON users (group_id)');
|
||||||
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_1483A5E95E237E06 ON users (name)');
|
||||||
|
$this->addSql('CREATE INDEX user_idx_username ON users (name)');
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__webauthn_keys AS SELECT id, user_id, public_key_credential_id, type, transports, attestation_type, trust_path, aaguid, credential_public_key, user_handle, counter, name, last_modified, datetime_added, other_ui, backup_eligible, backup_status, uv_initialized, last_time_used FROM webauthn_keys');
|
||||||
|
$this->addSql('DROP TABLE webauthn_keys');
|
||||||
|
$this->addSql('CREATE TABLE webauthn_keys (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, user_id INTEGER DEFAULT NULL, public_key_credential_id CLOB NOT NULL, type VARCHAR(255) NOT NULL, transports CLOB NOT NULL, attestation_type VARCHAR(255) NOT NULL, trust_path CLOB NOT NULL, aaguid CLOB NOT NULL, credential_public_key CLOB NOT NULL, user_handle VARCHAR(255) NOT NULL, counter INTEGER NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, other_ui CLOB DEFAULT NULL, backup_eligible BOOLEAN DEFAULT NULL, backup_status BOOLEAN DEFAULT NULL, uv_initialized BOOLEAN DEFAULT NULL, last_time_used DATETIME DEFAULT NULL, CONSTRAINT FK_799FD143A76ED395 FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||||
|
$this->addSql('INSERT INTO webauthn_keys (id, user_id, public_key_credential_id, type, transports, attestation_type, trust_path, aaguid, credential_public_key, user_handle, counter, name, last_modified, datetime_added, other_ui, backup_eligible, backup_status, uv_initialized, last_time_used) SELECT id, user_id, public_key_credential_id, type, transports, attestation_type, trust_path, aaguid, credential_public_key, user_handle, counter, name, last_modified, datetime_added, other_ui, backup_eligible, backup_status, uv_initialized, last_time_used FROM __temp__webauthn_keys');
|
||||||
|
$this->addSql('DROP TABLE __temp__webauthn_keys');
|
||||||
|
$this->addSql('CREATE INDEX IDX_799FD143A76ED395 ON webauthn_keys (user_id)');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sqLiteDown(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__currencies AS SELECT id, name, last_modified, datetime_added, comment, not_selectable, alternative_names, exchange_rate, iso_code, parent_id, id_preview_attachment FROM currencies');
|
||||||
|
$this->addSql('DROP TABLE currencies');
|
||||||
|
$this->addSql('CREATE TABLE currencies (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, comment CLOB NOT NULL, not_selectable BOOLEAN NOT NULL, alternative_names CLOB DEFAULT NULL, exchange_rate NUMERIC(11, 5) DEFAULT NULL --(DC2Type:big_decimal)
|
||||||
|
, iso_code VARCHAR(255) NOT NULL, parent_id INTEGER DEFAULT NULL, id_preview_attachment INTEGER DEFAULT NULL, CONSTRAINT FK_37C44693727ACA70 FOREIGN KEY (parent_id) REFERENCES currencies (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_37C44693EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES "attachments" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||||
|
$this->addSql('INSERT INTO currencies (id, name, last_modified, datetime_added, comment, not_selectable, alternative_names, exchange_rate, iso_code, parent_id, id_preview_attachment) SELECT id, name, last_modified, datetime_added, comment, not_selectable, alternative_names, exchange_rate, iso_code, parent_id, id_preview_attachment FROM __temp__currencies');
|
||||||
|
$this->addSql('DROP TABLE __temp__currencies');
|
||||||
|
$this->addSql('CREATE INDEX IDX_37C44693727ACA70 ON currencies (parent_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_37C44693EA7100A1 ON currencies (id_preview_attachment)');
|
||||||
|
$this->addSql('CREATE INDEX currency_idx_name ON currencies (name)');
|
||||||
|
$this->addSql('CREATE INDEX currency_idx_parent_name ON currencies (parent_id, name)');
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__groups AS SELECT id, name, last_modified, datetime_added, comment, not_selectable, alternative_names, enforce_2fa, permissions_data, parent_id, id_preview_attachment FROM "groups"');
|
||||||
|
$this->addSql('DROP TABLE "groups"');
|
||||||
|
$this->addSql('CREATE TABLE "groups" (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, comment CLOB NOT NULL, not_selectable BOOLEAN NOT NULL, alternative_names CLOB DEFAULT NULL, enforce_2fa BOOLEAN NOT NULL, permissions_data CLOB NOT NULL --(DC2Type:json)
|
||||||
|
, parent_id INTEGER DEFAULT NULL, id_preview_attachment INTEGER DEFAULT NULL, CONSTRAINT FK_F06D3970727ACA70 FOREIGN KEY (parent_id) REFERENCES "groups" (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_F06D3970EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES "attachments" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||||
|
$this->addSql('INSERT INTO "groups" (id, name, last_modified, datetime_added, comment, not_selectable, alternative_names, enforce_2fa, permissions_data, parent_id, id_preview_attachment) SELECT id, name, last_modified, datetime_added, comment, not_selectable, alternative_names, enforce_2fa, permissions_data, parent_id, id_preview_attachment FROM __temp__groups');
|
||||||
|
$this->addSql('DROP TABLE __temp__groups');
|
||||||
|
$this->addSql('CREATE INDEX IDX_F06D3970727ACA70 ON "groups" (parent_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_F06D3970EA7100A1 ON "groups" (id_preview_attachment)');
|
||||||
|
$this->addSql('CREATE INDEX group_idx_name ON "groups" (name)');
|
||||||
|
$this->addSql('CREATE INDEX group_idx_parent_name ON "groups" (parent_id, name)');
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__log AS SELECT id, username, datetime, level, target_id, target_type, extra, id_user, type FROM log');
|
||||||
|
$this->addSql('DROP TABLE log');
|
||||||
|
$this->addSql('CREATE TABLE log (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, username VARCHAR(255) NOT NULL, datetime DATETIME NOT NULL, level BOOLEAN NOT NULL --(DC2Type:tinyint)
|
||||||
|
, target_id INTEGER NOT NULL, target_type SMALLINT NOT NULL, extra CLOB NOT NULL --(DC2Type:json)
|
||||||
|
, id_user INTEGER DEFAULT NULL, type SMALLINT NOT NULL, CONSTRAINT FK_8F3F68C56B3CA4B FOREIGN KEY (id_user) REFERENCES "users" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||||
|
$this->addSql('INSERT INTO log (id, username, datetime, level, target_id, target_type, extra, id_user, type) SELECT id, username, datetime, level, target_id, target_type, extra, id_user, type FROM __temp__log');
|
||||||
|
$this->addSql('DROP TABLE __temp__log');
|
||||||
|
$this->addSql('CREATE INDEX IDX_8F3F68C56B3CA4B ON log (id_user)');
|
||||||
|
$this->addSql('CREATE INDEX log_idx_type ON log (type)');
|
||||||
|
$this->addSql('CREATE INDEX log_idx_type_target ON log (type, target_type, target_id)');
|
||||||
|
$this->addSql('CREATE INDEX log_idx_datetime ON log (datetime)');
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__oauth_tokens AS SELECT id, name, last_modified, datetime_added, token, expires_at, refresh_token FROM oauth_tokens');
|
||||||
|
$this->addSql('DROP TABLE oauth_tokens');
|
||||||
|
$this->addSql('CREATE TABLE oauth_tokens (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, token CLOB DEFAULT NULL, expires_at DATETIME DEFAULT NULL --(DC2Type:datetime_immutable)
|
||||||
|
, refresh_token CLOB DEFAULT NULL)');
|
||||||
|
$this->addSql('INSERT INTO oauth_tokens (id, name, last_modified, datetime_added, token, expires_at, refresh_token) SELECT id, name, last_modified, datetime_added, token, expires_at, refresh_token FROM __temp__oauth_tokens');
|
||||||
|
$this->addSql('DROP TABLE __temp__oauth_tokens');
|
||||||
|
$this->addSql('CREATE UNIQUE INDEX oauth_tokens_unique_name ON oauth_tokens (name)');
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__pricedetails AS SELECT id, price, price_related_quantity, min_discount_quantity, manual_input, last_modified, datetime_added, id_currency, orderdetails_id FROM "pricedetails"');
|
||||||
|
$this->addSql('DROP TABLE "pricedetails"');
|
||||||
|
$this->addSql('CREATE TABLE "pricedetails" (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, price NUMERIC(11, 5) NOT NULL --(DC2Type:big_decimal)
|
||||||
|
, price_related_quantity DOUBLE PRECISION NOT NULL, min_discount_quantity DOUBLE PRECISION NOT NULL, manual_input BOOLEAN NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, id_currency INTEGER DEFAULT NULL, orderdetails_id INTEGER NOT NULL, CONSTRAINT FK_C68C4459398D64AA FOREIGN KEY (id_currency) REFERENCES currencies (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_C68C44594A01DDC7 FOREIGN KEY (orderdetails_id) REFERENCES "orderdetails" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||||
|
$this->addSql('INSERT INTO "pricedetails" (id, price, price_related_quantity, min_discount_quantity, manual_input, last_modified, datetime_added, id_currency, orderdetails_id) SELECT id, price, price_related_quantity, min_discount_quantity, manual_input, last_modified, datetime_added, id_currency, orderdetails_id FROM __temp__pricedetails');
|
||||||
|
$this->addSql('DROP TABLE __temp__pricedetails');
|
||||||
|
$this->addSql('CREATE INDEX IDX_C68C4459398D64AA ON "pricedetails" (id_currency)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_C68C44594A01DDC7 ON "pricedetails" (orderdetails_id)');
|
||||||
|
$this->addSql('CREATE INDEX pricedetails_idx_min_discount ON "pricedetails" (min_discount_quantity)');
|
||||||
|
$this->addSql('CREATE INDEX pricedetails_idx_min_discount_price_qty ON "pricedetails" (min_discount_quantity, price_related_quantity)');
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__project_bom_entries AS SELECT id, quantity, mountnames, name, comment, price, last_modified, datetime_added, id_device, id_part, price_currency_id FROM project_bom_entries');
|
||||||
|
$this->addSql('DROP TABLE project_bom_entries');
|
||||||
|
$this->addSql('CREATE TABLE project_bom_entries (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, quantity DOUBLE PRECISION NOT NULL, mountnames CLOB NOT NULL, name VARCHAR(255) DEFAULT NULL, comment CLOB NOT NULL, price NUMERIC(11, 5) DEFAULT NULL --(DC2Type:big_decimal)
|
||||||
|
, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, id_device INTEGER DEFAULT NULL, id_part INTEGER DEFAULT NULL, price_currency_id INTEGER DEFAULT NULL, CONSTRAINT FK_1AA2DD312F180363 FOREIGN KEY (id_device) REFERENCES projects (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_1AA2DD31C22F6CC4 FOREIGN KEY (id_part) REFERENCES "parts" (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_1AA2DD313FFDCD60 FOREIGN KEY (price_currency_id) REFERENCES currencies (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||||
|
$this->addSql('INSERT INTO project_bom_entries (id, quantity, mountnames, name, comment, price, last_modified, datetime_added, id_device, id_part, price_currency_id) SELECT id, quantity, mountnames, name, comment, price, last_modified, datetime_added, id_device, id_part, price_currency_id FROM __temp__project_bom_entries');
|
||||||
|
$this->addSql('DROP TABLE __temp__project_bom_entries');
|
||||||
|
$this->addSql('CREATE INDEX IDX_1AA2DD312F180363 ON project_bom_entries (id_device)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_1AA2DD31C22F6CC4 ON project_bom_entries (id_part)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_1AA2DD313FFDCD60 ON project_bom_entries (price_currency_id)');
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__suppliers AS SELECT id, name, last_modified, datetime_added, comment, not_selectable, alternative_names, address, phone_number, fax_number, email_address, website, auto_product_url, shipping_costs, parent_id, default_currency_id, id_preview_attachment FROM "suppliers"');
|
||||||
|
$this->addSql('DROP TABLE "suppliers"');
|
||||||
|
$this->addSql('CREATE TABLE "suppliers" (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, comment CLOB NOT NULL, not_selectable BOOLEAN NOT NULL, alternative_names CLOB DEFAULT NULL, address VARCHAR(255) NOT NULL, phone_number VARCHAR(255) NOT NULL, fax_number VARCHAR(255) NOT NULL, email_address VARCHAR(255) NOT NULL, website VARCHAR(255) NOT NULL, auto_product_url VARCHAR(255) NOT NULL, shipping_costs NUMERIC(11, 5) DEFAULT NULL --(DC2Type:big_decimal)
|
||||||
|
, parent_id INTEGER DEFAULT NULL, default_currency_id INTEGER DEFAULT NULL, id_preview_attachment INTEGER DEFAULT NULL, CONSTRAINT FK_AC28B95C727ACA70 FOREIGN KEY (parent_id) REFERENCES "suppliers" (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_AC28B95CECD792C0 FOREIGN KEY (default_currency_id) REFERENCES currencies (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_AC28B95CEA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES "attachments" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||||
|
$this->addSql('INSERT INTO "suppliers" (id, name, last_modified, datetime_added, comment, not_selectable, alternative_names, address, phone_number, fax_number, email_address, website, auto_product_url, shipping_costs, parent_id, default_currency_id, id_preview_attachment) SELECT id, name, last_modified, datetime_added, comment, not_selectable, alternative_names, address, phone_number, fax_number, email_address, website, auto_product_url, shipping_costs, parent_id, default_currency_id, id_preview_attachment FROM __temp__suppliers');
|
||||||
|
$this->addSql('DROP TABLE __temp__suppliers');
|
||||||
|
$this->addSql('CREATE INDEX IDX_AC28B95C727ACA70 ON "suppliers" (parent_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_AC28B95CECD792C0 ON "suppliers" (default_currency_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_AC28B95CEA7100A1 ON "suppliers" (id_preview_attachment)');
|
||||||
|
$this->addSql('CREATE INDEX supplier_idx_name ON "suppliers" (name)');
|
||||||
|
$this->addSql('CREATE INDEX supplier_idx_parent_name ON "suppliers" (parent_id, name)');
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__users AS SELECT id, last_modified, datetime_added, disabled, config_theme, pw_reset_token, config_instock_comment_a, config_instock_comment_w, about_me, trusted_device_cookie_version, backup_codes, google_authenticator_secret, config_timezone, config_language, email, show_email_on_profile, department, last_name, first_name, need_pw_change, password, settings, backup_codes_generation_date, pw_reset_expires, saml_user, name, permissions_data, group_id, id_preview_attachment, currency_id FROM "users"');
|
||||||
|
$this->addSql('DROP TABLE "users"');
|
||||||
|
$this->addSql('CREATE TABLE "users" (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, disabled BOOLEAN NOT NULL, config_theme VARCHAR(255) DEFAULT NULL, pw_reset_token VARCHAR(255) DEFAULT NULL, config_instock_comment_a CLOB NOT NULL, config_instock_comment_w CLOB NOT NULL, about_me CLOB NOT NULL, trusted_device_cookie_version INTEGER NOT NULL, backup_codes CLOB NOT NULL --(DC2Type:json)
|
||||||
|
, google_authenticator_secret VARCHAR(255) DEFAULT NULL, config_timezone VARCHAR(255) DEFAULT NULL, config_language VARCHAR(255) DEFAULT NULL, email VARCHAR(255) DEFAULT NULL, show_email_on_profile BOOLEAN DEFAULT 0 NOT NULL, department VARCHAR(255) DEFAULT NULL, last_name VARCHAR(255) DEFAULT NULL, first_name VARCHAR(255) DEFAULT NULL, need_pw_change BOOLEAN NOT NULL, password VARCHAR(255) DEFAULT NULL, settings CLOB NOT NULL --(DC2Type:json)
|
||||||
|
, backup_codes_generation_date DATETIME DEFAULT NULL, pw_reset_expires DATETIME DEFAULT NULL, saml_user BOOLEAN NOT NULL, name VARCHAR(180) NOT NULL, permissions_data CLOB NOT NULL --(DC2Type:json)
|
||||||
|
, group_id INTEGER DEFAULT NULL, id_preview_attachment INTEGER DEFAULT NULL, currency_id INTEGER DEFAULT NULL, CONSTRAINT FK_1483A5E9FE54D947 FOREIGN KEY (group_id) REFERENCES "groups" (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_1483A5E9EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES "attachments" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_1483A5E938248176 FOREIGN KEY (currency_id) REFERENCES currencies (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||||
|
$this->addSql('INSERT INTO "users" (id, last_modified, datetime_added, disabled, config_theme, pw_reset_token, config_instock_comment_a, config_instock_comment_w, about_me, trusted_device_cookie_version, backup_codes, google_authenticator_secret, config_timezone, config_language, email, show_email_on_profile, department, last_name, first_name, need_pw_change, password, settings, backup_codes_generation_date, pw_reset_expires, saml_user, name, permissions_data, group_id, id_preview_attachment, currency_id) SELECT id, last_modified, datetime_added, disabled, config_theme, pw_reset_token, config_instock_comment_a, config_instock_comment_w, about_me, trusted_device_cookie_version, backup_codes, google_authenticator_secret, config_timezone, config_language, email, show_email_on_profile, department, last_name, first_name, need_pw_change, password, settings, backup_codes_generation_date, pw_reset_expires, saml_user, name, permissions_data, group_id, id_preview_attachment, currency_id FROM __temp__users');
|
||||||
|
$this->addSql('DROP TABLE __temp__users');
|
||||||
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_1483A5E95E237E06 ON "users" (name)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_1483A5E9FE54D947 ON "users" (group_id)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_1483A5E9EA7100A1 ON "users" (id_preview_attachment)');
|
||||||
|
$this->addSql('CREATE INDEX IDX_1483A5E938248176 ON "users" (currency_id)');
|
||||||
|
$this->addSql('CREATE INDEX user_idx_username ON "users" (name)');
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__webauthn_keys AS SELECT public_key_credential_id, type, transports, attestation_type, trust_path, aaguid, credential_public_key, user_handle, counter, other_ui, backup_eligible, backup_status, uv_initialized, id, name, last_time_used, last_modified, datetime_added, user_id FROM webauthn_keys');
|
||||||
|
$this->addSql('DROP TABLE webauthn_keys');
|
||||||
|
$this->addSql('CREATE TABLE webauthn_keys (public_key_credential_id CLOB NOT NULL --(DC2Type:base64)
|
||||||
|
, type VARCHAR(255) NOT NULL, transports CLOB NOT NULL --(DC2Type:array)
|
||||||
|
, attestation_type VARCHAR(255) NOT NULL, trust_path CLOB NOT NULL --(DC2Type:trust_path)
|
||||||
|
, aaguid CLOB NOT NULL --(DC2Type:aaguid)
|
||||||
|
, credential_public_key CLOB NOT NULL --(DC2Type:base64)
|
||||||
|
, user_handle VARCHAR(255) NOT NULL, counter INTEGER NOT NULL, other_ui CLOB DEFAULT NULL --(DC2Type:array)
|
||||||
|
, backup_eligible BOOLEAN DEFAULT NULL, backup_status BOOLEAN DEFAULT NULL, uv_initialized BOOLEAN DEFAULT NULL, id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR(255) NOT NULL, last_time_used DATETIME DEFAULT NULL --(DC2Type:datetime_immutable)
|
||||||
|
, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, user_id INTEGER DEFAULT NULL, CONSTRAINT FK_799FD143A76ED395 FOREIGN KEY (user_id) REFERENCES "users" (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||||
|
$this->addSql('INSERT INTO webauthn_keys (public_key_credential_id, type, transports, attestation_type, trust_path, aaguid, credential_public_key, user_handle, counter, other_ui, backup_eligible, backup_status, uv_initialized, id, name, last_time_used, last_modified, datetime_added, user_id) SELECT public_key_credential_id, type, transports, attestation_type, trust_path, aaguid, credential_public_key, user_handle, counter, other_ui, backup_eligible, backup_status, uv_initialized, id, name, last_time_used, last_modified, datetime_added, user_id FROM __temp__webauthn_keys');
|
||||||
|
$this->addSql('DROP TABLE __temp__webauthn_keys');
|
||||||
|
$this->addSql('CREATE INDEX IDX_799FD143A76ED395 ON webauthn_keys (user_id)');
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,7 +13,7 @@
|
||||||
<server name="SHELL_VERBOSITY" value="-1"/>
|
<server name="SHELL_VERBOSITY" value="-1"/>
|
||||||
<server name="SYMFONY_PHPUNIT_REMOVE" value=""/>
|
<server name="SYMFONY_PHPUNIT_REMOVE" value=""/>
|
||||||
<server name="SYMFONY_PHPUNIT_VERSION" value="9.5"/>
|
<server name="SYMFONY_PHPUNIT_VERSION" value="9.5"/>
|
||||||
<ini name="memory_limit" value="512M"/>
|
<ini name="memory_limit" value="1G"/>
|
||||||
<ini name="display_errors" value="1"/>
|
<ini name="display_errors" value="1"/>
|
||||||
</php>
|
</php>
|
||||||
<coverage processUncoveredFiles="true">
|
<coverage processUncoveredFiles="true">
|
||||||
|
|
55
psalm.xml
55
psalm.xml
|
@ -1,55 +0,0 @@
|
||||||
<?xml version="1.0"?>
|
|
||||||
<psalm
|
|
||||||
errorLevel="5"
|
|
||||||
totallyTyped="false"
|
|
||||||
resolveFromConfigFile="true"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns="https://getpsalm.org/schema/config"
|
|
||||||
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
|
|
||||||
>
|
|
||||||
<projectFiles>
|
|
||||||
<directory name="src"/>
|
|
||||||
<ignoreFiles>
|
|
||||||
<directory name="vendor"/>
|
|
||||||
</ignoreFiles>
|
|
||||||
</projectFiles>
|
|
||||||
|
|
||||||
<issueHandlers>
|
|
||||||
<LessSpecificReturnType errorLevel="info"/>
|
|
||||||
|
|
||||||
<!-- level 3 issues - slightly lazy code writing, but provably low false-negatives -->
|
|
||||||
|
|
||||||
<DeprecatedMethod errorLevel="info"/>
|
|
||||||
<DeprecatedProperty errorLevel="info"/>
|
|
||||||
<DeprecatedClass errorLevel="info"/>
|
|
||||||
<DeprecatedConstant errorLevel="info"/>
|
|
||||||
<DeprecatedFunction errorLevel="info"/>
|
|
||||||
<DeprecatedInterface errorLevel="info"/>
|
|
||||||
<DeprecatedTrait errorLevel="info"/>
|
|
||||||
|
|
||||||
<InternalMethod errorLevel="info"/>
|
|
||||||
<InternalProperty errorLevel="info"/>
|
|
||||||
<InternalClass errorLevel="info"/>
|
|
||||||
|
|
||||||
<MissingClosureReturnType errorLevel="info"/>
|
|
||||||
<MissingReturnType errorLevel="info"/>
|
|
||||||
<MissingPropertyType errorLevel="info"/>
|
|
||||||
<InvalidDocblock errorLevel="info"/>
|
|
||||||
|
|
||||||
<PropertyNotSetInConstructor errorLevel="info"/>
|
|
||||||
<MissingConstructor errorLevel="info"/>
|
|
||||||
<MissingClosureParamType errorLevel="info"/>
|
|
||||||
<MissingParamType errorLevel="info"/>
|
|
||||||
|
|
||||||
<RedundantCondition errorLevel="info"/>
|
|
||||||
|
|
||||||
<DocblockTypeContradiction errorLevel="info"/>
|
|
||||||
<RedundantConditionGivenDocblockType errorLevel="info"/>
|
|
||||||
|
|
||||||
<UnresolvableInclude errorLevel="info"/>
|
|
||||||
|
|
||||||
<RawObjectIteration errorLevel="info"/>
|
|
||||||
|
|
||||||
<InvalidStringClass errorLevel="info"/>
|
|
||||||
</issueHandlers>
|
|
||||||
<plugins><pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/></plugins></psalm>
|
|
30
rector.php
30
rector.php
|
@ -2,15 +2,17 @@
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
|
||||||
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
|
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
|
||||||
use Rector\Config\RectorConfig;
|
use Rector\Config\RectorConfig;
|
||||||
use Rector\Doctrine\Set\DoctrineSetList;
|
use Rector\Doctrine\Set\DoctrineSetList;
|
||||||
use Rector\PHPUnit\Rector\ClassMethod\AddDoesNotPerformAssertionToNonAssertingTestRector;
|
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
|
||||||
use Rector\PHPUnit\Set\PHPUnitLevelSetList;
|
|
||||||
use Rector\PHPUnit\Set\PHPUnitSetList;
|
use Rector\PHPUnit\Set\PHPUnitSetList;
|
||||||
use Rector\Set\ValueObject\LevelSetList;
|
use Rector\Set\ValueObject\LevelSetList;
|
||||||
use Rector\Set\ValueObject\SetList;
|
use Rector\Set\ValueObject\SetList;
|
||||||
use Rector\Symfony\Set\SymfonyLevelSetList;
|
use Rector\Symfony\CodeQuality\Rector\Class_\EventListenerToEventSubscriberRector;
|
||||||
|
use Rector\Symfony\CodeQuality\Rector\ClassMethod\ActionSuffixRemoverRector;
|
||||||
|
use Rector\Symfony\CodeQuality\Rector\MethodCall\LiteralGetToRequestClassConstantRector;
|
||||||
use Rector\Symfony\Set\SymfonySetList;
|
use Rector\Symfony\Set\SymfonySetList;
|
||||||
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;
|
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;
|
||||||
|
|
||||||
|
@ -44,20 +46,36 @@ return static function (RectorConfig $rectorConfig): void {
|
||||||
LevelSetList::UP_TO_PHP_81,
|
LevelSetList::UP_TO_PHP_81,
|
||||||
|
|
||||||
//Symfony rules
|
//Symfony rules
|
||||||
SymfonyLevelSetList::UP_TO_SYMFONY_62,
|
|
||||||
SymfonySetList::SYMFONY_CODE_QUALITY,
|
SymfonySetList::SYMFONY_CODE_QUALITY,
|
||||||
|
SymfonySetList::SYMFONY_64,
|
||||||
|
|
||||||
//Doctrine rules
|
//Doctrine rules
|
||||||
DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
|
DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
|
||||||
DoctrineSetList::DOCTRINE_CODE_QUALITY,
|
DoctrineSetList::DOCTRINE_CODE_QUALITY,
|
||||||
|
|
||||||
//PHPUnit rules
|
//PHPUnit rules
|
||||||
PHPUnitLevelSetList::UP_TO_PHPUNIT_90,
|
|
||||||
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
|
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
|
||||||
|
PHPUnitSetList::PHPUNIT_90,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$rectorConfig->skip([
|
$rectorConfig->skip([
|
||||||
AddDoesNotPerformAssertionToNonAssertingTestRector::class,
|
|
||||||
CountArrayToEmptyArrayComparisonRector::class,
|
CountArrayToEmptyArrayComparisonRector::class,
|
||||||
|
//Leave our !== null checks alone
|
||||||
|
FlipTypeControlToUseExclusiveTypeRector::class,
|
||||||
|
//Leave our PartList TableAction alone
|
||||||
|
ActionSuffixRemoverRector::class,
|
||||||
|
//We declare event listeners via attributes, therefore no need to migrate them to subscribers
|
||||||
|
EventListenerToEventSubscriberRector::class,
|
||||||
|
PreferPHPUnitThisCallRector::class,
|
||||||
|
//Do not replace 'GET' with class constant,
|
||||||
|
LiteralGetToRequestClassConstantRector::class,
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Do not apply rules to Symfony own files
|
||||||
|
$rectorConfig->skip([
|
||||||
|
__DIR__ . '/public/index.php',
|
||||||
|
__DIR__ . '/src/Kernel.php',
|
||||||
|
__DIR__ . '/config/preload.php',
|
||||||
|
__DIR__ . '/config/bundles.php',
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
|
@ -81,12 +81,12 @@ class EntityFilterHelper
|
||||||
|
|
||||||
public function getDescription(array $properties): array
|
public function getDescription(array $properties): array
|
||||||
{
|
{
|
||||||
if (!$properties) {
|
if ($properties === []) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$description = [];
|
$description = [];
|
||||||
foreach ($properties as $property => $strategy) {
|
foreach (array_keys($properties) as $property) {
|
||||||
$description[(string)$property] = [
|
$description[(string)$property] = [
|
||||||
'property' => $property,
|
'property' => $property,
|
||||||
'type' => Type::BUILTIN_TYPE_STRING,
|
'type' => Type::BUILTIN_TYPE_STRING,
|
||||||
|
|
|
@ -61,7 +61,7 @@ final class LikeFilter extends AbstractFilter
|
||||||
}
|
}
|
||||||
|
|
||||||
$description = [];
|
$description = [];
|
||||||
foreach ($this->properties as $property => $strategy) {
|
foreach (array_keys($this->properties) as $property) {
|
||||||
$description[(string)$property] = [
|
$description[(string)$property] = [
|
||||||
'property' => $property,
|
'property' => $property,
|
||||||
'type' => Type::BUILTIN_TYPE_STRING,
|
'type' => Type::BUILTIN_TYPE_STRING,
|
||||||
|
|
|
@ -46,7 +46,7 @@ final class HandleAttachmentsUploadsProcessor implements ProcessorInterface
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = [])
|
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
|
||||||
{
|
{
|
||||||
if ($operation instanceof DeleteOperationInterface) {
|
if ($operation instanceof DeleteOperationInterface) {
|
||||||
return $this->removeProcessor->process($data, $operation, $uriVariables, $context);
|
return $this->removeProcessor->process($data, $operation, $uriVariables, $context);
|
||||||
|
|
|
@ -4,8 +4,10 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Command;
|
namespace App\Command;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
|
||||||
|
use Spatie\DbDumper\Databases\PostgreSql;
|
||||||
use Symfony\Component\Console\Attribute\AsCommand;
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
use Doctrine\DBAL\Platforms\SqlitePlatform;
|
use Doctrine\DBAL\Platforms\SQLitePlatform;
|
||||||
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
|
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use PhpZip\Constants\ZipCompressionMethod;
|
use PhpZip\Constants\ZipCompressionMethod;
|
||||||
|
@ -50,6 +52,7 @@ class BackupCommand extends Command
|
||||||
$backup_attachments = $input->getOption('attachments');
|
$backup_attachments = $input->getOption('attachments');
|
||||||
$backup_config = $input->getOption('config');
|
$backup_config = $input->getOption('config');
|
||||||
$backup_full = $input->getOption('full');
|
$backup_full = $input->getOption('full');
|
||||||
|
$overwrite = $input->getOption('overwrite');
|
||||||
|
|
||||||
if ($backup_full) {
|
if ($backup_full) {
|
||||||
$backup_database = true;
|
$backup_database = true;
|
||||||
|
@ -68,7 +71,9 @@ class BackupCommand extends Command
|
||||||
|
|
||||||
//Check if the file already exists
|
//Check if the file already exists
|
||||||
//Then ask the user, if he wants to overwrite the file
|
//Then ask the user, if he wants to overwrite the file
|
||||||
if (file_exists($output_filepath) && !$io->confirm('The file '.realpath($output_filepath).' already exists. Do you want to overwrite it?', false)) {
|
if (!$overwrite
|
||||||
|
&& file_exists($output_filepath)
|
||||||
|
&& !$io->confirm('The file '.realpath($output_filepath).' already exists. Do you want to overwrite it?', false)) {
|
||||||
$io->error('Backup aborted!');
|
$io->error('Backup aborted!');
|
||||||
return Command::FAILURE;
|
return Command::FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -136,30 +141,42 @@ class BackupCommand extends Command
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function runSQLDumper(DbDumper $dumper, ZipFile $zip, array $connectionParams): void
|
||||||
|
{
|
||||||
|
$this->configureDumper($connectionParams, $dumper);
|
||||||
|
|
||||||
|
$tmp_file = tempnam(sys_get_temp_dir(), 'partdb_sql_dump');
|
||||||
|
|
||||||
|
$dumper->dumpToFile($tmp_file);
|
||||||
|
$zip->addFile($tmp_file, 'database.sql');
|
||||||
|
}
|
||||||
|
|
||||||
protected function backupDatabase(ZipFile $zip, SymfonyStyle $io): void
|
protected function backupDatabase(ZipFile $zip, SymfonyStyle $io): void
|
||||||
{
|
{
|
||||||
$io->note('Backup database...');
|
$io->note('Backup database...');
|
||||||
|
|
||||||
//Determine if we use MySQL or SQLite
|
//Determine if we use MySQL or SQLite
|
||||||
$connection = $this->entityManager->getConnection();
|
$connection = $this->entityManager->getConnection();
|
||||||
if ($connection->getDatabasePlatform() instanceof AbstractMySQLPlatform) {
|
$params = $connection->getParams();
|
||||||
|
$platform = $connection->getDatabasePlatform();
|
||||||
|
if ($platform instanceof AbstractMySQLPlatform) {
|
||||||
try {
|
try {
|
||||||
$io->note('MySQL database detected. Dump DB to SQL using mysqldump...');
|
$io->note('MySQL database detected. Dump DB to SQL using mysqldump...');
|
||||||
$params = $connection->getParams();
|
$this->runSQLDumper(MySql::create(), $zip, $params);
|
||||||
$dumper = MySql::create();
|
|
||||||
$this->configureDumper($params, $dumper);
|
|
||||||
|
|
||||||
$tmp_file = tempnam(sys_get_temp_dir(), 'partdb_sql_dump');
|
|
||||||
|
|
||||||
$dumper->dumpToFile($tmp_file);
|
|
||||||
$zip->addFile($tmp_file, 'mysql_dump.sql');
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$io->error('Could not dump database: '.$e->getMessage());
|
$io->error('Could not dump database: '.$e->getMessage());
|
||||||
$io->error('This can maybe be fixed by installing the mysqldump binary and adding it to the PATH variable!');
|
$io->error('This can maybe be fixed by installing the mysqldump binary and adding it to the PATH variable!');
|
||||||
}
|
}
|
||||||
} elseif ($connection->getDatabasePlatform() instanceof SqlitePlatform) {
|
} elseif ($platform instanceof PostgreSQLPlatform) {
|
||||||
|
try {
|
||||||
|
$io->note('PostgreSQL database detected. Dump DB to SQL using pg_dump...');
|
||||||
|
$this->runSQLDumper(PostgreSql::create(), $zip, $params);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$io->error('Could not dump database: '.$e->getMessage());
|
||||||
|
$io->error('This can maybe be fixed by installing the pg_dump binary and adding it to the PATH variable!');
|
||||||
|
}
|
||||||
|
} elseif ($platform instanceof SQLitePlatform) {
|
||||||
$io->note('SQLite database detected. Copy DB file to ZIP...');
|
$io->note('SQLite database detected. Copy DB file to ZIP...');
|
||||||
$params = $connection->getParams();
|
|
||||||
$zip->addFile($params['path'], 'var/app.db');
|
$zip->addFile($params['path'], 'var/app.db');
|
||||||
} else {
|
} else {
|
||||||
$io->error('Unknown database platform. Could not backup database!');
|
$io->error('Unknown database platform. Could not backup database!');
|
||||||
|
|
|
@ -52,7 +52,6 @@ use Doctrine\ORM\EntityManagerInterface;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Omines\DataTablesBundle\DataTableFactory;
|
use Omines\DataTablesBundle\DataTableFactory;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Symfony\Component\Form\FormInterface;
|
use Symfony\Component\Form\FormInterface;
|
||||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||||
|
@ -61,6 +60,8 @@ use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||||
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
||||||
|
use Symfony\Component\Validator\ConstraintViolationInterface;
|
||||||
|
use Symfony\Component\Validator\ConstraintViolationListInterface;
|
||||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
use function Symfony\Component\Translation\t;
|
use function Symfony\Component\Translation\t;
|
||||||
|
@ -74,15 +75,10 @@ abstract class BaseAdminController extends AbstractController
|
||||||
protected string $attachment_class = '';
|
protected string $attachment_class = '';
|
||||||
protected ?string $parameter_class = '';
|
protected ?string $parameter_class = '';
|
||||||
|
|
||||||
/**
|
|
||||||
* @var EventDispatcher|EventDispatcherInterface
|
|
||||||
*/
|
|
||||||
protected EventDispatcher|EventDispatcherInterface $eventDispatcher;
|
|
||||||
|
|
||||||
public function __construct(protected TranslatorInterface $translator, protected UserPasswordHasherInterface $passwordEncoder,
|
public function __construct(protected TranslatorInterface $translator, protected UserPasswordHasherInterface $passwordEncoder,
|
||||||
protected AttachmentSubmitHandler $attachmentSubmitHandler,
|
protected AttachmentSubmitHandler $attachmentSubmitHandler,
|
||||||
protected EventCommentHelper $commentHelper, protected HistoryHelper $historyHelper, protected TimeTravel $timeTravel,
|
protected EventCommentHelper $commentHelper, protected HistoryHelper $historyHelper, protected TimeTravel $timeTravel,
|
||||||
protected DataTableFactory $dataTableFactory, EventDispatcherInterface $eventDispatcher, protected LabelExampleElementsGenerator $barcodeExampleGenerator,
|
protected DataTableFactory $dataTableFactory, protected EventDispatcherInterface $eventDispatcher, protected LabelExampleElementsGenerator $barcodeExampleGenerator,
|
||||||
protected LabelGenerator $labelGenerator, protected EntityManagerInterface $entityManager)
|
protected LabelGenerator $labelGenerator, protected EntityManagerInterface $entityManager)
|
||||||
{
|
{
|
||||||
if ('' === $this->entity_class || '' === $this->form_class || '' === $this->twig_template || '' === $this->route_base) {
|
if ('' === $this->entity_class || '' === $this->form_class || '' === $this->twig_template || '' === $this->route_base) {
|
||||||
|
@ -96,7 +92,6 @@ abstract class BaseAdminController extends AbstractController
|
||||||
if ('' === $this->parameter_class || ($this->parameter_class && !is_a($this->parameter_class, AbstractParameter::class, true))) {
|
if ('' === $this->parameter_class || ($this->parameter_class && !is_a($this->parameter_class, AbstractParameter::class, true))) {
|
||||||
throw new InvalidArgumentException('You have to override the $parameter_class value with a valid Parameter class in your subclass!');
|
throw new InvalidArgumentException('You have to override the $parameter_class value with a valid Parameter class in your subclass!');
|
||||||
}
|
}
|
||||||
$this->eventDispatcher = $eventDispatcher;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function revertElementIfNeeded(AbstractDBElement $entity, ?string $timestamp): ?DateTime
|
protected function revertElementIfNeeded(AbstractDBElement $entity, ?string $timestamp): ?DateTime
|
||||||
|
@ -192,10 +187,8 @@ abstract class BaseAdminController extends AbstractController
|
||||||
}
|
}
|
||||||
|
|
||||||
//Ensure that the master picture is still part of the attachments
|
//Ensure that the master picture is still part of the attachments
|
||||||
if ($entity instanceof AttachmentContainingDBElement) {
|
if ($entity instanceof AttachmentContainingDBElement && ($entity->getMasterPictureAttachment() !== null && !$entity->getAttachments()->contains($entity->getMasterPictureAttachment()))) {
|
||||||
if ($entity->getMasterPictureAttachment() !== null && !$entity->getAttachments()->contains($entity->getMasterPictureAttachment())) {
|
$entity->setMasterPictureAttachment(null);
|
||||||
$entity->setMasterPictureAttachment(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->commentHelper->setMessage($form['log_comment']->getData());
|
$this->commentHelper->setMessage($form['log_comment']->getData());
|
||||||
|
@ -283,10 +276,8 @@ abstract class BaseAdminController extends AbstractController
|
||||||
}
|
}
|
||||||
|
|
||||||
//Ensure that the master picture is still part of the attachments
|
//Ensure that the master picture is still part of the attachments
|
||||||
if ($new_entity instanceof AttachmentContainingDBElement) {
|
if ($new_entity instanceof AttachmentContainingDBElement && ($new_entity->getMasterPictureAttachment() !== null && !$new_entity->getAttachments()->contains($new_entity->getMasterPictureAttachment()))) {
|
||||||
if ($new_entity->getMasterPictureAttachment() !== null && !$new_entity->getAttachments()->contains($new_entity->getMasterPictureAttachment())) {
|
$new_entity->setMasterPictureAttachment(null);
|
||||||
$new_entity->setMasterPictureAttachment(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->commentHelper->setMessage($form['log_comment']->getData());
|
$this->commentHelper->setMessage($form['log_comment']->getData());
|
||||||
|
@ -333,8 +324,8 @@ abstract class BaseAdminController extends AbstractController
|
||||||
try {
|
try {
|
||||||
$errors = $importer->importFileAndPersistToDB($file, $options);
|
$errors = $importer->importFileAndPersistToDB($file, $options);
|
||||||
|
|
||||||
foreach ($errors as $name => $error) {
|
foreach ($errors as $name => ['violations' => $violations]) {
|
||||||
foreach ($error as $violation) {
|
foreach ($violations as $violation) {
|
||||||
$this->addFlash('error', $name.': '.$violation->getMessage());
|
$this->addFlash('error', $name.': '.$violation->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -344,6 +335,7 @@ abstract class BaseAdminController extends AbstractController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret:
|
||||||
//Mass creation form
|
//Mass creation form
|
||||||
$mass_creation_form = $this->createForm(MassCreationForm::class, ['entity_class' => $this->entity_class]);
|
$mass_creation_form = $this->createForm(MassCreationForm::class, ['entity_class' => $this->entity_class]);
|
||||||
$mass_creation_form->handleRequest($request);
|
$mass_creation_form->handleRequest($request);
|
||||||
|
@ -356,11 +348,14 @@ abstract class BaseAdminController extends AbstractController
|
||||||
$results = $importer->massCreation($data['lines'], $this->entity_class, $data['parent'] ?? null, $errors);
|
$results = $importer->massCreation($data['lines'], $this->entity_class, $data['parent'] ?? null, $errors);
|
||||||
|
|
||||||
//Show errors to user:
|
//Show errors to user:
|
||||||
foreach ($errors as $error) {
|
foreach ($errors as ['entity' => $new_entity, 'violations' => $violations]) {
|
||||||
if ($error['entity'] instanceof AbstractStructuralDBElement) {
|
/** @var ConstraintViolationInterface $violation */
|
||||||
$this->addFlash('error', $error['entity']->getFullPath().':'.$error['violations']);
|
foreach ($violations as $violation) {
|
||||||
} else { //When we don't have a structural element, we can only show the name
|
if ($new_entity instanceof AbstractStructuralDBElement) {
|
||||||
$this->addFlash('error', $error['entity']->getName().':'.$error['violations']);
|
$this->addFlash('error', $new_entity->getFullPath().':'.$violation->getMessage());
|
||||||
|
} else { //When we don't have a structural element, we can only show the name
|
||||||
|
$this->addFlash('error', $new_entity->getName().':'.$violation->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,11 +366,10 @@ abstract class BaseAdminController extends AbstractController
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
if (count($results) > 0) {
|
if (count($results) > 0) {
|
||||||
$this->addFlash('success', t('entity.mass_creation_flash', ['%COUNT%' => count($results)]));
|
$this->addFlash('success', t('entity.mass_creation_flash', ['%COUNT%' => count($results)]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret:
|
|
||||||
return $this->render($this->twig_template, [
|
return $this->render($this->twig_template, [
|
||||||
'entity' => $new_entity,
|
'entity' => $new_entity,
|
||||||
'form' => $form,
|
'form' => $form,
|
||||||
|
|
|
@ -30,6 +30,9 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see \App\Tests\Controller\KiCadApiControllerTest
|
||||||
|
*/
|
||||||
#[Route('/kicad-api/v1')]
|
#[Route('/kicad-api/v1')]
|
||||||
class KiCadApiController extends AbstractController
|
class KiCadApiController extends AbstractController
|
||||||
{
|
{
|
||||||
|
@ -62,7 +65,7 @@ class KiCadApiController extends AbstractController
|
||||||
#[Route('/parts/category/{category}.json', name: 'kicad_api_category')]
|
#[Route('/parts/category/{category}.json', name: 'kicad_api_category')]
|
||||||
public function categoryParts(?Category $category): Response
|
public function categoryParts(?Category $category): Response
|
||||||
{
|
{
|
||||||
if ($category) {
|
if ($category !== null) {
|
||||||
$this->denyAccessUnlessGranted('read', $category);
|
$this->denyAccessUnlessGranted('read', $category);
|
||||||
} else {
|
} else {
|
||||||
$this->denyAccessUnlessGranted('@categories.read');
|
$this->denyAccessUnlessGranted('@categories.read');
|
||||||
|
|
|
@ -151,7 +151,7 @@ class LogController extends AbstractController
|
||||||
|
|
||||||
if (EventUndoMode::UNDO === $mode) {
|
if (EventUndoMode::UNDO === $mode) {
|
||||||
$this->undoLog($log_element);
|
$this->undoLog($log_element);
|
||||||
} elseif (EventUndoMode::REVERT === $mode) {
|
} else {
|
||||||
$this->revertLog($log_element);
|
$this->revertLog($log_element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ class OAuthClientController extends AbstractController
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/{name}/check', name: 'oauth_client_check')]
|
#[Route('/{name}/check', name: 'oauth_client_check')]
|
||||||
public function check(string $name, Request $request): Response
|
public function check(string $name): Response
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('@system.manage_oauth_tokens');
|
$this->denyAccessUnlessGranted('@system.manage_oauth_tokens');
|
||||||
|
|
||||||
|
|
|
@ -329,7 +329,7 @@ class PartController extends AbstractController
|
||||||
$this->em->flush();
|
$this->em->flush();
|
||||||
if ($mode === 'new') {
|
if ($mode === 'new') {
|
||||||
$this->addFlash('success', 'part.created_flash');
|
$this->addFlash('success', 'part.created_flash');
|
||||||
} else if ($mode === 'edit') {
|
} elseif ($mode === 'edit') {
|
||||||
$this->addFlash('success', 'part.edited_flash');
|
$this->addFlash('success', 'part.edited_flash');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,11 +358,11 @@ class PartController extends AbstractController
|
||||||
$template = '';
|
$template = '';
|
||||||
if ($mode === 'new') {
|
if ($mode === 'new') {
|
||||||
$template = 'parts/edit/new_part.html.twig';
|
$template = 'parts/edit/new_part.html.twig';
|
||||||
} else if ($mode === 'edit') {
|
} elseif ($mode === 'edit') {
|
||||||
$template = 'parts/edit/edit_part_info.html.twig';
|
$template = 'parts/edit/edit_part_info.html.twig';
|
||||||
} else if ($mode === 'merge') {
|
} elseif ($mode === 'merge') {
|
||||||
$template = 'parts/edit/merge_parts.html.twig';
|
$template = 'parts/edit/merge_parts.html.twig';
|
||||||
} else if ($mode === 'update_from_ip') {
|
} elseif ($mode === 'update_from_ip') {
|
||||||
$template = 'parts/edit/update_from_ip.html.twig';
|
$template = 'parts/edit/update_from_ip.html.twig';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -207,6 +207,11 @@ class ProjectController extends AbstractController
|
||||||
//Preset the BOM entries with the selected parts, when the form was not submitted yet
|
//Preset the BOM entries with the selected parts, when the form was not submitted yet
|
||||||
$preset_data = new ArrayCollection();
|
$preset_data = new ArrayCollection();
|
||||||
foreach (explode(',', (string) $request->get('parts', '')) as $part_id) {
|
foreach (explode(',', (string) $request->get('parts', '')) as $part_id) {
|
||||||
|
//Skip empty part IDs. Postgres seems to be especially sensitive to empty strings, as it does not allow them in integer columns
|
||||||
|
if ($part_id === '') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$part = $entityManager->getRepository(Part::class)->find($part_id);
|
$part = $entityManager->getRepository(Part::class)->find($part_id);
|
||||||
if (null !== $part) {
|
if (null !== $part) {
|
||||||
//If there is already a BOM entry for this part, we use this one (we edit it then)
|
//If there is already a BOM entry for this part, we use this one (we edit it then)
|
||||||
|
@ -214,7 +219,7 @@ class ProjectController extends AbstractController
|
||||||
'project' => $project,
|
'project' => $project,
|
||||||
'part' => $part
|
'part' => $part
|
||||||
]);
|
]);
|
||||||
if ($bom_entry) {
|
if ($bom_entry !== null) {
|
||||||
$preset_data->add($bom_entry);
|
$preset_data->add($bom_entry);
|
||||||
} else { //Otherwise create an empty one
|
} else { //Otherwise create an empty one
|
||||||
$entry = new ProjectBOMEntry();
|
$entry = new ProjectBOMEntry();
|
||||||
|
|
|
@ -54,6 +54,9 @@ use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
|
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see \App\Tests\Controller\ScanControllerTest
|
||||||
|
*/
|
||||||
#[Route(path: '/scan')]
|
#[Route(path: '/scan')]
|
||||||
class ScanController extends AbstractController
|
class ScanController extends AbstractController
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
||||||
*/
|
*/
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use Symfony\Component\Runtime\SymfonyRuntime;
|
||||||
use App\Services\Attachments\AttachmentSubmitHandler;
|
use App\Services\Attachments\AttachmentSubmitHandler;
|
||||||
use App\Services\Attachments\AttachmentURLGenerator;
|
use App\Services\Attachments\AttachmentURLGenerator;
|
||||||
use App\Services\Attachments\BuiltinAttachmentsFinder;
|
use App\Services\Attachments\BuiltinAttachmentsFinder;
|
||||||
|
@ -86,7 +87,7 @@ class ToolsController extends AbstractController
|
||||||
'php_post_max_size' => ini_get('post_max_size'),
|
'php_post_max_size' => ini_get('post_max_size'),
|
||||||
'kernel_runtime_environment' => $this->getParameter('kernel.runtime_environment'),
|
'kernel_runtime_environment' => $this->getParameter('kernel.runtime_environment'),
|
||||||
'kernel_runtime_mode' => $this->getParameter('kernel.runtime_mode'),
|
'kernel_runtime_mode' => $this->getParameter('kernel.runtime_mode'),
|
||||||
'kernel_runtime' => $_SERVER['APP_RUNTIME'] ?? $_ENV['APP_RUNTIME'] ?? 'Symfony\\Component\\Runtime\\SymfonyRuntime',
|
'kernel_runtime' => $_SERVER['APP_RUNTIME'] ?? $_ENV['APP_RUNTIME'] ?? SymfonyRuntime::class,
|
||||||
|
|
||||||
//DB section
|
//DB section
|
||||||
'db_type' => $DBInfoHelper->getDatabaseType() ?? 'Unknown',
|
'db_type' => $DBInfoHelper->getDatabaseType() ?? 'Unknown',
|
||||||
|
|
|
@ -38,7 +38,6 @@ use Doctrine\ORM\EntityManagerInterface;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Google\GoogleAuthenticatorInterface;
|
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Google\GoogleAuthenticatorInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
|
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\EnumType;
|
use Symfony\Component\Form\Extension\Core\Type\EnumType;
|
||||||
|
@ -59,11 +58,8 @@ use Symfony\Component\Validator\Constraints\Length;
|
||||||
#[Route(path: '/user')]
|
#[Route(path: '/user')]
|
||||||
class UserSettingsController extends AbstractController
|
class UserSettingsController extends AbstractController
|
||||||
{
|
{
|
||||||
protected EventDispatcher|EventDispatcherInterface $eventDispatcher;
|
public function __construct(protected bool $demo_mode, protected EventDispatcherInterface $eventDispatcher)
|
||||||
|
|
||||||
public function __construct(protected bool $demo_mode, EventDispatcherInterface $eventDispatcher)
|
|
||||||
{
|
{
|
||||||
$this->eventDispatcher = $eventDispatcher;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route(path: '/2fa_backup_codes', name: 'show_backup_codes')]
|
#[Route(path: '/2fa_backup_codes', name: 'show_backup_codes')]
|
||||||
|
|
|
@ -74,30 +74,37 @@ class DataStructureFixtures extends Fixture implements DependentFixtureInterface
|
||||||
/** @var AbstractStructuralDBElement $node1 */
|
/** @var AbstractStructuralDBElement $node1 */
|
||||||
$node1 = new $class();
|
$node1 = new $class();
|
||||||
$node1->setName('Node 1');
|
$node1->setName('Node 1');
|
||||||
|
$this->addReference($class . '_1', $node1);
|
||||||
|
|
||||||
/** @var AbstractStructuralDBElement $node2 */
|
/** @var AbstractStructuralDBElement $node2 */
|
||||||
$node2 = new $class();
|
$node2 = new $class();
|
||||||
$node2->setName('Node 2');
|
$node2->setName('Node 2');
|
||||||
|
$this->addReference($class . '_2', $node2);
|
||||||
|
|
||||||
/** @var AbstractStructuralDBElement $node3 */
|
/** @var AbstractStructuralDBElement $node3 */
|
||||||
$node3 = new $class();
|
$node3 = new $class();
|
||||||
$node3->setName('Node 3');
|
$node3->setName('Node 3');
|
||||||
|
$this->addReference($class . '_3', $node3);
|
||||||
|
|
||||||
$node1_1 = new $class();
|
$node1_1 = new $class();
|
||||||
$node1_1->setName('Node 1.1');
|
$node1_1->setName('Node 1.1');
|
||||||
$node1_1->setParent($node1);
|
$node1_1->setParent($node1);
|
||||||
|
$this->addReference($class . '_4', $node1_1);
|
||||||
|
|
||||||
$node1_2 = new $class();
|
$node1_2 = new $class();
|
||||||
$node1_2->setName('Node 1.2');
|
$node1_2->setName('Node 1.2');
|
||||||
$node1_2->setParent($node1);
|
$node1_2->setParent($node1);
|
||||||
|
$this->addReference($class . '_5', $node1_2);
|
||||||
|
|
||||||
$node2_1 = new $class();
|
$node2_1 = new $class();
|
||||||
$node2_1->setName('Node 2.1');
|
$node2_1->setName('Node 2.1');
|
||||||
$node2_1->setParent($node2);
|
$node2_1->setParent($node2);
|
||||||
|
$this->addReference($class . '_6', $node2_1);
|
||||||
|
|
||||||
$node1_1_1 = new $class();
|
$node1_1_1 = new $class();
|
||||||
$node1_1_1->setName('Node 1.1.1');
|
$node1_1_1->setName('Node 1.1.1');
|
||||||
$node1_1_1->setParent($node1_1);
|
$node1_1_1->setParent($node1_1);
|
||||||
|
$this->addReference($class . '_7', $node1_1_1);
|
||||||
|
|
||||||
$manager->persist($node1);
|
$manager->persist($node1);
|
||||||
$manager->persist($node2);
|
$manager->persist($node2);
|
||||||
|
|
106
src/DataFixtures/LogEntryFixtures.php
Normal file
106
src/DataFixtures/LogEntryFixtures.php
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
|
||||||
|
namespace App\DataFixtures;
|
||||||
|
|
||||||
|
use App\Entity\LogSystem\ElementCreatedLogEntry;
|
||||||
|
use App\Entity\LogSystem\ElementDeletedLogEntry;
|
||||||
|
use App\Entity\LogSystem\ElementEditedLogEntry;
|
||||||
|
use App\Entity\Parts\Category;
|
||||||
|
use App\Entity\UserSystem\User;
|
||||||
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
|
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||||
|
use Doctrine\Persistence\ObjectManager;
|
||||||
|
|
||||||
|
class LogEntryFixtures extends Fixture implements DependentFixtureInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
public function load(ObjectManager $manager)
|
||||||
|
{
|
||||||
|
$this->createCategoryEntries($manager);
|
||||||
|
$this->createDeletedCategory($manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createCategoryEntries(ObjectManager $manager): void
|
||||||
|
{
|
||||||
|
$category = $this->getReference(Category::class . '_1', Category::class);
|
||||||
|
|
||||||
|
$logEntry = new ElementCreatedLogEntry($category);
|
||||||
|
$logEntry->setTimestamp(new \DateTimeImmutable("+1 second"));
|
||||||
|
$logEntry->setUser($this->getReference(UserFixtures::ADMIN, User::class));
|
||||||
|
$logEntry->setComment('Test');
|
||||||
|
$manager->persist($logEntry);
|
||||||
|
|
||||||
|
$logEntry = new ElementEditedLogEntry($category);
|
||||||
|
$logEntry->setTimestamp(new \DateTimeImmutable("+2 second"));
|
||||||
|
$logEntry->setUser($this->getReference(UserFixtures::ADMIN, User::class));
|
||||||
|
$logEntry->setComment('Test');
|
||||||
|
|
||||||
|
$logEntry->setOldData(['name' => 'Test']);
|
||||||
|
$logEntry->setNewData(['name' => 'Node 1.1']);
|
||||||
|
|
||||||
|
$manager->persist($logEntry);
|
||||||
|
$manager->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createDeletedCategory(ObjectManager $manager): void
|
||||||
|
{
|
||||||
|
//We create a fictive category to test the deletion
|
||||||
|
$category = new Category();
|
||||||
|
$category->setName('Node 100');
|
||||||
|
|
||||||
|
//Assume a category with id 100 was deleted
|
||||||
|
$reflClass = new \ReflectionClass($category);
|
||||||
|
$reflClass->getProperty('id')->setValue($category, 100);
|
||||||
|
|
||||||
|
//The whole lifecycle from creation to deletion
|
||||||
|
$logEntry = new ElementCreatedLogEntry($category);
|
||||||
|
$logEntry->setUser($this->getReference(UserFixtures::ADMIN, User::class));
|
||||||
|
$logEntry->setComment('Creation');
|
||||||
|
$manager->persist($logEntry);
|
||||||
|
|
||||||
|
$logEntry = new ElementEditedLogEntry($category);
|
||||||
|
$logEntry->setTimestamp(new \DateTimeImmutable("+1 second"));
|
||||||
|
$logEntry->setUser($this->getReference(UserFixtures::ADMIN, User::class));
|
||||||
|
$logEntry->setComment('Edit');
|
||||||
|
$logEntry->setOldData(['name' => 'Test']);
|
||||||
|
$logEntry->setNewData(['name' => 'Node 100']);
|
||||||
|
$manager->persist($logEntry);
|
||||||
|
|
||||||
|
$logEntry = new ElementDeletedLogEntry($category);
|
||||||
|
$logEntry->setTimestamp(new \DateTimeImmutable("+2 second"));
|
||||||
|
$logEntry->setUser($this->getReference(UserFixtures::ADMIN, User::class));
|
||||||
|
$logEntry->setOldData(['name' => 'Node 100', 'id' => 100, 'comment' => 'Test comment']);
|
||||||
|
$manager->persist($logEntry);
|
||||||
|
|
||||||
|
$manager->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDependencies(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
UserFixtures::class,
|
||||||
|
DataStructureFixtures::class
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
|
@ -73,6 +73,7 @@ class PartFixtures extends Fixture implements DependentFixtureInterface
|
||||||
$part = new Part();
|
$part = new Part();
|
||||||
$part->setName('Part 1');
|
$part->setName('Part 1');
|
||||||
$part->setCategory($manager->find(Category::class, 1));
|
$part->setCategory($manager->find(Category::class, 1));
|
||||||
|
$this->addReference(Part::class . '_1', $part);
|
||||||
$manager->persist($part);
|
$manager->persist($part);
|
||||||
|
|
||||||
/** More complex part */
|
/** More complex part */
|
||||||
|
@ -86,6 +87,7 @@ class PartFixtures extends Fixture implements DependentFixtureInterface
|
||||||
$part->setIpn('IPN123');
|
$part->setIpn('IPN123');
|
||||||
$part->setNeedsReview(true);
|
$part->setNeedsReview(true);
|
||||||
$part->setManufacturingStatus(ManufacturingStatus::ACTIVE);
|
$part->setManufacturingStatus(ManufacturingStatus::ACTIVE);
|
||||||
|
$this->addReference(Part::class . '_2', $part);
|
||||||
$manager->persist($part);
|
$manager->persist($part);
|
||||||
|
|
||||||
/** Part with orderdetails, storelocations and Attachments */
|
/** Part with orderdetails, storelocations and Attachments */
|
||||||
|
@ -98,8 +100,9 @@ class PartFixtures extends Fixture implements DependentFixtureInterface
|
||||||
$partLot1->setStorageLocation($manager->find(StorageLocation::class, 1));
|
$partLot1->setStorageLocation($manager->find(StorageLocation::class, 1));
|
||||||
$part->addPartLot($partLot1);
|
$part->addPartLot($partLot1);
|
||||||
|
|
||||||
|
|
||||||
$partLot2 = new PartLot();
|
$partLot2 = new PartLot();
|
||||||
$partLot2->setExpirationDate(new DateTime());
|
$partLot2->setExpirationDate(new \DateTimeImmutable());
|
||||||
$partLot2->setComment('Test');
|
$partLot2->setComment('Test');
|
||||||
$partLot2->setNeedsRefill(true);
|
$partLot2->setNeedsRefill(true);
|
||||||
$partLot2->setStorageLocation($manager->find(StorageLocation::class, 3));
|
$partLot2->setStorageLocation($manager->find(StorageLocation::class, 3));
|
||||||
|
@ -133,6 +136,8 @@ class PartFixtures extends Fixture implements DependentFixtureInterface
|
||||||
$attachment->setAttachmentType($manager->find(AttachmentType::class, 1));
|
$attachment->setAttachmentType($manager->find(AttachmentType::class, 1));
|
||||||
$part->addAttachment($attachment);
|
$part->addAttachment($attachment);
|
||||||
|
|
||||||
|
$this->addReference(Part::class . '_3', $part);
|
||||||
|
|
||||||
$manager->persist($part);
|
$manager->persist($part);
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,6 @@ class CustomFetchJoinORMAdapter extends FetchJoinORMAdapter
|
||||||
|
|
||||||
$paginator = new Paginator($qb_without_group_by);
|
$paginator = new Paginator($qb_without_group_by);
|
||||||
|
|
||||||
return $paginator->count() ?? 0;
|
return $paginator->count();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\DataTables\Adapters;
|
namespace App\DataTables\Adapters;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Query\Expr\From;
|
||||||
use Doctrine\ORM\Query;
|
use Doctrine\ORM\Query;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Doctrine\ORM\Tools\Pagination\Paginator;
|
use Doctrine\ORM\Tools\Pagination\Paginator;
|
||||||
|
@ -51,12 +52,12 @@ class TwoStepORMAdapter extends ORMAdapter
|
||||||
|
|
||||||
private bool $use_simple_total = false;
|
private bool $use_simple_total = false;
|
||||||
|
|
||||||
private \Closure|null $query_modifier;
|
private \Closure|null $query_modifier = null;
|
||||||
|
|
||||||
public function __construct(ManagerRegistry $registry = null)
|
public function __construct(ManagerRegistry $registry = null)
|
||||||
{
|
{
|
||||||
parent::__construct($registry);
|
parent::__construct($registry);
|
||||||
$this->detailQueryCallable = static function (QueryBuilder $qb, array $ids) {
|
$this->detailQueryCallable = static function (QueryBuilder $qb, array $ids): never {
|
||||||
throw new \RuntimeException('You need to set the detail_query option to use the TwoStepORMAdapter');
|
throw new \RuntimeException('You need to set the detail_query option to use the TwoStepORMAdapter');
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -66,9 +67,7 @@ class TwoStepORMAdapter extends ORMAdapter
|
||||||
parent::configureOptions($resolver);
|
parent::configureOptions($resolver);
|
||||||
|
|
||||||
$resolver->setRequired('filter_query');
|
$resolver->setRequired('filter_query');
|
||||||
$resolver->setDefault('query', function (Options $options) {
|
$resolver->setDefault('query', fn(Options $options) => $options['filter_query']);
|
||||||
return $options['filter_query'];
|
|
||||||
});
|
|
||||||
|
|
||||||
$resolver->setRequired('detail_query');
|
$resolver->setRequired('detail_query');
|
||||||
$resolver->setAllowedTypes('detail_query', \Closure::class);
|
$resolver->setAllowedTypes('detail_query', \Closure::class);
|
||||||
|
@ -108,7 +107,7 @@ class TwoStepORMAdapter extends ORMAdapter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var Query\Expr\From $fromClause */
|
/** @var From $fromClause */
|
||||||
$fromClause = $builder->getDQLPart('from')[0];
|
$fromClause = $builder->getDQLPart('from')[0];
|
||||||
$identifier = "{$fromClause->getAlias()}.{$this->metadata->getSingleIdentifierFieldName()}";
|
$identifier = "{$fromClause->getAlias()}.{$this->metadata->getSingleIdentifierFieldName()}";
|
||||||
|
|
||||||
|
@ -129,6 +128,12 @@ class TwoStepORMAdapter extends ORMAdapter
|
||||||
$query->setIdentifierPropertyPath($this->mapFieldToPropertyPath($identifier, $aliases));
|
$query->setIdentifierPropertyPath($this->mapFieldToPropertyPath($identifier, $aliases));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function hasGroupByPart(string $identifier, array $gbList): bool
|
||||||
|
{
|
||||||
|
//Always return true, to fix the issue with the count query, when having mutliple group by parts
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected function getCount(QueryBuilder $queryBuilder, $identifier): int
|
protected function getCount(QueryBuilder $queryBuilder, $identifier): int
|
||||||
{
|
{
|
||||||
if ($this->query_modifier !== null) {
|
if ($this->query_modifier !== null) {
|
||||||
|
@ -195,7 +200,7 @@ class TwoStepORMAdapter extends ORMAdapter
|
||||||
/** The paginator count queries can be rather slow, so when query for total count (100ms or longer),
|
/** The paginator count queries can be rather slow, so when query for total count (100ms or longer),
|
||||||
* just return the entity count.
|
* just return the entity count.
|
||||||
*/
|
*/
|
||||||
/** @var Query\Expr\From $from_expr */
|
/** @var From $from_expr */
|
||||||
$from_expr = $queryBuilder->getDQLPart('from')[0];
|
$from_expr = $queryBuilder->getDQLPart('from')[0];
|
||||||
|
|
||||||
return $this->manager->getRepository($from_expr->getFrom())->count([]);
|
return $this->manager->getRepository($from_expr->getFrom())->count([]);
|
||||||
|
|
|
@ -86,12 +86,13 @@ final class AttachmentDataTable implements DataTableTypeInterface
|
||||||
|
|
||||||
$dataTable->add('name', TextColumn::class, [
|
$dataTable->add('name', TextColumn::class, [
|
||||||
'label' => 'attachment.edit.name',
|
'label' => 'attachment.edit.name',
|
||||||
|
'orderField' => 'NATSORT(attachment.name)',
|
||||||
'render' => function ($value, Attachment $context) {
|
'render' => function ($value, Attachment $context) {
|
||||||
//Link to external source
|
//Link to external source
|
||||||
if ($context->isExternal()) {
|
if ($context->isExternal()) {
|
||||||
return sprintf(
|
return sprintf(
|
||||||
'<a href="%s" class="link-external">%s</a>',
|
'<a href="%s" class="link-external">%s</a>',
|
||||||
htmlspecialchars($context->getURL()),
|
htmlspecialchars((string) $context->getURL()),
|
||||||
htmlspecialchars($value)
|
htmlspecialchars($value)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -111,6 +112,7 @@ final class AttachmentDataTable implements DataTableTypeInterface
|
||||||
$dataTable->add('attachment_type', TextColumn::class, [
|
$dataTable->add('attachment_type', TextColumn::class, [
|
||||||
'label' => 'attachment.table.type',
|
'label' => 'attachment.table.type',
|
||||||
'field' => 'attachment_type.name',
|
'field' => 'attachment_type.name',
|
||||||
|
'orderField' => 'NATSORT(attachment_type.name)',
|
||||||
'render' => fn($value, Attachment $context): string => sprintf(
|
'render' => fn($value, Attachment $context): string => sprintf(
|
||||||
'<a href="%s">%s</a>',
|
'<a href="%s">%s</a>',
|
||||||
$this->entityURLGenerator->editURL($context->getAttachmentType()),
|
$this->entityURLGenerator->editURL($context->getAttachmentType()),
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||||
*
|
*
|
||||||
|
@ -17,7 +20,6 @@
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace App\DataTables\Column;
|
namespace App\DataTables\Column;
|
||||||
|
|
||||||
use Omines\DataTablesBundle\Column\AbstractColumn;
|
use Omines\DataTablesBundle\Column\AbstractColumn;
|
||||||
|
|
|
@ -47,7 +47,7 @@ class LocaleDateTimeColumn extends AbstractColumn
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$value instanceof DateTimeInterface) {
|
if (!$value instanceof DateTimeInterface) {
|
||||||
$value = new DateTime((string) $value);
|
$value = new \DateTimeImmutable((string) $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
$formatValues = [
|
$formatValues = [
|
||||||
|
|
|
@ -22,9 +22,92 @@ declare(strict_types=1);
|
||||||
*/
|
*/
|
||||||
namespace App\DataTables\Filters\Constraints;
|
namespace App\DataTables\Filters\Constraints;
|
||||||
|
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An alias of NumberConstraint to use to filter on a DateTime
|
* Similar to NumberConstraint but for DateTime values
|
||||||
*/
|
*/
|
||||||
class DateTimeConstraint extends NumberConstraint
|
class DateTimeConstraint extends AbstractConstraint
|
||||||
{
|
{
|
||||||
|
protected const ALLOWED_OPERATOR_VALUES = ['=', '!=', '<', '>', '<=', '>=', 'BETWEEN'];
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
string $property,
|
||||||
|
string $identifier = null,
|
||||||
|
/**
|
||||||
|
* The value1 used for comparison (this is the main one used for all mono-value comparisons)
|
||||||
|
*/
|
||||||
|
protected \DateTimeInterface|null $value1 = null,
|
||||||
|
protected ?string $operator = null,
|
||||||
|
/**
|
||||||
|
* The second value used when operator is RANGE; this is the upper bound of the range
|
||||||
|
*/
|
||||||
|
protected \DateTimeInterface|null $value2 = null)
|
||||||
|
{
|
||||||
|
parent::__construct($property, $identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getValue1(): ?\DateTimeInterface
|
||||||
|
{
|
||||||
|
return $this->value1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setValue1(\DateTimeInterface|null $value1): void
|
||||||
|
{
|
||||||
|
$this->value1 = $value1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getValue2(): ?\DateTimeInterface
|
||||||
|
{
|
||||||
|
return $this->value2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setValue2(?\DateTimeInterface $value2): void
|
||||||
|
{
|
||||||
|
$this->value2 = $value2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOperator(): string|null
|
||||||
|
{
|
||||||
|
return $this->operator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $operator
|
||||||
|
*/
|
||||||
|
public function setOperator(?string $operator): void
|
||||||
|
{
|
||||||
|
$this->operator = $operator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isEnabled(): bool
|
||||||
|
{
|
||||||
|
return $this->value1 !== null
|
||||||
|
&& ($this->operator !== null && $this->operator !== '');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function apply(QueryBuilder $queryBuilder): void
|
||||||
|
{
|
||||||
|
//If no value is provided then we do not apply a filter
|
||||||
|
if (!$this->isEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Ensure we have an valid operator
|
||||||
|
if(!in_array($this->operator, self::ALLOWED_OPERATOR_VALUES, true)) {
|
||||||
|
throw new \RuntimeException('Invalid operator '. $this->operator . ' provided. Valid operators are '. implode(', ', self::ALLOWED_OPERATOR_VALUES));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->operator !== 'BETWEEN') {
|
||||||
|
$this->addSimpleAndConstraint($queryBuilder, $this->property, $this->identifier, $this->operator, $this->value1);
|
||||||
|
} else {
|
||||||
|
if ($this->value2 === null) {
|
||||||
|
throw new RuntimeException("Cannot use operator BETWEEN without value2!");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->addSimpleAndConstraint($queryBuilder, $this->property, $this->identifier . '1', '>=', $this->value1);
|
||||||
|
$this->addSimpleAndConstraint($queryBuilder, $this->property, $this->identifier . '2', '<=', $this->value2);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,12 +29,28 @@ class NumberConstraint extends AbstractConstraint
|
||||||
{
|
{
|
||||||
protected const ALLOWED_OPERATOR_VALUES = ['=', '!=', '<', '>', '<=', '>=', 'BETWEEN'];
|
protected const ALLOWED_OPERATOR_VALUES = ['=', '!=', '<', '>', '<=', '>=', 'BETWEEN'];
|
||||||
|
|
||||||
public function getValue1(): float|int|null|\DateTimeInterface
|
public function __construct(
|
||||||
|
string $property,
|
||||||
|
string $identifier = null,
|
||||||
|
/**
|
||||||
|
* The value1 used for comparison (this is the main one used for all mono-value comparisons)
|
||||||
|
*/
|
||||||
|
protected float|int|null $value1 = null,
|
||||||
|
protected ?string $operator = null,
|
||||||
|
/**
|
||||||
|
* The second value used when operator is RANGE; this is the upper bound of the range
|
||||||
|
*/
|
||||||
|
protected float|int|null $value2 = null)
|
||||||
|
{
|
||||||
|
parent::__construct($property, $identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getValue1(): float|int|null
|
||||||
{
|
{
|
||||||
return $this->value1;
|
return $this->value1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setValue1(float|int|\DateTimeInterface|null $value1): void
|
public function setValue1(float|int|null $value1): void
|
||||||
{
|
{
|
||||||
$this->value1 = $value1;
|
$this->value1 = $value1;
|
||||||
}
|
}
|
||||||
|
@ -63,22 +79,6 @@ class NumberConstraint extends AbstractConstraint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
string $property,
|
|
||||||
string $identifier = null,
|
|
||||||
/**
|
|
||||||
* The value1 used for comparison (this is the main one used for all mono-value comparisons)
|
|
||||||
*/
|
|
||||||
protected float|int|\DateTimeInterface|null $value1 = null,
|
|
||||||
protected ?string $operator = null,
|
|
||||||
/**
|
|
||||||
* The second value used when operator is RANGE; this is the upper bound of the range
|
|
||||||
*/
|
|
||||||
protected float|int|\DateTimeInterface|null $value2 = null)
|
|
||||||
{
|
|
||||||
parent::__construct($property, $identifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isEnabled(): bool
|
public function isEnabled(): bool
|
||||||
{
|
{
|
||||||
return $this->value1 !== null
|
return $this->value1 !== null
|
||||||
|
@ -105,7 +105,13 @@ class NumberConstraint extends AbstractConstraint
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addSimpleAndConstraint($queryBuilder, $this->property, $this->identifier . '1', '>=', $this->value1);
|
$this->addSimpleAndConstraint($queryBuilder, $this->property, $this->identifier . '1', '>=', $this->value1);
|
||||||
$this->addSimpleAndConstraint($queryBuilder, $this->property, $this->identifier . '2', '<=', $this->value2);
|
|
||||||
|
//Workaround for the amountSum which we need to add twice on postgres. Replace one of the __ with __2 to make it work
|
||||||
|
//Otherwise we get an error, that __partLot was already defined
|
||||||
|
|
||||||
|
$property2 = str_replace('__', '__2', $this->property);
|
||||||
|
|
||||||
|
$this->addSimpleAndConstraint($queryBuilder, $property2, $this->identifier . '2', '<=', $this->value2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,13 +23,20 @@ declare(strict_types=1);
|
||||||
namespace App\DataTables\Filters\Constraints\Part;
|
namespace App\DataTables\Filters\Constraints\Part;
|
||||||
|
|
||||||
use App\DataTables\Filters\Constraints\BooleanConstraint;
|
use App\DataTables\Filters\Constraints\BooleanConstraint;
|
||||||
|
use App\Entity\Parts\PartLot;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
|
||||||
class LessThanDesiredConstraint extends BooleanConstraint
|
class LessThanDesiredConstraint extends BooleanConstraint
|
||||||
{
|
{
|
||||||
public function __construct(string $property = null, string $identifier = null, ?bool $default_value = null)
|
public function __construct(string $property = null, string $identifier = null, ?bool $default_value = null)
|
||||||
{
|
{
|
||||||
parent::__construct($property ?? 'amountSum', $identifier, $default_value);
|
parent::__construct($property ?? '(
|
||||||
|
SELECT COALESCE(SUM(ld_partLot.amount), 0.0)
|
||||||
|
FROM '.PartLot::class.' ld_partLot
|
||||||
|
WHERE ld_partLot.part = part.id
|
||||||
|
AND ld_partLot.instock_unknown = false
|
||||||
|
AND (ld_partLot.expiration_date IS NULL OR ld_partLot.expiration_date > CURRENT_DATE())
|
||||||
|
)', $identifier ?? 'amountSumLessThanDesired', $default_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function apply(QueryBuilder $queryBuilder): void
|
public function apply(QueryBuilder $queryBuilder): void
|
||||||
|
@ -41,9 +48,9 @@ class LessThanDesiredConstraint extends BooleanConstraint
|
||||||
|
|
||||||
//If value is true, we want to filter for parts with stock < desired stock
|
//If value is true, we want to filter for parts with stock < desired stock
|
||||||
if ($this->value) {
|
if ($this->value) {
|
||||||
$queryBuilder->andHaving('amountSum < minamount');
|
$queryBuilder->andHaving( $this->property . ' < part.minamount');
|
||||||
} else {
|
} else {
|
||||||
$queryBuilder->andHaving('amountSum >= minamount');
|
$queryBuilder->andHaving($this->property . ' >= part.minamount');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,16 +30,9 @@ class TagsConstraint extends AbstractConstraint
|
||||||
{
|
{
|
||||||
final public const ALLOWED_OPERATOR_VALUES = ['ANY', 'ALL', 'NONE'];
|
final public const ALLOWED_OPERATOR_VALUES = ['ANY', 'ALL', 'NONE'];
|
||||||
|
|
||||||
/**
|
public function __construct(string $property, string $identifier = null,
|
||||||
* @param string $value
|
protected ?string $value = null,
|
||||||
*/
|
protected ?string $operator = '')
|
||||||
public function __construct(string $property, string $identifier = null, /**
|
|
||||||
* @var string The value to compare to
|
|
||||||
*/
|
|
||||||
protected $value = null, /**
|
|
||||||
* @var string|null The operator to use
|
|
||||||
*/
|
|
||||||
protected ?string $operator = '')
|
|
||||||
{
|
{
|
||||||
parent::__construct($property, $identifier);
|
parent::__construct($property, $identifier);
|
||||||
}
|
}
|
||||||
|
@ -61,12 +54,12 @@ class TagsConstraint extends AbstractConstraint
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getValue(): string
|
public function getValue(): ?string
|
||||||
{
|
{
|
||||||
return $this->value;
|
return $this->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setValue(string $value): self
|
public function setValue(?string $value): self
|
||||||
{
|
{
|
||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
return $this;
|
return $this;
|
||||||
|
|
|
@ -33,9 +33,9 @@ class TextConstraint extends AbstractConstraint
|
||||||
* @param string $value
|
* @param string $value
|
||||||
*/
|
*/
|
||||||
public function __construct(string $property, string $identifier = null, /**
|
public function __construct(string $property, string $identifier = null, /**
|
||||||
* @var string The value to compare to
|
* @var string|null The value to compare to
|
||||||
*/
|
*/
|
||||||
protected $value = null, /**
|
protected ?string $value = null, /**
|
||||||
* @var string|null The operator to use
|
* @var string|null The operator to use
|
||||||
*/
|
*/
|
||||||
protected ?string $operator = '')
|
protected ?string $operator = '')
|
||||||
|
@ -60,12 +60,12 @@ class TextConstraint extends AbstractConstraint
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getValue(): string
|
public function getValue(): ?string
|
||||||
{
|
{
|
||||||
return $this->value;
|
return $this->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setValue(string $value): self
|
public function setValue(?string $value): self
|
||||||
{
|
{
|
||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -113,7 +113,7 @@ class TextConstraint extends AbstractConstraint
|
||||||
|
|
||||||
//Regex is only supported on MySQL and needs a special function
|
//Regex is only supported on MySQL and needs a special function
|
||||||
if ($this->operator === 'REGEX') {
|
if ($this->operator === 'REGEX') {
|
||||||
$queryBuilder->andWhere(sprintf('REGEXP(%s, :%s) = 1', $this->property, $this->identifier));
|
$queryBuilder->andWhere(sprintf('REGEXP(%s, :%s) = TRUE', $this->property, $this->identifier));
|
||||||
$queryBuilder->setParameter($this->identifier, $this->value);
|
$queryBuilder->setParameter($this->identifier, $this->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ use App\Entity\Parts\Category;
|
||||||
use App\Entity\Parts\Footprint;
|
use App\Entity\Parts\Footprint;
|
||||||
use App\Entity\Parts\Manufacturer;
|
use App\Entity\Parts\Manufacturer;
|
||||||
use App\Entity\Parts\MeasurementUnit;
|
use App\Entity\Parts\MeasurementUnit;
|
||||||
|
use App\Entity\Parts\PartLot;
|
||||||
use App\Entity\Parts\StorageLocation;
|
use App\Entity\Parts\StorageLocation;
|
||||||
use App\Entity\Parts\Supplier;
|
use App\Entity\Parts\Supplier;
|
||||||
use App\Entity\ProjectSystem\Project;
|
use App\Entity\ProjectSystem\Project;
|
||||||
|
@ -123,8 +124,13 @@ class PartFilter implements FilterInterface
|
||||||
This seems to be related to the fact, that PDO does not have an float parameter type and using string type does not work in this situation (at least in SQLite)
|
This seems to be related to the fact, that PDO does not have an float parameter type and using string type does not work in this situation (at least in SQLite)
|
||||||
TODO: Find a better solution here
|
TODO: Find a better solution here
|
||||||
*/
|
*/
|
||||||
//We have to use Having here, as we use an alias column which is not supported on the where clause and would result in an error
|
$this->amountSum = (new IntConstraint('(
|
||||||
$this->amountSum = (new IntConstraint('amountSum'))->useHaving();
|
SELECT COALESCE(SUM(__partLot.amount), 0.0)
|
||||||
|
FROM '.PartLot::class.' __partLot
|
||||||
|
WHERE __partLot.part = part.id
|
||||||
|
AND __partLot.instock_unknown = false
|
||||||
|
AND (__partLot.expiration_date IS NULL OR __partLot.expiration_date > CURRENT_DATE())
|
||||||
|
)', identifier: "amountSumWhere"));
|
||||||
$this->lotCount = new IntConstraint('COUNT(_partLots)');
|
$this->lotCount = new IntConstraint('COUNT(_partLots)');
|
||||||
$this->lessThanDesired = new LessThanDesiredConstraint();
|
$this->lessThanDesired = new LessThanDesiredConstraint();
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,7 @@ class PartSearchFilter implements FilterInterface
|
||||||
//Convert the fields to search to a list of expressions
|
//Convert the fields to search to a list of expressions
|
||||||
$expressions = array_map(function (string $field): string {
|
$expressions = array_map(function (string $field): string {
|
||||||
if ($this->regex) {
|
if ($this->regex) {
|
||||||
return sprintf("REGEXP(%s, :search_query) = 1", $field);
|
return sprintf("REGEXP(%s, :search_query) = TRUE", $field);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sprintf("%s LIKE :search_query", $field);
|
return sprintf("%s LIKE :search_query", $field);
|
||||||
|
|
|
@ -109,7 +109,7 @@ class ColumnSortHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
//and the remaining non-visible columns
|
//and the remaining non-visible columns
|
||||||
foreach ($this->columns as $col_id => $col_data) {
|
foreach (array_keys($this->columns) as $col_id) {
|
||||||
if (in_array($col_id, $processed_columns, true)) {
|
if (in_array($col_id, $processed_columns, true)) {
|
||||||
// column already processed
|
// column already processed
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -154,7 +154,7 @@ class LogDataTable implements DataTableTypeInterface
|
||||||
|
|
||||||
$dataTable->add('user', TextColumn::class, [
|
$dataTable->add('user', TextColumn::class, [
|
||||||
'label' => 'log.user',
|
'label' => 'log.user',
|
||||||
'orderField' => 'user.name',
|
'orderField' => 'NATSORT(user.name)',
|
||||||
'render' => function ($value, AbstractLogEntry $context): string {
|
'render' => function ($value, AbstractLogEntry $context): string {
|
||||||
$user = $context->getUser();
|
$user = $context->getUser();
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ class LogDataTable implements DataTableTypeInterface
|
||||||
if (!$user instanceof User) {
|
if (!$user instanceof User) {
|
||||||
if ($context->isCLIEntry()) {
|
if ($context->isCLIEntry()) {
|
||||||
return sprintf('%s [%s]',
|
return sprintf('%s [%s]',
|
||||||
htmlentities($context->getCLIUsername()),
|
htmlentities((string) $context->getCLIUsername()),
|
||||||
$this->translator->trans('log.cli_user')
|
$this->translator->trans('log.cli_user')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,12 +108,14 @@ final class PartsDataTable implements DataTableTypeInterface
|
||||||
->add('name', TextColumn::class, [
|
->add('name', TextColumn::class, [
|
||||||
'label' => $this->translator->trans('part.table.name'),
|
'label' => $this->translator->trans('part.table.name'),
|
||||||
'render' => fn($value, Part $context) => $this->partDataTableHelper->renderName($context),
|
'render' => fn($value, Part $context) => $this->partDataTableHelper->renderName($context),
|
||||||
|
'orderField' => 'NATSORT(part.name)'
|
||||||
])
|
])
|
||||||
->add('id', TextColumn::class, [
|
->add('id', TextColumn::class, [
|
||||||
'label' => $this->translator->trans('part.table.id'),
|
'label' => $this->translator->trans('part.table.id'),
|
||||||
])
|
])
|
||||||
->add('ipn', TextColumn::class, [
|
->add('ipn', TextColumn::class, [
|
||||||
'label' => $this->translator->trans('part.table.ipn'),
|
'label' => $this->translator->trans('part.table.ipn'),
|
||||||
|
'orderField' => 'NATSORT(part.ipn)'
|
||||||
])
|
])
|
||||||
->add('description', MarkdownColumn::class, [
|
->add('description', MarkdownColumn::class, [
|
||||||
'label' => $this->translator->trans('part.table.description'),
|
'label' => $this->translator->trans('part.table.description'),
|
||||||
|
@ -121,23 +123,24 @@ final class PartsDataTable implements DataTableTypeInterface
|
||||||
->add('category', EntityColumn::class, [
|
->add('category', EntityColumn::class, [
|
||||||
'label' => $this->translator->trans('part.table.category'),
|
'label' => $this->translator->trans('part.table.category'),
|
||||||
'property' => 'category',
|
'property' => 'category',
|
||||||
'orderField' => '_category.name'
|
'orderField' => 'NATSORT(_category.name)'
|
||||||
])
|
])
|
||||||
->add('footprint', EntityColumn::class, [
|
->add('footprint', EntityColumn::class, [
|
||||||
'property' => 'footprint',
|
'property' => 'footprint',
|
||||||
'label' => $this->translator->trans('part.table.footprint'),
|
'label' => $this->translator->trans('part.table.footprint'),
|
||||||
'orderField' => '_footprint.name'
|
'orderField' => 'NATSORT(_footprint.name)'
|
||||||
])
|
])
|
||||||
->add('manufacturer', EntityColumn::class, [
|
->add('manufacturer', EntityColumn::class, [
|
||||||
'property' => 'manufacturer',
|
'property' => 'manufacturer',
|
||||||
'label' => $this->translator->trans('part.table.manufacturer'),
|
'label' => $this->translator->trans('part.table.manufacturer'),
|
||||||
'orderField' => '_manufacturer.name'
|
'orderField' => 'NATSORT(_manufacturer.name)'
|
||||||
])
|
])
|
||||||
->add('storelocation', TextColumn::class, [
|
->add('storelocation', TextColumn::class, [
|
||||||
'label' => $this->translator->trans('part.table.storeLocations'),
|
'label' => $this->translator->trans('part.table.storeLocations'),
|
||||||
'orderField' => '_storelocations.name',
|
'orderField' => 'NATSORT(_storelocations.name)',
|
||||||
'render' => fn ($value, Part $context) => $this->partDataTableHelper->renderStorageLocations($context),
|
'render' => fn ($value, Part $context) => $this->partDataTableHelper->renderStorageLocations($context),
|
||||||
], alias: 'storage_location')
|
], alias: 'storage_location')
|
||||||
|
|
||||||
->add('amount', TextColumn::class, [
|
->add('amount', TextColumn::class, [
|
||||||
'label' => $this->translator->trans('part.table.amount'),
|
'label' => $this->translator->trans('part.table.amount'),
|
||||||
'render' => fn ($value, Part $context) => $this->partDataTableHelper->renderAmount($context),
|
'render' => fn ($value, Part $context) => $this->partDataTableHelper->renderAmount($context),
|
||||||
|
@ -149,9 +152,21 @@ final class PartsDataTable implements DataTableTypeInterface
|
||||||
$context->getPartUnit())),
|
$context->getPartUnit())),
|
||||||
])
|
])
|
||||||
->add('partUnit', TextColumn::class, [
|
->add('partUnit', TextColumn::class, [
|
||||||
'field' => 'partUnit.name',
|
|
||||||
'label' => $this->translator->trans('part.table.partUnit'),
|
'label' => $this->translator->trans('part.table.partUnit'),
|
||||||
'orderField' => '_partUnit.name'
|
'orderField' => 'NATSORT(_partUnit.name)',
|
||||||
|
'render' => function($value, Part $context): string {
|
||||||
|
$partUnit = $context->getPartUnit();
|
||||||
|
if ($partUnit === null) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$tmp = htmlspecialchars($partUnit->getName());
|
||||||
|
|
||||||
|
if ($partUnit->getUnit()) {
|
||||||
|
$tmp .= ' ('.htmlspecialchars($partUnit->getUnit()).')';
|
||||||
|
}
|
||||||
|
return $tmp;
|
||||||
|
}
|
||||||
])
|
])
|
||||||
->add('addedDate', LocaleDateTimeColumn::class, [
|
->add('addedDate', LocaleDateTimeColumn::class, [
|
||||||
'label' => $this->translator->trans('part.table.addedDate'),
|
'label' => $this->translator->trans('part.table.addedDate'),
|
||||||
|
@ -169,7 +184,7 @@ final class PartsDataTable implements DataTableTypeInterface
|
||||||
'label' => $this->translator->trans('part.table.manufacturingStatus'),
|
'label' => $this->translator->trans('part.table.manufacturingStatus'),
|
||||||
'class' => ManufacturingStatus::class,
|
'class' => ManufacturingStatus::class,
|
||||||
'render' => function (?ManufacturingStatus $status, Part $context): string {
|
'render' => function (?ManufacturingStatus $status, Part $context): string {
|
||||||
if (!$status) {
|
if ($status === null) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,6 +193,7 @@ final class PartsDataTable implements DataTableTypeInterface
|
||||||
])
|
])
|
||||||
->add('manufacturer_product_number', TextColumn::class, [
|
->add('manufacturer_product_number', TextColumn::class, [
|
||||||
'label' => $this->translator->trans('part.table.mpn'),
|
'label' => $this->translator->trans('part.table.mpn'),
|
||||||
|
'orderField' => 'NATSORT(part.manufacturer_product_number)'
|
||||||
])
|
])
|
||||||
->add('mass', SIUnitNumberColumn::class, [
|
->add('mass', SIUnitNumberColumn::class, [
|
||||||
'label' => $this->translator->trans('part.table.mass'),
|
'label' => $this->translator->trans('part.table.mass'),
|
||||||
|
@ -264,8 +280,8 @@ final class PartsDataTable implements DataTableTypeInterface
|
||||||
->addSelect('part.minamount AS HIDDEN minamount')
|
->addSelect('part.minamount AS HIDDEN minamount')
|
||||||
->from(Part::class, 'part')
|
->from(Part::class, 'part')
|
||||||
|
|
||||||
//This must be the only group by, or the paginator will not work correctly
|
//The other group by fields, are dynamically added by the addJoins method
|
||||||
->addGroupBy('part.id');
|
->addGroupBy('part');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDetailQuery(QueryBuilder $builder, array $filter_results): void
|
private function getDetailQuery(QueryBuilder $builder, array $filter_results): void
|
||||||
|
@ -345,7 +361,7 @@ final class PartsDataTable implements DataTableTypeInterface
|
||||||
//Calculate amount sum using a subquery, so we can filter and sort by it
|
//Calculate amount sum using a subquery, so we can filter and sort by it
|
||||||
$builder->addSelect(
|
$builder->addSelect(
|
||||||
'(
|
'(
|
||||||
SELECT IFNULL(SUM(partLot.amount), 0.0)
|
SELECT COALESCE(SUM(partLot.amount), 0.0)
|
||||||
FROM '.PartLot::class.' partLot
|
FROM '.PartLot::class.' partLot
|
||||||
WHERE partLot.part = part.id
|
WHERE partLot.part = part.id
|
||||||
AND partLot.instock_unknown = false
|
AND partLot.instock_unknown = false
|
||||||
|
@ -356,35 +372,52 @@ final class PartsDataTable implements DataTableTypeInterface
|
||||||
|
|
||||||
if (str_contains($dql, '_category')) {
|
if (str_contains($dql, '_category')) {
|
||||||
$builder->leftJoin('part.category', '_category');
|
$builder->leftJoin('part.category', '_category');
|
||||||
|
$builder->addGroupBy('_category');
|
||||||
}
|
}
|
||||||
if (str_contains($dql, '_master_picture_attachment')) {
|
if (str_contains($dql, '_master_picture_attachment')) {
|
||||||
$builder->leftJoin('part.master_picture_attachment', '_master_picture_attachment');
|
$builder->leftJoin('part.master_picture_attachment', '_master_picture_attachment');
|
||||||
|
$builder->addGroupBy('_master_picture_attachment');
|
||||||
}
|
}
|
||||||
if (str_contains($dql, '_partLots') || str_contains($dql, '_storelocations')) {
|
if (str_contains($dql, '_partLots') || str_contains($dql, '_storelocations')) {
|
||||||
$builder->leftJoin('part.partLots', '_partLots');
|
$builder->leftJoin('part.partLots', '_partLots');
|
||||||
$builder->leftJoin('_partLots.storage_location', '_storelocations');
|
$builder->leftJoin('_partLots.storage_location', '_storelocations');
|
||||||
|
//Do not group by many-to-* relations, as it would restrict the COUNT having clauses to be maximum 1
|
||||||
|
//$builder->addGroupBy('_partLots');
|
||||||
|
//$builder->addGroupBy('_storelocations');
|
||||||
}
|
}
|
||||||
if (str_contains($dql, '_footprint')) {
|
if (str_contains($dql, '_footprint')) {
|
||||||
$builder->leftJoin('part.footprint', '_footprint');
|
$builder->leftJoin('part.footprint', '_footprint');
|
||||||
|
$builder->addGroupBy('_footprint');
|
||||||
}
|
}
|
||||||
if (str_contains($dql, '_manufacturer')) {
|
if (str_contains($dql, '_manufacturer')) {
|
||||||
$builder->leftJoin('part.manufacturer', '_manufacturer');
|
$builder->leftJoin('part.manufacturer', '_manufacturer');
|
||||||
|
$builder->addGroupBy('_manufacturer');
|
||||||
}
|
}
|
||||||
if (str_contains($dql, '_orderdetails') || str_contains($dql, '_suppliers')) {
|
if (str_contains($dql, '_orderdetails') || str_contains($dql, '_suppliers')) {
|
||||||
$builder->leftJoin('part.orderdetails', '_orderdetails');
|
$builder->leftJoin('part.orderdetails', '_orderdetails');
|
||||||
$builder->leftJoin('_orderdetails.supplier', '_suppliers');
|
$builder->leftJoin('_orderdetails.supplier', '_suppliers');
|
||||||
|
//Do not group by many-to-* relations, as it would restrict the COUNT having clauses to be maximum 1
|
||||||
|
//$builder->addGroupBy('_orderdetails');
|
||||||
|
//$builder->addGroupBy('_suppliers');
|
||||||
}
|
}
|
||||||
if (str_contains($dql, '_attachments')) {
|
if (str_contains($dql, '_attachments')) {
|
||||||
$builder->leftJoin('part.attachments', '_attachments');
|
$builder->leftJoin('part.attachments', '_attachments');
|
||||||
|
//Do not group by many-to-* relations, as it would restrict the COUNT having clauses to be maximum 1
|
||||||
|
//$builder->addGroupBy('_attachments');
|
||||||
}
|
}
|
||||||
if (str_contains($dql, '_partUnit')) {
|
if (str_contains($dql, '_partUnit')) {
|
||||||
$builder->leftJoin('part.partUnit', '_partUnit');
|
$builder->leftJoin('part.partUnit', '_partUnit');
|
||||||
|
$builder->addGroupBy('_partUnit');
|
||||||
}
|
}
|
||||||
if (str_contains($dql, '_parameters')) {
|
if (str_contains($dql, '_parameters')) {
|
||||||
$builder->leftJoin('part.parameters', '_parameters');
|
$builder->leftJoin('part.parameters', '_parameters');
|
||||||
|
//Do not group by many-to-* relations, as it would restrict the COUNT having clauses to be maximum 1
|
||||||
|
//$builder->addGroupBy('_parameters');
|
||||||
}
|
}
|
||||||
if (str_contains($dql, '_projectBomEntries')) {
|
if (str_contains($dql, '_projectBomEntries')) {
|
||||||
$builder->leftJoin('part.project_bom_entries', '_projectBomEntries');
|
$builder->leftJoin('part.project_bom_entries', '_projectBomEntries');
|
||||||
|
//Do not group by many-to-* relations, as it would restrict the COUNT having clauses to be maximum 1
|
||||||
|
//$builder->addGroupBy('_projectBomEntries');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $builder;
|
return $builder;
|
||||||
|
|
|
@ -82,10 +82,10 @@ class ProjectBomEntriesDataTable implements DataTableTypeInterface
|
||||||
|
|
||||||
->add('name', TextColumn::class, [
|
->add('name', TextColumn::class, [
|
||||||
'label' => $this->translator->trans('part.table.name'),
|
'label' => $this->translator->trans('part.table.name'),
|
||||||
'orderField' => 'part.name',
|
'orderField' => 'NATSORT(part.name)',
|
||||||
'render' => function ($value, ProjectBOMEntry $context) {
|
'render' => function ($value, ProjectBOMEntry $context) {
|
||||||
if(!$context->getPart() instanceof Part) {
|
if(!$context->getPart() instanceof Part) {
|
||||||
return htmlspecialchars($context->getName());
|
return htmlspecialchars((string) $context->getName());
|
||||||
}
|
}
|
||||||
if($context->getPart() instanceof Part) {
|
if($context->getPart() instanceof Part) {
|
||||||
$tmp = $this->partDataTableHelper->renderName($context->getPart());
|
$tmp = $this->partDataTableHelper->renderName($context->getPart());
|
||||||
|
@ -101,7 +101,7 @@ class ProjectBomEntriesDataTable implements DataTableTypeInterface
|
||||||
])
|
])
|
||||||
->add('ipn', TextColumn::class, [
|
->add('ipn', TextColumn::class, [
|
||||||
'label' => $this->translator->trans('part.table.ipn'),
|
'label' => $this->translator->trans('part.table.ipn'),
|
||||||
'orderField' => 'part.ipn',
|
'orderField' => 'NATSORT(part.ipn)',
|
||||||
'visible' => false,
|
'visible' => false,
|
||||||
'render' => function ($value, ProjectBOMEntry $context) {
|
'render' => function ($value, ProjectBOMEntry $context) {
|
||||||
if($context->getPart() instanceof Part) {
|
if($context->getPart() instanceof Part) {
|
||||||
|
@ -124,18 +124,18 @@ class ProjectBomEntriesDataTable implements DataTableTypeInterface
|
||||||
->add('category', EntityColumn::class, [
|
->add('category', EntityColumn::class, [
|
||||||
'label' => $this->translator->trans('part.table.category'),
|
'label' => $this->translator->trans('part.table.category'),
|
||||||
'property' => 'part.category',
|
'property' => 'part.category',
|
||||||
'orderField' => 'category.name',
|
'orderField' => 'NATSORT(category.name)',
|
||||||
])
|
])
|
||||||
->add('footprint', EntityColumn::class, [
|
->add('footprint', EntityColumn::class, [
|
||||||
'property' => 'part.footprint',
|
'property' => 'part.footprint',
|
||||||
'label' => $this->translator->trans('part.table.footprint'),
|
'label' => $this->translator->trans('part.table.footprint'),
|
||||||
'orderField' => 'footprint.name',
|
'orderField' => 'NATSORT(footprint.name)',
|
||||||
])
|
])
|
||||||
|
|
||||||
->add('manufacturer', EntityColumn::class, [
|
->add('manufacturer', EntityColumn::class, [
|
||||||
'property' => 'part.manufacturer',
|
'property' => 'part.manufacturer',
|
||||||
'label' => $this->translator->trans('part.table.manufacturer'),
|
'label' => $this->translator->trans('part.table.manufacturer'),
|
||||||
'orderField' => 'manufacturer.name',
|
'orderField' => 'NATSORT(manufacturer.name)',
|
||||||
])
|
])
|
||||||
|
|
||||||
->add('mountnames', TextColumn::class, [
|
->add('mountnames', TextColumn::class, [
|
||||||
|
@ -154,7 +154,7 @@ class ProjectBomEntriesDataTable implements DataTableTypeInterface
|
||||||
'label' => 'project.bom.instockAmount',
|
'label' => 'project.bom.instockAmount',
|
||||||
'visible' => false,
|
'visible' => false,
|
||||||
'render' => function ($value, ProjectBOMEntry $context) {
|
'render' => function ($value, ProjectBOMEntry $context) {
|
||||||
if ($context->getPart()) {
|
if ($context->getPart() !== null) {
|
||||||
return $this->partDataTableHelper->renderAmount($context->getPart());
|
return $this->partDataTableHelper->renderAmount($context->getPart());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ class ProjectBomEntriesDataTable implements DataTableTypeInterface
|
||||||
'label' => 'part.table.storeLocations',
|
'label' => 'part.table.storeLocations',
|
||||||
'visible' => false,
|
'visible' => false,
|
||||||
'render' => function ($value, ProjectBOMEntry $context) {
|
'render' => function ($value, ProjectBOMEntry $context) {
|
||||||
if ($context->getPart()) {
|
if ($context->getPart() !== null) {
|
||||||
return $this->partDataTableHelper->renderStorageLocations($context->getPart());
|
return $this->partDataTableHelper->renderStorageLocations($context->getPart());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
59
src/Doctrine/Functions/ArrayPosition.php
Normal file
59
src/Doctrine/Functions/ArrayPosition.php
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
|
||||||
|
namespace App\Doctrine\Functions;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
|
||||||
|
use Doctrine\ORM\Query\AST\Node;
|
||||||
|
use Doctrine\ORM\Query\Parser;
|
||||||
|
use Doctrine\ORM\Query\SqlWalker;
|
||||||
|
use Doctrine\ORM\Query\TokenType;
|
||||||
|
|
||||||
|
class ArrayPosition extends FunctionNode
|
||||||
|
{
|
||||||
|
private ?Node $array = null;
|
||||||
|
|
||||||
|
private ?Node $field = null;
|
||||||
|
|
||||||
|
public function parse(Parser $parser): void
|
||||||
|
{
|
||||||
|
$parser->match(TokenType::T_IDENTIFIER);
|
||||||
|
$parser->match(TokenType::T_OPEN_PARENTHESIS);
|
||||||
|
|
||||||
|
$this->array = $parser->InParameter();
|
||||||
|
|
||||||
|
$parser->match(TokenType::T_COMMA);
|
||||||
|
|
||||||
|
$this->field = $parser->ArithmeticPrimary();
|
||||||
|
|
||||||
|
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSql(SqlWalker $sqlWalker): string
|
||||||
|
{
|
||||||
|
return 'ARRAY_POSITION(' .
|
||||||
|
$this->array->dispatch($sqlWalker) . ', ' .
|
||||||
|
$this->field->dispatch($sqlWalker) .
|
||||||
|
')';
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,6 +23,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Doctrine\Functions;
|
namespace App\Doctrine\Functions;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Query\Parser;
|
||||||
|
use Doctrine\ORM\Query\SqlWalker;
|
||||||
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
|
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
|
||||||
use Doctrine\ORM\Query\TokenType;
|
use Doctrine\ORM\Query\TokenType;
|
||||||
|
|
||||||
|
@ -36,7 +38,7 @@ class Field2 extends FunctionNode
|
||||||
|
|
||||||
private $values = [];
|
private $values = [];
|
||||||
|
|
||||||
public function parse(\Doctrine\ORM\Query\Parser $parser): void
|
public function parse(Parser $parser): void
|
||||||
{
|
{
|
||||||
$parser->match(TokenType::T_IDENTIFIER);
|
$parser->match(TokenType::T_IDENTIFIER);
|
||||||
$parser->match(TokenType::T_OPEN_PARENTHESIS);
|
$parser->match(TokenType::T_OPEN_PARENTHESIS);
|
||||||
|
@ -50,7 +52,7 @@ class Field2 extends FunctionNode
|
||||||
$lexer = $parser->getLexer();
|
$lexer = $parser->getLexer();
|
||||||
|
|
||||||
while (count($this->values) < 1 ||
|
while (count($this->values) < 1 ||
|
||||||
$lexer->lookahead['type'] != TokenType::T_CLOSE_PARENTHESIS) {
|
$lexer->lookahead->type !== TokenType::T_CLOSE_PARENTHESIS) {
|
||||||
$parser->match(TokenType::T_COMMA);
|
$parser->match(TokenType::T_COMMA);
|
||||||
$this->values[] = $parser->ArithmeticPrimary();
|
$this->values[] = $parser->ArithmeticPrimary();
|
||||||
}
|
}
|
||||||
|
@ -58,15 +60,16 @@ class Field2 extends FunctionNode
|
||||||
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
|
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker): string
|
public function getSql(SqlWalker $sqlWalker): string
|
||||||
{
|
{
|
||||||
$query = 'FIELD2(';
|
$query = 'FIELD2(';
|
||||||
|
|
||||||
$query .= $this->field->dispatch($sqlWalker);
|
$query .= $this->field->dispatch($sqlWalker);
|
||||||
|
|
||||||
$query .= ', ';
|
$query .= ', ';
|
||||||
|
$counter = count($this->values);
|
||||||
|
|
||||||
for ($i = 0; $i < count($this->values); $i++) {
|
for ($i = 0; $i < $counter; $i++) {
|
||||||
if ($i > 0) {
|
if ($i > 0) {
|
||||||
$query .= ', ';
|
$query .= ', ';
|
||||||
}
|
}
|
||||||
|
@ -74,8 +77,6 @@ class Field2 extends FunctionNode
|
||||||
$query .= $this->values[$i]->dispatch($sqlWalker);
|
$query .= $this->values[$i]->dispatch($sqlWalker);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query .= ')';
|
return $query . ')';
|
||||||
|
|
||||||
return $query;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
142
src/Doctrine/Functions/Natsort.php
Normal file
142
src/Doctrine/Functions/Natsort.php
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
|
||||||
|
namespace App\Doctrine\Functions;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Exception;
|
||||||
|
use Doctrine\DBAL\Connection;
|
||||||
|
use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver;
|
||||||
|
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
|
||||||
|
use Doctrine\DBAL\Platforms\MariaDBPlatform;
|
||||||
|
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
|
||||||
|
use Doctrine\DBAL\Platforms\SQLitePlatform;
|
||||||
|
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
|
||||||
|
use Doctrine\ORM\Query\AST\Node;
|
||||||
|
use Doctrine\ORM\Query\Parser;
|
||||||
|
use Doctrine\ORM\Query\SqlWalker;
|
||||||
|
use Doctrine\ORM\Query\TokenType;
|
||||||
|
|
||||||
|
class Natsort extends FunctionNode
|
||||||
|
{
|
||||||
|
private ?Node $field = null;
|
||||||
|
|
||||||
|
private static ?bool $supportsNaturalSort = null;
|
||||||
|
|
||||||
|
private static bool $allowSlowNaturalSort = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* As we can not inject parameters into the function, we use an event listener, to call the value on the static function.
|
||||||
|
* This is the only way to inject the value into the function.
|
||||||
|
* @param bool $allow
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function allowSlowNaturalSort(bool $allow = true): void
|
||||||
|
{
|
||||||
|
self::$allowSlowNaturalSort = $allow;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the MariaDB version which is connected to supports the natural sort (meaning it has a version of 10.7.0 or higher)
|
||||||
|
* The result is cached in memory.
|
||||||
|
* @param Connection $connection
|
||||||
|
* @return bool
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private function mariaDBSupportsNaturalSort(Connection $connection): bool
|
||||||
|
{
|
||||||
|
if (self::$supportsNaturalSort !== null) {
|
||||||
|
return self::$supportsNaturalSort;
|
||||||
|
}
|
||||||
|
|
||||||
|
$version = $connection->getServerVersion();
|
||||||
|
|
||||||
|
//Get the effective MariaDB version number
|
||||||
|
$version = $this->getMariaDbMysqlVersionNumber($version);
|
||||||
|
|
||||||
|
//We need at least MariaDB 10.7.0 to support the natural sort
|
||||||
|
self::$supportsNaturalSort = version_compare($version, '10.7.0', '>=');
|
||||||
|
return self::$supportsNaturalSort;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Taken from Doctrine\DBAL\Driver\AbstractMySQLDriver
|
||||||
|
*
|
||||||
|
* Detect MariaDB server version, including hack for some mariadb distributions
|
||||||
|
* that starts with the prefix '5.5.5-'
|
||||||
|
*
|
||||||
|
* @param string $versionString Version string as returned by mariadb server, i.e. '5.5.5-Mariadb-10.0.8-xenial'
|
||||||
|
*/
|
||||||
|
private function getMariaDbMysqlVersionNumber(string $versionString) : string
|
||||||
|
{
|
||||||
|
if ( ! preg_match(
|
||||||
|
'/^(?:5\.5\.5-)?(mariadb-)?(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)/i',
|
||||||
|
$versionString,
|
||||||
|
$versionParts
|
||||||
|
)) {
|
||||||
|
throw new \RuntimeException('Could not detect MariaDB version from version string ' . $versionString);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $versionParts['major'] . '.' . $versionParts['minor'] . '.' . $versionParts['patch'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function parse(Parser $parser): void
|
||||||
|
{
|
||||||
|
$parser->match(TokenType::T_IDENTIFIER);
|
||||||
|
$parser->match(TokenType::T_OPEN_PARENTHESIS);
|
||||||
|
|
||||||
|
$this->field = $parser->ArithmeticExpression();
|
||||||
|
|
||||||
|
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSql(SqlWalker $sqlWalker): string
|
||||||
|
{
|
||||||
|
assert($this->field !== null, 'Field is not set');
|
||||||
|
|
||||||
|
$platform = $sqlWalker->getConnection()->getDatabasePlatform();
|
||||||
|
|
||||||
|
if ($platform instanceof PostgreSQLPlatform) {
|
||||||
|
return $this->field->dispatch($sqlWalker) . ' COLLATE numeric';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($platform instanceof MariaDBPlatform && $this->mariaDBSupportsNaturalSort($sqlWalker->getConnection())) {
|
||||||
|
return 'NATURAL_SORT_KEY(' . $this->field->dispatch($sqlWalker) . ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
//Do the following operations only if we allow slow natural sort
|
||||||
|
if (self::$allowSlowNaturalSort) {
|
||||||
|
if ($platform instanceof SQLitePlatform) {
|
||||||
|
return $this->field->dispatch($sqlWalker).' COLLATE NATURAL_CMP';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($platform instanceof AbstractMySQLPlatform) {
|
||||||
|
return 'NatSortKey(' . $this->field->dispatch($sqlWalker) . ', 0)';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//For every other platform, return the field as is
|
||||||
|
return $this->field->dispatch($sqlWalker);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
52
src/Doctrine/Functions/Regexp.php
Normal file
52
src/Doctrine/Functions/Regexp.php
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
|
||||||
|
namespace App\Doctrine\Functions;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
|
||||||
|
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
|
||||||
|
use Doctrine\DBAL\Platforms\SQLitePlatform;
|
||||||
|
use Doctrine\ORM\Query\SqlWalker;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Similar to the regexp function, but with support for multi platform.
|
||||||
|
*/
|
||||||
|
class Regexp extends \DoctrineExtensions\Query\Mysql\Regexp
|
||||||
|
{
|
||||||
|
public function getSql(SqlWalker $sqlWalker): string
|
||||||
|
{
|
||||||
|
$platform = $sqlWalker->getConnection()->getDatabasePlatform();
|
||||||
|
|
||||||
|
//
|
||||||
|
if ($platform instanceof AbstractMySQLPlatform || $platform instanceof SQLitePlatform) {
|
||||||
|
$operator = 'REGEXP';
|
||||||
|
} elseif ($platform instanceof PostgreSQLPlatform) {
|
||||||
|
//Use the case-insensitive operator, to have the same behavior as MySQL
|
||||||
|
$operator = '~*';
|
||||||
|
} else {
|
||||||
|
throw new \RuntimeException('Platform ' . gettype($platform) . ' does not support regular expressions.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return '(' . $this->value->dispatch($sqlWalker) . ' ' . $operator . ' ' . $this->regexp->dispatch($sqlWalker) . ')';
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||||
namespace App\Doctrine\Helpers;
|
namespace App\Doctrine\Helpers;
|
||||||
|
|
||||||
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
|
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
|
||||||
|
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,10 +46,10 @@ final class FieldHelper
|
||||||
$db_platform = $qb->getEntityManager()->getConnection()->getDatabasePlatform();
|
$db_platform = $qb->getEntityManager()->getConnection()->getDatabasePlatform();
|
||||||
|
|
||||||
//If we are on MySQL, we can just use the FIELD function
|
//If we are on MySQL, we can just use the FIELD function
|
||||||
if ($db_platform instanceof AbstractMySQLPlatform) {
|
if ($db_platform instanceof AbstractMySQLPlatform ) {
|
||||||
$param = (is_numeric($bound_param) ? '?' : ":") . (string) $bound_param;
|
$param = (is_numeric($bound_param) ? '?' : ":").(string)$bound_param;
|
||||||
$qb->orderBy("FIELD($field_expr, $param)", $order);
|
$qb->orderBy("FIELD($field_expr, $param)", $order);
|
||||||
} else {
|
} else { //Use the sqlite/portable version or postgresql
|
||||||
//Retrieve the values from the bound parameter
|
//Retrieve the values from the bound parameter
|
||||||
$param = $qb->getParameter($bound_param);
|
$param = $qb->getParameter($bound_param);
|
||||||
if ($param === null) {
|
if ($param === null) {
|
||||||
|
@ -57,12 +58,31 @@ final class FieldHelper
|
||||||
|
|
||||||
//Generate a unique key from the field_expr
|
//Generate a unique key from the field_expr
|
||||||
$key = 'field2_' . (string) $bound_param;
|
$key = 'field2_' . (string) $bound_param;
|
||||||
self::addSqliteOrderBy($qb, $field_expr, $key, $param->getValue(), $order);
|
|
||||||
|
if ($db_platform instanceof PostgreSQLPlatform) {
|
||||||
|
self::addPostgresOrderBy($qb, $field_expr, $key, $param->getValue(), $order);
|
||||||
|
} else {
|
||||||
|
self::addSqliteOrderBy($qb, $field_expr, $key, $param->getValue(), $order);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $qb;
|
return $qb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static function addPostgresOrderBy(QueryBuilder $qb, string $field_expr, string $key, array $values, ?string $order = null): void
|
||||||
|
{
|
||||||
|
//Use postgres native array_position function, to get the index of the value in the array
|
||||||
|
//In the end it gives a similar result as the FIELD function
|
||||||
|
$qb->orderBy("array_position(:$key, $field_expr)", $order);
|
||||||
|
|
||||||
|
//Convert the values to a literal array, to overcome the problem of passing more than 100 parameters
|
||||||
|
$values = array_map(fn($value) => is_string($value) ? "'$value'" : $value, $values);
|
||||||
|
$literalArray = '{' . implode(',', $values) . '}';
|
||||||
|
|
||||||
|
$qb->setParameter($key, $literalArray);
|
||||||
|
}
|
||||||
|
|
||||||
private static function addSqliteOrderBy(QueryBuilder $qb, string $field_expr, string $key, array $values, ?string $order = null): void
|
private static function addSqliteOrderBy(QueryBuilder $qb, string $field_expr, string $key, array $values, ?string $order = null): void
|
||||||
{
|
{
|
||||||
//Otherwise we emulate it using
|
//Otherwise we emulate it using
|
||||||
|
@ -88,11 +108,12 @@ final class FieldHelper
|
||||||
|
|
||||||
//If we are on MySQL, we can just use the FIELD function
|
//If we are on MySQL, we can just use the FIELD function
|
||||||
if ($db_platform instanceof AbstractMySQLPlatform) {
|
if ($db_platform instanceof AbstractMySQLPlatform) {
|
||||||
$qb->orderBy("FIELD($field_expr, :field_arr)", $order);
|
$qb->orderBy("FIELD2($field_expr, :field_arr)", $order);
|
||||||
|
} elseif ($db_platform instanceof PostgreSQLPlatform) {
|
||||||
|
//Use the postgres native array_position function
|
||||||
|
self::addPostgresOrderBy($qb, $field_expr, $key, $values, $order);
|
||||||
} else {
|
} else {
|
||||||
//Generate a unique key from the field_expr
|
//Otherwise use the portable version using string concatenation
|
||||||
|
|
||||||
//Otherwise we have to it using the FIELD2 function
|
|
||||||
self::addSqliteOrderBy($qb, $field_expr, $key, $values, $order);
|
self::addSqliteOrderBy($qb, $field_expr, $key, $values, $order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@ use Composer\CaBundle\CaBundle;
|
||||||
use Doctrine\DBAL\Driver;
|
use Doctrine\DBAL\Driver;
|
||||||
use Doctrine\DBAL\Driver\Connection;
|
use Doctrine\DBAL\Driver\Connection;
|
||||||
use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;
|
use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;
|
||||||
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This middleware sets SSL options for MySQL connections
|
* This middleware sets SSL options for MySQL connections
|
||||||
|
@ -42,7 +41,7 @@ class MySQLSSLConnectionMiddlewareDriver extends AbstractDriverMiddleware
|
||||||
public function connect(array $params): Connection
|
public function connect(array $params): Connection
|
||||||
{
|
{
|
||||||
//Only set this on MySQL connections, as other databases don't support this parameter
|
//Only set this on MySQL connections, as other databases don't support this parameter
|
||||||
if($this->enabled && $this->getDatabasePlatform() instanceof AbstractMySQLPlatform) {
|
if($this->enabled && $params['driver'] === 'pdo_mysql') {
|
||||||
$params['driverOptions'][\PDO::MYSQL_ATTR_SSL_CA] = CaBundle::getSystemCaRootBundlePath();
|
$params['driverOptions'][\PDO::MYSQL_ATTR_SSL_CA] = CaBundle::getSystemCaRootBundlePath();
|
||||||
$params['driverOptions'][\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = $this->verify;
|
$params['driverOptions'][\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = $this->verify;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ namespace App\Doctrine\Middleware;
|
||||||
use App\Exceptions\InvalidRegexException;
|
use App\Exceptions\InvalidRegexException;
|
||||||
use Doctrine\DBAL\Driver\Connection;
|
use Doctrine\DBAL\Driver\Connection;
|
||||||
use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;
|
use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;
|
||||||
use Doctrine\DBAL\Platforms\SqlitePlatform;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This middleware is used to add the regexp operator to the SQLite platform.
|
* This middleware is used to add the regexp operator to the SQLite platform.
|
||||||
|
@ -41,7 +40,7 @@ class SQLiteRegexExtensionMiddlewareDriver extends AbstractDriverMiddleware
|
||||||
$connection = parent::connect($params); // TODO: Change the autogenerated stub
|
$connection = parent::connect($params); // TODO: Change the autogenerated stub
|
||||||
|
|
||||||
//Then add the functions if we are on SQLite
|
//Then add the functions if we are on SQLite
|
||||||
if ($this->getDatabasePlatform() instanceof SqlitePlatform) {
|
if ($params['driver'] === 'pdo_sqlite') {
|
||||||
$native_connection = $connection->getNativeConnection();
|
$native_connection = $connection->getNativeConnection();
|
||||||
|
|
||||||
//Ensure that the function really exists on the connection, as it is marked as experimental according to PHP documentation
|
//Ensure that the function really exists on the connection, as it is marked as experimental according to PHP documentation
|
||||||
|
@ -49,6 +48,11 @@ class SQLiteRegexExtensionMiddlewareDriver extends AbstractDriverMiddleware
|
||||||
$native_connection->sqliteCreateFunction('REGEXP', self::regexp(...), 2, \PDO::SQLITE_DETERMINISTIC);
|
$native_connection->sqliteCreateFunction('REGEXP', self::regexp(...), 2, \PDO::SQLITE_DETERMINISTIC);
|
||||||
$native_connection->sqliteCreateFunction('FIELD', self::field(...), -1, \PDO::SQLITE_DETERMINISTIC);
|
$native_connection->sqliteCreateFunction('FIELD', self::field(...), -1, \PDO::SQLITE_DETERMINISTIC);
|
||||||
$native_connection->sqliteCreateFunction('FIELD2', self::field2(...), 2, \PDO::SQLITE_DETERMINISTIC);
|
$native_connection->sqliteCreateFunction('FIELD2', self::field2(...), 2, \PDO::SQLITE_DETERMINISTIC);
|
||||||
|
|
||||||
|
//Create a new collation for natural sorting
|
||||||
|
if (method_exists($native_connection, 'sqliteCreateCollation')) {
|
||||||
|
$native_connection->sqliteCreateCollation('NATURAL_CMP', strnatcmp(...));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,10 +98,9 @@ class SQLiteRegexExtensionMiddlewareDriver extends AbstractDriverMiddleware
|
||||||
* This function returns the index (position) of the first argument in the subsequent arguments.
|
* This function returns the index (position) of the first argument in the subsequent arguments.
|
||||||
* If the first argument is not found or is NULL, 0 is returned.
|
* If the first argument is not found or is NULL, 0 is returned.
|
||||||
* @param string|int|null $value
|
* @param string|int|null $value
|
||||||
* @param mixed ...$array
|
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
final public static function field(string|int|null $value, ...$array): int
|
final public static function field(string|int|null $value, mixed ...$array): int
|
||||||
{
|
{
|
||||||
if ($value === null) {
|
if ($value === null) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -24,7 +24,6 @@ namespace App\Doctrine\Middleware;
|
||||||
|
|
||||||
use Doctrine\DBAL\Driver\Connection;
|
use Doctrine\DBAL\Driver\Connection;
|
||||||
use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;
|
use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;
|
||||||
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This command sets the initial command parameter for MySQL connections, so we can set the SQL mode
|
* This command sets the initial command parameter for MySQL connections, so we can set the SQL mode
|
||||||
|
@ -35,7 +34,7 @@ class SetSQLModeMiddlewareDriver extends AbstractDriverMiddleware
|
||||||
public function connect(array $params): Connection
|
public function connect(array $params): Connection
|
||||||
{
|
{
|
||||||
//Only set this on MySQL connections, as other databases don't support this parameter
|
//Only set this on MySQL connections, as other databases don't support this parameter
|
||||||
if($this->getDatabasePlatform() instanceof AbstractMySQLPlatform) {
|
if($params['driver'] === 'pdo_mysql') {
|
||||||
//1002 is \PDO::MYSQL_ATTR_INIT_COMMAND constant value
|
//1002 is \PDO::MYSQL_ATTR_INIT_COMMAND constant value
|
||||||
$params['driverOptions'][\PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode, \'ONLY_FULL_GROUP_BY\', \'\'))';
|
$params['driverOptions'][\PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode, \'ONLY_FULL_GROUP_BY\', \'\'))';
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,6 @@ use Doctrine\DBAL\Schema\Identifier;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
|
||||||
|
|
||||||
use function array_reverse;
|
use function array_reverse;
|
||||||
use function assert;
|
use function assert;
|
||||||
use function count;
|
use function count;
|
||||||
|
@ -207,6 +205,8 @@ class ResetAutoIncrementORMPurger implements PurgerInterface, ORMPurgerInterface
|
||||||
return 'ALTER TABLE '.$tableIdentifier->getQuotedName($platform).' AUTO_INCREMENT = 1;';
|
return 'ALTER TABLE '.$tableIdentifier->getQuotedName($platform).' AUTO_INCREMENT = 1;';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new \RuntimeException("Resetting autoincrement is not supported on this platform!");
|
||||||
|
|
||||||
//This seems to cause problems somehow
|
//This seems to cause problems somehow
|
||||||
/*if ($platform instanceof SqlitePlatform) {
|
/*if ($platform instanceof SqlitePlatform) {
|
||||||
return 'DELETE FROM `sqlite_sequence` WHERE name = \''.$tableIdentifier->getQuotedName($platform).'\';';
|
return 'DELETE FROM `sqlite_sequence` WHERE name = \''.$tableIdentifier->getQuotedName($platform).'\';';
|
||||||
|
@ -278,7 +278,7 @@ class ResetAutoIncrementORMPurger implements PurgerInterface, ORMPurgerInterface
|
||||||
|
|
||||||
foreach ($classes as $class) {
|
foreach ($classes as $class) {
|
||||||
foreach ($class->associationMappings as $assoc) {
|
foreach ($class->associationMappings as $assoc) {
|
||||||
if (! $assoc['isOwningSide'] || $assoc['type'] !== ClassMetadataInfo::MANY_TO_MANY) {
|
if (! $assoc['isOwningSide'] || $assoc['type'] !== ClassMetadata::MANY_TO_MANY) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
116
src/Doctrine/Types/ArrayType.php
Normal file
116
src/Doctrine/Types/ArrayType.php
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Doctrine\Types;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||||
|
use Doctrine\DBAL\Types\Exception\SerializationFailed;
|
||||||
|
use Doctrine\DBAL\Types\Type;
|
||||||
|
use Doctrine\Deprecations\Deprecation;
|
||||||
|
|
||||||
|
use function is_resource;
|
||||||
|
use function restore_error_handler;
|
||||||
|
use function serialize;
|
||||||
|
use function set_error_handler;
|
||||||
|
use function stream_get_contents;
|
||||||
|
use function unserialize;
|
||||||
|
|
||||||
|
use const E_DEPRECATED;
|
||||||
|
use const E_USER_DEPRECATED;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is taken from doctrine ORM 3.8. https://github.com/doctrine/dbal/blob/3.8.x/src/Types/ArrayType.php
|
||||||
|
*
|
||||||
|
* It was removed in doctrine ORM 4.0. However, we require it for backward compatibility with WebauthnKey.
|
||||||
|
* Therefore, we manually added it here as a custom type as a forward compatibility layer.
|
||||||
|
*/
|
||||||
|
class ArrayType extends Type
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
|
||||||
|
{
|
||||||
|
return $platform->getClobTypeDeclarationSQL($column);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): string
|
||||||
|
{
|
||||||
|
return serialize($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mixed
|
||||||
|
{
|
||||||
|
if ($value === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$value = is_resource($value) ? stream_get_contents($value) : $value;
|
||||||
|
|
||||||
|
set_error_handler(function (int $code, string $message): bool {
|
||||||
|
if ($code === E_DEPRECATED || $code === E_USER_DEPRECATED) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Change to original code. Use SerializationFailed instead of ConversionException.
|
||||||
|
throw new SerializationFailed("Serialization failed (Code $code): " . $message);
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
//Change to original code. Use false for allowed_classes, to avoid unsafe unserialization of objects.
|
||||||
|
return unserialize($value, ['allowed_classes' => false]);
|
||||||
|
} finally {
|
||||||
|
restore_error_handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function getName(): string
|
||||||
|
{
|
||||||
|
return "array";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
|
||||||
|
{
|
||||||
|
Deprecation::triggerIfCalledFromOutside(
|
||||||
|
'doctrine/dbal',
|
||||||
|
'https://github.com/doctrine/dbal/pull/5509',
|
||||||
|
'%s is deprecated.',
|
||||||
|
__METHOD__,
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,7 +22,9 @@ declare(strict_types=1);
|
||||||
*/
|
*/
|
||||||
namespace App\Doctrine\Types;
|
namespace App\Doctrine\Types;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
|
||||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||||
|
use Doctrine\DBAL\Platforms\SQLitePlatform;
|
||||||
use Doctrine\DBAL\Types\Type;
|
use Doctrine\DBAL\Types\Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,7 +35,15 @@ class TinyIntType extends Type
|
||||||
|
|
||||||
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
|
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
|
||||||
{
|
{
|
||||||
return 'TINYINT';
|
//MySQL knows the TINYINT type directly
|
||||||
|
//We do not use the TINYINT for sqlite, as it will be resolved to a BOOL type and bring problems with migrations
|
||||||
|
if ($platform instanceof AbstractMySQLPlatform ) {
|
||||||
|
//Use TINYINT(1) to allow for proper migration diffs
|
||||||
|
return 'TINYINT(1)';
|
||||||
|
}
|
||||||
|
|
||||||
|
//For other platforms, we use the smallest integer type available
|
||||||
|
return $platform->getSmallIntTypeDeclarationSQL($column);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName(): string
|
public function getName(): string
|
||||||
|
|
97
src/Doctrine/Types/UTCDateTimeImmutableType.php
Normal file
97
src/Doctrine/Types/UTCDateTimeImmutableType.php
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Doctrine\Types;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
use DateTimeInterface;
|
||||||
|
use DateTimeZone;
|
||||||
|
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||||
|
use Doctrine\DBAL\Types\ConversionException;
|
||||||
|
use Doctrine\DBAL\Types\DateTimeImmutableType;
|
||||||
|
use Doctrine\DBAL\Types\DateTimeType;
|
||||||
|
use Doctrine\DBAL\Types\Exception\InvalidFormat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This DateTimeImmutableType all dates to UTC, so it can be later used with the timezones.
|
||||||
|
* Taken (and adapted) from here: https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/cookbook/working-with-datetime.html.
|
||||||
|
*/
|
||||||
|
class UTCDateTimeImmutableType extends DateTimeImmutableType
|
||||||
|
{
|
||||||
|
private static ?DateTimeZone $utc_timezone = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @param T $value
|
||||||
|
*
|
||||||
|
* @return (T is null ? null : string)
|
||||||
|
*
|
||||||
|
* @template T
|
||||||
|
*/
|
||||||
|
public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
|
||||||
|
{
|
||||||
|
if (!self::$utc_timezone instanceof \DateTimeZone) {
|
||||||
|
self::$utc_timezone = new DateTimeZone('UTC');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($value instanceof \DateTimeImmutable) {
|
||||||
|
$value = $value->setTimezone(self::$utc_timezone);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::convertToDatabaseValue($value, $platform);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* @param T $value
|
||||||
|
*
|
||||||
|
* @template T
|
||||||
|
*/
|
||||||
|
public function convertToPHPValue($value, AbstractPlatform $platform): ?\DateTimeImmutable
|
||||||
|
{
|
||||||
|
if (!self::$utc_timezone instanceof \DateTimeZone) {
|
||||||
|
self::$utc_timezone = new DateTimeZone('UTC');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null === $value || $value instanceof \DateTimeImmutable) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
$converted = \DateTimeImmutable::createFromFormat(
|
||||||
|
$platform->getDateTimeFormatString(),
|
||||||
|
$value,
|
||||||
|
self::$utc_timezone
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!$converted) {
|
||||||
|
throw InvalidFormat::new(
|
||||||
|
$value,
|
||||||
|
static::class,
|
||||||
|
$platform->getDateTimeFormatString(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $converted;
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,6 +28,7 @@ use DateTimeZone;
|
||||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||||
use Doctrine\DBAL\Types\ConversionException;
|
use Doctrine\DBAL\Types\ConversionException;
|
||||||
use Doctrine\DBAL\Types\DateTimeType;
|
use Doctrine\DBAL\Types\DateTimeType;
|
||||||
|
use Doctrine\DBAL\Types\Exception\InvalidFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This DateTimeType all dates to UTC, so it can be later used with the timezones.
|
* This DateTimeType all dates to UTC, so it can be later used with the timezones.
|
||||||
|
@ -64,11 +65,9 @@ class UTCDateTimeType extends DateTimeType
|
||||||
*
|
*
|
||||||
* @param T $value
|
* @param T $value
|
||||||
*
|
*
|
||||||
* @return (T is null ? null : DateTimeInterface)
|
|
||||||
*
|
|
||||||
* @template T
|
* @template T
|
||||||
*/
|
*/
|
||||||
public function convertToPHPValue($value, AbstractPlatform $platform): ?\DateTimeInterface
|
public function convertToPHPValue($value, AbstractPlatform $platform): ?DateTime
|
||||||
{
|
{
|
||||||
if (!self::$utc_timezone instanceof \DateTimeZone) {
|
if (!self::$utc_timezone instanceof \DateTimeZone) {
|
||||||
self::$utc_timezone = new DateTimeZone('UTC');
|
self::$utc_timezone = new DateTimeZone('UTC');
|
||||||
|
@ -85,7 +84,11 @@ class UTCDateTimeType extends DateTimeType
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!$converted) {
|
if (!$converted) {
|
||||||
throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString());
|
throw InvalidFormat::new(
|
||||||
|
$value,
|
||||||
|
static::class,
|
||||||
|
$platform->getDateTimeFormatString(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $converted;
|
return $converted;
|
||||||
|
|
|
@ -147,7 +147,7 @@ abstract class Attachment extends AbstractNamedDBElement
|
||||||
* @var string|null the original filename the file had, when the user uploaded it
|
* @var string|null the original filename the file had, when the user uploaded it
|
||||||
*/
|
*/
|
||||||
#[ORM\Column(type: Types::STRING, nullable: true)]
|
#[ORM\Column(type: Types::STRING, nullable: true)]
|
||||||
#[Groups(['full', 'attachment:read'])]
|
#[Groups(['attachment:read', 'import'])]
|
||||||
#[Assert\Length(max: 255)]
|
#[Assert\Length(max: 255)]
|
||||||
protected ?string $original_filename = null;
|
protected ?string $original_filename = null;
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ abstract class Attachment extends AbstractNamedDBElement
|
||||||
* @var string the name of this element
|
* @var string the name of this element
|
||||||
*/
|
*/
|
||||||
#[Assert\NotBlank(message: 'validator.attachment.name_not_blank')]
|
#[Assert\NotBlank(message: 'validator.attachment.name_not_blank')]
|
||||||
#[Groups(['simple', 'extended', 'full', 'attachment:read', 'attachment:write'])]
|
#[Groups(['simple', 'extended', 'full', 'attachment:read', 'attachment:write', 'import'])]
|
||||||
protected string $name = '';
|
protected string $name = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -173,21 +173,21 @@ abstract class Attachment extends AbstractNamedDBElement
|
||||||
protected ?AttachmentContainingDBElement $element = null;
|
protected ?AttachmentContainingDBElement $element = null;
|
||||||
|
|
||||||
#[ORM\Column(type: Types::BOOLEAN)]
|
#[ORM\Column(type: Types::BOOLEAN)]
|
||||||
#[Groups(['attachment:read', 'attachment_write'])]
|
#[Groups(['attachment:read', 'attachment_write', 'full', 'import'])]
|
||||||
protected bool $show_in_table = false;
|
protected bool $show_in_table = false;
|
||||||
|
|
||||||
#[Assert\NotNull(message: 'validator.attachment.must_not_be_null')]
|
#[Assert\NotNull(message: 'validator.attachment.must_not_be_null')]
|
||||||
#[ORM\ManyToOne(targetEntity: AttachmentType::class, inversedBy: 'attachments_with_type')]
|
#[ORM\ManyToOne(targetEntity: AttachmentType::class, inversedBy: 'attachments_with_type')]
|
||||||
#[ORM\JoinColumn(name: 'type_id', nullable: false)]
|
#[ORM\JoinColumn(name: 'type_id', nullable: false)]
|
||||||
#[Selectable]
|
#[Selectable]
|
||||||
#[Groups(['attachment:read', 'attachment:write'])]
|
#[Groups(['attachment:read', 'attachment:write', 'import', 'full'])]
|
||||||
#[ApiProperty(readableLink: false)]
|
#[ApiProperty(readableLink: false)]
|
||||||
protected ?AttachmentType $attachment_type = null;
|
protected ?AttachmentType $attachment_type = null;
|
||||||
|
|
||||||
#[Groups(['attachment:read'])]
|
#[Groups(['attachment:read'])]
|
||||||
protected ?\DateTimeInterface $addedDate = null;
|
protected ?\DateTimeImmutable $addedDate = null;
|
||||||
#[Groups(['attachment:read'])]
|
#[Groups(['attachment:read'])]
|
||||||
protected ?\DateTimeInterface $lastModified = null;
|
protected ?\DateTimeImmutable $lastModified = null;
|
||||||
|
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
|
@ -385,7 +385,7 @@ abstract class Attachment extends AbstractNamedDBElement
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parse_url($this->getURL(), PHP_URL_HOST);
|
return parse_url((string) $this->getURL(), PHP_URL_HOST);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -477,7 +477,8 @@ abstract class Attachment extends AbstractNamedDBElement
|
||||||
*/
|
*/
|
||||||
public function setElement(AttachmentContainingDBElement $element): self
|
public function setElement(AttachmentContainingDBElement $element): self
|
||||||
{
|
{
|
||||||
if (!is_a($element, static::ALLOWED_ELEMENT_CLASS)) {
|
//Do not allow Rector to replace this check with a instanceof. It will not work!!
|
||||||
|
if (!is_a($element, static::ALLOWED_ELEMENT_CLASS, true)) {
|
||||||
throw new InvalidArgumentException(sprintf('The element associated with a %s must be a %s!', static::class, static::ALLOWED_ELEMENT_CLASS));
|
throw new InvalidArgumentException(sprintf('The element associated with a %s must be a %s!', static::class, static::ALLOWED_ELEMENT_CLASS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ abstract class AttachmentContainingDBElement extends AbstractNamedDBElement impl
|
||||||
* @phpstan-var Collection<int, AT>
|
* @phpstan-var Collection<int, AT>
|
||||||
* ORM Mapping is done in subclasses (e.g. Part)
|
* ORM Mapping is done in subclasses (e.g. Part)
|
||||||
*/
|
*/
|
||||||
#[Groups(['full'])]
|
#[Groups(['full', 'import'])]
|
||||||
protected Collection $attachments;
|
protected Collection $attachments;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
|
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Entity\Attachments;
|
namespace App\Entity\Attachments;
|
||||||
|
|
||||||
|
use Doctrine\Common\Collections\Criteria;
|
||||||
use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface;
|
use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface;
|
||||||
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
|
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
|
||||||
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
|
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
|
||||||
|
@ -86,7 +87,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||||
class AttachmentType extends AbstractStructuralDBElement
|
class AttachmentType extends AbstractStructuralDBElement
|
||||||
{
|
{
|
||||||
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: AttachmentType::class, cascade: ['persist'])]
|
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: AttachmentType::class, cascade: ['persist'])]
|
||||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||||
protected Collection $children;
|
protected Collection $children;
|
||||||
|
|
||||||
#[ORM\ManyToOne(targetEntity: AttachmentType::class, inversedBy: 'children')]
|
#[ORM\ManyToOne(targetEntity: AttachmentType::class, inversedBy: 'children')]
|
||||||
|
@ -102,7 +103,7 @@ class AttachmentType extends AbstractStructuralDBElement
|
||||||
*/
|
*/
|
||||||
#[ORM\Column(type: Types::TEXT)]
|
#[ORM\Column(type: Types::TEXT)]
|
||||||
#[ValidFileFilter]
|
#[ValidFileFilter]
|
||||||
#[Groups(['attachment_type:read', 'attachment_type:write'])]
|
#[Groups(['attachment_type:read', 'attachment_type:write', 'import', 'extended'])]
|
||||||
protected string $filetype_filter = '';
|
protected string $filetype_filter = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,21 +111,21 @@ class AttachmentType extends AbstractStructuralDBElement
|
||||||
*/
|
*/
|
||||||
#[Assert\Valid]
|
#[Assert\Valid]
|
||||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: AttachmentTypeAttachment::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
#[ORM\OneToMany(mappedBy: 'element', targetEntity: AttachmentTypeAttachment::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||||
#[Groups(['attachment_type:read', 'attachment_type:write'])]
|
#[Groups(['attachment_type:read', 'attachment_type:write', 'import', 'full'])]
|
||||||
protected Collection $attachments;
|
protected Collection $attachments;
|
||||||
|
|
||||||
#[ORM\ManyToOne(targetEntity: AttachmentTypeAttachment::class)]
|
#[ORM\ManyToOne(targetEntity: AttachmentTypeAttachment::class)]
|
||||||
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
|
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
|
||||||
#[Groups(['attachment_type:read', 'attachment_type:write'])]
|
#[Groups(['attachment_type:read', 'attachment_type:write', 'full'])]
|
||||||
protected ?Attachment $master_picture_attachment = null;
|
protected ?Attachment $master_picture_attachment = null;
|
||||||
|
|
||||||
/** @var Collection<int, AttachmentTypeParameter>
|
/** @var Collection<int, AttachmentTypeParameter>
|
||||||
*/
|
*/
|
||||||
#[Assert\Valid]
|
#[Assert\Valid]
|
||||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: AttachmentTypeParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
#[ORM\OneToMany(mappedBy: 'element', targetEntity: AttachmentTypeParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||||
#[ORM\OrderBy(['group' => 'ASC', 'name' => 'ASC'])]
|
#[ORM\OrderBy(['group' => Criteria::ASC, 'name' => 'ASC'])]
|
||||||
#[Groups(['attachment_type:read', 'attachment_type:write'])]
|
#[Groups(['attachment_type:read', 'attachment_type:write', 'import', 'full'])]
|
||||||
protected Collection $parameters;
|
protected Collection $parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,9 +135,9 @@ class AttachmentType extends AbstractStructuralDBElement
|
||||||
protected Collection $attachments_with_type;
|
protected Collection $attachments_with_type;
|
||||||
|
|
||||||
#[Groups(['attachment_type:read'])]
|
#[Groups(['attachment_type:read'])]
|
||||||
protected ?\DateTimeInterface $addedDate = null;
|
protected ?\DateTimeImmutable $addedDate = null;
|
||||||
#[Groups(['attachment_type:read'])]
|
#[Groups(['attachment_type:read'])]
|
||||||
protected ?\DateTimeInterface $lastModified = null;
|
protected ?\DateTimeImmutable $lastModified = null;
|
||||||
|
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
|
|
|
@ -41,14 +41,14 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||||
abstract class AbstractCompany extends AbstractPartsContainingDBElement
|
abstract class AbstractCompany extends AbstractPartsContainingDBElement
|
||||||
{
|
{
|
||||||
#[Groups(['company:read'])]
|
#[Groups(['company:read'])]
|
||||||
protected ?\DateTimeInterface $addedDate = null;
|
protected ?\DateTimeImmutable $addedDate = null;
|
||||||
#[Groups(['company:read'])]
|
#[Groups(['company:read'])]
|
||||||
protected ?\DateTimeInterface $lastModified = null;
|
protected ?\DateTimeImmutable $lastModified = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string The address of the company
|
* @var string The address of the company
|
||||||
*/
|
*/
|
||||||
#[Groups(['full', 'company:read', 'company:write'])]
|
#[Groups(['full', 'company:read', 'company:write', 'import', 'extended'])]
|
||||||
#[ORM\Column(type: Types::STRING)]
|
#[ORM\Column(type: Types::STRING)]
|
||||||
#[Assert\Length(max: 255)]
|
#[Assert\Length(max: 255)]
|
||||||
protected string $address = '';
|
protected string $address = '';
|
||||||
|
@ -56,7 +56,7 @@ abstract class AbstractCompany extends AbstractPartsContainingDBElement
|
||||||
/**
|
/**
|
||||||
* @var string The phone number of the company
|
* @var string The phone number of the company
|
||||||
*/
|
*/
|
||||||
#[Groups(['full', 'company:read', 'company:write'])]
|
#[Groups(['full', 'company:read', 'company:write', 'import', 'extended'])]
|
||||||
#[ORM\Column(type: Types::STRING)]
|
#[ORM\Column(type: Types::STRING)]
|
||||||
#[Assert\Length(max: 255)]
|
#[Assert\Length(max: 255)]
|
||||||
protected string $phone_number = '';
|
protected string $phone_number = '';
|
||||||
|
@ -64,7 +64,7 @@ abstract class AbstractCompany extends AbstractPartsContainingDBElement
|
||||||
/**
|
/**
|
||||||
* @var string The fax number of the company
|
* @var string The fax number of the company
|
||||||
*/
|
*/
|
||||||
#[Groups(['full', 'company:read', 'company:write'])]
|
#[Groups(['full', 'company:read', 'company:write', 'import', 'extended'])]
|
||||||
#[ORM\Column(type: Types::STRING)]
|
#[ORM\Column(type: Types::STRING)]
|
||||||
#[Assert\Length(max: 255)]
|
#[Assert\Length(max: 255)]
|
||||||
protected string $fax_number = '';
|
protected string $fax_number = '';
|
||||||
|
@ -73,7 +73,7 @@ abstract class AbstractCompany extends AbstractPartsContainingDBElement
|
||||||
* @var string The email address of the company
|
* @var string The email address of the company
|
||||||
*/
|
*/
|
||||||
#[Assert\Email]
|
#[Assert\Email]
|
||||||
#[Groups(['full', 'company:read', 'company:write'])]
|
#[Groups(['full', 'company:read', 'company:write', 'import', 'extended'])]
|
||||||
#[ORM\Column(type: Types::STRING)]
|
#[ORM\Column(type: Types::STRING)]
|
||||||
#[Assert\Length(max: 255)]
|
#[Assert\Length(max: 255)]
|
||||||
protected string $email_address = '';
|
protected string $email_address = '';
|
||||||
|
@ -82,12 +82,12 @@ abstract class AbstractCompany extends AbstractPartsContainingDBElement
|
||||||
* @var string The website of the company
|
* @var string The website of the company
|
||||||
*/
|
*/
|
||||||
#[Assert\Url]
|
#[Assert\Url]
|
||||||
#[Groups(['full', 'company:read', 'company:write'])]
|
#[Groups(['full', 'company:read', 'company:write', 'import', 'extended'])]
|
||||||
#[ORM\Column(type: Types::STRING)]
|
#[ORM\Column(type: Types::STRING)]
|
||||||
#[Assert\Length(max: 255)]
|
#[Assert\Length(max: 255)]
|
||||||
protected string $website = '';
|
protected string $website = '';
|
||||||
|
|
||||||
#[Groups(['company:read', 'company:write'])]
|
#[Groups(['company:read', 'company:write', 'import', 'full', 'extended'])]
|
||||||
protected string $comment = '';
|
protected string $comment = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,6 +95,7 @@ abstract class AbstractCompany extends AbstractPartsContainingDBElement
|
||||||
*/
|
*/
|
||||||
#[ORM\Column(type: Types::STRING)]
|
#[ORM\Column(type: Types::STRING)]
|
||||||
#[Assert\Length(max: 255)]
|
#[Assert\Length(max: 255)]
|
||||||
|
#[Groups(['full', 'company:read', 'company:write', 'import', 'extended'])]
|
||||||
protected string $auto_product_url = '';
|
protected string $auto_product_url = '';
|
||||||
|
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
|
|
|
@ -38,7 +38,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
#[ORM\MappedSuperclass(repositoryClass: AbstractPartsContainingRepository::class)]
|
#[ORM\MappedSuperclass(repositoryClass: AbstractPartsContainingRepository::class)]
|
||||||
abstract class AbstractPartsContainingDBElement extends AbstractStructuralDBElement
|
abstract class AbstractPartsContainingDBElement extends AbstractStructuralDBElement
|
||||||
{
|
{
|
||||||
#[Groups(['full'])]
|
#[Groups(['full', 'import'])]
|
||||||
protected Collection $parameters;
|
protected Collection $parameters;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
|
|
|
@ -30,11 +30,11 @@ interface PartsContainingRepositoryInterface
|
||||||
* Returns all parts associated with this element.
|
* Returns all parts associated with this element.
|
||||||
*
|
*
|
||||||
* @param object $element the element for which the parts should be determined
|
* @param object $element the element for which the parts should be determined
|
||||||
* @param array $order_by The order of the parts. Format ['name' => 'ASC']
|
* @param string $nameOrderDirection the direction in which the parts should be ordered by name, either ASC or DESC
|
||||||
*
|
*
|
||||||
* @return Part[]
|
* @return Part[]
|
||||||
*/
|
*/
|
||||||
public function getParts(object $element, array $order_by = ['name' => 'ASC']): array;
|
public function getParts(object $element, string $nameOrderDirection = "ASC"): array;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the count of the parts associated with this element.
|
* Gets the count of the parts associated with this element.
|
||||||
|
|
|
@ -34,28 +34,28 @@ use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
trait TimestampTrait
|
trait TimestampTrait
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \DateTimeInterface|null the date when this element was modified the last time
|
* @var \DateTimeImmutable|null the date when this element was modified the last time
|
||||||
*/
|
*/
|
||||||
#[Groups(['extended', 'full'])]
|
#[Groups(['extended', 'full'])]
|
||||||
#[ApiProperty(writable: false)]
|
#[ApiProperty(writable: false)]
|
||||||
#[ORM\Column(name: 'last_modified', type: Types::DATETIME_MUTABLE, options: ['default' => 'CURRENT_TIMESTAMP'])]
|
#[ORM\Column(name: 'last_modified', type: Types::DATETIME_IMMUTABLE, options: ['default' => 'CURRENT_TIMESTAMP'])]
|
||||||
protected ?\DateTimeInterface $lastModified = null;
|
protected ?\DateTimeImmutable $lastModified = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \DateTimeInterface|null the date when this element was created
|
* @var \DateTimeImmutable|null the date when this element was created
|
||||||
*/
|
*/
|
||||||
#[Groups(['extended', 'full'])]
|
#[Groups(['extended', 'full'])]
|
||||||
#[ApiProperty(writable: false)]
|
#[ApiProperty(writable: false)]
|
||||||
#[ORM\Column(name: 'datetime_added', type: Types::DATETIME_MUTABLE, options: ['default' => 'CURRENT_TIMESTAMP'])]
|
#[ORM\Column(name: 'datetime_added', type: Types::DATETIME_IMMUTABLE, options: ['default' => 'CURRENT_TIMESTAMP'])]
|
||||||
protected ?\DateTimeInterface $addedDate = null;
|
protected ?\DateTimeImmutable $addedDate = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the last time when the element was modified.
|
* Returns the last time when the element was modified.
|
||||||
* Returns null if the element was not yet saved to DB yet.
|
* Returns null if the element was not yet saved to DB yet.
|
||||||
*
|
*
|
||||||
* @return \DateTimeInterface|null the time of the last edit
|
* @return \DateTimeImmutable|null the time of the last edit
|
||||||
*/
|
*/
|
||||||
public function getLastModified(): ?\DateTimeInterface
|
public function getLastModified(): ?\DateTimeImmutable
|
||||||
{
|
{
|
||||||
return $this->lastModified;
|
return $this->lastModified;
|
||||||
}
|
}
|
||||||
|
@ -64,9 +64,9 @@ trait TimestampTrait
|
||||||
* Returns the date/time when the element was created.
|
* Returns the date/time when the element was created.
|
||||||
* Returns null if the element was not yet saved to DB yet.
|
* Returns null if the element was not yet saved to DB yet.
|
||||||
*
|
*
|
||||||
* @return \DateTimeInterface|null the creation time of the part
|
* @return \DateTimeImmutable|null the creation time of the part
|
||||||
*/
|
*/
|
||||||
public function getAddedDate(): ?\DateTimeInterface
|
public function getAddedDate(): ?\DateTimeImmutable
|
||||||
{
|
{
|
||||||
return $this->addedDate;
|
return $this->addedDate;
|
||||||
}
|
}
|
||||||
|
@ -78,9 +78,9 @@ trait TimestampTrait
|
||||||
#[ORM\PreUpdate]
|
#[ORM\PreUpdate]
|
||||||
public function updateTimestamps(): void
|
public function updateTimestamps(): void
|
||||||
{
|
{
|
||||||
$this->lastModified = new DateTime('now');
|
$this->lastModified = new \DateTimeImmutable('now');
|
||||||
if (null === $this->addedDate) {
|
if (null === $this->addedDate) {
|
||||||
$this->addedDate = new DateTime('now');
|
$this->addedDate = new \DateTimeImmutable('now');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue