Release 2.17 (#4836)

see https://github.com/kimai/kimai/pull/4836
This commit is contained in:
Kevin Papst
2024-05-19 17:42:03 +02:00
committed by GitHub
parent 5f7114e008
commit 0c445d1bc4
41 changed files with 318 additions and 307 deletions

View File

@@ -45,29 +45,47 @@ final class TagArrayToStringTransformer implements DataTransformerInterface
*
* @see \Symfony\Bridge\Doctrine\Form\DataTransformer\CollectionToArrayTransformer::reverseTransform()
*
* @param string|null $value
* @param array<string>|string|null $value
* @return Tag[]
* @throws TransformationFailedException
*/
public function reverseTransform(mixed $value): mixed
public function reverseTransform(mixed $value): array
{
// check for empty tag list
if ('' === $value || null === $value) {
return [];
}
$names = array_filter(array_unique(array_map('trim', explode(',', $value))));
if (!\is_array($value)) {
$names = array_filter(array_unique(array_map('trim', explode(',', $value))));
} else {
$names = $value;
}
// get the current tags and find the new ones that should be created
$tags = $this->tagRepository->findBy(['name' => $names]);
if ($this->create) {
// works, because of the implicit case: (string) $tag
$newNames = array_diff($names, $tags);
$tags = [];
foreach ($names as $tagName) {
if ($tagName === null || $tagName === '') {
continue;
}
foreach ($newNames as $name) {
$tagName = trim($tagName);
$tag = null;
if (is_numeric($tagName)) {
$tag = $this->tagRepository->find($tagName);
}
if ($tag === null) {
$tag = $this->tagRepository->findTagByName($tagName);
}
// get the current tags and find the new ones that should be created
if ($this->create && $tag === null) {
$tag = new Tag();
$tag->setName(mb_substr($name, 0, 100));
$tag->setName(mb_substr($tagName, 0, 100));
$this->tagRepository->saveTag($tag);
}
if ($tag !== null) {
$tags[] = $tag;
}
}