From 3809539587c86bf01d4a1f8a9839d75b1e97f919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Fri, 21 Aug 2020 23:28:46 +0200 Subject: [PATCH] Implemented a stub DeviceRepository to prevent exception when try to delete a device. Now the devices can not be deleted (but no exception), to prevent users to accidentally delete still useful devices from old Part-DB versions (as currently it is not possible to view which infos a device contains). This fixes issue #60. --- src/Entity/Devices/Device.php | 2 +- src/Repository/Parts/DeviceRepository.php | 37 +++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/Repository/Parts/DeviceRepository.php diff --git a/src/Entity/Devices/Device.php b/src/Entity/Devices/Device.php index 3b1931f3..e6ce5e8a 100644 --- a/src/Entity/Devices/Device.php +++ b/src/Entity/Devices/Device.php @@ -60,7 +60,7 @@ use InvalidArgumentException; /** * Class AttachmentType. * - * @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository") + * @ORM\Entity(repositoryClass="App\Repository\Parts\DeviceRepository") * @ORM\Table(name="`devices`") */ class Device extends AbstractPartsContainingDBElement diff --git a/src/Repository/Parts/DeviceRepository.php b/src/Repository/Parts/DeviceRepository.php new file mode 100644 index 00000000..1e6166a8 --- /dev/null +++ b/src/Repository/Parts/DeviceRepository.php @@ -0,0 +1,37 @@ + 'ASC']): array + { + if (!$element instanceof Device) { + throw new \InvalidArgumentException('$element must be an Device!'); + } + + + //TODO: Change this later, when properly implemented devices + return []; + } + + public function getPartsCount(object $element): int + { + if (!$element instanceof Device) { + throw new \InvalidArgumentException('$element must be an Device!'); + } + + //TODO: Change this later, when properly implemented devices + //Prevent user from deleting devices, to not accidentally remove filled devices from old versions + return 1; + } +} \ No newline at end of file