Skip to content

Commit 9448f0c

Browse files
Merge pull request #6467 from christianbeeznest/fixes-updates104
Internal: Ensure persisted AccessUrl used during installation to avoid ORM errors
2 parents 093bc64 + 74434cd commit 9448f0c

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

public/main/install/install.lib.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,16 @@ function finishInstallationWithContainer(
15101510
/** @var User $admin */
15111511
$admin = $repo->findOneBy(['username' => 'admin']);
15121512

1513-
$accessUrl = Container::getAccessUrlUtil()->getCurrent();
1513+
$em = Container::getEntityManager();
1514+
$accessUrlRepo = $em->getRepository(AccessUrl::class);
1515+
1516+
$accessUrl = $accessUrlRepo->findOneBy([]);
1517+
1518+
if (!$accessUrl) {
1519+
$accessUrl = Container::getAccessUrlUtil()->getCurrent();
1520+
$em->persist($accessUrl);
1521+
$em->flush();
1522+
}
15141523

15151524
$admin
15161525
->setLastname($adminLastName)

src/CoreBundle/DataFixtures/ColorThemeFixtures.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Chamilo\CoreBundle\DataFixtures;
88

9+
use Chamilo\CoreBundle\Entity\AccessUrl;
910
use Chamilo\CoreBundle\Entity\AccessUrlRelColorTheme;
1011
use Chamilo\CoreBundle\Entity\ColorTheme;
1112
use Chamilo\CoreBundle\Helpers\AccessUrlHelper;
@@ -30,7 +31,6 @@ public function load(ObjectManager $manager): void
3031
->findOneBy(['slug' => 'chamilo']);
3132

3233
if ($existing) {
33-
echo "Chamilo color theme already exists. Skipping fixture.\n";
3434
return;
3535
}
3636

@@ -66,6 +66,11 @@ public function load(ObjectManager $manager): void
6666

6767
$accessUrl = $this->accessUrlHelper->getCurrent();
6868

69+
if (!$accessUrl->getId()) {
70+
$manager->persist($accessUrl);
71+
$manager->flush();
72+
}
73+
6974
$accessUrlRel = (new AccessUrlRelColorTheme())
7075
->setUrl($accessUrl)
7176
->setColorTheme($theme)
@@ -76,7 +81,5 @@ public function load(ObjectManager $manager): void
7681
$manager->persist($theme);
7782
$manager->persist($accessUrlRel);
7883
$manager->flush();
79-
80-
echo "Chamilo color theme fixture loaded successfully.\n";
8184
}
8285
}

0 commit comments

Comments
 (0)