thirdparty: fix denormalization of thirdparty

This commit is contained in:
2021-12-14 15:46:55 +01:00
parent d3127bed6d
commit da7bfa8a4e
4 changed files with 71 additions and 30 deletions

View File

@@ -222,7 +222,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
* @var array|null
* @ORM\Column(name="types", type="json", nullable=true)
*/
private $types;
private ?array $thirdPartyTypes = [];
/**
* @ORM\Column(name="updated_at", type="datetime_immutable", nullable=true)
@@ -303,18 +303,18 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
return $this;
}
public function addType(?string $type): self
public function addThirdPartyTypes(?string $type): self
{
if (null === $type) {
return $this;
}
if (!in_array($type, $this->types ?? [], true)) {
$this->types[] = $type;
if (!in_array($type, $this->thirdPartyTypes ?? [], true)) {
$this->thirdPartyTypes[] = $type;
}
foreach ($this->children as $child) {
$child->addType($type);
$child->addThirdPartyTypes($type);
}
return $this;
@@ -329,7 +329,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
}
if (is_string($typeAndCategory)) {
$this->addType($typeAndCategory);
$this->addThirdPartyTypes($typeAndCategory);
return $this;
}
@@ -473,16 +473,16 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
*
* @return array|null
*/
public function getTypes()
public function getThirdPartyTypes()
{
return $this->types;
return $this->thirdPartyTypes ?? [];
}
public function getTypesAndCategories(): array
{
return array_merge(
$this->getCategories()->toArray(),
$this->getTypes() ?? []
$this->getThirdPartyTypes() ?? []
);
}
@@ -574,18 +574,18 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
return $this;
}
public function removeType(?string $type): self
public function removeThirdPartyTypes(?string $type): self
{
if (null === $type) {
return $this;
}
if (in_array($type, $this->types ?? [], true)) {
$this->types = array_filter($this->types, fn ($e) => !in_array($e, $this->types, true));
if (in_array($type, $this->thirdPartyTypes ?? [], true)) {
$this->thirdPartyTypes = array_filter($this->thirdPartyTypes, fn ($e) => !in_array($e, $this->thirdPartyTypes, true));
}
foreach ($this->children as $child) {
$child->removeType($type);
$child->removeThirdPartyTypes($type);
}
return $this;
@@ -600,7 +600,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
}
if (is_string($typeAndCategory)) {
$this->removeType($typeAndCategory);
$this->removeThirdPartyTypes($typeAndCategory);
return $this;
}
@@ -799,13 +799,13 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
*
* @return ThirdParty
*/
public function setTypes(?array $type = null)
public function setThirdPartyTypes(?array $type = [])
{
// remove all keys from the input data
$this->types = array_values($type);
$this->thirdPartyTypes = array_values($type);
foreach ($this->children as $child) {
$child->setTypes($type);
$child->setThirdPartyTypes($type);
}
return $this;
@@ -814,7 +814,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
public function setTypesAndCategories(array $typesAndCategories): self
{
$types = array_filter($typesAndCategories, static fn ($item) => !$item instanceof ThirdPartyCategory);
$this->setTypes($types);
$this->setThirdPartyTypes($types);
// handle categories
foreach ($typesAndCategories as $t) {