From 99e60b47d4dc50fed0f806e2fc7a3670e94ce2aa Mon Sep 17 00:00:00 2001 From: Julio Date: Tue, 21 Sep 2021 14:33:53 +0200 Subject: [PATCH] Migrations: Fix add file --- .../Schema/V200/Version20201215160445.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20201215160445.php b/src/CoreBundle/Migrations/Schema/V200/Version20201215160445.php index 2364077139..b83f8ae03e 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20201215160445.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20201215160445.php @@ -133,10 +133,15 @@ final class Version20201215160445 extends AbstractMigrationChamilo $parent ); + $em->persist($resource); + $em->flush(); + $forumImage = $itemData['forum_image']; if (!empty($forumImage)) { $filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/upload/forum/images/'.$forumImage; - $this->addLegacyFileToResource($filePath, $forumRepo, $resource, $id, $forumImage); + if ($this->fileExists($filePath)) { + $this->addLegacyFileToResource($filePath, $forumRepo, $resource, $id, $forumImage); + } } if (false === $result) { @@ -255,7 +260,7 @@ final class Version20201215160445 extends AbstractMigrationChamilo $forumPostRepo = $container->get(CForumPostRepository::class); foreach ($items as $itemData) { $id = $itemData['iid']; - $postId = $itemData['post_id']; + $postId = (int) $itemData['post_id']; $path = $itemData['path']; $fileName = $itemData['filename']; @@ -267,9 +272,11 @@ final class Version20201215160445 extends AbstractMigrationChamilo if (!empty($fileName) && !empty($path)) { $filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/upload/forum/'.$path; - $this->addLegacyFileToResource($filePath, $forumPostRepo, $post, $id, $fileName); - $em->persist($post); - $em->flush(); + if ($this->fileExists($filePath)) { + $this->addLegacyFileToResource($filePath, $forumPostRepo, $post, $id, $fileName); + $em->persist($post); + $em->flush(); + } } } $em->flush();