From 34b7626e624d55a2a8d57813e404d8d0269132ed Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos <1697880+AngelFQC@users.noreply.github.com> Date: Tue, 3 Sep 2024 18:04:10 -0500 Subject: [PATCH] Remove EntityManager::clear calls in migrations to avoid detach objects from Doctrine --- .../Migrations/Schema/V200/Version20191206150030.php | 2 -- .../Migrations/Schema/V200/Version20200821224245.php | 2 -- .../Migrations/Schema/V200/Version20201212114910.php | 2 -- .../Migrations/Schema/V200/Version20201212195011.php | 4 ---- .../Migrations/Schema/V200/Version20201212195112.php | 4 ---- .../Migrations/Schema/V200/Version20201212203625.php | 7 ------- .../Migrations/Schema/V200/Version20201215142610.php | 3 --- .../Migrations/Schema/V200/Version20201215160445.php | 5 ----- .../Migrations/Schema/V200/Version20201216105331.php | 7 ++----- .../Migrations/Schema/V200/Version20201216132000.php | 2 -- .../Migrations/Schema/V200/Version20201217124011.php | 3 --- .../Migrations/Schema/V200/Version20201218132719.php | 1 - .../Migrations/Schema/V200/Version20201219115244.php | 1 - .../Migrations/Schema/V200/Version20210205082253.php | 5 ----- .../Migrations/Schema/V200/Version20210221082033.php | 1 - .../Migrations/Schema/V200/Version20210930130343.php | 1 - .../Migrations/Schema/V200/Version20230204150030.php | 2 -- .../Migrations/Schema/V200/Version20240507160300.php | 1 - .../Migrations/Schema/V200/Version20240509123200.php | 1 - .../Migrations/Schema/V200/Version20240515124400.php | 2 -- 20 files changed, 2 insertions(+), 54 deletions(-) diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20191206150030.php b/src/CoreBundle/Migrations/Schema/V200/Version20191206150030.php index 331f0295e2c..3fa643876d8 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20191206150030.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20191206150030.php @@ -61,11 +61,9 @@ public function up(Schema $schema): void if (($counter % $batchSize) === 0) { $em->flush(); - $em->clear(); // Detaches all objects from Doctrine! } $counter++; } $em->flush(); - $em->clear(); } } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20200821224245.php b/src/CoreBundle/Migrations/Schema/V200/Version20200821224245.php index c335b4e4c65..48ef8330757 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20200821224245.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20200821224245.php @@ -59,8 +59,6 @@ private function migrateTagsFromInboxMessages(): void } } - $this->entityManager->clear(); - $this->removeFile(Version20200821224230::INBOX_TAGS_FILE); } } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20201212114910.php b/src/CoreBundle/Migrations/Schema/V200/Version20201212114910.php index 89352d46d3f..38d7d5a875c 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20201212114910.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20201212114910.php @@ -107,12 +107,10 @@ public function up(Schema $schema): void if (($counter % $batchSize) === 0) { $this->entityManager->flush(); - $this->entityManager->clear(); // Detaches all objects from Doctrine! } $counter++; } $this->entityManager->flush(); - $this->entityManager->clear(); $table = $schema->getTable('user'); if (false === $table->hasIndex('UNIQ_8D93D649D17F50A6')) { diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20201212195011.php b/src/CoreBundle/Migrations/Schema/V200/Version20201212195011.php index 4484f44854e..08f7029d921 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20201212195011.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20201212195011.php @@ -66,14 +66,12 @@ public function up(Schema $schema): void // $course = $course->getGroups(); if (($counter % $batchSize) === 0) { $this->entityManager->flush(); - $this->entityManager->clear(); // Detaches all objects from Doctrine! } $counter++; } } $this->entityManager->flush(); - $this->entityManager->clear(); // Special course. $extraFieldType = ExtraField::COURSE_FIELD_TYPE; @@ -132,12 +130,10 @@ public function up(Schema $schema): void $this->entityManager->persist($tool); if (($counter % $batchSize) === 0) { $this->entityManager->flush(); - $this->entityManager->clear(); // Detaches all objects from Doctrine! } $counter++; } } $this->entityManager->flush(); - $this->entityManager->clear(); } } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20201212195112.php b/src/CoreBundle/Migrations/Schema/V200/Version20201212195112.php index 2a58bdfb5c9..13b2c9f32c9 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20201212195112.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20201212195112.php @@ -68,13 +68,11 @@ public function up(Schema $schema): void $this->entityManager->persist($category); if (($counter % $batchSize) === 0) { $this->entityManager->flush(); - $this->entityManager->clear(); } $counter++; } $this->entityManager->flush(); - $this->entityManager->clear(); // Groups $counter = 1; @@ -108,12 +106,10 @@ public function up(Schema $schema): void $this->entityManager->persist($group); if (($counter % $batchSize) === 0) { $this->entityManager->flush(); - $this->entityManager->clear(); } $counter++; } } $this->entityManager->flush(); - $this->entityManager->clear(); } } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20201212203625.php b/src/CoreBundle/Migrations/Schema/V200/Version20201212203625.php index 7dc6001132b..94bbd4f54ba 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20201212203625.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20201212203625.php @@ -100,11 +100,9 @@ public function up(Schema $schema): void } } $this->entityManager->flush(); - $this->entityManager->clear(); } $this->entityManager->flush(); - $this->entityManager->clear(); // Migrate student exercise audio $q = $this->entityManager->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); @@ -177,11 +175,9 @@ public function up(Schema $schema): void } } $this->entityManager->flush(); - $this->entityManager->clear(); } $this->entityManager->flush(); - $this->entityManager->clear(); // Migrate normal documents. $q = $this->entityManager->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); @@ -245,16 +241,13 @@ public function up(Schema $schema): void if (($counter % $batchSize) === 0) { $this->entityManager->flush(); - $this->entityManager->clear(); } $counter++; } $this->entityManager->flush(); - $this->entityManager->clear(); } $this->entityManager->flush(); - $this->entityManager->clear(); } public function down(Schema $schema): void {} diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20201215142610.php b/src/CoreBundle/Migrations/Schema/V200/Version20201215142610.php index 2257ec920e9..201a23a49e3 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20201215142610.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20201215142610.php @@ -104,7 +104,6 @@ public function up(Schema $schema): void } $this->entityManager->flush(); - $this->entityManager->clear(); // Question categories. $sql = "SELECT * FROM c_quiz_question_category WHERE c_id = {$courseId} @@ -138,7 +137,6 @@ public function up(Schema $schema): void } $this->entityManager->flush(); - $this->entityManager->clear(); $sql = "SELECT * FROM c_quiz_question WHERE c_id = {$courseId} ORDER BY iid"; @@ -179,7 +177,6 @@ public function up(Schema $schema): void $this->entityManager->flush(); } $this->entityManager->flush(); - $this->entityManager->clear(); } } } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20201215160445.php b/src/CoreBundle/Migrations/Schema/V200/Version20201215160445.php index 8644916a2b7..2653aa0fd4d 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20201215160445.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20201215160445.php @@ -79,7 +79,6 @@ public function up(Schema $schema): void } $this->entityManager->flush(); - $this->entityManager->clear(); // Forums. $sql = "SELECT * FROM c_forum_forum WHERE c_id = {$courseId} @@ -139,7 +138,6 @@ public function up(Schema $schema): void $this->entityManager->flush(); } $this->entityManager->flush(); - $this->entityManager->clear(); // Threads. $sql = "SELECT * FROM c_forum_thread WHERE c_id = {$courseId} @@ -188,7 +186,6 @@ public function up(Schema $schema): void } $this->entityManager->flush(); - $this->entityManager->clear(); // Posts. $sql = "SELECT * FROM c_forum_post WHERE c_id = {$courseId} @@ -250,7 +247,6 @@ public function up(Schema $schema): void } $this->entityManager->flush(); - $this->entityManager->clear(); // Post attachments $sql = "SELECT * FROM c_forum_attachment WHERE c_id = {$courseId} @@ -282,7 +278,6 @@ public function up(Schema $schema): void } } $this->entityManager->flush(); - $this->entityManager->clear(); } } } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20201216105331.php b/src/CoreBundle/Migrations/Schema/V200/Version20201216105331.php index 150a0f094fa..671c44bb3a2 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20201216105331.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20201216105331.php @@ -69,7 +69,6 @@ public function up(Schema $schema): void } $this->entityManager->flush(); - $this->entityManager->clear(); // c_thematic_advance. /*$sql = "SELECT * FROM c_thematic_advance WHERE c_id = $courseId @@ -98,8 +97,7 @@ public function up(Schema $schema): void * $this->entityManager->persist($resource); * $this->entityManager->flush(); * } - * $this->entityManager->flush(); - * $this->entityManager->clear();*/ + * $this->entityManager->flush();*/ // c_thematic_plan. /*$sql = "SELECT * FROM c_thematic_plan WHERE c_id = $courseId @@ -127,8 +125,7 @@ public function up(Schema $schema): void * $this->entityManager->persist($resource); * $this->entityManager->flush(); * } - * $this->entityManager->flush(); - * $this->entityManager->clear();*/ + * $this->entityManager->flush();*/ } } } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20201216132000.php b/src/CoreBundle/Migrations/Schema/V200/Version20201216132000.php index d60d94387fc..2c77c9d58a4 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20201216132000.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20201216132000.php @@ -76,13 +76,11 @@ public function up(Schema $schema): void learnpath::sortItemByOrderList($rootItem, $orderList, true, $lpItemRepo, $this->entityManager); if (($counter % $batchSize) === 0) { $this->entityManager->flush(); - $this->entityManager->clear(); // Detaches all objects from Doctrine! } $counter++; $this->entityManager->flush(); } $this->entityManager->flush(); - $this->entityManager->clear(); } } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20201217124011.php b/src/CoreBundle/Migrations/Schema/V200/Version20201217124011.php index f581e3014c7..8f53e678898 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20201217124011.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20201217124011.php @@ -84,7 +84,6 @@ public function up(Schema $schema): void } $this->entityManager->flush(); - $this->entityManager->clear(); // Assignments files. $sql = "SELECT * FROM c_student_publication @@ -130,7 +129,6 @@ public function up(Schema $schema): void } $this->entityManager->flush(); - $this->entityManager->clear(); $admin = $this->getAdmin(); @@ -170,7 +168,6 @@ public function up(Schema $schema): void } $this->entityManager->flush(); - $this->entityManager->clear(); // Comments. $sql = "SELECT * FROM c_student_publication_comment WHERE c_id = {$courseId} diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20201218132719.php b/src/CoreBundle/Migrations/Schema/V200/Version20201218132719.php index 78a90d06b34..7595a842ff8 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20201218132719.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20201218132719.php @@ -64,7 +64,6 @@ public function up(Schema $schema): void } $this->entityManager->flush(); - $this->entityManager->clear(); } } } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20201219115244.php b/src/CoreBundle/Migrations/Schema/V200/Version20201219115244.php index 03cc92e24e9..ff599e96ab1 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20201219115244.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20201219115244.php @@ -64,7 +64,6 @@ public function up(Schema $schema): void } $this->entityManager->flush(); - $this->entityManager->clear(); } } } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20210205082253.php b/src/CoreBundle/Migrations/Schema/V200/Version20210205082253.php index 51492133f16..70896c5f0af 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20210205082253.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20210205082253.php @@ -62,13 +62,11 @@ public function up(Schema $schema): void if (($counter % $batchSize) === 0) { $this->entityManager->flush(); - $this->entityManager->clear(); // Detaches all objects from Doctrine! } $counter++; } $this->entityManager->flush(); - $this->entityManager->clear(); // Migrate Usergroup. $counter = 1; @@ -102,7 +100,6 @@ public function up(Schema $schema): void $this->entityManager->persist($userGroup); $this->entityManager->flush(); } - $this->entityManager->clear(); // Migrate Usergroup images. $q = $this->entityManager->createQuery('SELECT u FROM Chamilo\CoreBundle\Entity\Usergroup u'); @@ -132,12 +129,10 @@ public function up(Schema $schema): void if (($counter % $batchSize) === 0) { $this->entityManager->flush(); - $this->entityManager->clear(); // Detaches all objects from Doctrine! } $counter++; } $this->entityManager->flush(); - $this->entityManager->clear(); } } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20210221082033.php b/src/CoreBundle/Migrations/Schema/V200/Version20210221082033.php index 58c3cdc34bc..04c67aeb389 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20210221082033.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20210221082033.php @@ -52,7 +52,6 @@ public function up(Schema $schema): void } $this->entityManager->flush(); - $this->entityManager->clear(); } } } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20210930130343.php b/src/CoreBundle/Migrations/Schema/V200/Version20210930130343.php index 0cdaa1ad621..dcd515f0801 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20210930130343.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20210930130343.php @@ -116,7 +116,6 @@ public function up(Schema $schema): void } $this->entityManager->flush(); - $this->entityManager->clear(); } } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20230204150030.php b/src/CoreBundle/Migrations/Schema/V200/Version20230204150030.php index b639ae7c481..e91536061f4 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20230204150030.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20230204150030.php @@ -72,12 +72,10 @@ public function up(Schema $schema): void if (($counter % $batchSize) === 0) { $this->entityManager->flush(); - $this->entityManager->clear(); // Detaches all objects from Doctrine! } $counter++; } $this->entityManager->flush(); - $this->entityManager->clear(); } public function down(Schema $schema): void {} diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20240507160300.php b/src/CoreBundle/Migrations/Schema/V200/Version20240507160300.php index 5f5961eb90d..a72682afa74 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20240507160300.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20240507160300.php @@ -53,7 +53,6 @@ public function up(Schema $schema): void } $this->entityManager->flush(); - $this->entityManager->clear(); } private function determinePath(int $userId, string $picture): string diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20240509123200.php b/src/CoreBundle/Migrations/Schema/V200/Version20240509123200.php index e5fceebd0bd..61ace172b58 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20240509123200.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20240509123200.php @@ -83,6 +83,5 @@ public function up(Schema $schema): void } } $this->entityManager->flush(); - $this->entityManager->clear(); } } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20240515124400.php b/src/CoreBundle/Migrations/Schema/V200/Version20240515124400.php index ba35afec186..17e158e8467 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20240515124400.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20240515124400.php @@ -81,8 +81,6 @@ public function up(Schema $schema): void echo "Failed for download ID {$download->getDownId()}: ".$e->getMessage()."\n"; break; - } finally { - $this->entityManager->clear(); } $offset += $batchSize;