mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-22 01:49:05 +02:00
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.
This commit is contained in:
parent
37c076c4c8
commit
3809539587
2 changed files with 38 additions and 1 deletions
|
@ -60,7 +60,7 @@ use InvalidArgumentException;
|
||||||
/**
|
/**
|
||||||
* Class AttachmentType.
|
* Class AttachmentType.
|
||||||
*
|
*
|
||||||
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository")
|
* @ORM\Entity(repositoryClass="App\Repository\Parts\DeviceRepository")
|
||||||
* @ORM\Table(name="`devices`")
|
* @ORM\Table(name="`devices`")
|
||||||
*/
|
*/
|
||||||
class Device extends AbstractPartsContainingDBElement
|
class Device extends AbstractPartsContainingDBElement
|
||||||
|
|
37
src/Repository/Parts/DeviceRepository.php
Normal file
37
src/Repository/Parts/DeviceRepository.php
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace App\Repository\Parts;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Entity\Base\AbstractPartsContainingDBElement;
|
||||||
|
use App\Entity\Devices\Device;
|
||||||
|
use App\Entity\Parts\Category;
|
||||||
|
use App\Entity\Parts\Part;
|
||||||
|
use App\Repository\AbstractPartsContainingRepository;
|
||||||
|
|
||||||
|
class DeviceRepository extends AbstractPartsContainingRepository
|
||||||
|
{
|
||||||
|
|
||||||
|
public function getParts(object $element, array $order_by = ['name' => '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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue