From bf74302b7052396b8f6bf553919b3073f7ba0d60 Mon Sep 17 00:00:00 2001 From: Marcel Diegelmann Date: Mon, 24 Mar 2025 15:15:15 +0100 Subject: [PATCH 1/9] =?UTF-8?q?Benutzerdefinierten=20Bauteilstatus=20einf?= =?UTF-8?q?=C3=BChren?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/permissions.yaml | 6 +- docs/configuration.md | 2 +- migrations/Version20250321075747.php | 23 ++++ migrations/Version20250321141740.php | 25 ++++ .../Migrations/ImportPartKeeprCommand.php | 5 + .../AdminPages/BaseAdminController.php | 2 + src/DataTables/Filters/PartFilter.php | 3 + src/DataTables/PartsDataTable.php | 20 +++ src/Entity/Attachments/Attachment.php | 5 +- .../Attachments/PartCustomStateAttachment.php | 45 +++++++ src/Entity/Base/AbstractDBElement.php | 38 +++++- .../LogSystem/CollectionElementDeleted.php | 5 + src/Entity/LogSystem/LogTargetType.php | 3 + src/Entity/Parameters/AbstractParameter.php | 5 +- .../Parameters/PartCustomStateParameter.php | 65 ++++++++++ src/Entity/Parts/Part.php | 2 +- src/Entity/Parts/PartCustomState.php | 121 ++++++++++++++++++ .../PartTraits/AdvancedPropertyTrait.php | 28 +++- .../AdminPages/PartCustomStateAdminForm.php | 27 ++++ src/Form/Filters/PartFilterType.php | 6 + src/Form/Part/PartBaseType.php | 7 + .../Parts/PartCustomStateRepository.php | 48 +++++++ src/Security/Voter/AttachmentVoter.php | 3 + src/Security/Voter/ParameterVoter.php | 3 + src/Security/Voter/StructureVoter.php | 2 + .../Attachments/PartPreviewGenerator.php | 8 ++ src/Services/EDA/KiCadHelper.php | 4 + src/Services/ElementTypeNameGenerator.php | 2 + .../EntityMergers/Mergers/PartMerger.php | 1 + src/Services/EntityURLGenerator.php | 7 + .../PKDatastructureImporter.php | 21 +++ .../PartKeeprImporter/PKPartImporter.php | 2 + .../LabelSystem/SandboxedTwigFactory.php | 2 +- src/Services/Trees/ToolsTreeBuilder.php | 7 + .../UserSystem/PermissionPresetsHelper.php | 1 + src/Twig/EntityExtension.php | 2 + templates/admin/base_admin.html.twig | 2 +- .../admin/part_custom_state_admin.html.twig | 14 ++ templates/parts/edit/_advanced.html.twig | 3 +- templates/parts/lists/_filter.html.twig | 1 + .../PartCustomStateControllerTest.php | 35 +++++ tests/Entity/Attachments/AttachmentTest.php | 3 + .../EntityMergers/Mergers/PartMergerTest.php | 6 +- tests/assets/partkeepr_import_test.xml | 2 + translations/messages.cs.xlf | 54 ++++++++ translations/messages.da.xlf | 54 ++++++++ translations/messages.de.xlf | 54 ++++++++ translations/messages.el.xlf | 54 ++++++++ translations/messages.en.xlf | 54 ++++++++ translations/messages.es.xlf | 54 ++++++++ translations/messages.fr.xlf | 56 +++++++- translations/messages.it.xlf | 54 ++++++++ translations/messages.ja.xlf | 54 ++++++++ translations/messages.nl.xlf | 54 ++++++++ translations/messages.pl.xlf | 54 ++++++++ translations/messages.ru.xlf | 54 ++++++++ translations/messages.zh.xlf | 54 ++++++++ 57 files changed, 1312 insertions(+), 14 deletions(-) create mode 100644 migrations/Version20250321075747.php create mode 100644 migrations/Version20250321141740.php create mode 100644 src/Entity/Attachments/PartCustomStateAttachment.php create mode 100644 src/Entity/Parameters/PartCustomStateParameter.php create mode 100644 src/Entity/Parts/PartCustomState.php create mode 100644 src/Form/AdminPages/PartCustomStateAdminForm.php create mode 100644 src/Repository/Parts/PartCustomStateRepository.php create mode 100644 templates/admin/part_custom_state_admin.html.twig create mode 100644 tests/Controller/AdminPages/PartCustomStateControllerTest.php diff --git a/config/permissions.yaml b/config/permissions.yaml index 8cbd60c3f..7acee7f0e 100644 --- a/config/permissions.yaml +++ b/config/permissions.yaml @@ -24,7 +24,7 @@ perms: # Here comes a list with all Permission names (they have a perm_[name] co label: "perm.read" # If a part can be read by a user, he can also see all the datastructures (except devices) alsoSet: ['storelocations.read', 'footprints.read', 'categories.read', 'suppliers.read', 'manufacturers.read', - 'currencies.read', 'attachment_types.read', 'measurement_units.read'] + 'currencies.read', 'attachment_types.read', 'measurement_units.read', 'part_custom_states.read'] apiTokenRole: ROLE_API_READ_ONLY edit: label: "perm.edit" @@ -133,6 +133,10 @@ perms: # Here comes a list with all Permission names (they have a perm_[name] co <<: *PART_CONTAINING label: "perm.measurement_units" + part_custom_states: + <<: *PART_CONTAINING + label: "perm.part_custom_states" + tools: label: "perm.part.tools" operations: diff --git a/docs/configuration.md b/docs/configuration.md index d4b217816..2ba5ce903 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -136,7 +136,7 @@ bundled with Part-DB. Set `DATABASE_MYSQL_SSL_VERIFY_CERT` if you want to accept * `TABLE_PARTS_DEFAULT_COLUMNS`: The columns in parts tables, which are visible by default (when loading table for first time). Also specify the default order of the columns. This is a comma separated list of column names. Available columns - are: `name`, `id`, `ipn`, `description`, `category`, `footprint`, `manufacturer`, `storage_location`, `amount`, `minamount`, `partUnit`, `addedDate`, `lastModified`, `needs_review`, `favorite`, `manufacturing_status`, `manufacturer_product_number`, `mass`, `tags`, `attachments`, `edit`. + are: `name`, `id`, `ipn`, `description`, `category`, `footprint`, `manufacturer`, `storage_location`, `amount`, `minamount`, `partUnit`, `partCustomState`, `addedDate`, `lastModified`, `needs_review`, `favorite`, `manufacturing_status`, `manufacturer_product_number`, `mass`, `tags`, `attachments`, `edit`. ### History/Eventlog-related settings diff --git a/migrations/Version20250321075747.php b/migrations/Version20250321075747.php new file mode 100644 index 000000000..45b35397e --- /dev/null +++ b/migrations/Version20250321075747.php @@ -0,0 +1,23 @@ +addSql('CREATE TABLE `part_custom_states` (id INT AUTO_INCREMENT NOT NULL, parent_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, comment LONGTEXT NOT NULL, not_selectable TINYINT(1) NOT NULL, alternative_names LONGTEXT DEFAULT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, INDEX IDX_F552745D727ACA70 (parent_id), INDEX part_custom_state_name (name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci`'); + $this->addSql('ALTER TABLE `part_custom_states` ADD CONSTRAINT FK_F552745D727ACA70 FOREIGN KEY (parent_id) REFERENCES `part_custom_states` (id)'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE `part_custom_states` DROP FOREIGN KEY FK_F552745D727ACA70'); + $this->addSql('DROP TABLE `part_custom_states`'); + } +} diff --git a/migrations/Version20250321141740.php b/migrations/Version20250321141740.php new file mode 100644 index 000000000..cd1aefdc0 --- /dev/null +++ b/migrations/Version20250321141740.php @@ -0,0 +1,25 @@ +addSql('ALTER TABLE parts ADD id_part_custom_state INT DEFAULT NULL AFTER id_part_unit'); + $this->addSql('ALTER TABLE parts ADD CONSTRAINT FK_6940A7FEA3ED1215 FOREIGN KEY (id_part_custom_state) REFERENCES `part_custom_states` (id)'); + $this->addSql('CREATE INDEX IDX_6940A7FEA3ED1215 ON parts (id_part_custom_state)'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE `parts` DROP FOREIGN KEY FK_6940A7FEA3ED1215'); + $this->addSql('DROP INDEX IDX_6940A7FEA3ED1215 ON `parts`'); + $this->addSql('ALTER TABLE `parts` DROP id_part_custom_state'); + } +} diff --git a/src/Command/Migrations/ImportPartKeeprCommand.php b/src/Command/Migrations/ImportPartKeeprCommand.php index aee71afe7..429f018d5 100644 --- a/src/Command/Migrations/ImportPartKeeprCommand.php +++ b/src/Command/Migrations/ImportPartKeeprCommand.php @@ -121,6 +121,11 @@ private function doImport(SymfonyStyle $io, array $data): void $count = $this->datastructureImporter->importPartUnits($data); $io->success('Imported '.$count.' measurement units.'); + //Import the custom states + $io->info('Importing custom states...'); + $count = $this->datastructureImporter->importPartCustomStates($data); + $io->success('Imported '.$count.' custom states.'); + //Import manufacturers $io->info('Importing manufacturers...'); $count = $this->datastructureImporter->importManufacturers($data); diff --git a/src/Controller/AdminPages/BaseAdminController.php b/src/Controller/AdminPages/BaseAdminController.php index edc5917ac..e7dd74218 100644 --- a/src/Controller/AdminPages/BaseAdminController.php +++ b/src/Controller/AdminPages/BaseAdminController.php @@ -232,6 +232,7 @@ protected function _edit(AbstractNamedDBElement $entity, Request $request, Entit 'timeTravel' => $timeTravel_timestamp, 'repo' => $repo, 'partsContainingElement' => $repo instanceof PartsContainingRepositoryInterface, + 'showParameters' => !($this instanceof PartCustomStateController), ]); } @@ -382,6 +383,7 @@ protected function _new(Request $request, EntityManagerInterface $em, EntityImpo 'import_form' => $import_form, 'mass_creation_form' => $mass_creation_form, 'route_base' => $this->route_base, + 'showParameters' => !($this instanceof PartCustomStateController), ]); } diff --git a/src/DataTables/Filters/PartFilter.php b/src/DataTables/Filters/PartFilter.php index e44cf69d7..cf185dfd7 100644 --- a/src/DataTables/Filters/PartFilter.php +++ b/src/DataTables/Filters/PartFilter.php @@ -41,6 +41,7 @@ use App\Entity\Parts\Footprint; use App\Entity\Parts\Manufacturer; use App\Entity\Parts\MeasurementUnit; +use App\Entity\Parts\PartCustomState; use App\Entity\Parts\PartLot; use App\Entity\Parts\StorageLocation; use App\Entity\Parts\Supplier; @@ -86,6 +87,7 @@ class PartFilter implements FilterInterface public readonly EntityConstraint $lotOwner; public readonly EntityConstraint $measurementUnit; + public readonly EntityConstraint $partCustomState; public readonly TextConstraint $manufacturer_product_url; public readonly TextConstraint $manufacturer_product_number; public readonly IntConstraint $attachmentsCount; @@ -128,6 +130,7 @@ public function __construct(NodesListBuilder $nodesListBuilder) $this->favorite = new BooleanConstraint('part.favorite'); $this->needsReview = new BooleanConstraint('part.needs_review'); $this->measurementUnit = new EntityConstraint($nodesListBuilder, MeasurementUnit::class, 'part.partUnit'); + $this->partCustomState = new EntityConstraint($nodesListBuilder, PartCustomState::class, 'part.partCustomState'); $this->mass = new NumberConstraint('part.mass'); $this->dbId = new IntConstraint('part.id'); $this->ipn = new TextConstraint('part.ipn'); diff --git a/src/DataTables/PartsDataTable.php b/src/DataTables/PartsDataTable.php index a97762b11..0baee6300 100644 --- a/src/DataTables/PartsDataTable.php +++ b/src/DataTables/PartsDataTable.php @@ -174,6 +174,19 @@ public function configure(DataTable $dataTable, array $options): void return $tmp; } ]) + ->add('partCustomState', TextColumn::class, [ + 'label' => $this->translator->trans('part.table.partCustomState'), + 'orderField' => 'NATSORT(_partCustomState.name)', + 'render' => function($value, Part $context): string { + $partCustomState = $context->getPartCustomState(); + + if ($partCustomState === null) { + return ''; + } + + return htmlspecialchars($partCustomState->getName()); + } + ]) ->add('addedDate', LocaleDateTimeColumn::class, [ 'label' => $this->translator->trans('part.table.addedDate'), ]) @@ -309,6 +322,7 @@ private function getDetailQuery(QueryBuilder $builder, array $filter_results): v ->addSelect('footprint') ->addSelect('manufacturer') ->addSelect('partUnit') + ->addSelect('partCustomState') ->addSelect('master_picture_attachment') ->addSelect('footprint_attachment') ->addSelect('partLots') @@ -327,6 +341,7 @@ private function getDetailQuery(QueryBuilder $builder, array $filter_results): v ->leftJoin('orderdetails.supplier', 'suppliers') ->leftJoin('part.attachments', 'attachments') ->leftJoin('part.partUnit', 'partUnit') + ->leftJoin('part.partCustomState', 'partCustomState') ->leftJoin('part.parameters', 'parameters') ->where('part.id IN (:ids)') ->setParameter('ids', $ids) @@ -344,6 +359,7 @@ private function getDetailQuery(QueryBuilder $builder, array $filter_results): v ->addGroupBy('suppliers') ->addGroupBy('attachments') ->addGroupBy('partUnit') + ->addGroupBy('partCustomState') ->addGroupBy('parameters'); //Get the results in the same order as the IDs were passed @@ -415,6 +431,10 @@ private function addJoins(QueryBuilder $builder): QueryBuilder $builder->leftJoin('part.partUnit', '_partUnit'); $builder->addGroupBy('_partUnit'); } + if (str_contains($dql, '_partCustomState')) { + $builder->leftJoin('part.partCustomState', '_partCustomState'); + $builder->addGroupBy('_partCustomState'); + } if (str_contains($dql, '_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 diff --git a/src/Entity/Attachments/Attachment.php b/src/Entity/Attachments/Attachment.php index 00cf581a8..35a6a5293 100644 --- a/src/Entity/Attachments/Attachment.php +++ b/src/Entity/Attachments/Attachment.php @@ -97,7 +97,7 @@ #[DiscriminatorMap(typeProperty: '_type', mapping: self::API_DISCRIMINATOR_MAP)] abstract class Attachment extends AbstractNamedDBElement { - private const ORM_DISCRIMINATOR_MAP = ['Part' => PartAttachment::class, 'Device' => ProjectAttachment::class, + private const ORM_DISCRIMINATOR_MAP = ['Part' => PartAttachment::class, 'PartCustomState' => PartCustomStateAttachment::class, 'Device' => ProjectAttachment::class, 'AttachmentType' => AttachmentTypeAttachment::class, 'Category' => CategoryAttachment::class, 'Footprint' => FootprintAttachment::class, 'Manufacturer' => ManufacturerAttachment::class, 'Currency' => CurrencyAttachment::class, 'Group' => GroupAttachment::class, 'MeasurementUnit' => MeasurementUnitAttachment::class, @@ -107,7 +107,8 @@ abstract class Attachment extends AbstractNamedDBElement /* * The discriminator map used for API platform. The key should be the same as the api platform short type (the @type JSONLD field). */ - private const API_DISCRIMINATOR_MAP = ["Part" => PartAttachment::class, "Project" => ProjectAttachment::class, "AttachmentType" => AttachmentTypeAttachment::class, + private const API_DISCRIMINATOR_MAP = ["Part" => PartAttachment::class, "PartCustomState" => PartCustomStateAttachment::class, "Project" => ProjectAttachment::class, + "AttachmentType" => AttachmentTypeAttachment::class, "Category" => CategoryAttachment::class, "Footprint" => FootprintAttachment::class, "Manufacturer" => ManufacturerAttachment::class, "Currency" => CurrencyAttachment::class, "Group" => GroupAttachment::class, "MeasurementUnit" => MeasurementUnitAttachment::class, "StorageLocation" => StorageLocationAttachment::class, "Supplier" => SupplierAttachment::class, "User" => UserAttachment::class, "LabelProfile" => LabelAttachment::class]; diff --git a/src/Entity/Attachments/PartCustomStateAttachment.php b/src/Entity/Attachments/PartCustomStateAttachment.php new file mode 100644 index 000000000..3a561b136 --- /dev/null +++ b/src/Entity/Attachments/PartCustomStateAttachment.php @@ -0,0 +1,45 @@ +. + */ + +declare(strict_types=1); + +namespace App\Entity\Attachments; + +use App\Entity\Parts\PartCustomState; +use App\Serializer\APIPlatform\OverrideClassDenormalizer; +use Doctrine\ORM\Mapping as ORM; +use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; +use Symfony\Component\Serializer\Attribute\Context; + +/** + * An attachment attached to a part custom state element. + * @extends Attachment + */ +#[UniqueEntity(['name', 'attachment_type', 'element'])] +#[ORM\Entity] +class PartCustomStateAttachment extends Attachment +{ + final public const ALLOWED_ELEMENT_CLASS = PartCustomState::class; + + #[ORM\ManyToOne(targetEntity: PartCustomState::class, inversedBy: 'attachments')] + #[ORM\JoinColumn(name: 'element_id', nullable: false, onDelete: 'CASCADE')] + #[Context(denormalizationContext: [OverrideClassDenormalizer::CONTEXT_KEY => self::ALLOWED_ELEMENT_CLASS])] + protected ?AttachmentContainingDBElement $element = null; +} diff --git a/src/Entity/Base/AbstractDBElement.php b/src/Entity/Base/AbstractDBElement.php index 9fb5d6489..a088b3dfc 100644 --- a/src/Entity/Base/AbstractDBElement.php +++ b/src/Entity/Base/AbstractDBElement.php @@ -33,6 +33,7 @@ use App\Entity\Attachments\ManufacturerAttachment; use App\Entity\Attachments\MeasurementUnitAttachment; use App\Entity\Attachments\PartAttachment; +use App\Entity\Attachments\PartCustomStateAttachment; use App\Entity\Attachments\ProjectAttachment; use App\Entity\Attachments\StorageLocationAttachment; use App\Entity\Attachments\SupplierAttachment; @@ -40,6 +41,7 @@ use App\Entity\Parameters\AbstractParameter; use App\Entity\Parts\Category; use App\Entity\PriceInformations\Pricedetail; +use App\Entity\Parts\PartCustomState; use App\Entity\ProjectSystem\Project; use App\Entity\ProjectSystem\ProjectBOMEntry; use App\Entity\Parts\Footprint; @@ -68,7 +70,41 @@ * Every database table which are managed with this class (or a subclass of it) * must have the table row "id"!! The ID is the unique key to identify the elements. */ -#[DiscriminatorMap(typeProperty: 'type', mapping: ['attachment_type' => AttachmentType::class, 'attachment' => Attachment::class, 'attachment_type_attachment' => AttachmentTypeAttachment::class, 'category_attachment' => CategoryAttachment::class, 'currency_attachment' => CurrencyAttachment::class, 'footprint_attachment' => FootprintAttachment::class, 'group_attachment' => GroupAttachment::class, 'label_attachment' => LabelAttachment::class, 'manufacturer_attachment' => ManufacturerAttachment::class, 'measurement_unit_attachment' => MeasurementUnitAttachment::class, 'part_attachment' => PartAttachment::class, 'project_attachment' => ProjectAttachment::class, 'storelocation_attachment' => StorageLocationAttachment::class, 'supplier_attachment' => SupplierAttachment::class, 'user_attachment' => UserAttachment::class, 'category' => Category::class, 'project' => Project::class, 'project_bom_entry' => ProjectBOMEntry::class, 'footprint' => Footprint::class, 'group' => Group::class, 'manufacturer' => Manufacturer::class, 'orderdetail' => Orderdetail::class, 'part' => Part::class, 'pricedetail' => Pricedetail::class, 'storelocation' => StorageLocation::class, 'part_lot' => PartLot::class, 'currency' => Currency::class, 'measurement_unit' => MeasurementUnit::class, 'parameter' => AbstractParameter::class, 'supplier' => Supplier::class, 'user' => User::class])] +#[DiscriminatorMap(typeProperty: 'type', mapping: [ + 'attachment_type' => AttachmentType::class, + 'attachment' => Attachment::class, + 'attachment_type_attachment' => AttachmentTypeAttachment::class, + 'category_attachment' => CategoryAttachment::class, + 'currency_attachment' => CurrencyAttachment::class, + 'footprint_attachment' => FootprintAttachment::class, + 'group_attachment' => GroupAttachment::class, + 'label_attachment' => LabelAttachment::class, + 'manufacturer_attachment' => ManufacturerAttachment::class, + 'measurement_unit_attachment' => MeasurementUnitAttachment::class, + 'part_attachment' => PartAttachment::class, + 'part_custom_state_attachment' => PartCustomStateAttachment::class, + 'project_attachment' => ProjectAttachment::class, + 'storelocation_attachment' => StorageLocationAttachment::class, + 'supplier_attachment' => SupplierAttachment::class, + 'user_attachment' => UserAttachment::class, + 'category' => Category::class, + 'project' => Project::class, + 'project_bom_entry' => ProjectBOMEntry::class, + 'footprint' => Footprint::class, + 'group' => Group::class, + 'manufacturer' => Manufacturer::class, + 'orderdetail' => Orderdetail::class, + 'part' => Part::class, + 'part_custom_state' => PartCustomState::class, + 'pricedetail' => Pricedetail::class, + 'storelocation' => StorageLocation::class, + 'part_lot' => PartLot::class, + 'currency' => Currency::class, + 'measurement_unit' => MeasurementUnit::class, + 'parameter' => AbstractParameter::class, + 'supplier' => Supplier::class, + 'user' => User::class] +)] #[ORM\MappedSuperclass(repositoryClass: DBElementRepository::class)] abstract class AbstractDBElement implements JsonSerializable { diff --git a/src/Entity/LogSystem/CollectionElementDeleted.php b/src/Entity/LogSystem/CollectionElementDeleted.php index 16bf33f59..34ab8fba8 100644 --- a/src/Entity/LogSystem/CollectionElementDeleted.php +++ b/src/Entity/LogSystem/CollectionElementDeleted.php @@ -46,6 +46,7 @@ use App\Entity\Attachments\AttachmentTypeAttachment; use App\Entity\Attachments\CategoryAttachment; use App\Entity\Attachments\CurrencyAttachment; +use App\Entity\Attachments\PartCustomStateAttachment; use App\Entity\Attachments\ProjectAttachment; use App\Entity\Attachments\FootprintAttachment; use App\Entity\Attachments\GroupAttachment; @@ -58,6 +59,8 @@ use App\Entity\Base\AbstractDBElement; use App\Entity\Contracts\LogWithEventUndoInterface; use App\Entity\Contracts\NamedElementInterface; +use App\Entity\Parameters\PartCustomStateParameter; +use App\Entity\Parts\PartCustomState; use App\Entity\ProjectSystem\Project; use App\Entity\Parameters\AbstractParameter; use App\Entity\Parameters\AttachmentTypeParameter; @@ -158,6 +161,7 @@ private function resolveAbstractClassToInstantiableClass(string $abstract_class) Part::class => PartParameter::class, StorageLocation::class => StorageLocationParameter::class, Supplier::class => SupplierParameter::class, + PartCustomState::class => PartCustomStateParameter::class, default => throw new \RuntimeException('Unknown target class for parameter: '.$this->getTargetClass()), }; } @@ -173,6 +177,7 @@ private function resolveAbstractClassToInstantiableClass(string $abstract_class) Manufacturer::class => ManufacturerAttachment::class, MeasurementUnit::class => MeasurementUnitAttachment::class, Part::class => PartAttachment::class, + PartCustomState::class => PartCustomStateAttachment::class, StorageLocation::class => StorageLocationAttachment::class, Supplier::class => SupplierAttachment::class, User::class => UserAttachment::class, diff --git a/src/Entity/LogSystem/LogTargetType.php b/src/Entity/LogSystem/LogTargetType.php index 61a2b081c..3b2d8682a 100644 --- a/src/Entity/LogSystem/LogTargetType.php +++ b/src/Entity/LogSystem/LogTargetType.php @@ -34,6 +34,7 @@ use App\Entity\Parts\MeasurementUnit; use App\Entity\Parts\Part; use App\Entity\Parts\PartAssociation; +use App\Entity\Parts\PartCustomState; use App\Entity\Parts\PartLot; use App\Entity\Parts\StorageLocation; use App\Entity\Parts\Supplier; @@ -71,6 +72,7 @@ enum LogTargetType: int case PART_ASSOCIATION = 20; case BULK_INFO_PROVIDER_IMPORT_JOB = 21; case BULK_INFO_PROVIDER_IMPORT_JOB_PART = 22; + case PART_CUSTOM_STATE = 23; /** * Returns the class name of the target type or null if the target type is NONE. @@ -102,6 +104,7 @@ public function toClass(): ?string self::PART_ASSOCIATION => PartAssociation::class, self::BULK_INFO_PROVIDER_IMPORT_JOB => BulkInfoProviderImportJob::class, self::BULK_INFO_PROVIDER_IMPORT_JOB_PART => BulkInfoProviderImportJobPart::class, + self::PART_CUSTOM_STATE => PartCustomState::class }; } diff --git a/src/Entity/Parameters/AbstractParameter.php b/src/Entity/Parameters/AbstractParameter.php index 39f333dad..388745d49 100644 --- a/src/Entity/Parameters/AbstractParameter.php +++ b/src/Entity/Parameters/AbstractParameter.php @@ -73,7 +73,8 @@ #[ORM\DiscriminatorMap([0 => CategoryParameter::class, 1 => CurrencyParameter::class, 2 => ProjectParameter::class, 3 => FootprintParameter::class, 4 => GroupParameter::class, 5 => ManufacturerParameter::class, 6 => MeasurementUnitParameter::class, 7 => PartParameter::class, 8 => StorageLocationParameter::class, - 9 => SupplierParameter::class, 10 => AttachmentTypeParameter::class])] + 9 => SupplierParameter::class, 10 => AttachmentTypeParameter::class, + 12 => PartCustomStateParameter::class])] #[ORM\Table('parameters')] #[ORM\Index(columns: ['name'], name: 'parameter_name_idx')] #[ORM\Index(columns: ['param_group'], name: 'parameter_group_idx')] @@ -105,7 +106,7 @@ abstract class AbstractParameter extends AbstractNamedDBElement implements Uniqu "AttachmentType" => AttachmentTypeParameter::class, "Category" => CategoryParameter::class, "Currency" => CurrencyParameter::class, "Project" => ProjectParameter::class, "Footprint" => FootprintParameter::class, "Group" => GroupParameter::class, "Manufacturer" => ManufacturerParameter::class, "MeasurementUnit" => MeasurementUnitParameter::class, - "StorageLocation" => StorageLocationParameter::class, "Supplier" => SupplierParameter::class]; + "StorageLocation" => StorageLocationParameter::class, "Supplier" => SupplierParameter::class, "PartCustomState" => PartCustomStateParameter::class]; /** * @var string The class of the element that can be passed to this attachment. Must be overridden in subclasses. diff --git a/src/Entity/Parameters/PartCustomStateParameter.php b/src/Entity/Parameters/PartCustomStateParameter.php new file mode 100644 index 000000000..ceedf7b4d --- /dev/null +++ b/src/Entity/Parameters/PartCustomStateParameter.php @@ -0,0 +1,65 @@ +. + */ + +declare(strict_types=1); + +/** + * 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 . + */ + +namespace App\Entity\Parameters; + +use App\Entity\Base\AbstractDBElement; +use App\Entity\Parts\PartCustomState; +use App\Repository\ParameterRepository; +use App\Serializer\APIPlatform\OverrideClassDenormalizer; +use Doctrine\ORM\Mapping as ORM; +use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; +use Symfony\Component\Serializer\Attribute\Context; + +#[UniqueEntity(fields: ['name', 'group', 'element'])] +#[ORM\Entity(repositoryClass: ParameterRepository::class)] +class PartCustomStateParameter extends AbstractParameter +{ + final public const ALLOWED_ELEMENT_CLASS = PartCustomState::class; + + /** + * @var PartCustomState the element this para is associated with + */ + #[ORM\ManyToOne(targetEntity: PartCustomState::class, inversedBy: 'parameters')] + #[ORM\JoinColumn(name: 'element_id', nullable: false, onDelete: 'CASCADE')] + #[Context(denormalizationContext: [OverrideClassDenormalizer::CONTEXT_KEY => self::ALLOWED_ELEMENT_CLASS])] + protected ?AbstractDBElement $element = null; +} diff --git a/src/Entity/Parts/Part.php b/src/Entity/Parts/Part.php index 2f274a8af..f1dd6040a 100644 --- a/src/Entity/Parts/Part.php +++ b/src/Entity/Parts/Part.php @@ -107,7 +107,7 @@ denormalizationContext: ['groups' => ['part:write', 'api:basic:write', 'eda_info:write', 'attachment:write', 'parameter:write'], 'openapi_definition_name' => 'Write'], )] #[ApiFilter(PropertyFilter::class)] -#[ApiFilter(EntityFilter::class, properties: ["category", "footprint", "manufacturer", "partUnit"])] +#[ApiFilter(EntityFilter::class, properties: ["category", "footprint", "manufacturer", "partUnit", "partCustomState"])] #[ApiFilter(PartStoragelocationFilter::class, properties: ["storage_location"])] #[ApiFilter(LikeFilter::class, properties: ["name", "comment", "description", "ipn", "manufacturer_product_number"])] #[ApiFilter(TagFilter::class, properties: ["tags"])] diff --git a/src/Entity/Parts/PartCustomState.php b/src/Entity/Parts/PartCustomState.php new file mode 100644 index 000000000..dac7fe58a --- /dev/null +++ b/src/Entity/Parts/PartCustomState.php @@ -0,0 +1,121 @@ +. + */ + +declare(strict_types=1); + +namespace App\Entity\Parts; + +use ApiPlatform\Metadata\ApiProperty; +use App\Entity\Attachments\PartCustomStateAttachment; +use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface; +use ApiPlatform\Doctrine\Orm\Filter\DateFilter; +use ApiPlatform\Doctrine\Orm\Filter\OrderFilter; +use ApiPlatform\Metadata\ApiFilter; +use ApiPlatform\Metadata\ApiResource; +use ApiPlatform\Metadata\Delete; +use ApiPlatform\Metadata\Get; +use ApiPlatform\Metadata\GetCollection; +use ApiPlatform\Metadata\Patch; +use ApiPlatform\Metadata\Post; +use ApiPlatform\Serializer\Filter\PropertyFilter; +use App\ApiPlatform\Filter\LikeFilter; +use App\Entity\Base\AbstractPartsContainingDBElement; +use App\Entity\Base\AbstractStructuralDBElement; +use App\Entity\Parameters\PartCustomStateParameter; +use App\Repository\Parts\PartCustomStateRepository; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; +use Doctrine\Common\Collections\Criteria; +use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Serializer\Annotation\Groups; +use Symfony\Component\Validator\Constraints as Assert; + +/** + * This entity represents a custom part state. + * If an organisation uses Part-DB and has its custom part states, this is useful. + * + * @extends AbstractPartsContainingDBElement + */ +#[ORM\Entity(repositoryClass: PartCustomStateRepository::class)] +#[ORM\Table('`part_custom_states`')] +#[ORM\Index(columns: ['name'], name: 'part_custom_state_name')] +#[ApiResource( + operations: [ + new Get(security: 'is_granted("read", object)'), + new GetCollection(security: 'is_granted("@part_custom_states.read")'), + new Post(securityPostDenormalize: 'is_granted("create", object)'), + new Patch(security: 'is_granted("edit", object)'), + new Delete(security: 'is_granted("delete", object)'), + ], + normalizationContext: ['groups' => ['part_custom_state:read', 'api:basic:read'], 'openapi_definition_name' => 'Read'], + denormalizationContext: ['groups' => ['part_custom_state:write', 'api:basic:write'], 'openapi_definition_name' => 'Write'], +)] +#[ApiFilter(PropertyFilter::class)] +#[ApiFilter(LikeFilter::class, properties: ["name"])] +#[ApiFilter(DateFilter::class, strategy: DateFilterInterface::EXCLUDE_NULL)] +#[ApiFilter(OrderFilter::class, properties: ['name', 'id', 'addedDate', 'lastModified'])] +class PartCustomState extends AbstractPartsContainingDBElement +{ + /** + * @var string The comment info for this element as markdown + */ + #[Groups(['part_custom_state:read', 'part_custom_state:write', 'full', 'import'])] + protected string $comment = ''; + + #[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class, cascade: ['persist'])] + #[ORM\OrderBy(['name' => Criteria::ASC])] + protected Collection $children; + + #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')] + #[ORM\JoinColumn(name: 'parent_id')] + #[Groups(['part_custom_state:read', 'part_custom_state:write'])] + #[ApiProperty(readableLink: false, writableLink: false)] + protected ?AbstractStructuralDBElement $parent = null; + + /** + * @var Collection + */ + #[Assert\Valid] + #[ORM\OneToMany(targetEntity: PartCustomStateAttachment::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)] + #[ORM\OrderBy(['name' => Criteria::ASC])] + #[Groups(['part_custom_state:read', 'part_custom_state:write'])] + protected Collection $attachments; + + /** @var Collection + */ + #[Assert\Valid] + #[ORM\OneToMany(mappedBy: 'element', targetEntity: PartCustomStateAttachment::class, cascade: ['persist', 'remove'], orphanRemoval: true)] + #[ORM\OrderBy(['name' => 'ASC'])] + #[Groups(['part_custom_state:read', 'part_custom_state:write'])] + protected Collection $parameters; + + #[Groups(['part_custom_state:read'])] + protected ?\DateTimeImmutable $addedDate = null; + #[Groups(['part_custom_state:read'])] + protected ?\DateTimeImmutable $lastModified = null; + + public function __construct() + { + parent::__construct(); + $this->children = new ArrayCollection(); + $this->attachments = new ArrayCollection(); + $this->parameters = new ArrayCollection(); + } +} diff --git a/src/Entity/Parts/PartTraits/AdvancedPropertyTrait.php b/src/Entity/Parts/PartTraits/AdvancedPropertyTrait.php index 230ba7b76..dd541d79a 100644 --- a/src/Entity/Parts/PartTraits/AdvancedPropertyTrait.php +++ b/src/Entity/Parts/PartTraits/AdvancedPropertyTrait.php @@ -23,6 +23,7 @@ namespace App\Entity\Parts\PartTraits; use App\Entity\Parts\InfoProviderReference; +use App\Entity\Parts\PartCustomState; use Doctrine\DBAL\Types\Types; use App\Entity\Parts\Part; use Doctrine\ORM\Mapping as ORM; @@ -73,6 +74,14 @@ trait AdvancedPropertyTrait #[Groups(['full', 'part:read'])] protected InfoProviderReference $providerReference; + /** + * @var ?PartCustomState the custom state for the part + */ + #[Groups(['extended', 'full', 'import', 'part:read', 'part:write'])] + #[ORM\ManyToOne(targetEntity: PartCustomState::class)] + #[ORM\JoinColumn(name: 'id_part_custom_state')] + protected ?PartCustomState $partCustomState = null; + /** * Checks if this part is marked, for that it needs further review. */ @@ -180,7 +189,24 @@ public function setProviderReference(InfoProviderReference $providerReference): return $this; } + /** + * Gets the custom part state for the part + * Returns null if no specific part state is set. + */ + public function getPartCustomState(): ?PartCustomState + { + return $this->partCustomState; + } + /** + * Sets the custom part state. + * + * @return $this + */ + public function setPartCustomState(?PartCustomState $partCustomState): self + { + $this->partCustomState = $partCustomState; - + return $this; + } } diff --git a/src/Form/AdminPages/PartCustomStateAdminForm.php b/src/Form/AdminPages/PartCustomStateAdminForm.php new file mode 100644 index 000000000..b8bb2815e --- /dev/null +++ b/src/Form/AdminPages/PartCustomStateAdminForm.php @@ -0,0 +1,27 @@ +. + */ + +declare(strict_types=1); + +namespace App\Form\AdminPages; + +class PartCustomStateAdminForm extends BaseEntityAdminForm +{ +} diff --git a/src/Form/Filters/PartFilterType.php b/src/Form/Filters/PartFilterType.php index 871f9b074..e101c6351 100644 --- a/src/Form/Filters/PartFilterType.php +++ b/src/Form/Filters/PartFilterType.php @@ -32,6 +32,7 @@ use App\Entity\Parts\Footprint; use App\Entity\Parts\Manufacturer; use App\Entity\Parts\MeasurementUnit; +use App\Entity\Parts\PartCustomState; use App\Entity\Parts\StorageLocation; use App\Entity\Parts\Supplier; use App\Entity\ProjectSystem\Project; @@ -139,6 +140,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'entity_class' => MeasurementUnit::class ]); + $builder->add('partCustomState', StructuralEntityConstraintType::class, [ + 'label' => 'part.edit.partCustomState', + 'entity_class' => PartCustomState::class + ]); + $builder->add('lastModified', DateTimeConstraintType::class, [ 'label' => 'lastModified' ]); diff --git a/src/Form/Part/PartBaseType.php b/src/Form/Part/PartBaseType.php index 0bd3d0e3f..f0ba180e0 100644 --- a/src/Form/Part/PartBaseType.php +++ b/src/Form/Part/PartBaseType.php @@ -30,6 +30,7 @@ use App\Entity\Parts\ManufacturingStatus; use App\Entity\Parts\MeasurementUnit; use App\Entity\Parts\Part; +use App\Entity\Parts\PartCustomState; use App\Entity\PriceInformations\Orderdetail; use App\Form\AttachmentFormType; use App\Form\ParameterType; @@ -171,6 +172,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'disable_not_selectable' => true, 'label' => 'part.edit.partUnit', ]) + ->add('partCustomState', StructuralEntityType::class, [ + 'class' => PartCustomState::class, + 'required' => false, + 'disable_not_selectable' => true, + 'label' => 'part.edit.partCustomState', + ]) ->add('ipn', TextType::class, [ 'required' => false, 'empty_data' => null, diff --git a/src/Repository/Parts/PartCustomStateRepository.php b/src/Repository/Parts/PartCustomStateRepository.php new file mode 100644 index 000000000..d66221a24 --- /dev/null +++ b/src/Repository/Parts/PartCustomStateRepository.php @@ -0,0 +1,48 @@ +. + */ +namespace App\Repository\Parts; + +use App\Entity\Parts\PartCustomState; +use App\Repository\AbstractPartsContainingRepository; +use InvalidArgumentException; + +class PartCustomStateRepository extends AbstractPartsContainingRepository +{ + public function getParts(object $element, string $nameOrderDirection = "ASC"): array + { + if (!$element instanceof PartCustomState) { + throw new InvalidArgumentException('$element must be an PartCustomState!'); + } + + return $this->getPartsByField($element, $nameOrderDirection, 'partUnit'); + } + + public function getPartsCount(object $element): int + { + if (!$element instanceof PartCustomState) { + throw new InvalidArgumentException('$element must be an PartCustomState!'); + } + + return $this->getPartsCountByField($element, 'partUnit'); + } +} diff --git a/src/Security/Voter/AttachmentVoter.php b/src/Security/Voter/AttachmentVoter.php index bd7ae4df8..df3d73a72 100644 --- a/src/Security/Voter/AttachmentVoter.php +++ b/src/Security/Voter/AttachmentVoter.php @@ -22,6 +22,7 @@ namespace App\Security\Voter; +use App\Entity\Attachments\PartCustomStateAttachment; use App\Services\UserSystem\VoterHelper; use Symfony\Bundle\SecurityBundle\Security; use App\Entity\Attachments\AttachmentContainingDBElement; @@ -99,6 +100,8 @@ protected function voteOnAttribute(string $attribute, $subject, TokenInterface $ $param = 'measurement_units'; } elseif (is_a($subject, PartAttachment::class, true)) { $param = 'parts'; + } elseif (is_a($subject, PartCustomStateAttachment::class, true)) { + $param = 'part_custom_states'; } elseif (is_a($subject, StorageLocationAttachment::class, true)) { $param = 'storelocations'; } elseif (is_a($subject, SupplierAttachment::class, true)) { diff --git a/src/Security/Voter/ParameterVoter.php b/src/Security/Voter/ParameterVoter.php index f59bdeaf5..5dc30ea25 100644 --- a/src/Security/Voter/ParameterVoter.php +++ b/src/Security/Voter/ParameterVoter.php @@ -22,6 +22,7 @@ */ namespace App\Security\Voter; +use App\Entity\Parameters\PartCustomStateParameter; use App\Services\UserSystem\VoterHelper; use Symfony\Bundle\SecurityBundle\Security; use App\Entity\Base\AbstractDBElement; @@ -97,6 +98,8 @@ protected function voteOnAttribute(string $attribute, $subject, TokenInterface $ $param = 'measurement_units'; } elseif (is_a($subject, PartParameter::class, true)) { $param = 'parts'; + } elseif (is_a($subject, PartCustomStateParameter::class, true)) { + $param = 'part_custom_states'; } elseif (is_a($subject, StorageLocationParameter::class, true)) { $param = 'storelocations'; } elseif (is_a($subject, SupplierParameter::class, true)) { diff --git a/src/Security/Voter/StructureVoter.php b/src/Security/Voter/StructureVoter.php index ad0299a79..16d38e058 100644 --- a/src/Security/Voter/StructureVoter.php +++ b/src/Security/Voter/StructureVoter.php @@ -23,6 +23,7 @@ namespace App\Security\Voter; use App\Entity\Attachments\AttachmentType; +use App\Entity\Parts\PartCustomState; use App\Entity\ProjectSystem\Project; use App\Entity\Parts\Category; use App\Entity\Parts\Footprint; @@ -53,6 +54,7 @@ final class StructureVoter extends Voter Supplier::class => 'suppliers', Currency::class => 'currencies', MeasurementUnit::class => 'measurement_units', + PartCustomState::class => 'part_custom_states', ]; public function __construct(private readonly VoterHelper $helper) diff --git a/src/Services/Attachments/PartPreviewGenerator.php b/src/Services/Attachments/PartPreviewGenerator.php index ba6e5db0d..ef13265f1 100644 --- a/src/Services/Attachments/PartPreviewGenerator.php +++ b/src/Services/Attachments/PartPreviewGenerator.php @@ -23,6 +23,7 @@ namespace App\Services\Attachments; use App\Entity\Parts\Footprint; +use App\Entity\Parts\PartCustomState; use App\Entity\ProjectSystem\Project; use App\Entity\Parts\Category; use App\Entity\Parts\StorageLocation; @@ -103,6 +104,13 @@ public function getPreviewAttachments(Part $part): array } } + if ($part->getPartCustomState() instanceof PartCustomState) { + $attachment = $part->getPartCustomState()->getMasterPictureAttachment(); + if ($this->isAttachmentValidPicture($attachment)) { + $list[] = $attachment; + } + } + if ($part->getManufacturer() instanceof Manufacturer) { $attachment = $part->getManufacturer()->getMasterPictureAttachment(); if ($this->isAttachmentValidPicture($attachment)) { diff --git a/src/Services/EDA/KiCadHelper.php b/src/Services/EDA/KiCadHelper.php index 75c2cc346..4b7c5e5a5 100644 --- a/src/Services/EDA/KiCadHelper.php +++ b/src/Services/EDA/KiCadHelper.php @@ -233,6 +233,10 @@ public function getKiCADPart(Part $part): array } $result["fields"]["Part-DB Unit"] = $this->createField($unit); } + if ($part->getPartCustomState() !== null) { + $customState = $part->getPartCustomState()->getName(); + $result["fields"]["Part-DB Custom state"] = $this->createField($customState); + } if ($part->getMass()) { $result["fields"]["Mass"] = $this->createField($part->getMass() . ' g'); } diff --git a/src/Services/ElementTypeNameGenerator.php b/src/Services/ElementTypeNameGenerator.php index 326707b77..deb4cf30c 100644 --- a/src/Services/ElementTypeNameGenerator.php +++ b/src/Services/ElementTypeNameGenerator.php @@ -37,6 +37,7 @@ use App\Entity\Parts\MeasurementUnit; use App\Entity\Parts\Part; use App\Entity\Parts\PartAssociation; +use App\Entity\Parts\PartCustomState; use App\Entity\Parts\PartLot; use App\Entity\Parts\StorageLocation; use App\Entity\Parts\Supplier; @@ -83,6 +84,7 @@ public function __construct(protected TranslatorInterface $translator, private r PartAssociation::class => $this->translator->trans('part_association.label'), BulkInfoProviderImportJob::class => $this->translator->trans('bulk_info_provider_import_job.label'), BulkInfoProviderImportJobPart::class => $this->translator->trans('bulk_info_provider_import_job_part.label'), + PartCustomState::class => $this->translator->trans('part_custom_state.label'), ]; } diff --git a/src/Services/EntityMergers/Mergers/PartMerger.php b/src/Services/EntityMergers/Mergers/PartMerger.php index 01b53e25e..d1f5c1374 100644 --- a/src/Services/EntityMergers/Mergers/PartMerger.php +++ b/src/Services/EntityMergers/Mergers/PartMerger.php @@ -65,6 +65,7 @@ public function merge(object $target, object $other, array $context = []): Part $this->useOtherValueIfNotNull($target, $other, 'footprint'); $this->useOtherValueIfNotNull($target, $other, 'category'); $this->useOtherValueIfNotNull($target, $other, 'partUnit'); + $this->useOtherValueIfNotNull($target, $other, 'partCustomState'); //We assume that the higher value is the correct one for minimum instock $this->useLargerValue($target, $other, 'minamount'); diff --git a/src/Services/EntityURLGenerator.php b/src/Services/EntityURLGenerator.php index 78db06f07..91e271cc0 100644 --- a/src/Services/EntityURLGenerator.php +++ b/src/Services/EntityURLGenerator.php @@ -27,6 +27,7 @@ use App\Entity\Attachments\PartAttachment; use App\Entity\Base\AbstractDBElement; use App\Entity\Parameters\PartParameter; +use App\Entity\Parts\PartCustomState; use App\Entity\ProjectSystem\Project; use App\Entity\LabelSystem\LabelProfile; use App\Entity\Parts\Category; @@ -107,6 +108,7 @@ public function timeTravelURL(AbstractDBElement $entity, \DateTimeInterface $dat MeasurementUnit::class => 'measurement_unit_edit', Group::class => 'group_edit', LabelProfile::class => 'label_profile_edit', + PartCustomState::class => 'part_custom_state_edit', ]; try { @@ -213,6 +215,7 @@ public function infoURL(AbstractDBElement $entity): string MeasurementUnit::class => 'measurement_unit_edit', Group::class => 'group_edit', LabelProfile::class => 'label_profile_edit', + PartCustomState::class => 'part_custom_state_edit', ]; return $this->urlGenerator->generate($this->mapToController($map, $entity), ['id' => $entity->getID()]); @@ -243,6 +246,7 @@ public function editURL(AbstractDBElement $entity): string MeasurementUnit::class => 'measurement_unit_edit', Group::class => 'group_edit', LabelProfile::class => 'label_profile_edit', + PartCustomState::class => 'part_custom_state_edit', ]; return $this->urlGenerator->generate($this->mapToController($map, $entity), ['id' => $entity->getID()]); @@ -274,6 +278,7 @@ public function createURL(AbstractDBElement|string $entity): string MeasurementUnit::class => 'measurement_unit_new', Group::class => 'group_new', LabelProfile::class => 'label_profile_new', + PartCustomState::class => 'part_custom_state_new', ]; return $this->urlGenerator->generate($this->mapToController($map, $entity)); @@ -305,6 +310,7 @@ public function cloneURL(AbstractDBElement $entity): string MeasurementUnit::class => 'measurement_unit_clone', Group::class => 'group_clone', LabelProfile::class => 'label_profile_clone', + PartCustomState::class => 'part_custom_state_clone', ]; return $this->urlGenerator->generate($this->mapToController($map, $entity), ['id' => $entity->getID()]); @@ -350,6 +356,7 @@ public function deleteURL(AbstractDBElement $entity): string MeasurementUnit::class => 'measurement_unit_delete', Group::class => 'group_delete', LabelProfile::class => 'label_profile_delete', + PartCustomState::class => 'part_custom_state_delete', ]; return $this->urlGenerator->generate($this->mapToController($map, $entity), ['id' => $entity->getID()]); diff --git a/src/Services/ImportExportSystem/PartKeeprImporter/PKDatastructureImporter.php b/src/Services/ImportExportSystem/PartKeeprImporter/PKDatastructureImporter.php index 1f842c23d..9e674f05c 100644 --- a/src/Services/ImportExportSystem/PartKeeprImporter/PKDatastructureImporter.php +++ b/src/Services/ImportExportSystem/PartKeeprImporter/PKDatastructureImporter.php @@ -29,6 +29,7 @@ use App\Entity\Parts\Footprint; use App\Entity\Parts\Manufacturer; use App\Entity\Parts\MeasurementUnit; +use App\Entity\Parts\PartCustomState; use App\Entity\Parts\StorageLocation; use App\Entity\Parts\Supplier; use Doctrine\ORM\EntityManagerInterface; @@ -148,6 +149,26 @@ public function importPartUnits(array $data): int return is_countable($partunit_data) ? count($partunit_data) : 0; } + public function importPartCustomStates(array $data): int + { + if (!isset($data['partcustomstate'])) { + throw new \RuntimeException('$data must contain a "partcustomstate" key!'); + } + + $partCustomStateData = $data['partcustomstate']; + foreach ($partCustomStateData as $partCustomState) { + $customState = new PartCustomState(); + $customState->setName($partCustomState['name']); + + $this->setIDOfEntity($customState, $partCustomState['id']); + $this->em->persist($customState); + } + + $this->em->flush(); + + return is_countable($partCustomStateData) ? count($partCustomStateData) : 0; + } + public function importCategories(array $data): int { if (!isset($data['partcategory'])) { diff --git a/src/Services/ImportExportSystem/PartKeeprImporter/PKPartImporter.php b/src/Services/ImportExportSystem/PartKeeprImporter/PKPartImporter.php index 80c2dbf77..ab06a1346 100644 --- a/src/Services/ImportExportSystem/PartKeeprImporter/PKPartImporter.php +++ b/src/Services/ImportExportSystem/PartKeeprImporter/PKPartImporter.php @@ -91,6 +91,8 @@ public function importParts(array $data): int $this->setAssociationField($entity, 'partUnit', MeasurementUnit::class, $part['partUnit_id']); } + $this->setAssociationField($entity, 'partCustomState', MeasurementUnit::class, $part['partCustomState_id']); + //Create a part lot to store the stock level and location $lot = new PartLot(); $lot->setAmount((float) ($part['stockLevel'] ?? 0)); diff --git a/src/Services/LabelSystem/SandboxedTwigFactory.php b/src/Services/LabelSystem/SandboxedTwigFactory.php index d6ea69685..d5e09fa54 100644 --- a/src/Services/LabelSystem/SandboxedTwigFactory.php +++ b/src/Services/LabelSystem/SandboxedTwigFactory.php @@ -133,7 +133,7 @@ final class SandboxedTwigFactory Supplier::class => ['getShippingCosts', 'getDefaultCurrency'], Part::class => ['isNeedsReview', 'getTags', 'getMass', 'getIpn', 'getProviderReference', 'getDescription', 'getComment', 'isFavorite', 'getCategory', 'getFootprint', - 'getPartLots', 'getPartUnit', 'useFloatAmount', 'getMinAmount', 'getAmountSum', 'isNotEnoughInstock', 'isAmountUnknown', 'getExpiredAmountSum', + 'getPartLots', 'getPartUnit', 'getPartCustomState', 'useFloatAmount', 'getMinAmount', 'getAmountSum', 'isNotEnoughInstock', 'isAmountUnknown', 'getExpiredAmountSum', 'getManufacturerProductUrl', 'getCustomProductURL', 'getManufacturingStatus', 'getManufacturer', 'getManufacturerProductNumber', 'getOrderdetails', 'isObsolete', 'getParameters', 'getGroupedParameters', diff --git a/src/Services/Trees/ToolsTreeBuilder.php b/src/Services/Trees/ToolsTreeBuilder.php index 036797f61..56064ba46 100644 --- a/src/Services/Trees/ToolsTreeBuilder.php +++ b/src/Services/Trees/ToolsTreeBuilder.php @@ -29,6 +29,7 @@ use App\Entity\Parts\Manufacturer; use App\Entity\Parts\MeasurementUnit; use App\Entity\Parts\Part; +use App\Entity\Parts\PartCustomState; use App\Entity\Parts\StorageLocation; use App\Entity\Parts\Supplier; use App\Entity\PriceInformations\Currency; @@ -217,6 +218,12 @@ protected function getEditNodes(): array $this->urlGenerator->generate('label_profile_new') ))->setIcon('fa-fw fa-treeview fa-solid fa-qrcode'); } + if ($this->security->isGranted('read', new PartCustomState())) { + $nodes[] = (new TreeViewNode( + $this->translator->trans('tree.tools.edit.part_custom_state'), + $this->urlGenerator->generate('part_custom_state_new') + ))->setIcon('fa-fw fa-treeview fa-solid fa-tools'); + } if ($this->security->isGranted('create', new Part())) { $nodes[] = (new TreeViewNode( $this->translator->trans('tree.tools.edit.part'), diff --git a/src/Services/UserSystem/PermissionPresetsHelper.php b/src/Services/UserSystem/PermissionPresetsHelper.php index 554da8b32..a63013886 100644 --- a/src/Services/UserSystem/PermissionPresetsHelper.php +++ b/src/Services/UserSystem/PermissionPresetsHelper.php @@ -102,6 +102,7 @@ private function admin(HasPermissionsInterface $perm_holder): void $this->permissionResolver->setAllOperationsOfPermission($perm_holder, 'attachment_types', PermissionData::ALLOW); $this->permissionResolver->setAllOperationsOfPermission($perm_holder, 'currencies', PermissionData::ALLOW); $this->permissionResolver->setAllOperationsOfPermission($perm_holder, 'measurement_units', PermissionData::ALLOW); + $this->permissionResolver->setAllOperationsOfPermission($perm_holder, 'part_custom_states', PermissionData::ALLOW); $this->permissionResolver->setAllOperationsOfPermission($perm_holder, 'suppliers', PermissionData::ALLOW); $this->permissionResolver->setAllOperationsOfPermission($perm_holder, 'projects', PermissionData::ALLOW); diff --git a/src/Twig/EntityExtension.php b/src/Twig/EntityExtension.php index 762ebb094..b5e5c3ca2 100644 --- a/src/Twig/EntityExtension.php +++ b/src/Twig/EntityExtension.php @@ -24,6 +24,7 @@ use App\Entity\Attachments\Attachment; use App\Entity\Base\AbstractDBElement; +use App\Entity\Parts\PartCustomState; use App\Entity\ProjectSystem\Project; use App\Entity\LabelSystem\LabelProfile; use App\Entity\Parts\Category; @@ -115,6 +116,7 @@ public function getEntityType(object $entity): ?string Currency::class => 'currency', MeasurementUnit::class => 'measurement_unit', LabelProfile::class => 'label_profile', + PartCustomState::class => 'part_custom_state', ]; foreach ($map as $class => $type) { diff --git a/templates/admin/base_admin.html.twig b/templates/admin/base_admin.html.twig index 51790c3c1..e9fc0fb99 100644 --- a/templates/admin/base_admin.html.twig +++ b/templates/admin/base_admin.html.twig @@ -86,7 +86,7 @@ - {% if entity.parameters is defined %} + {% if entity.parameters is defined and showParameters == true %} diff --git a/templates/admin/part_custom_state_admin.html.twig b/templates/admin/part_custom_state_admin.html.twig new file mode 100644 index 000000000..004ceb657 --- /dev/null +++ b/templates/admin/part_custom_state_admin.html.twig @@ -0,0 +1,14 @@ +{% extends "admin/base_admin.html.twig" %} + +{% block card_title %} + {% trans %}part_custom_state.caption{% endtrans %} +{% endblock %} + +{% block edit_title %} + {% trans %}part_custom_state.edit{% endtrans %}: {{ entity.name }} +{% endblock %} + +{% block new_title %} + {% trans %}part_custom_state.new{% endtrans %} +{% endblock %} + diff --git a/templates/parts/edit/_advanced.html.twig b/templates/parts/edit/_advanced.html.twig index 12b546abc..46aac7b61 100644 --- a/templates/parts/edit/_advanced.html.twig +++ b/templates/parts/edit/_advanced.html.twig @@ -2,4 +2,5 @@ {{ form_row(form.favorite) }} {{ form_row(form.mass) }} {{ form_row(form.ipn) }} -{{ form_row(form.partUnit) }} \ No newline at end of file +{{ form_row(form.partUnit) }} +{{ form_row(form.partCustomState) }} \ No newline at end of file diff --git a/templates/parts/lists/_filter.html.twig b/templates/parts/lists/_filter.html.twig index ba9168d16..2fb5bff21 100644 --- a/templates/parts/lists/_filter.html.twig +++ b/templates/parts/lists/_filter.html.twig @@ -61,6 +61,7 @@ {{ form_row(filterForm.favorite) }} {{ form_row(filterForm.needsReview) }} {{ form_row(filterForm.measurementUnit) }} + {{ form_row(filterForm.partCustomState) }} {{ form_row(filterForm.mass) }} {{ form_row(filterForm.dbId) }} {{ form_row(filterForm.ipn) }} diff --git a/tests/Controller/AdminPages/PartCustomStateControllerTest.php b/tests/Controller/AdminPages/PartCustomStateControllerTest.php new file mode 100644 index 000000000..b92308893 --- /dev/null +++ b/tests/Controller/AdminPages/PartCustomStateControllerTest.php @@ -0,0 +1,35 @@ +. + */ + +declare(strict_types=1); + +namespace App\Tests\Controller\AdminPages; + +use App\Entity\Parts\PartCustomState; + +/** + * @group slow + * @group DB + */ +class PartCustomStateControllerTest extends AbstractAdminControllerTest +{ + protected static string $base_path = '/en/part_custom_state'; + protected static string $entity_class = PartCustomState::class; +} diff --git a/tests/Entity/Attachments/AttachmentTest.php b/tests/Entity/Attachments/AttachmentTest.php index 00a68d7d4..35222d63d 100644 --- a/tests/Entity/Attachments/AttachmentTest.php +++ b/tests/Entity/Attachments/AttachmentTest.php @@ -29,6 +29,7 @@ use App\Entity\Attachments\AttachmentTypeAttachment; use App\Entity\Attachments\CategoryAttachment; use App\Entity\Attachments\CurrencyAttachment; +use App\Entity\Attachments\PartCustomStateAttachment; use App\Entity\Attachments\ProjectAttachment; use App\Entity\Attachments\FootprintAttachment; use App\Entity\Attachments\GroupAttachment; @@ -38,6 +39,7 @@ use App\Entity\Attachments\StorageLocationAttachment; use App\Entity\Attachments\SupplierAttachment; use App\Entity\Attachments\UserAttachment; +use App\Entity\Parts\PartCustomState; use App\Entity\ProjectSystem\Project; use App\Entity\Parts\Category; use App\Entity\Parts\Footprint; @@ -86,6 +88,7 @@ public static function subClassesDataProvider(): \Iterator yield [ManufacturerAttachment::class, Manufacturer::class]; yield [MeasurementUnitAttachment::class, MeasurementUnit::class]; yield [PartAttachment::class, Part::class]; + yield [PartCustomStateAttachment::class, PartCustomState::class]; yield [StorageLocationAttachment::class, StorageLocation::class]; yield [SupplierAttachment::class, Supplier::class]; yield [UserAttachment::class, User::class]; diff --git a/tests/Services/EntityMergers/Mergers/PartMergerTest.php b/tests/Services/EntityMergers/Mergers/PartMergerTest.php index 56c7712e0..7db4ddd66 100644 --- a/tests/Services/EntityMergers/Mergers/PartMergerTest.php +++ b/tests/Services/EntityMergers/Mergers/PartMergerTest.php @@ -29,6 +29,7 @@ use App\Entity\Parts\MeasurementUnit; use App\Entity\Parts\Part; use App\Entity\Parts\PartAssociation; +use App\Entity\Parts\PartCustomState; use App\Entity\Parts\PartLot; use App\Entity\PriceInformations\Orderdetail; use App\Services\EntityMergers\Mergers\PartMerger; @@ -54,6 +55,7 @@ public function testMergeOfEntityRelations(): void $manufacturer1 = new Manufacturer(); $manufacturer2 = new Manufacturer(); $unit = new MeasurementUnit(); + $customState = new PartCustomState(); $part1 = (new Part()) ->setCategory($category) @@ -62,7 +64,8 @@ public function testMergeOfEntityRelations(): void $part2 = (new Part()) ->setFootprint($footprint) ->setManufacturer($manufacturer2) - ->setPartUnit($unit); + ->setPartUnit($unit) + ->setPartCustomState($customState); $merged = $this->merger->merge($part1, $part2); $this->assertSame($merged, $part1); @@ -70,6 +73,7 @@ public function testMergeOfEntityRelations(): void $this->assertSame($footprint, $merged->getFootprint()); $this->assertSame($manufacturer1, $merged->getManufacturer()); $this->assertSame($unit, $merged->getPartUnit()); + $this->assertSame($customState, $merged->getPartCustomState()); } public function testMergeOfTags(): void diff --git a/tests/assets/partkeepr_import_test.xml b/tests/assets/partkeepr_import_test.xml index 4fa497e2e..28e6f0991 100644 --- a/tests/assets/partkeepr_import_test.xml +++ b/tests/assets/partkeepr_import_test.xml @@ -7437,11 +7437,13 @@ + + diff --git a/translations/messages.cs.xlf b/translations/messages.cs.xlf index 1f234450e..2f6d8cc27 100644 --- a/translations/messages.cs.xlf +++ b/translations/messages.cs.xlf @@ -548,6 +548,12 @@ Měrné jednotky + + + part_custom_state.caption + Vlastní stav komponenty + + Part-DB1\templates\AdminPages\StorelocationAdmin.html.twig:5 @@ -4831,6 +4837,12 @@ Pokud jste to provedli nesprávně nebo pokud počítač již není důvěryhodn Měrné jednotky + + + part.table.partCustomState + Vlastní stav součásti + + Part-DB1\src\DataTables\PartsDataTable.php:236 @@ -5695,6 +5707,12 @@ Pokud jste to provedli nesprávně nebo pokud počítač již není důvěryhodn Měrná jednotka + + + part.edit.partCustomState + Vlastní stav součásti + + Part-DB1\src\Form\Part\PartBaseType.php:212 @@ -5982,6 +6000,12 @@ Pokud jste to provedli nesprávně nebo pokud počítač již není důvěryhodn Měrná jednotka + + + part_custom_state.label + Vlastní stav součásti + + Part-DB1\src\Services\ElementTypeNameGenerator.php:90 @@ -6225,6 +6249,12 @@ Pokud jste to provedli nesprávně nebo pokud počítač již není důvěryhodn Měrné jednotky + + + tree.tools.edit.part_custom_state + Vlastní stav součásti + + Part-DB1\src\Services\Trees\ToolsTreeBuilder.php:203 @@ -8495,6 +8525,12 @@ Element 3 Měrná jednotka + + + perm.part_custom_states + Vlastní stav součásti + + obsolete @@ -10806,6 +10842,12 @@ Element 3 Měrná jednotka + + + log.element_edited.changed_fields.partCustomState + Vlastní stav součásti + + log.element_edited.changed_fields.expiration_date @@ -11064,6 +11106,18 @@ Element 3 Upravit měrnou jednotku + + + part_custom_state.new + Nový vlastní stav komponenty + + + + + part_custom_state.edit + Upravit vlastní stav komponenty + + user.aboutMe.label diff --git a/translations/messages.da.xlf b/translations/messages.da.xlf index d72589864..d88ad77ef 100644 --- a/translations/messages.da.xlf +++ b/translations/messages.da.xlf @@ -548,6 +548,12 @@ Måleenhed + + + part_custom_state.caption + Brugerdefineret komponentstatus + + Part-DB1\templates\AdminPages\StorelocationAdmin.html.twig:5 @@ -4838,6 +4844,12 @@ Bemærk også, at uden to-faktor-godkendelse er din konto ikke længere så godt Måleenhed + + + part.table.partCustomState + Brugerdefineret komponentstatus + + Part-DB1\src\DataTables\PartsDataTable.php:236 @@ -5702,6 +5714,12 @@ Bemærk også, at uden to-faktor-godkendelse er din konto ikke længere så godt Måleenhed + + + part.edit.partCustomState + Brugerdefineret deltilstand + + Part-DB1\src\Form\Part\PartBaseType.php:212 @@ -5989,6 +6007,12 @@ Bemærk også, at uden to-faktor-godkendelse er din konto ikke længere så godt Måleenhed + + + part_custom_state.label + Brugerdefineret deltilstand + + Part-DB1\src\Services\ElementTypeNameGenerator.php:90 @@ -6232,6 +6256,12 @@ Bemærk også, at uden to-faktor-godkendelse er din konto ikke længere så godt Måleenhed + + + tree.tools.edit.part_custom_state + Brugerdefineret komponenttilstand + + Part-DB1\src\Services\Trees\ToolsTreeBuilder.php:203 @@ -8502,6 +8532,12 @@ Element 3 Måleenhed + + + perm.part_custom_states + Brugerdefineret komponentstatus + + obsolete @@ -10832,6 +10868,12 @@ Element 3 Måleenhed + + + log.element_edited.changed_fields.partCustomState + Brugerdefineret komponentstatus + + log.element_edited.changed_fields.expiration_date @@ -11096,6 +11138,18 @@ Oversættelsen Ret måleenhed + + + part_custom_state.new + Ny brugerdefineret komponentstatus + + + + + part_custom_state.edit + Rediger brugerdefineret komponentstatus + + user.aboutMe.label diff --git a/translations/messages.de.xlf b/translations/messages.de.xlf index 06326a21e..38020aac0 100644 --- a/translations/messages.de.xlf +++ b/translations/messages.de.xlf @@ -548,6 +548,12 @@ Maßeinheit + + + part_custom_state.caption + Benutzerdefinierter Bauteilstatus + + Part-DB1\templates\AdminPages\StorelocationAdmin.html.twig:5 @@ -4830,6 +4836,12 @@ Wenn Sie dies fehlerhafterweise gemacht haben oder ein Computer nicht mehr vertr Maßeinheit + + + part.table.partCustomState + Benutzerdefinierter Bauteilstatus + + Part-DB1\src\DataTables\PartsDataTable.php:236 @@ -5694,6 +5706,12 @@ Wenn Sie dies fehlerhafterweise gemacht haben oder ein Computer nicht mehr vertr Maßeinheit + + + part.edit.partCustomState + Benutzerdefinierter Bauteilstatus + + Part-DB1\src\Form\Part\PartBaseType.php:212 @@ -5981,6 +5999,12 @@ Wenn Sie dies fehlerhafterweise gemacht haben oder ein Computer nicht mehr vertr Maßeinheit + + + part_custom_state.label + Benutzerdefinierter Bauteilstatus + + Part-DB1\src\Services\ElementTypeNameGenerator.php:90 @@ -6224,6 +6248,12 @@ Wenn Sie dies fehlerhafterweise gemacht haben oder ein Computer nicht mehr vertr Maßeinheiten + + + tree.tools.edit.part_custom_state + Benutzerdefinierter Bauteilstatus + + Part-DB1\src\Services\Trees\ToolsTreeBuilder.php:203 @@ -8497,6 +8527,12 @@ Element 1 -> Element 1.2 Maßeinheiten + + + perm.part_custom_states + Benutzerdefinierter Bauteilstatus + + obsolete @@ -10880,6 +10916,12 @@ Element 1 -> Element 1.2 Maßeinheit + + + log.element_edited.changed_fields.partCustomState + Benutzerdefinierter Bauteilstatus + + log.element_edited.changed_fields.expiration_date @@ -11144,6 +11186,18 @@ Element 1 -> Element 1.2 Bearbeite Maßeinheit + + + part_custom_state.new + Neuer benutzerdefinierter Bauteilstatus + + + + + part_custom_state.edit + Bearbeite benutzerdefinierten Bauteilstatus + + user.aboutMe.label diff --git a/translations/messages.el.xlf b/translations/messages.el.xlf index cc17d9be4..4ea8a2e4b 100644 --- a/translations/messages.el.xlf +++ b/translations/messages.el.xlf @@ -318,6 +318,12 @@ Μονάδα μέτρησης + + + part_custom_state.caption + Προσαρμοσμένη κατάσταση εξαρτήματος + + Part-DB1\templates\AdminPages\StorelocationAdmin.html.twig:5 @@ -1535,5 +1541,53 @@ Επεξεργασία + + + perm.part_custom_states + Προσαρμοσμένη κατάσταση εξαρτήματος + + + + + tree.tools.edit.part_custom_state + Προσαρμοσμένη κατάσταση εξαρτήματος + + + + + part_custom_state.new + Νέα προσαρμοσμένη κατάσταση εξαρτήματος + + + + + part_custom_state.edit + Επεξεργασία προσαρμοσμένης κατάστασης εξαρτήματος + + + + + part_custom_state.label + Προσαρμοσμένη κατάσταση μέρους + + + + + log.element_edited.changed_fields.partCustomState + Προσαρμοσμένη κατάσταση εξαρτήματος + + + + + part.edit.partCustomState + Προσαρμοσμένη κατάσταση εξαρτήματος + + + + + part.table.partCustomState + Προσαρμοσμένη κατάσταση μέρους + + diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf index a2ec2f65c..3a2a66c28 100644 --- a/translations/messages.en.xlf +++ b/translations/messages.en.xlf @@ -548,6 +548,12 @@ Measurement Unit + + + part_custom_state.caption + Custom part state + + Part-DB1\templates\AdminPages\StorelocationAdmin.html.twig:5 @@ -4831,6 +4837,12 @@ If you have done this incorrectly or if a computer is no longer trusted, you can Measurement Unit + + + part.table.partCustomState + Custom part state + + Part-DB1\src\DataTables\PartsDataTable.php:236 @@ -5695,6 +5707,12 @@ If you have done this incorrectly or if a computer is no longer trusted, you can Measuring unit + + + part.edit.partCustomState + Custom part state + + Part-DB1\src\Form\Part\PartBaseType.php:212 @@ -5982,6 +6000,12 @@ If you have done this incorrectly or if a computer is no longer trusted, you can Measurement unit + + + part_custom_state.label + Custom part state + + Part-DB1\src\Services\ElementTypeNameGenerator.php:90 @@ -6225,6 +6249,12 @@ If you have done this incorrectly or if a computer is no longer trusted, you can Measurement Unit + + + tree.tools.edit.part_custom_state + Custom part state + + Part-DB1\src\Services\Trees\ToolsTreeBuilder.php:203 @@ -8498,6 +8528,12 @@ Element 1 -> Element 1.2 Measurement unit + + + perm.part_custom_states + Custom part state + + obsolete @@ -10881,6 +10917,12 @@ Element 1 -> Element 1.2 Measuring Unit + + + log.element_edited.changed_fields.partCustomState + Custom part state + + log.element_edited.changed_fields.expiration_date @@ -11145,6 +11187,18 @@ Element 1 -> Element 1.2 Edit Measurement Unit + + + part_custom_state.new + New custom part state + + + + + part_custom_state.edit + Edit custom part state + + user.aboutMe.label diff --git a/translations/messages.es.xlf b/translations/messages.es.xlf index fce38e52f..a79119aaa 100644 --- a/translations/messages.es.xlf +++ b/translations/messages.es.xlf @@ -548,6 +548,12 @@ Unidad de medida + + + part_custom_state.caption + Estado personalizado del componente + + Part-DB1\templates\AdminPages\StorelocationAdmin.html.twig:5 @@ -4830,6 +4836,12 @@ Subelementos serán desplazados hacia arriba. Unidad de Medida + + + part.table.partCustomState + Estado personalizado del componente + + Part-DB1\src\DataTables\PartsDataTable.php:236 @@ -5694,6 +5706,12 @@ Subelementos serán desplazados hacia arriba. Unidad de medida + + + part.edit.partCustomState + Estado personalizado de la pieza + + Part-DB1\src\Form\Part\PartBaseType.php:212 @@ -5981,6 +5999,12 @@ Subelementos serán desplazados hacia arriba. Unidad de medida + + + part_custom_state.label + Estado personalizado de la pieza + + Part-DB1\src\Services\ElementTypeNameGenerator.php:90 @@ -6224,6 +6248,12 @@ Subelementos serán desplazados hacia arriba. Unidad de medida + + + tree.tools.edit.part_custom_state + Estado personalizado del componente + + Part-DB1\src\Services\Trees\ToolsTreeBuilder.php:203 @@ -8494,6 +8524,12 @@ Elemento 3 Unidad de medida + + + perm.part_custom_states + Estado personalizado del componente + + obsolete @@ -10824,6 +10860,12 @@ Elemento 3 Unidad de medida + + + log.element_edited.changed_fields.partCustomState + Estado personalizado del componente + + log.element_edited.changed_fields.expiration_date @@ -11082,6 +11124,18 @@ Elemento 3 Editar Unidad de Medida + + + part_custom_state.new + Nuevo estado personalizado del componente + + + + + part_custom_state.edit + Editar estado personalizado del componente + + user.aboutMe.label diff --git a/translations/messages.fr.xlf b/translations/messages.fr.xlf index 292dbafaa..39ff97d3b 100644 --- a/translations/messages.fr.xlf +++ b/translations/messages.fr.xlf @@ -517,6 +517,12 @@ Unité de mesure + + + part_custom_state.caption + État personnalisé du composant + + Part-DB1\templates\AdminPages\StorelocationAdmin.html.twig:5 @@ -4793,6 +4799,12 @@ Si vous avez fait cela de manière incorrecte ou si un ordinateur n'est plus fia Unité de mesure + + + part.table.partCustomState + État personnalisé de la pièce + + Part-DB1\src\DataTables\PartsDataTable.php:236 @@ -5657,6 +5669,12 @@ Si vous avez fait cela de manière incorrecte ou si un ordinateur n'est plus fia Unité de mesure + + + part.edit.partCustomState + État personnalisé de la pièce + + Part-DB1\src\Form\Part\PartBaseType.php:212 @@ -5934,6 +5952,12 @@ Si vous avez fait cela de manière incorrecte ou si un ordinateur n'est plus fia Unité de mesure + + + part_custom_state.label + État personnalisé de la pièce + + Part-DB1\src\Services\ElementTypeNameGenerator.php:90 @@ -6166,6 +6190,12 @@ Si vous avez fait cela de manière incorrecte ou si un ordinateur n'est plus fia Unité de mesure + + + tree.tools.edit.part_custom_state + État personnalisé de la pièce + + Part-DB1\src\Services\Trees\ToolsTreeBuilder.php:203 @@ -6947,7 +6977,7 @@ Si vous avez fait cela de manière incorrecte ou si un ordinateur n'est plus fia company.edit.address.placeholder - Ex. 99 exemple de rue + Ex. 99 exemple de rue exemple de ville @@ -8423,6 +8453,12 @@ exemple de ville Unités de mesure + + + perm.part_custom_states + État personnalisé du composant + + obsolete @@ -9097,5 +9133,23 @@ exemple de ville Si vous avez des questions à propos de Part-DB , rendez vous sur <a href="%href%" class="link-external" target="_blank">Github</a> + + + part_custom_state.new + Nouveau statut personnalisé du composant + + + + + part_custom_state.edit + Modifier le statut personnalisé du composant + + + + + log.element_edited.changed_fields.partCustomState + État personnalisé de la pièce + + diff --git a/translations/messages.it.xlf b/translations/messages.it.xlf index 828304eba..781ca49fb 100644 --- a/translations/messages.it.xlf +++ b/translations/messages.it.xlf @@ -548,6 +548,12 @@ Unità di misura + + + part_custom_state.caption + Stato personalizzato del componente + + Part-DB1\templates\AdminPages\StorelocationAdmin.html.twig:5 @@ -4832,6 +4838,12 @@ Se è stato fatto in modo errato o se un computer non è più attendibile, puoi Unità di misura + + + part.table.partCustomState + Stato personalizzato del componente + + Part-DB1\src\DataTables\PartsDataTable.php:236 @@ -5696,6 +5708,12 @@ Se è stato fatto in modo errato o se un computer non è più attendibile, puoi Unità di misura + + + part.edit.partCustomState + Stato personalizzato della parte + + Part-DB1\src\Form\Part\PartBaseType.php:212 @@ -5983,6 +6001,12 @@ Se è stato fatto in modo errato o se un computer non è più attendibile, puoi Unità di misura + + + part_custom_state.label + Stato personalizzato della parte + + Part-DB1\src\Services\ElementTypeNameGenerator.php:90 @@ -6226,6 +6250,12 @@ Se è stato fatto in modo errato o se un computer non è più attendibile, puoi Unità di misura + + + tree.tools.edit.part_custom_state + Stato personalizzato del componente + + Part-DB1\src\Services\Trees\ToolsTreeBuilder.php:203 @@ -8496,6 +8526,12 @@ Element 3 Unità di misura + + + perm.part_custom_states + Stato personalizzato del componente + + obsolete @@ -10826,6 +10862,12 @@ Element 3 Unità di misura + + + log.element_edited.changed_fields.partCustomState + Stato personalizzato della parte + + log.element_edited.changed_fields.expiration_date @@ -11084,6 +11126,18 @@ Element 3 Modificare l'unità di misura + + + part_custom_state.new + Nuovo stato personalizzato del componente + + + + + part_custom_state.edit + Modifica stato personalizzato del componente + + user.aboutMe.label diff --git a/translations/messages.ja.xlf b/translations/messages.ja.xlf index 4becc319c..a0a146dc5 100644 --- a/translations/messages.ja.xlf +++ b/translations/messages.ja.xlf @@ -517,6 +517,12 @@ 単位 + + + part_custom_state.caption + 部品のカスタム状態 + + Part-DB1\templates\AdminPages\StorelocationAdmin.html.twig:5 @@ -4793,6 +4799,12 @@ 単位 + + + part.table.partCustomState + 部品のカスタム状態 + + Part-DB1\src\DataTables\PartsDataTable.php:236 @@ -5657,6 +5669,12 @@ 単位 + + + part.edit.partCustomState + 部品のカスタム状態 + + Part-DB1\src\Form\Part\PartBaseType.php:212 @@ -5934,6 +5952,12 @@ 単位 + + + part_custom_state.label + 部品のカスタム状態 + + Part-DB1\src\Services\ElementTypeNameGenerator.php:90 @@ -6166,6 +6190,12 @@ 単位 + + + tree.tools.edit.part_custom_state + 部品のカスタム状態 + + Part-DB1\src\Services\Trees\ToolsTreeBuilder.php:203 @@ -8424,6 +8454,12 @@ Exampletown 単位 + + + perm.part_custom_states + 部品のカスタム状態 + + obsolete @@ -8834,5 +8870,23 @@ Exampletown Part-DBについての質問は、<a href="%href%" class="link-external" target="_blank">GitHub</a> にスレッドがあります。 + + + part_custom_state.new + 部品の新しいカスタム状態 + + + + + part_custom_state.edit + 部品のカスタム状態を編集 + + + + + log.element_edited.changed_fields.partCustomState + 部品のカスタム状態 + + diff --git a/translations/messages.nl.xlf b/translations/messages.nl.xlf index 760533d7c..4afc28aac 100644 --- a/translations/messages.nl.xlf +++ b/translations/messages.nl.xlf @@ -548,6 +548,12 @@ Meeteenheden + + + part_custom_state.caption + Aangepaste status van het onderdeel + + Part-DB1\templates\AdminPages\StorelocationAdmin.html.twig:5 @@ -724,5 +730,53 @@ Weet u zeker dat u wilt doorgaan? + + + perm.part_custom_states + Aangepaste status van onderdeel + + + + + tree.tools.edit.part_custom_state + Aangepaste status van het onderdeel + + + + + part_custom_state.new + Nieuwe aangepaste status van het onderdeel + + + + + part_custom_state.edit + Aangepaste status van het onderdeel bewerken + + + + + part_custom_state.label + Aangepaste staat van onderdeel + + + + + log.element_edited.changed_fields.partCustomState + Aangepaste staat van het onderdeel + + + + + part.edit.partCustomState + Aangepaste staat van het onderdeel + + + + + part.table.partCustomState + Aangepaste status van onderdeel + + diff --git a/translations/messages.pl.xlf b/translations/messages.pl.xlf index b769e2737..cbecc3bf6 100644 --- a/translations/messages.pl.xlf +++ b/translations/messages.pl.xlf @@ -548,6 +548,12 @@ Jednostka miary + + + part_custom_state.caption + Stan niestandardowy komponentu + + Part-DB1\templates\AdminPages\StorelocationAdmin.html.twig:5 @@ -4835,6 +4841,12 @@ Jeśli zrobiłeś to niepoprawnie lub komputer nie jest już godny zaufania, mo Jednostka pomiarowa + + + part.table.partCustomState + Niestandardowy stan części + + Part-DB1\src\DataTables\PartsDataTable.php:236 @@ -5699,6 +5711,12 @@ Jeśli zrobiłeś to niepoprawnie lub komputer nie jest już godny zaufania, mo Jednostka pomiarowa + + + part.edit.partCustomState + Własny stan części + + Part-DB1\src\Form\Part\PartBaseType.php:212 @@ -5986,6 +6004,12 @@ Jeśli zrobiłeś to niepoprawnie lub komputer nie jest już godny zaufania, mo Jednostka pomiarowa + + + part_custom_state.label + Własny stan części + + Part-DB1\src\Services\ElementTypeNameGenerator.php:90 @@ -6229,6 +6253,12 @@ Jeśli zrobiłeś to niepoprawnie lub komputer nie jest już godny zaufania, mo Jednostka miary + + + tree.tools.edit.part_custom_state + Niestandardowy stan części + + Part-DB1\src\Services\Trees\ToolsTreeBuilder.php:203 @@ -8499,6 +8529,12 @@ Element 3 Jednostka miary + + + perm.part_custom_states + Stan niestandardowy komponentu + + obsolete @@ -10829,6 +10865,12 @@ Element 3 Jednostka pomiarowa + + + log.element_edited.changed_fields.partCustomState + Niestandardowy stan części + + log.element_edited.changed_fields.expiration_date @@ -11087,6 +11129,18 @@ Element 3 Edytuj jednostkę miary + + + part_custom_state.new + Nowy niestandardowy stan części + + + + + part_custom_state.edit + Edytuj niestandardowy stan części + + user.aboutMe.label diff --git a/translations/messages.ru.xlf b/translations/messages.ru.xlf index 62570acb0..517aca8ed 100644 --- a/translations/messages.ru.xlf +++ b/translations/messages.ru.xlf @@ -548,6 +548,12 @@ Единица измерения + + + part_custom_state.caption + Пользовательское состояние компонента + + Part-DB1\templates\AdminPages\StorelocationAdmin.html.twig:5 @@ -4841,6 +4847,12 @@ Единица измерения + + + part.table.partCustomState + Пользовательское состояние детали + + Part-DB1\src\DataTables\PartsDataTable.php:236 @@ -5705,6 +5717,12 @@ Единица измерения + + + part.edit.partCustomState + Пользовательское состояние части + + Part-DB1\src\Form\Part\PartBaseType.php:212 @@ -5992,6 +6010,12 @@ Единица измерения + + + part_custom_state.label + Пользовательское состояние детали + + Part-DB1\src\Services\ElementTypeNameGenerator.php:90 @@ -6235,6 +6259,12 @@ Единица измерения + + + tree.tools.edit.part_custom_state + Пользовательское состояние компонента + + Part-DB1\src\Services\Trees\ToolsTreeBuilder.php:203 @@ -8503,6 +8533,12 @@ Единица измерения + + + perm.part_custom_states + Пользовательское состояние компонента + + obsolete @@ -10833,6 +10869,12 @@ Единица измерения + + + log.element_edited.changed_fields.partCustomState + Пользовательское состояние детали + + log.element_edited.changed_fields.expiration_date @@ -11091,6 +11133,18 @@ Изменить единицу измерения + + + part_custom_state.new + Новое пользовательское состояние компонента + + + + + part_custom_state.edit + Редактировать пользовательское состояние компонента + + user.aboutMe.label diff --git a/translations/messages.zh.xlf b/translations/messages.zh.xlf index 668c32f28..4a5f5896f 100644 --- a/translations/messages.zh.xlf +++ b/translations/messages.zh.xlf @@ -548,6 +548,12 @@ 计量单位 + + + part_custom_state.caption + 部件的自定义状态 + + Part-DB1\templates\AdminPages\StorelocationAdmin.html.twig:5 @@ -4839,6 +4845,12 @@ 计量单位 + + + part.table.partCustomState + 部件的自定义状态 + + Part-DB1\src\DataTables\PartsDataTable.php:236 @@ -5703,6 +5715,12 @@ 计量单位 + + + part.edit.partCustomState + 部件的自定义状态 + + Part-DB1\src\Form\Part\PartBaseType.php:212 @@ -5990,6 +6008,12 @@ 计量单位 + + + part_custom_state.label + 部件自定义状态 + + Part-DB1\src\Services\ElementTypeNameGenerator.php:90 @@ -6233,6 +6257,12 @@ 计量单位 + + + tree.tools.edit.part_custom_state + 部件自定义状态 + + Part-DB1\src\Services\Trees\ToolsTreeBuilder.php:203 @@ -8502,6 +8532,12 @@ Element 3 计量单位 + + + perm.part_custom_states + 部件的自定义状态 + + obsolete @@ -10832,6 +10868,12 @@ Element 3 计量单位 + + + log.element_edited.changed_fields.partCustomState + 部件的自定义状态 + + log.element_edited.changed_fields.expiration_date @@ -11090,6 +11132,18 @@ Element 3 编辑度量单位 + + + part_custom_state.new + 部件的新自定义状态 + + + + + part_custom_state.edit + 编辑部件的自定义状态 + + user.aboutMe.label From d88850e95750d3ee93720bde21b522a1bb342160 Mon Sep 17 00:00:00 2001 From: Marcel Diegelmann Date: Mon, 24 Mar 2025 15:19:35 +0100 Subject: [PATCH 2/9] =?UTF-8?q?PartCustomStateController=20hinzuf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdminPages/PartCustomStateController.php | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/Controller/AdminPages/PartCustomStateController.php diff --git a/src/Controller/AdminPages/PartCustomStateController.php b/src/Controller/AdminPages/PartCustomStateController.php new file mode 100644 index 000000000..60f63abf3 --- /dev/null +++ b/src/Controller/AdminPages/PartCustomStateController.php @@ -0,0 +1,83 @@ +. + */ + +declare(strict_types=1); + +namespace App\Controller\AdminPages; + +use App\Entity\Attachments\PartCustomStateAttachment; +use App\Entity\Parameters\PartCustomStateParameter; +use App\Entity\Parts\PartCustomState; +use App\Form\AdminPages\PartCustomStateAdminForm; +use App\Services\ImportExportSystem\EntityExporter; +use App\Services\ImportExportSystem\EntityImporter; +use App\Services\Trees\StructuralElementRecursionHelper; +use Doctrine\ORM\EntityManagerInterface; +use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\Attribute\Route; + +/** + * @see \App\Tests\Controller\AdminPages\PartCustomStateControllerTest + */ +#[Route(path: '/part_custom_state')] +class PartCustomStateController extends BaseAdminController +{ + protected string $entity_class = PartCustomState::class; + protected string $twig_template = 'admin/part_custom_state_admin.html.twig'; + protected string $form_class = PartCustomStateAdminForm::class; + protected string $route_base = 'part_custom_state'; + protected string $attachment_class = PartCustomStateAttachment::class; + protected ?string $parameter_class = PartCustomStateParameter::class; + + #[Route(path: '/{id}', name: 'part_custom_state_delete', methods: ['DELETE'])] + public function delete(Request $request, PartCustomState $entity, StructuralElementRecursionHelper $recursionHelper): RedirectResponse + { + return $this->_delete($request, $entity, $recursionHelper); + } + + #[Route(path: '/{id}/edit/{timestamp}', name: 'part_custom_state_edit', requirements: ['id' => '\d+'])] + #[Route(path: '/{id}', requirements: ['id' => '\d+'])] + public function edit(PartCustomState $entity, Request $request, EntityManagerInterface $em, ?string $timestamp = null): Response + { + return $this->_edit($entity, $request, $em, $timestamp); + } + + #[Route(path: '/new', name: 'part_custom_state_new')] + #[Route(path: '/{id}/clone', name: 'part_custom_state_clone')] + #[Route(path: '/')] + public function new(Request $request, EntityManagerInterface $em, EntityImporter $importer, ?PartCustomState $entity = null): Response + { + return $this->_new($request, $em, $importer, $entity); + } + + #[Route(path: '/export', name: 'part_custom_state_export_all')] + public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request): Response + { + return $this->_exportAll($em, $exporter, $request); + } + + #[Route(path: '/{id}/export', name: 'part_custom_state_export')] + public function exportEntity(PartCustomState $entity, EntityExporter $exporter, Request $request): Response + { + return $this->_exportEntity($entity, $exporter, $request); + } +} From 22f7add66bf072d06f9ee68b20cf19b02a953b19 Mon Sep 17 00:00:00 2001 From: Marcel Diegelmann Date: Wed, 23 Apr 2025 10:49:07 +0200 Subject: [PATCH 3/9] =?UTF-8?q?Umstellung=20Migrationen=20bzgl.=20Multi-Pl?= =?UTF-8?q?attform-Support.=20Zun=C3=A4chst=20MySQL,=20SQLite=20Statements?= =?UTF-8?q?=20integrieren.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- migrations/Version20250321075747.php | 59 +++- migrations/Version20250321141740.php | 458 ++++++++++++++++++++++++++- src/Entity/Parts/PartCustomState.php | 6 + 3 files changed, 514 insertions(+), 9 deletions(-) diff --git a/migrations/Version20250321075747.php b/migrations/Version20250321075747.php index 45b35397e..08466961b 100644 --- a/migrations/Version20250321075747.php +++ b/migrations/Version20250321075747.php @@ -4,20 +4,69 @@ namespace DoctrineMigrations; +use App\Migration\AbstractMultiPlatformMigration; use Doctrine\DBAL\Schema\Schema; -use Doctrine\Migrations\AbstractMigration; -final class Version20250321075747 extends AbstractMigration +final class Version20250321075747 extends AbstractMultiPlatformMigration { - public function up(Schema $schema): void + public function getDescription(): string { - $this->addSql('CREATE TABLE `part_custom_states` (id INT AUTO_INCREMENT NOT NULL, parent_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, comment LONGTEXT NOT NULL, not_selectable TINYINT(1) NOT NULL, alternative_names LONGTEXT DEFAULT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, INDEX IDX_F552745D727ACA70 (parent_id), INDEX part_custom_state_name (name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci`'); + return 'Create entity table for custom part states'; + } + + public function mySQLUp(Schema $schema): void + { + $this->addSql('CREATE TABLE `part_custom_states` (id INT AUTO_INCREMENT NOT NULL, parent_id INT DEFAULT NULL, id_preview_attachment INT DEFAULT NULL, name VARCHAR(255) NOT NULL, comment LONGTEXT NOT NULL, not_selectable TINYINT(1) NOT NULL, alternative_names LONGTEXT DEFAULT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, INDEX IDX_F552745D727ACA70 (parent_id), INDEX IDX_F552745DEA7100A1 (id_preview_attachment), INDEX part_custom_state_name (name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci`'); $this->addSql('ALTER TABLE `part_custom_states` ADD CONSTRAINT FK_F552745D727ACA70 FOREIGN KEY (parent_id) REFERENCES `part_custom_states` (id)'); + $this->addSql('ALTER TABLE `part_custom_states` ADD CONSTRAINT FK_F552745DEA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES `attachments` (id) ON DELETE SET NULL'); } - public function down(Schema $schema): void + public function mySQLDown(Schema $schema): void { $this->addSql('ALTER TABLE `part_custom_states` DROP FOREIGN KEY FK_F552745D727ACA70'); + $this->addSql('ALTER TABLE `part_custom_states` DROP FOREIGN KEY FK_F552745DEA7100A1'); $this->addSql('DROP TABLE `part_custom_states`'); } + + public function sqLiteUp(Schema $schema): void + { + $this->addSql(<<<'SQL' + CREATE TABLE "part_custom_states" ( + id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + parent_id INTEGER DEFAULT NULL, + id_preview_attachment INTEGER DEFAULT NULL, + name VARCHAR(255) NOT NULL, + comment CLOB NOT NULL, + not_selectable BOOLEAN NOT NULL, + alternative_names CLOB DEFAULT NULL, + last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, + datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, + CONSTRAINT FK_F552745D727ACA70 FOREIGN KEY (parent_id) REFERENCES "part_custom_states" (id) NOT DEFERRABLE INITIALLY IMMEDIATE, + CONSTRAINT FK_F5AF83CFEA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES "attachments" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE + ) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX IDX_F552745D727ACA70 ON "part_custom_states" (parent_id) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX part_custom_state_name ON "part_custom_states" (name) + SQL); + } + + public function sqLiteDown(Schema $schema): void + { + $this->addSql(<<<'SQL' + DROP TABLE "part_custom_states" + SQL); + } + + public function postgreSQLUp(Schema $schema): void + { + //Not needed + } + + public function postgreSQLDown(Schema $schema): void + { + //Not needed + } } diff --git a/migrations/Version20250321141740.php b/migrations/Version20250321141740.php index cd1aefdc0..d518b1f68 100644 --- a/migrations/Version20250321141740.php +++ b/migrations/Version20250321141740.php @@ -4,22 +4,472 @@ namespace DoctrineMigrations; +use App\Migration\AbstractMultiPlatformMigration; use Doctrine\DBAL\Schema\Schema; -use Doctrine\Migrations\AbstractMigration; -final class Version20250321141740 extends AbstractMigration +final class Version20250321141740 extends AbstractMultiPlatformMigration { - public function up(Schema $schema): void + public function getDescription(): string + { + return 'Add custom state to parts'; + } + + public function mySQLUp(Schema $schema): void { $this->addSql('ALTER TABLE parts ADD id_part_custom_state INT DEFAULT NULL AFTER id_part_unit'); $this->addSql('ALTER TABLE parts ADD CONSTRAINT FK_6940A7FEA3ED1215 FOREIGN KEY (id_part_custom_state) REFERENCES `part_custom_states` (id)'); $this->addSql('CREATE INDEX IDX_6940A7FEA3ED1215 ON parts (id_part_custom_state)'); } - public function down(Schema $schema): void + public function mySQLDown(Schema $schema): void { $this->addSql('ALTER TABLE `parts` DROP FOREIGN KEY FK_6940A7FEA3ED1215'); $this->addSql('DROP INDEX IDX_6940A7FEA3ED1215 ON `parts`'); $this->addSql('ALTER TABLE `parts` DROP id_part_custom_state'); } + + public function sqLiteUp(Schema $schema): void + { + $this->addSql(<<<'SQL' + CREATE TEMPORARY TABLE __temp__parts AS + SELECT + id, + id_preview_attachment, + id_category, + id_footprint, + id_part_unit, + id_manufacturer, + order_orderdetails_id, + built_project_id, + datetime_added, + name, + last_modified, + needs_review, + tags, + mass, + description, + comment, + visible, + favorite, + minamount, + manufacturer_product_url, + manufacturer_product_number, + manufacturing_status, + order_quantity, + manual_order, + ipn, + provider_reference_provider_key, + provider_reference_provider_id, + provider_reference_provider_url, + provider_reference_last_updated, + eda_info_reference_prefix, + eda_info_value, + eda_info_invisible, + eda_info_exclude_from_bom, + eda_info_exclude_from_board, + eda_info_exclude_from_sim, + eda_info_kicad_symbol, + eda_info_kicad_footprint + FROM parts + SQL); + + $this->addSql(<<<'SQL' + DROP TABLE parts + SQL); + + $this->addSql(<<<'SQL' + CREATE TABLE parts ( + id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + id_preview_attachment INTEGER DEFAULT NULL, + id_category INTEGER NOT NULL, + id_footprint INTEGER DEFAULT NULL, + id_part_unit INTEGER DEFAULT NULL, + id_manufacturer INTEGER DEFAULT NULL, + id_part_custom_state INTEGER DEFAULT NULL, + order_orderdetails_id INTEGER DEFAULT NULL, + built_project_id INTEGER DEFAULT NULL, + datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, + name VARCHAR(255) NOT NULL, + last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, + needs_review BOOLEAN NOT NULL, + tags CLOB NOT NULL, + mass DOUBLE PRECISION DEFAULT NULL, + description CLOB NOT NULL, + comment CLOB NOT NULL, + visible BOOLEAN NOT NULL, + favorite BOOLEAN NOT NULL, + minamount DOUBLE PRECISION NOT NULL, + manufacturer_product_url CLOB NOT NULL, + manufacturer_product_number VARCHAR(255) NOT NULL, + manufacturing_status VARCHAR(255) DEFAULT NULL, + order_quantity INTEGER NOT NULL, + manual_order BOOLEAN NOT NULL, + ipn VARCHAR(100) DEFAULT 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 DATETIME 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, + CONSTRAINT FK_6940A7FEEA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES attachments (id) ON UPDATE NO ACTION ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE, + CONSTRAINT FK_6940A7FE5697F554 FOREIGN KEY (id_category) REFERENCES categories (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, + CONSTRAINT FK_6940A7FE7E371A10 FOREIGN KEY (id_footprint) REFERENCES footprints (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, + CONSTRAINT FK_6940A7FE2626CEF9 FOREIGN KEY (id_part_unit) REFERENCES measurement_units (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, + CONSTRAINT FK_6940A7FE1ECB93AE FOREIGN KEY (id_manufacturer) REFERENCES manufacturers (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, + CONSTRAINT FK_6940A7FEA3ED1215 FOREIGN KEY (id_part_custom_state) REFERENCES "part_custom_states" (id) NOT DEFERRABLE INITIALLY IMMEDIATE, + CONSTRAINT FK_6940A7FE81081E9B FOREIGN KEY (order_orderdetails_id) REFERENCES orderdetails (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, + CONSTRAINT FK_6940A7FEE8AE70D9 FOREIGN KEY (built_project_id) REFERENCES projects (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE + ) + SQL); + + $this->addSql(<<<'SQL' + INSERT INTO parts ( + id, + id_preview_attachment, + id_category, + id_footprint, + id_part_unit, + id_manufacturer, + order_orderdetails_id, + built_project_id, + datetime_added, + name, + last_modified, + needs_review, + tags, + mass, + description, + comment, + visible, + favorite, + minamount, + manufacturer_product_url, + manufacturer_product_number, + manufacturing_status, + order_quantity, + manual_order, + ipn, + provider_reference_provider_key, + provider_reference_provider_id, + provider_reference_provider_url, + provider_reference_last_updated, + eda_info_reference_prefix, + eda_info_value, + eda_info_invisible, + eda_info_exclude_from_bom, + eda_info_exclude_from_board, + eda_info_exclude_from_sim, + eda_info_kicad_symbol, + eda_info_kicad_footprint) + SELECT + id, + id_preview_attachment, + id_category, + id_footprint, + id_part_unit, + id_manufacturer, + order_orderdetails_id, + built_project_id, + datetime_added, + name, + last_modified, + needs_review, + tags, + mass, + description, + comment, + visible, + favorite, + minamount, + manufacturer_product_url, + manufacturer_product_number, + manufacturing_status, + order_quantity, + manual_order, + ipn, + provider_reference_provider_key, + provider_reference_provider_id, + provider_reference_provider_url, + provider_reference_last_updated, + eda_info_reference_prefix, + eda_info_value, + eda_info_invisible, + eda_info_exclude_from_bom, + eda_info_exclude_from_board, + eda_info_exclude_from_sim, + eda_info_kicad_symbol, + eda_info_kicad_footprint + FROM __temp__parts + SQL); + + $this->addSql(<<<'SQL' + DROP TABLE __temp__parts + SQL); + + $this->addSql(<<<'SQL' + CREATE INDEX parts_idx_name ON parts (name) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX parts_idx_ipn ON parts (ipn) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX parts_idx_datet_name_last_id_needs ON parts (datetime_added, name, last_modified, id, needs_review) + SQL); + $this->addSql(<<<'SQL' + CREATE UNIQUE INDEX UNIQ_6940A7FEE8AE70D9 ON parts (built_project_id) + SQL); + $this->addSql(<<<'SQL' + CREATE UNIQUE INDEX UNIQ_6940A7FE81081E9B ON parts (order_orderdetails_id) + SQL); + $this->addSql(<<<'SQL' + CREATE UNIQUE INDEX UNIQ_6940A7FE3D721C14 ON parts (ipn) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX IDX_6940A7FEEA7100A1 ON parts (id_preview_attachment) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX IDX_6940A7FE7E371A10 ON parts (id_footprint) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX IDX_6940A7FE5697F554 ON parts (id_category) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX IDX_6940A7FE2626CEF9 ON parts (id_part_unit) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX IDX_6940A7FE1ECB93AE ON parts (id_manufacturer) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX IDX_6940A7FEA3ED1215 ON parts (id_part_custom_state) + SQL); + } + + public function sqLiteDown(Schema $schema): void + { + $this->addSql(<<<'SQL' + CREATE TEMPORARY TABLE __temp__parts AS + SELECT + id, + id_preview_attachment, + id_category, + id_footprint, + id_part_unit, + id_manufacturer, + order_orderdetails_id, + built_project_id, + datetime_added, + name, + last_modified, + needs_review, + tags, + mass, + description, + comment, + visible, + favorite, + minamount, + manufacturer_product_url, + manufacturer_product_number, + manufacturing_status, + order_quantity, + manual_order, + ipn, + provider_reference_provider_key, + provider_reference_provider_id, + provider_reference_provider_url, + provider_reference_last_updated, + eda_info_reference_prefix, + eda_info_value, + eda_info_invisible, + eda_info_exclude_from_bom, + eda_info_exclude_from_board, + eda_info_exclude_from_sim, + eda_info_kicad_symbol, + eda_info_kicad_footprint + FROM "parts" + SQL); + $this->addSql(<<<'SQL' + DROP TABLE "parts" + SQL); + $this->addSql(<<<'SQL' + CREATE TABLE "parts" ( + id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + id_preview_attachment INTEGER DEFAULT NULL, + id_category INTEGER NOT NULL, + id_footprint INTEGER DEFAULT NULL, + id_part_unit INTEGER DEFAULT NULL, + id_manufacturer INTEGER DEFAULT NULL, + order_orderdetails_id INTEGER DEFAULT NULL, + built_project_id INTEGER DEFAULT NULL, + datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, + name VARCHAR(255) NOT NULL, + last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, + needs_review BOOLEAN NOT NULL, + tags CLOB NOT NULL, + mass DOUBLE PRECISION DEFAULT NULL, + description CLOB NOT NULL, + comment CLOB NOT NULL, + visible BOOLEAN NOT NULL, + favorite BOOLEAN NOT NULL, + minamount DOUBLE PRECISION NOT NULL, + manufacturer_product_url CLOB NOT NULL, + manufacturer_product_number VARCHAR(255) NOT NULL, + manufacturing_status VARCHAR(255) DEFAULT NULL, + order_quantity INTEGER NOT NULL, + manual_order BOOLEAN NOT NULL, + ipn VARCHAR(100) DEFAULT 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 DATETIME 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, + CONSTRAINT FK_6940A7FEEA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES "attachments" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE, + CONSTRAINT FK_6940A7FE5697F554 FOREIGN KEY (id_category) REFERENCES "categories" (id) NOT DEFERRABLE INITIALLY IMMEDIATE, + CONSTRAINT FK_6940A7FE7E371A10 FOREIGN KEY (id_footprint) REFERENCES "footprints" (id) NOT DEFERRABLE INITIALLY IMMEDIATE, + CONSTRAINT FK_6940A7FE2626CEF9 FOREIGN KEY (id_part_unit) REFERENCES "measurement_units" (id) NOT DEFERRABLE INITIALLY IMMEDIATE, + CONSTRAINT FK_6940A7FE1ECB93AE FOREIGN KEY (id_manufacturer) REFERENCES "manufacturers" (id) NOT DEFERRABLE INITIALLY IMMEDIATE, + CONSTRAINT FK_6940A7FE81081E9B FOREIGN KEY (order_orderdetails_id) REFERENCES "orderdetails" (id) NOT DEFERRABLE INITIALLY IMMEDIATE, + CONSTRAINT FK_6940A7FEE8AE70D9 FOREIGN KEY (built_project_id) REFERENCES projects (id) NOT DEFERRABLE INITIALLY IMMEDIATE + ) + SQL); + $this->addSql(<<<'SQL' + INSERT INTO "parts" ( + id, + id_preview_attachment, + id_category, + id_footprint, + id_part_unit, + id_manufacturer, + order_orderdetails_id, + built_project_id, + datetime_added, + name, + last_modified, + needs_review, + tags, + mass, + description, + comment, + visible, + favorite, + minamount, + manufacturer_product_url, + manufacturer_product_number, + manufacturing_status, + order_quantity, + manual_order, + ipn, + provider_reference_provider_key, + provider_reference_provider_id, + provider_reference_provider_url, + provider_reference_last_updated, + eda_info_reference_prefix, + eda_info_value, + eda_info_invisible, + eda_info_exclude_from_bom, + eda_info_exclude_from_board, + eda_info_exclude_from_sim, + eda_info_kicad_symbol, + eda_info_kicad_footprint + ) SELECT + id, + id_preview_attachment, + id_category, + id_footprint, + id_part_unit, + id_manufacturer, + order_orderdetails_id, + built_project_id, + datetime_added, + name, + last_modified, + needs_review, + tags, + mass, + description, + comment, + visible, + favorite, + minamount, + manufacturer_product_url, + manufacturer_product_number, + manufacturing_status, + order_quantity, + manual_order, + ipn, + provider_reference_provider_key, + provider_reference_provider_id, + provider_reference_provider_url, + provider_reference_last_updated, + eda_info_reference_prefix, + eda_info_value, + eda_info_invisible, + eda_info_exclude_from_bom, + eda_info_exclude_from_board, + eda_info_exclude_from_sim, + eda_info_kicad_symbol, + eda_info_kicad_footprint + FROM __temp__parts + SQL); + + $this->addSql(<<<'SQL' + DROP TABLE __temp__parts + SQL); + $this->addSql(<<<'SQL' + CREATE UNIQUE INDEX UNIQ_6940A7FE3D721C14 ON "parts" (ipn) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX IDX_6940A7FEEA7100A1 ON "parts" (id_preview_attachment) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX IDX_6940A7FE5697F554 ON "parts" (id_category) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX IDX_6940A7FE7E371A10 ON "parts" (id_footprint) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX IDX_6940A7FE2626CEF9 ON "parts" (id_part_unit) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX IDX_6940A7FE1ECB93AE ON "parts" (id_manufacturer) + SQL); + $this->addSql(<<<'SQL' + CREATE UNIQUE INDEX UNIQ_6940A7FE81081E9B ON "parts" (order_orderdetails_id) + SQL); + $this->addSql(<<<'SQL' + CREATE UNIQUE INDEX UNIQ_6940A7FEE8AE70D9 ON "parts" (built_project_id) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX parts_idx_datet_name_last_id_needs ON "parts" (datetime_added, name, last_modified, id, needs_review) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX parts_idx_name ON "parts" (name) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX parts_idx_ipn ON "parts" (ipn) + SQL); + } + + public function postgreSQLUp(Schema $schema): void + { + //Not needed + } + + public function postgreSQLDown(Schema $schema): void + { + //Not needed + } } diff --git a/src/Entity/Parts/PartCustomState.php b/src/Entity/Parts/PartCustomState.php index dac7fe58a..e8429199c 100644 --- a/src/Entity/Parts/PartCustomState.php +++ b/src/Entity/Parts/PartCustomState.php @@ -23,6 +23,7 @@ namespace App\Entity\Parts; use ApiPlatform\Metadata\ApiProperty; +use App\Entity\Attachments\Attachment; use App\Entity\Attachments\PartCustomStateAttachment; use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface; use ApiPlatform\Doctrine\Orm\Filter\DateFilter; @@ -98,6 +99,11 @@ class PartCustomState extends AbstractPartsContainingDBElement #[Groups(['part_custom_state:read', 'part_custom_state:write'])] protected Collection $attachments; + #[ORM\ManyToOne(targetEntity: PartCustomStateAttachment::class)] + #[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')] + #[Groups(['part_custom_state:read', 'part_custom_state:write'])] + protected ?Attachment $master_picture_attachment = null; + /** @var Collection */ #[Assert\Valid] From 1b4259ba9b6cbd1dd71516919824b579755345f0 Mon Sep 17 00:00:00 2001 From: Marcel Diegelmann Date: Tue, 17 Jun 2025 13:48:52 +0200 Subject: [PATCH 4/9] Postgre Statements integrieren --- migrations/Version20250321075747.php | 69 ++++++++++++++++++++++++---- migrations/Version20250321141740.php | 44 ++++++++++++++---- 2 files changed, 97 insertions(+), 16 deletions(-) diff --git a/migrations/Version20250321075747.php b/migrations/Version20250321075747.php index 08466961b..4ab505b3b 100644 --- a/migrations/Version20250321075747.php +++ b/migrations/Version20250321075747.php @@ -16,16 +16,43 @@ public function getDescription(): string public function mySQLUp(Schema $schema): void { - $this->addSql('CREATE TABLE `part_custom_states` (id INT AUTO_INCREMENT NOT NULL, parent_id INT DEFAULT NULL, id_preview_attachment INT DEFAULT NULL, name VARCHAR(255) NOT NULL, comment LONGTEXT NOT NULL, not_selectable TINYINT(1) NOT NULL, alternative_names LONGTEXT DEFAULT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, INDEX IDX_F552745D727ACA70 (parent_id), INDEX IDX_F552745DEA7100A1 (id_preview_attachment), INDEX part_custom_state_name (name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci`'); - $this->addSql('ALTER TABLE `part_custom_states` ADD CONSTRAINT FK_F552745D727ACA70 FOREIGN KEY (parent_id) REFERENCES `part_custom_states` (id)'); - $this->addSql('ALTER TABLE `part_custom_states` ADD CONSTRAINT FK_F552745DEA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES `attachments` (id) ON DELETE SET NULL'); + $this->addSql(<<<'SQL' + CREATE TABLE part_custom_states ( + id INT AUTO_INCREMENT NOT NULL, + parent_id INT DEFAULT NULL, + id_preview_attachment INT DEFAULT NULL, + name VARCHAR(255) NOT NULL, + comment LONGTEXT NOT NULL, + not_selectable TINYINT(1) NOT NULL, + alternative_names LONGTEXT DEFAULT NULL, + last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, + datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, + INDEX IDX_F552745D727ACA70 (parent_id), + INDEX IDX_F552745DEA7100A1 (id_preview_attachment), + INDEX part_custom_state_name (name), + PRIMARY KEY(id) + ) + DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE part_custom_states ADD CONSTRAINT FK_F552745D727ACA70 FOREIGN KEY (parent_id) REFERENCES part_custom_states (id) + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE part_custom_states ADD CONSTRAINT FK_F552745DEA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES attachments (id) ON DELETE SET NULL + SQL); } public function mySQLDown(Schema $schema): void { - $this->addSql('ALTER TABLE `part_custom_states` DROP FOREIGN KEY FK_F552745D727ACA70'); - $this->addSql('ALTER TABLE `part_custom_states` DROP FOREIGN KEY FK_F552745DEA7100A1'); - $this->addSql('DROP TABLE `part_custom_states`'); + $this->addSql(<<<'SQL' + ALTER TABLE part_custom_states DROP FOREIGN KEY FK_F552745D727ACA70; + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE part_custom_states DROP FOREIGN KEY FK_F552745DEA7100A1 + SQL); + $this->addSql(<<<'SQL' + DROP TABLE part_custom_states + SQL); } public function sqLiteUp(Schema $schema): void @@ -62,11 +89,37 @@ public function sqLiteDown(Schema $schema): void public function postgreSQLUp(Schema $schema): void { - //Not needed + $this->addSql(<<<'SQL' + CREATE TABLE "part_custom_states" ( + id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, + parent_id INT DEFAULT NULL, + id_preview_attachment INT DEFAULT NULL, PRIMARY KEY(id), + name VARCHAR(255) NOT NULL, + comment TEXT NOT NULL, + not_selectable BOOLEAN NOT NULL, + alternative_names 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 + ) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX IDX_F552745D727ACA70 ON "part_custom_states" (parent_id) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX IDX_F552745DEA7100A1 ON "part_custom_states" (id_preview_attachment) + SQL); } public function postgreSQLDown(Schema $schema): void { - //Not needed + $this->addSql(<<<'SQL' + ALTER TABLE "part_custom_states" DROP CONSTRAINT FK_F552745D727ACA70 + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE "part_custom_states" DROP CONSTRAINT FK_F552745DEA7100A1 + SQL); + $this->addSql(<<<'SQL' + DROP TABLE "part_custom_states" + SQL); } } diff --git a/migrations/Version20250321141740.php b/migrations/Version20250321141740.php index d518b1f68..5e9f87d08 100644 --- a/migrations/Version20250321141740.php +++ b/migrations/Version20250321141740.php @@ -16,16 +16,28 @@ public function getDescription(): string public function mySQLUp(Schema $schema): void { - $this->addSql('ALTER TABLE parts ADD id_part_custom_state INT DEFAULT NULL AFTER id_part_unit'); - $this->addSql('ALTER TABLE parts ADD CONSTRAINT FK_6940A7FEA3ED1215 FOREIGN KEY (id_part_custom_state) REFERENCES `part_custom_states` (id)'); - $this->addSql('CREATE INDEX IDX_6940A7FEA3ED1215 ON parts (id_part_custom_state)'); + $this->addSql(<<<'SQL' + ALTER TABLE parts ADD id_part_custom_state INT DEFAULT NULL AFTER id_part_unit + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE parts ADD CONSTRAINT FK_6940A7FEA3ED1215 FOREIGN KEY (id_part_custom_state) REFERENCES part_custom_states (id) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX IDX_6940A7FEA3ED1215 ON parts (id_part_custom_state) + SQL); } public function mySQLDown(Schema $schema): void { - $this->addSql('ALTER TABLE `parts` DROP FOREIGN KEY FK_6940A7FEA3ED1215'); - $this->addSql('DROP INDEX IDX_6940A7FEA3ED1215 ON `parts`'); - $this->addSql('ALTER TABLE `parts` DROP id_part_custom_state'); + $this->addSql(<<<'SQL' + ALTER TABLE parts DROP FOREIGN KEY FK_6940A7FEA3ED1215 + SQL); + $this->addSql(<<<'SQL' + DROP INDEX IDX_6940A7FEA3ED1215 ON parts + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE parts DROP id_part_custom_state + SQL); } public function sqLiteUp(Schema $schema): void @@ -465,11 +477,27 @@ public function sqLiteDown(Schema $schema): void public function postgreSQLUp(Schema $schema): void { - //Not needed + $this->addSql(<<<'SQL' + ALTER TABLE parts ADD id_part_custom_state INT DEFAULT NULL + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE parts ADD CONSTRAINT FK_6940A7FEA3ED1215 FOREIGN KEY (id_part_custom_state) REFERENCES "part_custom_states" (id) NOT DEFERRABLE INITIALLY IMMEDIATE + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX IDX_6940A7FEA3ED1215 ON parts (id_part_custom_state) + SQL); } public function postgreSQLDown(Schema $schema): void { - //Not needed + $this->addSql(<<<'SQL' + ALTER TABLE "parts" DROP CONSTRAINT FK_6940A7FEA3ED1215 + SQL); + $this->addSql(<<<'SQL' + DROP INDEX IDX_6940A7FEA3ED1215 + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE "parts" DROP id_part_custom_state + SQL); } } From b72094a0e5464f9303c9c8422e5432bbfe629ee2 Mon Sep 17 00:00:00 2001 From: Marcel Diegelmann Date: Tue, 17 Jun 2025 13:51:29 +0200 Subject: [PATCH 5/9] Semikolon in Migration entfernen --- migrations/Version20250321075747.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/Version20250321075747.php b/migrations/Version20250321075747.php index 4ab505b3b..b236796dc 100644 --- a/migrations/Version20250321075747.php +++ b/migrations/Version20250321075747.php @@ -45,7 +45,7 @@ public function mySQLUp(Schema $schema): void public function mySQLDown(Schema $schema): void { $this->addSql(<<<'SQL' - ALTER TABLE part_custom_states DROP FOREIGN KEY FK_F552745D727ACA70; + ALTER TABLE part_custom_states DROP FOREIGN KEY FK_F552745D727ACA70 SQL); $this->addSql(<<<'SQL' ALTER TABLE part_custom_states DROP FOREIGN KEY FK_F552745DEA7100A1 From 155937838f232ecc165fa95f2543383dfc6bf0eb Mon Sep 17 00:00:00 2001 From: Marcel Diegelmann Date: Thu, 17 Jul 2025 11:02:20 +0200 Subject: [PATCH 6/9] =?UTF-8?q?Migration=20f=C3=BCr=20PartCustomState=20ak?= =?UTF-8?q?tualisieren?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- migrations/Version20250321141740.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/Version20250321141740.php b/migrations/Version20250321141740.php index 5e9f87d08..34eca6526 100644 --- a/migrations/Version20250321141740.php +++ b/migrations/Version20250321141740.php @@ -134,7 +134,7 @@ public function sqLiteUp(Schema $schema): void CONSTRAINT FK_6940A7FE7E371A10 FOREIGN KEY (id_footprint) REFERENCES footprints (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_6940A7FE2626CEF9 FOREIGN KEY (id_part_unit) REFERENCES measurement_units (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_6940A7FE1ECB93AE FOREIGN KEY (id_manufacturer) REFERENCES manufacturers (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, - CONSTRAINT FK_6940A7FEA3ED1215 FOREIGN KEY (id_part_custom_state) REFERENCES "part_custom_states" (id) NOT DEFERRABLE INITIALLY IMMEDIATE, + CONSTRAINT FK_6940A7FEA3ED1215 FOREIGN KEY (id_part_custom_state) REFERENCES "part_custom_states" (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_6940A7FE81081E9B FOREIGN KEY (order_orderdetails_id) REFERENCES orderdetails (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_6940A7FEE8AE70D9 FOREIGN KEY (built_project_id) REFERENCES projects (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE ) From d9260cb8e736943477d6c13c199f8c5737a48d1f Mon Sep 17 00:00:00 2001 From: Marcel Diegelmann Date: Wed, 24 Sep 2025 14:54:28 +0200 Subject: [PATCH 7/9] Benutzerdefinierten Bauteilstatus in TableSettings aufnehmen --- src/Settings/BehaviorSettings/PartTableColumns.php | 3 ++- src/Settings/BehaviorSettings/TableSettings.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Settings/BehaviorSettings/PartTableColumns.php b/src/Settings/BehaviorSettings/PartTableColumns.php index eea6ad860..c025c9529 100644 --- a/src/Settings/BehaviorSettings/PartTableColumns.php +++ b/src/Settings/BehaviorSettings/PartTableColumns.php @@ -46,6 +46,7 @@ enum PartTableColumns : string implements TranslatableInterface case FAVORITE = "favorite"; case MANUFACTURING_STATUS = "manufacturing_status"; case MPN = "manufacturer_product_number"; + case CUSTOM_PART_STATE = 'partCustomState'; case MASS = "mass"; case TAGS = "tags"; case ATTACHMENTS = "attachments"; @@ -63,4 +64,4 @@ public function trans(TranslatorInterface $translator, ?string $locale = null): return $translator->trans($key, locale: $locale); } -} \ No newline at end of file +} diff --git a/src/Settings/BehaviorSettings/TableSettings.php b/src/Settings/BehaviorSettings/TableSettings.php index b69648769..b3421e41b 100644 --- a/src/Settings/BehaviorSettings/TableSettings.php +++ b/src/Settings/BehaviorSettings/TableSettings.php @@ -68,7 +68,7 @@ class TableSettings #[Assert\All([new Assert\Type(PartTableColumns::class)])] public array $partsDefaultColumns = [PartTableColumns::NAME, PartTableColumns::DESCRIPTION, PartTableColumns::CATEGORY, PartTableColumns::FOOTPRINT, PartTableColumns::MANUFACTURER, - PartTableColumns::LOCATION, PartTableColumns::AMOUNT]; + PartTableColumns::LOCATION, PartTableColumns::AMOUNT, PartTableColumns::CUSTOM_PART_STATE]; #[SettingsParameter(label: new TM("settings.behavior.table.preview_image_min_width"), formOptions: ['attr' => ['min' => 1, 'max' => 100]], From b8bc2b9d95eb231b035c40a76d4bf13ae814e01d Mon Sep 17 00:00:00 2001 From: Marcel Diegelmann Date: Fri, 26 Sep 2025 14:07:35 +0200 Subject: [PATCH 8/9] =?UTF-8?q?PartCustomStateControllerTest:=20Attribute?= =?UTF-8?q?=20f=C3=BCr=20PHPUnit-Gruppen=20umgestellt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdminPages/PartCustomStateControllerTest.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/Controller/AdminPages/PartCustomStateControllerTest.php b/tests/Controller/AdminPages/PartCustomStateControllerTest.php index b92308893..3e87dfe2f 100644 --- a/tests/Controller/AdminPages/PartCustomStateControllerTest.php +++ b/tests/Controller/AdminPages/PartCustomStateControllerTest.php @@ -23,12 +23,11 @@ namespace App\Tests\Controller\AdminPages; use App\Entity\Parts\PartCustomState; +use PHPUnit\Framework\Attributes\Group; -/** - * @group slow - * @group DB - */ -class PartCustomStateControllerTest extends AbstractAdminControllerTest +#[Group('slow')] +#[Group('DB')] +class PartCustomStateControllerTest extends AbstractAdminController { protected static string $base_path = '/en/part_custom_state'; protected static string $entity_class = PartCustomState::class; From e88c354a352572a5044895f4e49992d7b8a39d6a Mon Sep 17 00:00:00 2001 From: Marcel Diegelmann Date: Fri, 26 Sep 2025 15:19:08 +0200 Subject: [PATCH 9/9] =?UTF-8?q?PartCustomState:=20Mapping=20f=C3=BCr=20Par?= =?UTF-8?q?ameter=20korrigieren?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Entity/Parts/PartCustomState.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Entity/Parts/PartCustomState.php b/src/Entity/Parts/PartCustomState.php index e8429199c..ab0941f3c 100644 --- a/src/Entity/Parts/PartCustomState.php +++ b/src/Entity/Parts/PartCustomState.php @@ -107,7 +107,7 @@ class PartCustomState extends AbstractPartsContainingDBElement /** @var Collection */ #[Assert\Valid] - #[ORM\OneToMany(mappedBy: 'element', targetEntity: PartCustomStateAttachment::class, cascade: ['persist', 'remove'], orphanRemoval: true)] + #[ORM\OneToMany(mappedBy: 'element', targetEntity: PartCustomStateParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)] #[ORM\OrderBy(['name' => 'ASC'])] #[Groups(['part_custom_state:read', 'part_custom_state:write'])] protected Collection $parameters;