diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20.php b/src/CoreBundle/Migrations/Schema/V200/Version20.php index 2b56098861..b6229bc55e 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20.php @@ -183,10 +183,19 @@ class Version20 extends AbstractMigrationChamilo ); $table = $schema->getTable('usergroup'); - if (!$table->hasColumn('author_id')) { + if (false === $table->hasColumn('author_id')) { $this->addSql('ALTER TABLE usergroup ADD author_id INT DEFAULT NULL'); } + if (false === $table->hasColumn('resource_node_id')) { + $this->addSql('ALTER TABLE usergroup ADD resource_node_id INT DEFAULT NULL'); + } + + if (false === $table->hasForeignKey('FK_4A6478171BAD783F')) { + $this->addSql('ALTER TABLE usergroup ADD CONSTRAINT FK_4A6478171BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_4A6478171BAD783F ON usergroup (resource_node_id)'); + } + // Update template. $table = $schema->getTable('templates'); if ($table->hasColumn('course_code')) { diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20200505064121.php b/src/CoreBundle/Migrations/Schema/V200/Version20200505064121.php index 4ea9915f74..0d8d7b488b 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20200505064121.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20200505064121.php @@ -9,6 +9,11 @@ use Doctrine\DBAL\Schema\Schema; final class Version20200505064121 extends AbstractMigrationChamilo { + public function getDescription(): string + { + return 'reset_password_request'; + } + public function up(Schema $schema): void { if (false === $schema->hasTable('reset_password_request')) { diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20200821224242.php b/src/CoreBundle/Migrations/Schema/V200/Version20200821224242.php index 31e5fd7954..3f611966f5 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20200821224242.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20200821224242.php @@ -7,16 +7,24 @@ namespace Chamilo\CoreBundle\Migrations\Schema\V200; use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; use Doctrine\DBAL\Schema\Schema; -/** - * Messages. - */ final class Version20200821224242 extends AbstractMigrationChamilo { + public function getDescription(): string + { + return 'Messages'; + } + public function up(Schema $schema): void { $table = $schema->getTable('message'); $this->addSql('ALTER TABLE message CHANGE parent_id parent_id BIGINT DEFAULT NULL'); + if (false === $table->hasForeignKey('FK_B6BD307F727ACA70')) { + $this->addSql( + 'ALTER TABLE message ADD CONSTRAINT FK_B6BD307F727ACA70 FOREIGN KEY (parent_id) REFERENCES message (id)' + ); + } + if ($table->hasIndex('idx_message_parent')) { $this->addSql('DROP INDEX idx_message_parent ON message'); } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20200822224141.php b/src/CoreBundle/Migrations/Schema/V200/Version20200822224141.php index 093a05fe18..89f074548a 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20200822224141.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20200822224141.php @@ -7,11 +7,13 @@ namespace Chamilo\CoreBundle\Migrations\Schema\V200; use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; use Doctrine\DBAL\Schema\Schema; -/** - * Messages. - */ final class Version20200822224141 extends AbstractMigrationChamilo { + public function getDescription(): string + { + return 'Portfolio'; + } + public function up(Schema $schema): void { // Portfolio diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20201216124011.php b/src/CoreBundle/Migrations/Schema/V200/Version20201216124011.php index b3183f54c5..d591744339 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20201216124011.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20201216124011.php @@ -43,7 +43,7 @@ final class Version20201216124011 extends AbstractMigrationChamilo $courseRepo = $container->get(CourseRepository::class); $sessionRepo = $container->get(SessionRepository::class); $groupRepo = $container->get(CGroupRepository::class); - $userRepo = $container->get(UserRepository::class); + //$userRepo = $container->get(UserRepository::class); /** @var Kernel $kernel */ $kernel = $container->get('kernel'); $rootPath = $kernel->getProjectDir(); diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20210205082253.php b/src/CoreBundle/Migrations/Schema/V200/Version20210205082253.php new file mode 100644 index 0000000000..e2266b1721 --- /dev/null +++ b/src/CoreBundle/Migrations/Schema/V200/Version20210205082253.php @@ -0,0 +1,98 @@ +getContainer(); + $doctrine = $container->get('doctrine'); + $em = $doctrine->getManager(); + /** @var Connection $connection */ + $connection = $em->getConnection(); + + $kernel = $container->get('kernel'); + $rootPath = $kernel->getProjectDir(); + + $userRepo = $container->get(UserRepository::class); + $illustrationRepo = $container->get(IllustrationRepository::class); + + // Adding users to the resource node tree. + $batchSize = self::BATCH_SIZE; + $counter = 1; + $q = $em->createQuery('SELECT u FROM Chamilo\CoreBundle\Entity\User u'); + + $sql = "SELECT * FROM settings_current WHERE variable = 'split_users_upload_directory' AND access_url = 1"; + $result = $connection->executeQuery($sql); + $setting = $result->fetchAssociative(); + + /** @var User $userEntity */ + foreach ($q->toIterable() as $userEntity) { + if ($userEntity->hasResourceNode()) { + continue; + } + $id = $userEntity->getId(); + $picture = $userEntity->getPictureUri(); + $path = "users/$id/"; + if (!empty($setting) && 'true' === $setting['selected_value']) { + $path = 'users/'.substr((string) $id, 0, 1).'/'.$id.'/'; + } + $picturePath = $rootPath.'/app/upload/'.$path.'/'.$picture; + if (file_exists($picturePath)) { + $file = new UploadedFile($picturePath, $picture, null, null, true); + $illustrationRepo->addIllustration($userEntity, $userEntity, $file); + } + + if (0 === $counter % $batchSize) { + $em->flush(); + $em->clear(); // Detaches all objects from Doctrine! + } + $counter++; + } + + // Migrate Usergroup images. + $counter = 1; + $q = $em->createQuery('SELECT u FROM Chamilo\CoreBundle\Entity\Usergroup u'); + + $admin = $this->getAdmin(); + + /** @var Usergroup $userGroup */ + foreach ($q->toIterable() as $userGroup) { + if ($userGroup->hasResourceNode()) { + continue; + } + $id = $userGroup->getId(); + $picture = $userGroup->getPicture(); + $path = "groups/$id/"; + if (!empty($setting) && 'true' === $setting['selected_value']) { + $path = 'groups/'.substr((string) $id, 0, 1).'/'.$id.'/'; + } + $picturePath = $rootPath.'/app/upload/'.$path.'/'.$picture; + if (file_exists($picturePath)) { + $file = new UploadedFile($picturePath, $picture, null, null, true); + $illustrationRepo->addIllustration($userGroup, $admin, $file); + } + + if (0 === $counter % $batchSize) { + $em->flush(); + $em->clear(); // Detaches all objects from Doctrine! + } + $counter++; + } + } +}