From 77db84a5cbb0d0dc43533c9a39316000aa160e43 Mon Sep 17 00:00:00 2001 From: christianbeeznst Date: Fri, 22 Nov 2024 12:12:48 -0500 Subject: [PATCH] Internal: Fix conflicts with last changes with master. --- .../Entity/SessionRelCourseRelUser.php | 3 +- .../Schema/V200/Version20230913162700.php | 78 ++++++++++++------- 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/src/CoreBundle/Entity/SessionRelCourseRelUser.php b/src/CoreBundle/Entity/SessionRelCourseRelUser.php index e55b4c047e..c1ab0561e3 100644 --- a/src/CoreBundle/Entity/SessionRelCourseRelUser.php +++ b/src/CoreBundle/Entity/SessionRelCourseRelUser.php @@ -10,6 +10,7 @@ use ApiPlatform\Doctrine\Orm\Filter\DateFilter; use ApiPlatform\Doctrine\Orm\Filter\SearchFilter; use ApiPlatform\Metadata\ApiFilter; use ApiPlatform\Metadata\ApiResource; +use Chamilo\CoreBundle\Repository\SessionRelCourseRelUserRepository; use Chamilo\CoreBundle\Traits\UserTrait; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\Groups; @@ -32,7 +33,7 @@ use Symfony\Component\Validator\Constraints as Assert; #[ORM\Index(columns: ['user_id'], name: 'idx_session_rel_course_rel_user_id_user')] #[ORM\Index(columns: ['c_id'], name: 'idx_session_rel_course_rel_user_course_id')] #[ORM\UniqueConstraint(name: 'course_session_unique', columns: ['session_id', 'c_id', 'user_id', 'status'])] -#[ORM\Entity] +#[ORM\Entity(repositoryClass: SessionRelCourseRelUserRepository::class)] #[ApiFilter( filterClass: SearchFilter::class, properties: [ diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20230913162700.php b/src/CoreBundle/Migrations/Schema/V200/Version20230913162700.php index 9f311ab97b..3e65d58aaf 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20230913162700.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20230913162700.php @@ -67,7 +67,6 @@ final class Version20230913162700 extends AbstractMigrationChamilo } } - private function updateContent($config, $courseDirectory, $courseId, $documentRepo): void { if (isset($config['field'])) { @@ -88,11 +87,9 @@ final class Version20230913162700 extends AbstractMigrationChamilo if (!empty($originalText)) { $updatedText = $this->replaceOldURLsWithNew($originalText, $courseDirectory, $courseId, $documentRepo); if ($originalText !== $updatedText) { - error_log("SIMULACIÓN: Actualizar campo {$field} en {$config['table']} para ID {$item['iid']}"); - // Simular sin guardar cambios - // $sql = "UPDATE {$config['table']} SET {$field} = :newText WHERE iid = :id"; - // $params = ['newText' => $updatedText, 'id' => $item['iid']]; - // $this->connection->executeQuery($sql, $params); + $sql = "UPDATE {$config['table']} SET {$field} = :newText WHERE iid = :id"; + $params = ['newText' => $updatedText, 'id' => $item['iid']]; + $this->connection->executeQuery($sql, $params); } } } @@ -101,7 +98,7 @@ final class Version20230913162700 extends AbstractMigrationChamilo private function updateHtmlContent($courseDirectory, $courseId, $documentRepo, $resourceNodeRepo): void { - $sql = "SELECT iid, resource_node_id FROM c_document WHERE filetype = 'file' AND resource_node_id IS NOT NULL"; + $sql = "SELECT iid, resource_node_id FROM c_document WHERE filetype = 'file'"; $result = $this->connection->executeQuery($sql); $items = $result->fetchAllAssociative(); @@ -126,20 +123,18 @@ final class Version20230913162700 extends AbstractMigrationChamilo $filePath = $resourceFile->getTitle(); if ('text/html' === $resourceFile->getMimeType()) { - error_log("Verificando archivo HTML: $filePath"); + error_log('Verifying HTML file: '.$filePath); try { $content = $resourceNodeRepo->getResourceNodeFileContent($resourceNode); $updatedContent = $this->replaceOldURLsWithNew($content, $courseDirectory, $courseId, $documentRepo); if ($content !== $updatedContent) { - error_log("SIMULACIÓN: Actualizar contenido HTML en {$filePath}"); - // Simular sin guardar cambios - // $documentRepo->updateResourceFileContent($document, $updatedContent); - // $documentRepo->update($document); + $documentRepo->updateResourceFileContent($document, $updatedContent); + $documentRepo->update($document); } } catch (Exception $e) { - error_log("Error al procesar archivo $filePath: " . $e->getMessage()); + error_log("Error processing file $filePath: ".$e->getMessage()); } } } @@ -203,7 +198,7 @@ final class Version20230913162700 extends AbstractMigrationChamilo $documentRepo = $this->container->get(CDocumentRepository::class); $kernel = $this->container->get('kernel'); $rootPath = $kernel->getProjectDir(); - $appCourseOldPath = $rootPath . '/app' . $videoPath; + $appCourseOldPath = $rootPath.'/app'.$videoPath; $title = basename($appCourseOldPath); $courseRepo = $this->container->get(CourseRepository::class); @@ -212,32 +207,59 @@ final class Version20230913162700 extends AbstractMigrationChamilo throw new Exception("Course with ID $courseId not found."); } - error_log("SIMULACIÓN: Intentando localizar archivo {$title} en la ruta esperada: {$appCourseOldPath}"); + $document = $documentRepo->findCourseResourceByTitle($title, $course->getResourceNode(), $course); + if (null !== $document) { + return $document; + } - // Verificar si el archivo existe en la ubicación esperada if (file_exists($appCourseOldPath) && !is_dir($appCourseOldPath)) { - error_log("SIMULACIÓN: Archivo encontrado en ruta esperada: {$appCourseOldPath}"); - return null; // Retorna null en modo de solo lectura + $document = new CDocument(); + $document->setFiletype('file') + ->setTitle($title) + ->setComment(null) + ->setReadonly(false) + ->setCreator($this->getAdmin()) + ->setParent($course) + ->addCourseLink($course) + ; + + $this->entityManager->persist($document); + $this->entityManager->flush(); + + $documentRepo->addFileFromPath($document, $title, $appCourseOldPath); + + return $document; } - - // Buscar en directorios alternativos usando recursiveFileSearch - $generalCoursesPath = $this->getUpdateRootPath() . '/app/courses/'; + $generalCoursesPath = $this->getUpdateRootPath().'/app/courses/'; $foundPath = $this->recursiveFileSearch($generalCoursesPath, $title); if ($foundPath) { - // Registrar el valor de foundPath sin realizar ninguna operación de escritura - error_log("SIMULACIÓN: Archivo encontrado en nueva ubicación: {$foundPath}"); - } else { - error_log("SIMULACIÓN: Archivo {$title} no encontrado en {$generalCoursesPath}"); + $document = new CDocument(); + $document->setFiletype('file') + ->setTitle($title) + ->setComment(null) + ->setReadonly(false) + ->setCreator($this->getAdmin()) + ->setParent($course) + ->addCourseLink($course) + ; + + $this->entityManager->persist($document); + $this->entityManager->flush(); + + $documentRepo->addFileFromPath($document, $title, $foundPath); + error_log('File found in new location: '.$foundPath); + + return $document; } - return null; // No realizar ninguna operación de creación + throw new Exception('File not found in any location.'); } catch (Exception $e) { - error_log('Error en la migración: ' . $e->getMessage()); + error_log('Migration error: '.$e->getMessage()); + return null; } } - private function recursiveFileSearch($directory, $title) { $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));