Skip to content

Commit e928d22

Browse files
committed
Internal: Fix migration priority
1 parent 38850d4 commit e928d22

File tree

7 files changed

+131
-131
lines changed

7 files changed

+131
-131
lines changed

src/CoreBundle/Migrations/Schema/V200/Version20250711143900.php renamed to src/CoreBundle/Migrations/Schema/V200/Version20201212114910.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
1010
use Doctrine\DBAL\Schema\Schema;
1111

12-
final class Version20250711143900 extends AbstractMigrationChamilo
12+
final class Version20201212114910 extends AbstractMigrationChamilo
1313
{
1414
public function getDescription(): string
1515
{
Lines changed: 5 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,23 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
/* For licensing terms, see /license.txt */
64

5+
declare(strict_types=1);
6+
77
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
88

9-
use Chamilo\CoreBundle\Entity\AccessUrl;
10-
use Chamilo\CoreBundle\Entity\User;
119
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
12-
use Chamilo\CoreBundle\Repository\Node\AccessUrlRepository;
13-
use Chamilo\CoreBundle\Repository\Node\UserRepository;
1410
use Doctrine\DBAL\Schema\Schema;
15-
use Symfony\Component\Uid\Uuid;
1611

17-
final class Version20201212114911 extends AbstractMigrationChamilo
12+
class Version20201212114911 extends AbstractMigrationChamilo
1813
{
1914
public function getDescription(): string
2015
{
21-
return 'Migrate access_url, users';
16+
return 'Prepare access_url table for login-only URLs';
2217
}
2318

2419
public function up(Schema $schema): void
2520
{
26-
$urlRepo = $this->container->get(AccessUrlRepository::class);
27-
$userRepo = $this->container->get(UserRepository::class);
28-
29-
$userList = [];
30-
// Adding first admin as main creator also adding to the resource node tree.
31-
$admin = $this->getAdmin();
32-
$admin->addRole('ROLE_ADMIN');
33-
34-
$adminId = $admin->getId();
35-
$userList[$adminId] = $admin;
36-
37-
$this->write('Adding admin user');
38-
if (false === $admin->hasResourceNode()) {
39-
$resourceNode = $userRepo->addUserToResourceNode($adminId, $adminId);
40-
$this->entityManager->persist($resourceNode);
41-
}
42-
43-
// Adding portals (AccessUrl) to the resource node tree.
44-
$urls = $urlRepo->findAll();
45-
46-
/** @var AccessUrl $url */
47-
foreach ($urls as $url) {
48-
if (false === $url->hasResourceNode()) {
49-
$urlRepo->createNodeForResourceWithNoParent($url, $admin);
50-
$this->entityManager->persist($url);
51-
}
52-
}
53-
$this->entityManager->flush();
54-
55-
$sql = 'SELECT DISTINCT(user_id) FROM admin';
56-
$result = $this->entityManager->getConnection()->executeQuery($sql);
57-
$results = $result->fetchAllAssociative();
58-
$adminList = [];
59-
if (!empty($results)) {
60-
$adminList = array_map('intval', array_column($results, 'user_id'));
61-
}
62-
63-
// Adding users to the resource node tree.
64-
$batchSize = self::BATCH_SIZE;
65-
$counter = 1;
66-
$q = $this->entityManager->createQuery('SELECT u FROM Chamilo\CoreBundle\Entity\User u');
67-
68-
$this->write('Migrating users');
69-
70-
/** @var User $userEntity */
71-
foreach ($q->toIterable() as $userEntity) {
72-
if ($userEntity->hasResourceNode()) {
73-
continue;
74-
}
75-
76-
$userId = $userEntity->getId();
77-
$this->write("Migrating user: #$userId");
78-
79-
$userEntity
80-
->setUuid(Uuid::v4())
81-
->setRoles([])
82-
->setRoleFromStatus($userEntity->getStatus())
83-
;
84-
85-
if (\in_array($userId, $adminList, true)) {
86-
$userEntity->addRole('ROLE_ADMIN');
87-
}
88-
89-
if ($userEntity::ANONYMOUS === $userEntity->getStatus()) {
90-
$userEntity->addRole('ROLE_ANONYMOUS');
91-
}
92-
93-
$creatorId = $userEntity->getCreatorId();
94-
$creator = null;
95-
if (isset($userList[$adminId])) {
96-
$creator = $userList[$adminId];
97-
} else {
98-
$creator = $userRepo->find($creatorId);
99-
$userList[$adminId] = $creator;
100-
}
101-
if (null === $creator) {
102-
$creator = $admin;
103-
}
104-
105-
$resourceNode = $userRepo->addUserToResourceNode($userId, $creator->getId());
106-
$this->entityManager->persist($resourceNode);
107-
108-
if (($counter % $batchSize) === 0) {
109-
$this->entityManager->flush();
110-
$this->entityManager->clear(); // Detaches all objects from Doctrine!
111-
}
112-
$counter++;
113-
}
114-
$this->entityManager->flush();
115-
$this->entityManager->clear();
116-
117-
$table = $schema->getTable('user');
118-
if (false === $table->hasIndex('UNIQ_8D93D649D17F50A6')) {
119-
$this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D649D17F50A6 ON user (uuid);');
120-
}
21+
$this->addSql('ALTER TABLE access_url ADD is_login_only TINYINT(1) DEFAULT 0 NOT NULL');
12122
}
12223
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/* For licensing terms, see /license.txt */
6+
7+
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
8+
9+
use Chamilo\CoreBundle\Entity\AccessUrl;
10+
use Chamilo\CoreBundle\Entity\User;
11+
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
12+
use Chamilo\CoreBundle\Repository\Node\AccessUrlRepository;
13+
use Chamilo\CoreBundle\Repository\Node\UserRepository;
14+
use Doctrine\DBAL\Schema\Schema;
15+
use Symfony\Component\Uid\Uuid;
16+
17+
final class Version20201212114912 extends AbstractMigrationChamilo
18+
{
19+
public function getDescription(): string
20+
{
21+
return 'Migrate access_url, users';
22+
}
23+
24+
public function up(Schema $schema): void
25+
{
26+
$urlRepo = $this->container->get(AccessUrlRepository::class);
27+
$userRepo = $this->container->get(UserRepository::class);
28+
29+
$userList = [];
30+
// Adding first admin as main creator also adding to the resource node tree.
31+
$admin = $this->getAdmin();
32+
$admin->addRole('ROLE_ADMIN');
33+
34+
$adminId = $admin->getId();
35+
$userList[$adminId] = $admin;
36+
37+
$this->write('Adding admin user');
38+
if (false === $admin->hasResourceNode()) {
39+
$resourceNode = $userRepo->addUserToResourceNode($adminId, $adminId);
40+
$this->entityManager->persist($resourceNode);
41+
}
42+
43+
// Adding portals (AccessUrl) to the resource node tree.
44+
$urls = $urlRepo->findAll();
45+
46+
/** @var AccessUrl $url */
47+
foreach ($urls as $url) {
48+
if (false === $url->hasResourceNode()) {
49+
$urlRepo->createNodeForResourceWithNoParent($url, $admin);
50+
$this->entityManager->persist($url);
51+
}
52+
}
53+
$this->entityManager->flush();
54+
55+
$sql = 'SELECT DISTINCT(user_id) FROM admin';
56+
$result = $this->entityManager->getConnection()->executeQuery($sql);
57+
$results = $result->fetchAllAssociative();
58+
$adminList = [];
59+
if (!empty($results)) {
60+
$adminList = array_map('intval', array_column($results, 'user_id'));
61+
}
62+
63+
// Adding users to the resource node tree.
64+
$batchSize = self::BATCH_SIZE;
65+
$counter = 1;
66+
$q = $this->entityManager->createQuery('SELECT u FROM Chamilo\CoreBundle\Entity\User u');
67+
68+
$this->write('Migrating users');
69+
70+
/** @var User $userEntity */
71+
foreach ($q->toIterable() as $userEntity) {
72+
if ($userEntity->hasResourceNode()) {
73+
continue;
74+
}
75+
76+
$userId = $userEntity->getId();
77+
$this->write("Migrating user: #$userId");
78+
79+
$userEntity
80+
->setUuid(Uuid::v4())
81+
->setRoles([])
82+
->setRoleFromStatus($userEntity->getStatus())
83+
;
84+
85+
if (\in_array($userId, $adminList, true)) {
86+
$userEntity->addRole('ROLE_ADMIN');
87+
}
88+
89+
if ($userEntity::ANONYMOUS === $userEntity->getStatus()) {
90+
$userEntity->addRole('ROLE_ANONYMOUS');
91+
}
92+
93+
$creatorId = $userEntity->getCreatorId();
94+
$creator = null;
95+
if (isset($userList[$adminId])) {
96+
$creator = $userList[$adminId];
97+
} else {
98+
$creator = $userRepo->find($creatorId);
99+
$userList[$adminId] = $creator;
100+
}
101+
if (null === $creator) {
102+
$creator = $admin;
103+
}
104+
105+
$resourceNode = $userRepo->addUserToResourceNode($userId, $creator->getId());
106+
$this->entityManager->persist($resourceNode);
107+
108+
if (($counter % $batchSize) === 0) {
109+
$this->entityManager->flush();
110+
$this->entityManager->clear(); // Detaches all objects from Doctrine!
111+
}
112+
$counter++;
113+
}
114+
$this->entityManager->flush();
115+
$this->entityManager->clear();
116+
117+
$table = $schema->getTable('user');
118+
if (false === $table->hasIndex('UNIQ_8D93D649D17F50A6')) {
119+
$this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D649D17F50A6 ON user (uuid);');
120+
}
121+
}
122+
}

src/CoreBundle/Migrations/Schema/V200/Version20250619114200.php renamed to src/CoreBundle/Migrations/Schema/V200/Version20201212203624.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
1010
use Doctrine\DBAL\Schema\Schema;
1111

12-
class Version20250619114200 extends AbstractMigrationChamilo
12+
class Version20201212203624 extends AbstractMigrationChamilo
1313
{
1414
public function getDescription(): string
1515
{

src/CoreBundle/Migrations/Schema/V200/Version20250709164400.php renamed to src/CoreBundle/Migrations/Schema/V200/Version20201216122010.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
1010
use Doctrine\DBAL\Schema\Schema;
1111

12-
final class Version20250709164400 extends AbstractMigrationChamilo
12+
final class Version20201216122010 extends AbstractMigrationChamilo
1313
{
1414
public function getDescription(): string
1515
{

src/CoreBundle/Migrations/Schema/V200/Version20250708002500.php renamed to src/CoreBundle/Migrations/Schema/V200/Version20240112103359.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
1010
use Doctrine\DBAL\Schema\Schema;
1111

12-
final class Version20250708002500 extends AbstractMigrationChamilo
12+
final class Version20240112103359 extends AbstractMigrationChamilo
1313
{
1414
public function getDescription(): string
1515
{

src/CoreBundle/Migrations/Schema/V200/Version20250717170725.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)