Skip to content

Commit

Permalink
Remove EntityManager::clear calls in migrations to avoid detach objec…
Browse files Browse the repository at this point in the history
…ts from Doctrine
  • Loading branch information
AngelFQC committed Sep 3, 2024
1 parent 8aeb699 commit 34b7626
Show file tree
Hide file tree
Showing 20 changed files with 2 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ private function migrateTagsFromInboxMessages(): void
}
}

$this->entityManager->clear();

$this->removeFile(Version20200821224230::INBOX_TAGS_FILE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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 {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -179,7 +177,6 @@ public function up(Schema $schema): void
$this->entityManager->flush();
}
$this->entityManager->flush();
$this->entityManager->clear();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -282,7 +278,6 @@ public function up(Schema $schema): void
}
}
$this->entityManager->flush();
$this->entityManager->clear();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();*/
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public function up(Schema $schema): void
}

$this->entityManager->flush();
$this->entityManager->clear();

// Assignments files.
$sql = "SELECT * FROM c_student_publication
Expand Down Expand Up @@ -130,7 +129,6 @@ public function up(Schema $schema): void
}

$this->entityManager->flush();
$this->entityManager->clear();

$admin = $this->getAdmin();

Expand Down Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public function up(Schema $schema): void
}

$this->entityManager->flush();
$this->entityManager->clear();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public function up(Schema $schema): void
}

$this->entityManager->flush();
$this->entityManager->clear();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public function up(Schema $schema): void
}

$this->entityManager->flush();
$this->entityManager->clear();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ public function up(Schema $schema): void
}

$this->entityManager->flush();
$this->entityManager->clear();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function up(Schema $schema): void
}

$this->entityManager->flush();
$this->entityManager->clear();
}

private function determinePath(int $userId, string $picture): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,5 @@ public function up(Schema $schema): void
}
}
$this->entityManager->flush();
$this->entityManager->clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 34b7626

Please sign in to comment.