|
|
|
@ -8,6 +8,8 @@ namespace Chamilo\CoreBundle\Migrations\Schema\V200; |
|
|
|
|
|
|
|
|
|
|
|
use Chamilo\CoreBundle\Entity\Course; |
|
|
|
use Chamilo\CoreBundle\Entity\Course; |
|
|
|
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; |
|
|
|
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; |
|
|
|
|
|
|
|
use Chamilo\CoreBundle\Repository\Node\CourseRepository; |
|
|
|
|
|
|
|
use Chamilo\CourseBundle\Entity\CDocument; |
|
|
|
use Chamilo\CourseBundle\Repository\CDocumentRepository; |
|
|
|
use Chamilo\CourseBundle\Repository\CDocumentRepository; |
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
|
|
|
|
|
|
|
|
|
|
@ -23,6 +25,23 @@ final class Version20230913162700 extends AbstractMigrationChamilo |
|
|
|
$documentRepo = $this->container->get(CDocumentRepository::class); |
|
|
|
$documentRepo = $this->container->get(CDocumentRepository::class); |
|
|
|
|
|
|
|
|
|
|
|
$q = $this->entityManager->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); |
|
|
|
$q = $this->entityManager->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); |
|
|
|
|
|
|
|
$updateConfigurations = [ |
|
|
|
|
|
|
|
['table' => 'c_tool_intro', 'field' => 'intro_text'], |
|
|
|
|
|
|
|
['table' => 'c_course_description', 'field' => 'content'], |
|
|
|
|
|
|
|
['table' => 'c_quiz', 'fields' => ['description', 'text_when_finished']], |
|
|
|
|
|
|
|
['table' => 'c_quiz_question', 'fields' => ['description', 'question']], |
|
|
|
|
|
|
|
['table' => 'c_quiz_answer', 'fields' => ['answer', 'comment']], |
|
|
|
|
|
|
|
['table' => 'c_course_description', 'field' => 'content'], |
|
|
|
|
|
|
|
['table' => 'c_student_publication', 'field' => 'description'], |
|
|
|
|
|
|
|
['table' => 'c_student_publication_comment', 'field' => 'comment'], |
|
|
|
|
|
|
|
['table' => 'c_forum_category', 'field' => 'cat_comment'], |
|
|
|
|
|
|
|
['table' => 'c_forum_forum', 'field' => 'forum_comment'], |
|
|
|
|
|
|
|
['table' => 'c_forum_post', 'field' => 'post_text'], |
|
|
|
|
|
|
|
['table' => 'c_glossary', 'field' => 'description'], |
|
|
|
|
|
|
|
['table' => 'c_survey', 'fields' => ['title', 'subtitle']], |
|
|
|
|
|
|
|
['table' => 'c_survey_question', 'fields' => ['survey_question', 'survey_question_comment']], |
|
|
|
|
|
|
|
['table' => 'c_survey_question_option', 'field' => 'option_text'], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
/** @var Course $course */ |
|
|
|
/** @var Course $course */ |
|
|
|
foreach ($q->toIterable() as $course) { |
|
|
|
foreach ($q->toIterable() as $course) { |
|
|
|
@ -33,406 +52,155 @@ final class Version20230913162700 extends AbstractMigrationChamilo |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tool intro |
|
|
|
foreach ($updateConfigurations as $config) { |
|
|
|
$sql = "SELECT * FROM c_tool_intro WHERE c_id = {$courseId} ORDER BY iid"; |
|
|
|
$this->updateContent($config, $courseDirectory, $courseId, $documentRepo); |
|
|
|
$result = $this->connection->executeQuery($sql); |
|
|
|
|
|
|
|
$items = $result->fetchAllAssociative(); |
|
|
|
|
|
|
|
if (!empty($items)) { |
|
|
|
|
|
|
|
foreach ($items as $itemData) { |
|
|
|
|
|
|
|
$originalIntroText = $itemData['intro_text']; |
|
|
|
|
|
|
|
if (!empty($originalIntroText)) { |
|
|
|
|
|
|
|
$updatedIntroText = $this->replaceOldURLsWithNew($originalIntroText, $courseDirectory, $courseId, $documentRepo); |
|
|
|
|
|
|
|
if ($originalIntroText !== $updatedIntroText) { |
|
|
|
|
|
|
|
$sql = 'UPDATE c_tool_intro SET intro_text = :newIntroText WHERE iid = :introId'; |
|
|
|
|
|
|
|
$params = [ |
|
|
|
|
|
|
|
'newIntroText' => $updatedIntroText, |
|
|
|
|
|
|
|
'introId' => $itemData['iid'], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$this->connection->executeQuery($sql, $params); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Course description |
|
|
|
|
|
|
|
$sql = "SELECT * FROM c_course_description WHERE c_id = {$courseId} ORDER BY iid"; |
|
|
|
|
|
|
|
$result = $this->connection->executeQuery($sql); |
|
|
|
|
|
|
|
$items = $result->fetchAllAssociative(); |
|
|
|
|
|
|
|
if (!empty($items)) { |
|
|
|
|
|
|
|
foreach ($items as $itemData) { |
|
|
|
|
|
|
|
$originalContent = $itemData['content']; |
|
|
|
|
|
|
|
if (!empty($originalContent)) { |
|
|
|
|
|
|
|
$updatedContent = $this->replaceOldURLsWithNew($originalContent, $courseDirectory, $courseId, $documentRepo); |
|
|
|
|
|
|
|
if ($originalContent !== $updatedContent) { |
|
|
|
|
|
|
|
$sql = 'UPDATE c_course_description SET content = :newContent WHERE iid = :id'; |
|
|
|
|
|
|
|
$params = [ |
|
|
|
|
|
|
|
'newContent' => $updatedContent, |
|
|
|
|
|
|
|
'id' => $itemData['iid'], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$this->connection->executeQuery($sql, $params); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Quiz |
|
|
|
|
|
|
|
$sql = "SELECT * FROM c_quiz WHERE c_id = {$courseId} ORDER BY iid"; |
|
|
|
|
|
|
|
$result = $this->connection->executeQuery($sql); |
|
|
|
|
|
|
|
$items = $result->fetchAllAssociative(); |
|
|
|
|
|
|
|
if (!empty($items)) { |
|
|
|
|
|
|
|
foreach ($items as $itemData) { |
|
|
|
|
|
|
|
$originalDescription = $itemData['description']; |
|
|
|
|
|
|
|
if (!empty($originalDescription)) { |
|
|
|
|
|
|
|
$updatedDescription = $this->replaceOldURLsWithNew($originalDescription, $courseDirectory, $courseId, $documentRepo); |
|
|
|
|
|
|
|
if ($originalDescription !== $updatedDescription) { |
|
|
|
|
|
|
|
$sql = 'UPDATE c_quiz SET description = :newDescription WHERE iid = :id'; |
|
|
|
|
|
|
|
$params = [ |
|
|
|
|
|
|
|
'newDescription' => $updatedDescription, |
|
|
|
|
|
|
|
'id' => $itemData['iid'], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$this->connection->executeQuery($sql, $params); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$originalText = $itemData['text_when_finished']; |
|
|
|
|
|
|
|
if (!empty($originalText)) { |
|
|
|
|
|
|
|
$updatedText = $this->replaceOldURLsWithNew($originalText, $courseDirectory, $courseId, $documentRepo); |
|
|
|
|
|
|
|
if ($originalText !== $updatedText) { |
|
|
|
|
|
|
|
$sql = 'UPDATE c_quiz SET text_when_finished = :newText WHERE iid = :id'; |
|
|
|
|
|
|
|
$params = [ |
|
|
|
|
|
|
|
'newText' => $updatedText, |
|
|
|
|
|
|
|
'id' => $itemData['iid'], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$this->connection->executeQuery($sql, $params); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Quiz question |
|
|
|
|
|
|
|
$sql = "SELECT * FROM c_quiz_question WHERE c_id = {$courseId} ORDER BY iid"; |
|
|
|
|
|
|
|
$result = $this->connection->executeQuery($sql); |
|
|
|
|
|
|
|
$items = $result->fetchAllAssociative(); |
|
|
|
|
|
|
|
if (!empty($items)) { |
|
|
|
|
|
|
|
foreach ($items as $itemData) { |
|
|
|
|
|
|
|
$originalDescription = $itemData['description']; |
|
|
|
|
|
|
|
if (!empty($originalDescription)) { |
|
|
|
|
|
|
|
$updatedDescription = $this->replaceOldURLsWithNew($originalDescription, $courseDirectory, $courseId, $documentRepo); |
|
|
|
|
|
|
|
if ($originalDescription !== $updatedDescription) { |
|
|
|
|
|
|
|
$sql = 'UPDATE c_quiz_question SET description = :newDescription WHERE iid = :id'; |
|
|
|
|
|
|
|
$params = [ |
|
|
|
|
|
|
|
'newDescription' => $updatedDescription, |
|
|
|
|
|
|
|
'id' => $itemData['iid'], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$this->connection->executeQuery($sql, $params); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$originalQuestion = $itemData['question']; |
|
|
|
|
|
|
|
if (!empty($originalQuestion)) { |
|
|
|
|
|
|
|
$updatedQuestion = $this->replaceOldURLsWithNew($originalQuestion, $courseDirectory, $courseId, $documentRepo); |
|
|
|
|
|
|
|
if ($originalQuestion !== $updatedQuestion) { |
|
|
|
|
|
|
|
$sql = 'UPDATE c_quiz_question SET question = :newQuestion WHERE iid = :id'; |
|
|
|
|
|
|
|
$params = [ |
|
|
|
|
|
|
|
'newQuestion' => $updatedQuestion, |
|
|
|
|
|
|
|
'id' => $itemData['iid'], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$this->connection->executeQuery($sql, $params); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Quiz answer |
|
|
|
|
|
|
|
$sql = "SELECT * FROM c_quiz_answer WHERE c_id = {$courseId} ORDER BY iid"; |
|
|
|
|
|
|
|
$result = $this->connection->executeQuery($sql); |
|
|
|
|
|
|
|
$items = $result->fetchAllAssociative(); |
|
|
|
|
|
|
|
if (!empty($items)) { |
|
|
|
|
|
|
|
foreach ($items as $itemData) { |
|
|
|
|
|
|
|
$originalAnswer = $itemData['answer']; |
|
|
|
|
|
|
|
if (!empty($originalAnswer)) { |
|
|
|
|
|
|
|
$updatedAnswer = $this->replaceOldURLsWithNew($originalAnswer, $courseDirectory, $courseId, $documentRepo); |
|
|
|
|
|
|
|
if ($originalAnswer !== $updatedAnswer) { |
|
|
|
|
|
|
|
$sql = 'UPDATE c_quiz_answer SET answer = :newAnswer WHERE iid = :id'; |
|
|
|
|
|
|
|
$params = [ |
|
|
|
|
|
|
|
'newAnswer' => $updatedAnswer, |
|
|
|
|
|
|
|
'id' => $itemData['iid'], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$this->connection->executeQuery($sql, $params); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$originalComment = $itemData['comment']; |
|
|
|
|
|
|
|
if (!empty($originalComment)) { |
|
|
|
|
|
|
|
$updatedComment = $this->replaceOldURLsWithNew($originalComment, $courseDirectory, $courseId, $documentRepo); |
|
|
|
|
|
|
|
if ($originalComment !== $updatedComment) { |
|
|
|
|
|
|
|
$sql = 'UPDATE c_quiz_answer SET comment = :newComment WHERE iid = :id'; |
|
|
|
|
|
|
|
$params = [ |
|
|
|
|
|
|
|
'newComment' => $updatedComment, |
|
|
|
|
|
|
|
'id' => $itemData['iid'], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$this->connection->executeQuery($sql, $params); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Student publication |
|
|
|
|
|
|
|
$sql = "SELECT * FROM c_student_publication WHERE c_id = {$courseId} ORDER BY iid"; |
|
|
|
|
|
|
|
$result = $this->connection->executeQuery($sql); |
|
|
|
|
|
|
|
$items = $result->fetchAllAssociative(); |
|
|
|
|
|
|
|
if (!empty($items)) { |
|
|
|
|
|
|
|
foreach ($items as $itemData) { |
|
|
|
|
|
|
|
$originalWorkDescription = $itemData['description']; |
|
|
|
|
|
|
|
if (!empty($originalWorkDescription)) { |
|
|
|
|
|
|
|
$updatedWorkDescription = $this->replaceOldURLsWithNew($originalWorkDescription, $courseDirectory, $courseId, $documentRepo); |
|
|
|
|
|
|
|
if ($originalWorkDescription !== $updatedWorkDescription) { |
|
|
|
|
|
|
|
$sql = 'UPDATE c_student_publication SET description = :newDescription WHERE iid = :id'; |
|
|
|
|
|
|
|
$params = [ |
|
|
|
|
|
|
|
'newDescription' => $updatedWorkDescription, |
|
|
|
|
|
|
|
'id' => $itemData['iid'], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$this->connection->executeQuery($sql, $params); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Student publication comment |
|
|
|
private function updateContent($config, $courseDirectory, $courseId, $documentRepo): void |
|
|
|
$sql = "SELECT * FROM c_student_publication_comment WHERE c_id = {$courseId} ORDER BY iid"; |
|
|
|
{ |
|
|
|
$result = $this->connection->executeQuery($sql); |
|
|
|
$sql = "SELECT iid, {$config['field']} FROM {$config['table']} WHERE c_id = {$courseId}"; |
|
|
|
$items = $result->fetchAllAssociative(); |
|
|
|
$result = $this->connection->executeQuery($sql); |
|
|
|
if (!empty($items)) { |
|
|
|
$items = $result->fetchAllAssociative(); |
|
|
|
foreach ($items as $itemData) { |
|
|
|
|
|
|
|
$originalWorkComment = $itemData['comment']; |
|
|
|
foreach ($items as $item) { |
|
|
|
if (!empty($originalWorkComment)) { |
|
|
|
$originalText = $item[$config['field']]; |
|
|
|
$updatedWorkComment = $this->replaceOldURLsWithNew($originalWorkComment, $courseDirectory, $courseId, $documentRepo); |
|
|
|
if (!empty($originalText)) { |
|
|
|
if ($originalWorkComment !== $updatedWorkComment) { |
|
|
|
$updatedText = $this->replaceOldURLsWithNew($originalText, $courseDirectory, $courseId, $documentRepo); |
|
|
|
$sql = 'UPDATE c_student_publication_comment SET comment = :newComment WHERE iid = :id'; |
|
|
|
if ($originalText !== $updatedText) { |
|
|
|
$params = [ |
|
|
|
$sql = "UPDATE {$config['table']} SET {$config['field']} = :newText WHERE iid = :id"; |
|
|
|
'newComment' => $updatedWorkComment, |
|
|
|
$params = ['newText' => $updatedText, 'id' => $item['iid']]; |
|
|
|
'id' => $itemData['iid'], |
|
|
|
$this->connection->executeQuery($sql, $params); |
|
|
|
]; |
|
|
|
|
|
|
|
$this->connection->executeQuery($sql, $params); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Forum category |
|
|
|
private function replaceOldURLsWithNew($itemDataText, $courseDirectory, $courseId, $documentRepo): array|string|null |
|
|
|
$sql = "SELECT * FROM c_forum_category WHERE c_id = {$courseId} ORDER BY iid"; |
|
|
|
{ |
|
|
|
$result = $this->connection->executeQuery($sql); |
|
|
|
$contentText = $itemDataText; |
|
|
|
$items = $result->fetchAllAssociative(); |
|
|
|
$specificCoursePattern = '/(src|href)=["\']((https?:\/\/[^\/]+)?(\/courses\/([^\/]+)\/document\/[^"\']+\.\w+))["\']/i'; |
|
|
|
if (!empty($items)) { |
|
|
|
preg_match_all($specificCoursePattern, $contentText, $matches); |
|
|
|
foreach ($items as $itemData) { |
|
|
|
|
|
|
|
$originalCatComment = $itemData['cat_comment']; |
|
|
|
|
|
|
|
if (!empty($originalCatComment)) { |
|
|
|
|
|
|
|
$updatedCatComment = $this->replaceOldURLsWithNew($originalCatComment, $courseDirectory, $courseId, $documentRepo); |
|
|
|
|
|
|
|
if ($originalCatComment !== $updatedCatComment) { |
|
|
|
|
|
|
|
$sql = 'UPDATE c_forum_category SET cat_comment = :newComment WHERE iid = :id'; |
|
|
|
|
|
|
|
$params = [ |
|
|
|
|
|
|
|
'newComment' => $updatedCatComment, |
|
|
|
|
|
|
|
'id' => $itemData['iid'], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$this->connection->executeQuery($sql, $params); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Forum |
|
|
|
foreach ($matches[2] as $index => $fullUrl) { |
|
|
|
$sql = "SELECT * FROM c_forum_forum WHERE c_id = {$courseId} ORDER BY iid"; |
|
|
|
|
|
|
|
$result = $this->connection->executeQuery($sql); |
|
|
|
|
|
|
|
$items = $result->fetchAllAssociative(); |
|
|
|
|
|
|
|
if (!empty($items)) { |
|
|
|
|
|
|
|
foreach ($items as $itemData) { |
|
|
|
|
|
|
|
$originalForumComment = $itemData['forum_comment']; |
|
|
|
|
|
|
|
if (!empty($originalForumComment)) { |
|
|
|
|
|
|
|
$updatedForumComment = $this->replaceOldURLsWithNew($originalForumComment, $courseDirectory, $courseId, $documentRepo); |
|
|
|
|
|
|
|
if ($originalForumComment !== $updatedForumComment) { |
|
|
|
|
|
|
|
$sql = 'UPDATE c_forum_forum SET forum_comment = :newComment WHERE iid = :id'; |
|
|
|
|
|
|
|
$params = [ |
|
|
|
|
|
|
|
'newComment' => $updatedForumComment, |
|
|
|
|
|
|
|
'id' => $itemData['iid'], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$this->connection->executeQuery($sql, $params); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Forum post |
|
|
|
$videoPath = parse_url($fullUrl, PHP_URL_PATH) ?: $fullUrl; |
|
|
|
$sql = "SELECT * FROM c_forum_post WHERE c_id = {$courseId} ORDER BY iid"; |
|
|
|
$actualCourseDirectory = $matches[5][$index]; |
|
|
|
$result = $this->connection->executeQuery($sql); |
|
|
|
if ($actualCourseDirectory !== $courseDirectory) { |
|
|
|
$items = $result->fetchAllAssociative(); |
|
|
|
$videoPath = preg_replace("/^\/courses\/$actualCourseDirectory\//i", "/courses/$courseDirectory/", $videoPath); |
|
|
|
if (!empty($items)) { |
|
|
|
|
|
|
|
foreach ($items as $itemData) { |
|
|
|
|
|
|
|
$originalPostText = $itemData['post_text']; |
|
|
|
|
|
|
|
if (!empty($originalPostText)) { |
|
|
|
|
|
|
|
$updatedPostText = $this->replaceOldURLsWithNew($originalPostText, $courseDirectory, $courseId, $documentRepo); |
|
|
|
|
|
|
|
if ($originalPostText !== $updatedPostText) { |
|
|
|
|
|
|
|
$sql = 'UPDATE c_forum_post SET post_text = :newText WHERE iid = :id'; |
|
|
|
|
|
|
|
$params = [ |
|
|
|
|
|
|
|
'newText' => $updatedPostText, |
|
|
|
|
|
|
|
'id' => $itemData['iid'], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$this->connection->executeQuery($sql, $params); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Glossary |
|
|
|
$documentPath = str_replace('/courses/'.$courseDirectory.'/document/', '/', $videoPath); |
|
|
|
$sql = "SELECT * FROM c_glossary WHERE c_id = {$courseId} ORDER BY iid"; |
|
|
|
|
|
|
|
$result = $this->connection->executeQuery($sql); |
|
|
|
|
|
|
|
$items = $result->fetchAllAssociative(); |
|
|
|
|
|
|
|
if (!empty($items)) { |
|
|
|
|
|
|
|
foreach ($items as $itemData) { |
|
|
|
|
|
|
|
$originalGlossaryDescription = $itemData['description']; |
|
|
|
|
|
|
|
if (!empty($originalGlossaryDescription)) { |
|
|
|
|
|
|
|
$updatedGlossaryDescription = $this->replaceOldURLsWithNew($originalGlossaryDescription, $courseDirectory, $courseId, $documentRepo); |
|
|
|
|
|
|
|
if ($originalGlossaryDescription !== $updatedGlossaryDescription) { |
|
|
|
|
|
|
|
$sql = 'UPDATE c_glossary SET description = :newDescription WHERE iid = :id'; |
|
|
|
|
|
|
|
$params = [ |
|
|
|
|
|
|
|
'newDescription' => $updatedGlossaryDescription, |
|
|
|
|
|
|
|
'id' => $itemData['iid'], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$this->connection->executeQuery($sql, $params); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Survey |
|
|
|
$sql = "SELECT iid, path, resource_node_id FROM c_document WHERE c_id = $courseId AND path LIKE '$documentPath'"; |
|
|
|
$sql = "SELECT * FROM c_survey WHERE c_id = {$courseId} ORDER BY iid"; |
|
|
|
|
|
|
|
$result = $this->connection->executeQuery($sql); |
|
|
|
$result = $this->connection->executeQuery($sql); |
|
|
|
$items = $result->fetchAllAssociative(); |
|
|
|
$documents = $result->fetchAllAssociative(); |
|
|
|
if (!empty($items)) { |
|
|
|
|
|
|
|
foreach ($items as $itemData) { |
|
|
|
if (!empty($documents)) { |
|
|
|
$originalSurveyTitle = $itemData['title']; |
|
|
|
$this->replaceDocumentLinks($documents, $documentRepo, $matches, $index, $videoPath, $courseId, $contentText); |
|
|
|
if (!empty($originalSurveyTitle)) { |
|
|
|
} else { |
|
|
|
$updatedSurveyTitle = $this->replaceOldURLsWithNew($originalSurveyTitle, $courseDirectory, $courseId, $documentRepo); |
|
|
|
$document = $this->createNewDocument($videoPath, $courseId); |
|
|
|
if ($originalSurveyTitle !== $updatedSurveyTitle) { |
|
|
|
if ($document) { |
|
|
|
$sql = 'UPDATE c_survey SET title = :newTitle WHERE iid = :id'; |
|
|
|
$newUrl = $documentRepo->getResourceFileUrl($document); |
|
|
|
$params = [ |
|
|
|
if ($newUrl) { |
|
|
|
'newTitle' => $updatedSurveyTitle, |
|
|
|
$replacement = $matches[1][$index] . '="' . $newUrl . '"'; |
|
|
|
'id' => $itemData['iid'], |
|
|
|
$contentText = str_replace($matches[0][$index], $replacement, $contentText); |
|
|
|
]; |
|
|
|
|
|
|
|
$this->connection->executeQuery($sql, $params); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$originalSurveySubTitle = $itemData['subtitle']; |
|
|
|
|
|
|
|
if (!empty($originalSurveySubTitle)) { |
|
|
|
|
|
|
|
$updatedSurveySubTitle = $this->replaceOldURLsWithNew($originalSurveySubTitle, $courseDirectory, $courseId, $documentRepo); |
|
|
|
|
|
|
|
if ($originalSurveySubTitle !== $updatedSurveySubTitle) { |
|
|
|
|
|
|
|
$sql = 'UPDATE c_survey SET subtitle = :newSubtitle WHERE iid = :id'; |
|
|
|
|
|
|
|
$params = [ |
|
|
|
|
|
|
|
'newSubtitle' => $updatedSurveySubTitle, |
|
|
|
|
|
|
|
'id' => $itemData['iid'], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$this->connection->executeQuery($sql, $params); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Survey question |
|
|
|
return $contentText; |
|
|
|
$sql = "SELECT * FROM c_survey_question WHERE c_id = {$courseId} ORDER BY iid"; |
|
|
|
} |
|
|
|
$result = $this->connection->executeQuery($sql); |
|
|
|
|
|
|
|
$items = $result->fetchAllAssociative(); |
|
|
|
|
|
|
|
if (!empty($items)) { |
|
|
|
|
|
|
|
foreach ($items as $itemData) { |
|
|
|
|
|
|
|
$originalSurveyQuestion = $itemData['survey_question']; |
|
|
|
|
|
|
|
if (!empty($originalSurveyQuestion)) { |
|
|
|
|
|
|
|
$updatedSurveyQuestion = $this->replaceOldURLsWithNew($originalSurveyQuestion, $courseDirectory, $courseId, $documentRepo); |
|
|
|
|
|
|
|
if ($originalSurveyQuestion !== $updatedSurveyQuestion) { |
|
|
|
|
|
|
|
$sql = 'UPDATE c_survey_question SET survey_question = :newQuestion WHERE iid = :id'; |
|
|
|
|
|
|
|
$params = [ |
|
|
|
|
|
|
|
'newQuestion' => $updatedSurveyQuestion, |
|
|
|
|
|
|
|
'id' => $itemData['iid'], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$this->connection->executeQuery($sql, $params); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$originalSurveyQuestionComment = $itemData['survey_question_comment']; |
|
|
|
|
|
|
|
if (!empty($originalSurveyQuestionComment)) { |
|
|
|
|
|
|
|
$updatedSurveyQuestionComment = $this->replaceOldURLsWithNew($originalSurveyQuestionComment, $courseDirectory, $courseId, $documentRepo); |
|
|
|
|
|
|
|
if ($originalSurveyQuestionComment !== $updatedSurveyQuestionComment) { |
|
|
|
|
|
|
|
$sql = 'UPDATE c_survey_question SET survey_question_comment = :newComment WHERE iid = :id'; |
|
|
|
|
|
|
|
$params = [ |
|
|
|
|
|
|
|
'newComment' => $updatedSurveyQuestionComment, |
|
|
|
|
|
|
|
'id' => $itemData['iid'], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$this->connection->executeQuery($sql, $params); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Survey question option |
|
|
|
private function replaceDocumentLinks($documents, $documentRepo, $matches, $index, $videoPath, $courseId, &$contentText): void |
|
|
|
$sql = "SELECT * FROM c_survey_question_option WHERE c_id = {$courseId} ORDER BY iid"; |
|
|
|
{ |
|
|
|
$result = $this->connection->executeQuery($sql); |
|
|
|
foreach ($documents as $documentData) { |
|
|
|
$items = $result->fetchAllAssociative(); |
|
|
|
$resourceNodeId = (int) $documentData['resource_node_id']; |
|
|
|
if (!empty($items)) { |
|
|
|
$documentFile = $documentRepo->getResourceFromResourceNode($resourceNodeId); |
|
|
|
foreach ($items as $itemData) { |
|
|
|
if ($documentFile) { |
|
|
|
$originalOptionText = $itemData['option_text']; |
|
|
|
$newUrl = $documentRepo->getResourceFileUrl($documentFile); |
|
|
|
if (!empty($originalOptionText)) { |
|
|
|
if (!empty($newUrl)) { |
|
|
|
$updatedOptionText = $this->replaceOldURLsWithNew($originalOptionText, $courseDirectory, $courseId, $documentRepo); |
|
|
|
$patternForReplacement = '/' . preg_quote($matches[0][$index], '/') . '/'; |
|
|
|
if ($originalOptionText !== $updatedOptionText) { |
|
|
|
$replacement = $matches[1][$index] . '="' . $newUrl . '"'; |
|
|
|
$sql = 'UPDATE c_survey_question_option SET option_text = :newText WHERE iid = :id'; |
|
|
|
$contentText = preg_replace($patternForReplacement, $replacement, $contentText, 1); |
|
|
|
$params = [ |
|
|
|
|
|
|
|
'newText' => $updatedOptionText, |
|
|
|
|
|
|
|
'id' => $itemData['iid'], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$this->connection->executeQuery($sql, $params); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private function replaceOldURLsWithNew($itemDataText, $courseDirectory, $courseId, $documentRepo): array|string|null |
|
|
|
private function createNewDocument($videoPath, $courseId) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$contentText = $itemDataText; |
|
|
|
try { |
|
|
|
|
|
|
|
$documentRepo = $this->container->get(CDocumentRepository::class); |
|
|
|
$pattern = '/(src|href)=(["\'])(\/courses\/'.preg_quote($courseDirectory, '/').'\/[^"\']+\.\w+)\2/i'; |
|
|
|
$kernel = $this->container->get('kernel'); |
|
|
|
preg_match_all($pattern, $contentText, $matches); |
|
|
|
$rootPath = $kernel->getProjectDir(); |
|
|
|
$videosSrcPath = $matches[3]; |
|
|
|
$appCourseOldPath = $rootPath . '/app' . $videoPath; |
|
|
|
|
|
|
|
$title = basename($appCourseOldPath); |
|
|
|
if (!empty($videosSrcPath)) { |
|
|
|
|
|
|
|
foreach ($videosSrcPath as $index => $videoPath) { |
|
|
|
$courseRepo = $this->container->get(CourseRepository::class); |
|
|
|
$documentPath = str_replace('/courses/'.$courseDirectory.'/document/', '/', $videoPath); |
|
|
|
$course = $courseRepo->find($courseId); |
|
|
|
$sql = "SELECT iid, path, resource_node_id |
|
|
|
if (!$course) { |
|
|
|
FROM c_document |
|
|
|
throw new \Exception("Course with ID $courseId not found."); |
|
|
|
WHERE |
|
|
|
} |
|
|
|
c_id = $courseId AND |
|
|
|
|
|
|
|
path LIKE '$documentPath' |
|
|
|
$document = $documentRepo->findCourseResourceByTitle($title, $course->getResourceNode(), $course); |
|
|
|
"; |
|
|
|
if ($document !== null) { |
|
|
|
$result = $this->connection->executeQuery($sql); |
|
|
|
return $document; |
|
|
|
$documents = $result->fetchAllAssociative(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($documents)) { |
|
|
|
if (file_exists($appCourseOldPath) && !is_dir($appCourseOldPath)) { |
|
|
|
foreach ($documents as $documentData) { |
|
|
|
$document = new CDocument(); |
|
|
|
$resourceNodeId = (int) $documentData['resource_node_id']; |
|
|
|
$document->setFiletype('file') |
|
|
|
$documentFile = $documentRepo->getResourceFromResourceNode($resourceNodeId); |
|
|
|
->setTitle($title) |
|
|
|
if ($documentFile) { |
|
|
|
->setComment(null) |
|
|
|
$newUrl = $documentRepo->getResourceFileUrl($documentFile); |
|
|
|
->setReadonly(false) |
|
|
|
if (!empty($newUrl)) { |
|
|
|
->setCreator($this->getAdmin()) |
|
|
|
$patternForReplacement = '/'.$matches[1][$index].'=(["\'])'.preg_quote($videoPath, '/').'\1/i'; |
|
|
|
->setParent($course) |
|
|
|
$replacement = $matches[1][$index].'=$1'.$newUrl.'$1'; |
|
|
|
->addCourseLink($course); |
|
|
|
$contentText = preg_replace($patternForReplacement, $replacement, $contentText); |
|
|
|
|
|
|
|
error_log('$documentPath ->'.$documentPath); |
|
|
|
$this->entityManager->persist($document); |
|
|
|
error_log('newUrl ->'.$newUrl); |
|
|
|
$this->entityManager->flush(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
$documentRepo->addFileFromPath($document, $title, $appCourseOldPath); |
|
|
|
} |
|
|
|
return $document; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$generalCoursesPath = $rootPath . '/app/courses/'; |
|
|
|
|
|
|
|
$foundPath = $this->recursiveFileSearch($generalCoursesPath, $title); |
|
|
|
|
|
|
|
if ($foundPath) { |
|
|
|
|
|
|
|
$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; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
throw new \Exception("File not found in any location."); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch (\Exception $e) { |
|
|
|
|
|
|
|
error_log('Migration error: ' . $e->getMessage()); |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $contentText; |
|
|
|
private function recursiveFileSearch($directory, $title) { |
|
|
|
|
|
|
|
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory)); |
|
|
|
|
|
|
|
foreach ($iterator as $file) { |
|
|
|
|
|
|
|
if ($file->isFile() && $file->getFilename() === $title) { |
|
|
|
|
|
|
|
return $file->getRealPath(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|