feat: add SeedDemoDataCommand for seeding production-like demo data for testing representations, doctors, clinics, users, appointments, and commissions
This commit is contained in:
@@ -29,6 +29,29 @@ class RepresentationRepository extends ServiceEntityRepository
|
||||
return $this->findOneBy(['domain' => $domain, 'active' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* تطبیق بر اساس اولین label دامنه (TLD-agnostic) — همراستا با تطبیق subdomainِ
|
||||
* شهرها؛ لازم برای dev (مثلاً host=`x-nobat.localhost` باید نمایندهی `x-nobat.ir`
|
||||
* را پیدا کند). فقط وقتی نتیجه یکتاست برمیگرداند تا از ابهام (چند TLD روی یک
|
||||
* prefix) جلوگیری شود.
|
||||
*/
|
||||
public function findActiveByDomainPrefix(string $prefix): ?Representation
|
||||
{
|
||||
if ($prefix === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$rows = $this->createQueryBuilder('r')
|
||||
->where('r.active = true')
|
||||
->andWhere('r.domain LIKE :p')
|
||||
->setParameter('p', $prefix . '.%')
|
||||
->setMaxResults(2)
|
||||
->getQuery()
|
||||
->getResult();
|
||||
|
||||
return count($rows) === 1 ? $rows[0] : null;
|
||||
}
|
||||
|
||||
public function save(Representation $entity, bool $flush = true): void
|
||||
{
|
||||
$this->getEntityManager()->persist($entity);
|
||||
|
||||
@@ -56,7 +56,10 @@ class DomainContextResolver
|
||||
return new DomainContext($rep, $city, false);
|
||||
}
|
||||
|
||||
$rep = $this->representationRepo->findActiveByDomain($domain);
|
||||
// exact ابتدا (production: host = دامنهی واقعی)، سپس fallback اولین-label
|
||||
// (dev: host = `<prefix>.localhost` باید نمایندهی `<prefix>.ir` را بیابد).
|
||||
$rep = $this->representationRepo->findActiveByDomain($domain)
|
||||
?? $this->representationRepo->findActiveByDomainPrefix(explode('.', $domain)[0]);
|
||||
if ($rep !== null) {
|
||||
return new DomainContext($rep, null, $rep->isGlobal());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user