Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions assets/vue/views/assignments/AssignmentDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
<div class="space-y-6">
<div class="flex items-center flex-wrap gap-2">
<BaseIcon
v-if="!fromLearnpath"
icon="back"
size="big"
@click="goBack"
/>

<template v-if="!isEditor">
<template v-if="forceStudentView">
<div class="ml-auto">
<BaseButton
icon="upload"
Expand Down Expand Up @@ -101,7 +102,7 @@
</div>
<div>
<StudentSubmissionList
v-if="!isEditor"
v-if="forceStudentView"
:assignment-id="assignmentId"
/>
<TeacherSubmissionList
Expand Down Expand Up @@ -132,20 +133,21 @@ const { t } = useI18n()
const { cid, sid, gid } = useCidReq()
const route = useRoute()
const router = useRouter()
const assignmentId = parseInt(route.params.id)

const assignment = ref(null)

const securityStore = useSecurityStore()
const assignmentId = parseInt(route.params.id)
const fromLearnpath = route.query.origin === "learnpath"
const isEditor = securityStore.isCourseAdmin || securityStore.isTeacher
const isStudentView = route.query.isStudentView === "true"
const forceStudentView = !isEditor || isStudentView
const assignment = ref(null)
const addedDocuments = ref([])
const notification = useNotification()
const submissionListKey = ref(0)

async function loadAddedDocuments() {
try {
const response = await axios.get(`${ENTRYPOINT}c_student_publication_rel_documents`, {
params: { publication: `/api/c_student_publications/${assignmentId}` }
params: { publication: `/api/c_student_publications/${assignmentId}` },
})
addedDocuments.value = response.data["hydra:member"]
} catch (e) {
Expand Down
144 changes: 144 additions & 0 deletions src/CoreBundle/Migrations/Schema/V200/Version20250501000100.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?php

declare(strict_types=1);

/* For licensing terms, see /license.txt */

namespace Chamilo\CoreBundle\Migrations\Schema\V200;

use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Chamilo\CoreBundle\Repository\Node\CourseRepository;
use Chamilo\CourseBundle\Entity\CStudentPublication;
use Chamilo\CourseBundle\Entity\CStudentPublicationComment;
use Chamilo\CourseBundle\Repository\CStudentPublicationCommentRepository;
use Chamilo\CourseBundle\Repository\CStudentPublicationRepository;
use Doctrine\DBAL\Schema\Schema;

final class Version20250501000100 extends AbstractMigrationChamilo
{
public function getDescription(): string
{
return 'Migrate student publications (works), corrections, and comments to ResourceNode/ResourceFile';
}

public function up(Schema $schema): void
{
$publicationRepo = $this->container->get(CStudentPublicationRepository::class);
$commentRepo = $this->container->get(CStudentPublicationCommentRepository::class);
$courseRepo = $this->container->get(CourseRepository::class);
$kernel = $this->container->get('kernel');
$root = $kernel->getProjectDir();

$courses = $this->entityManager
->createQuery('SELECT c FROM Chamilo\\CoreBundle\\Entity\\Course c')
->toIterable();

foreach ($courses as $course) {
$courseDir = $course->getDirectory();
$workPath = "{$root}/app/courses/{$courseDir}/work";
error_log("[MIGRATION] Processing course '{$course->getCode()}' (ID: {$course->getId()})");

$publications = $publicationRepo->createQueryBuilder('sp')
->join('sp.resourceNode', 'rn')
->join('rn.resourceLinks', 'rl')
->where('rl.course = :course')
->andWhere('sp.filetype = :file')
->setParameter('course', $course)
->setParameter('file', 'file')
->getQuery()
->getResult();

foreach ($publications as $publication) {
if (!$publication instanceof CStudentPublication || !$publication->getResourceNode()) {
continue;
}

$row = $this->connection->fetchAssociative(
'SELECT * FROM c_student_publication WHERE iid = ?',
[$publication->getIid()]
);
$resourceNode = $publication->getResourceNode();

$url = $row['url'] ?? null;
if (!empty($url) && str_starts_with($url, 'work/') && !$this->resourceNodeHasFile($resourceNode, basename($url))) {
$filename = basename($url);
$source = "{$workPath}/{$url}";
error_log("[MIGRATION] Submission source: $source");

if ($this->fileExists($source)) {
$this->addLegacyFileToResource($source, $publicationRepo, $publication, $row['iid'], $filename);
$this->entityManager->persist($publication);
} else {
error_log("[MIGRATION][ERROR] Submission file not found: $source");
}
}

$correctionUrl = $row['url_correction'] ?? null;
if (!empty($correctionUrl) && str_starts_with($correctionUrl, 'work/') && !$this->resourceNodeHasFile($resourceNode, basename($correctionUrl))) {
$filename = basename($correctionUrl);
$source = "{$workPath}/{$correctionUrl}";
error_log("[MIGRATION] Correction source: $source");

if ($this->fileExists($source)) {
$this->addLegacyFileToResource($source, $publicationRepo, $publication, $row['iid'], $filename);
$publication->setExtensions($filename);
$this->entityManager->persist($publication);
} else {
error_log("[MIGRATION][WARN] Correction file not found: $source");
}
}

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

$comments = $commentRepo->createQueryBuilder('c')
->join('c.publication', 'sp')
->join('sp.resourceNode', 'rn')
->join('rn.resourceLinks', 'rl')
->where('rl.course = :course')
->andWhere('c.file IS NOT NULL')
->setParameter('course', $course)
->getQuery()
->getResult();

foreach ($comments as $comment) {
if (!$comment instanceof CStudentPublicationComment || !$comment->getResourceNode()) {
continue;
}

$row = $this->connection->fetchAssociative(
'SELECT * FROM c_student_publication_comment WHERE iid = ?',
[$comment->getIid()]
);

$filename = basename($row['file']);
$source = "{$workPath}/{$filename}";
$resourceNode = $comment->getResourceNode();
error_log("[MIGRATION] Comment source: $source");

if (!$this->resourceNodeHasFile($resourceNode, $filename)) {
if ($this->fileExists($source)) {
$this->addLegacyFileToResource($source, $commentRepo, $comment, $row['iid'], $filename);
$this->entityManager->persist($comment);
$this->entityManager->flush();
} else {
error_log("[MIGRATION][WARN] Comment file not found: $source");
}
}
}

$this->entityManager->clear();
error_log("[MIGRATION] Finished processing course '{$course->getCode()}'");
}
}

private function resourceNodeHasFile($resourceNode, string $filename): bool
{
foreach ($resourceNode->getResourceFiles() as $file) {
if ($file->getTitle() === $filename || $file->getOriginalName() === $filename) {
return true;
}
}
return false;
}
}
Loading