getContent(), true) ?? []; $name = trim((string) ($d['name'] ?? '')); $slug = trim((string) ($d['slug'] ?? '')); if ('' === $name || '' === $slug) { return new JsonResponse(['error' => 'name und slug sind erforderlich.'], 422); } $reseller = (new Reseller())->setName($name)->setSlug($slug); if (!empty($d['primaryDomain'])) { $reseller->setPrimaryDomain((string) $d['primaryDomain']); } if (!empty($d['planId'])) { $plan = $this->em->getRepository(PlatformPlan::class)->find($d['planId']); if ($plan instanceof PlatformPlan) { $reseller->setPlatformPlan($plan); } } $adminEmail = trim((string) ($d['adminEmail'] ?? '')); $adminPassword = (string) ($d['adminPassword'] ?? ''); $admin = null; if ('' !== $adminEmail && '' !== $adminPassword) { $admin = (new User()) ->setEmail($adminEmail) ->setRoles([User::ROLE_RESELLER_ADMIN]) ->setReseller($reseller); $admin->setPassword($this->hasher->hashPassword($admin, $adminPassword)); } try { $this->em->persist($reseller); if ($admin) { $this->em->persist($admin); } $this->em->flush(); } catch (UniqueConstraintViolationException) { return new JsonResponse(['error' => 'Slug oder Admin-E-Mail bereits vergeben.'], 422); } return new JsonResponse([ 'id' => (string) $reseller->getId(), 'name' => $reseller->getName(), 'slug' => $reseller->getSlug(), 'adminCreated' => null !== $admin, ], 201); } }