mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-24 18:58:46 +02:00
Ensure that its own project builds part is not added to the project BOM
This commit is contained in:
parent
3a60a9848f
commit
9aa6e714f2
2 changed files with 23 additions and 1 deletions
|
@ -199,7 +199,7 @@ class ProjectBOMEntry extends AbstractDBElement
|
|||
/**
|
||||
* @Assert\Callback
|
||||
*/
|
||||
public function validate(ExecutionContextInterface $context, $payload)
|
||||
public function validate(ExecutionContextInterface $context, $payload): void
|
||||
{
|
||||
//Round quantity to whole numbers, if the part is not a decimal part
|
||||
if ($this->part) {
|
||||
|
@ -230,6 +230,22 @@ class ProjectBOMEntry extends AbstractDBElement
|
|||
->atPath('mountnames')
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
//Check that the part is not the build representation part of this device or one of its parents
|
||||
if ($this->part && $this->part->getBuiltProject() !== null) {
|
||||
//Get the associated project
|
||||
$associated_project = $this->part->getBuiltProject();
|
||||
//Check that it is not the same as the current project neither one of its parents
|
||||
$current_project = $this->project;
|
||||
while ($current_project) {
|
||||
if ($associated_project === $current_project) {
|
||||
$context->buildViolation('project.bom_entry.can_not_add_own_builds_part')
|
||||
->atPath('part')
|
||||
->addViolation();
|
||||
}
|
||||
$current_project = $current_project->getParent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue