';
diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20230216122900.php b/src/CoreBundle/Migrations/Schema/V200/Version20230216122900.php
index 224403e864..b8c381c53d 100644
--- a/src/CoreBundle/Migrations/Schema/V200/Version20230216122900.php
+++ b/src/CoreBundle/Migrations/Schema/V200/Version20230216122900.php
@@ -188,6 +188,7 @@ class Version20230216122900 extends AbstractMigrationChamilo
'allow_career_users',
'community_managers_user_list',
'allow_social_map_fields',
+ 'hide_username_in_course_chat',
],
'Admin' => [
'user_status_option_only_for_admin_enabled',
@@ -380,7 +381,6 @@ class Version20230216122900 extends AbstractMigrationChamilo
'video_player_renderers',
],
'Chat' => [
- 'hide_username_in_course_chat',
'hide_chat_video',
'course_chat_restrict_to_coach',
],
@@ -482,6 +482,7 @@ class Version20230216122900 extends AbstractMigrationChamilo
];
foreach ($configurationValues as $category => $variables) {
foreach ($variables as $variable) {
+ $category = strtolower($category);
$result = $connection
->executeQuery(
"SELECT COUNT(1) FROM settings_current WHERE variable = '$variable' AND category = '{$category}'"
@@ -496,7 +497,7 @@ class Version20230216122900 extends AbstractMigrationChamilo
);
} else {
$this->addSql(
- "UPDATE settings_current SET selected_value = '{$selectedValue}' WHERE variable = '$variable' AND category = '{$category}'"
+ "UPDATE settings_current SET selected_value = '{$selectedValue}', category = '{$category}' WHERE variable = '$variable' AND category = '{$category}'"
);
}
}
@@ -764,7 +765,6 @@ class Version20230216122900 extends AbstractMigrationChamilo
'Chat' => [
'course_chat_restrict_to_coach',
'hide_chat_video',
- 'hide_username_in_course_chat',
],
'Editor' => [
'video_player_renderers',
@@ -957,6 +957,7 @@ class Version20230216122900 extends AbstractMigrationChamilo
'user_status_option_only_for_admin_enabled',
],
'Profile' => [
+ 'hide_username_in_course_chat',
'allow_social_map_fields',
'community_managers_user_list',
'allow_career_users',
diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20230720143000.php b/src/CoreBundle/Migrations/Schema/V200/Version20230720143000.php
new file mode 100644
index 0000000000..d8b4b637d2
--- /dev/null
+++ b/src/CoreBundle/Migrations/Schema/V200/Version20230720143000.php
@@ -0,0 +1,117 @@
+getContainer();
+ $em = $this->getEntityManager();
+
+ $kernel = $container->get('kernel');
+ $rootPath = $kernel->getProjectDir();
+
+ $q = $em->createQuery('SELECT u FROM Chamilo\CoreBundle\Entity\User u');
+ /** @var User $userEntity */
+ foreach ($q->toIterable() as $userEntity) {
+
+ $id = $userEntity->getId();
+ $path = "users/{$id}/";
+
+ $variable = 'split_users_upload_directory';
+ // Query the 'selected_value' from the 'settings_current' table where the 'variable' is 'split_users_upload_directory'
+ $query = $em->createQuery('SELECT s.selectedValue FROM Chamilo\CoreBundle\Entity\SettingsCurrent s WHERE s.variable = :variable')
+ ->setParameter('variable', $variable);
+
+ // Get the result of the query (it should return a single row with the 'selected_value' column)
+ $result = $query->getOneOrNullResult();
+ $settingValueAsString = 'false';
+ if (null !== $result) {
+ // Convert the 'selected_value' to a string and store it in $settingValueAsString
+ $settingValue = $result['selectedValue'];
+ $settingValueAsString = (string) $settingValue;
+ }
+
+ // If the 'split_users_upload_directory' setting is 'true', adjust the path accordingly
+ if ('true' === $settingValueAsString) {
+ $path = 'users/' . substr((string) $id, 0, 1) . '/' . $id . '/';
+ }
+
+ $baseDir = $rootPath.'/app/upload/'.$path;
+
+ // Check if the base directory exists, if not, continue to the next user
+ if (!is_dir($baseDir)) {
+ continue;
+ }
+
+ // Get all the files in the 'my_files' directory
+ $myFilesDir = $baseDir . 'my_files/';
+ $files = glob($myFilesDir . '*');
+
+ // $files now contains a list of all files in the 'my_files' directory
+ foreach ($files as $file) {
+
+ if (!is_file($file)) {
+ continue;
+ }
+
+ $title = basename($file);
+ $queryBuilder = $em->createQueryBuilder();
+
+ // Build the query to join the ResourceNode and PersonalFile tables
+ $queryBuilder
+ ->select('p')
+ ->from(ResourceNode::class, 'n')
+ ->innerJoin(PersonalFile::class, 'p', Join::WITH, 'p.resourceNode = n.id')
+ ->where('n.title = :title')
+ ->andWhere('n.creator = :creator')
+ ->setParameter('title', $title)
+ ->setParameter('creator', $id);
+
+ $result = $queryBuilder->getQuery()->getOneOrNullResult();
+
+ if ($result) {
+ // Skip creating a new entity and log a message
+ error_log('MIGRATIONS :: $file -- ' . $file . ' (Skipped: Already exists) ...');
+ continue;
+ }
+
+ error_log('MIGRATIONS :: $file -- ' . $file . ' ...');
+ // Create a new PersonalFile entity if it doesn't already exist
+ $personalFile = new PersonalFile();
+ $personalFile->setTitle($title); // Set the file name as the title
+ $personalFile->setCreator($userEntity);
+ $personalFile->setParentResourceNode($userEntity->getResourceNode()->getId());
+ $personalFile->setResourceName($title);
+ $mimeType = mime_content_type($file);
+ $uploadedFile = new UploadedFile($file, $title, $mimeType, null, true);
+ $personalFile->setUploadFile($uploadedFile);
+
+ // Save the object to the database
+ $em->persist($personalFile);
+ $em->flush();
+
+ }
+ }
+ }
+
+}
diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20230720222140.php b/src/CoreBundle/Migrations/Schema/V200/Version20230720222140.php
new file mode 100644
index 0000000000..67e7e866ff
--- /dev/null
+++ b/src/CoreBundle/Migrations/Schema/V200/Version20230720222140.php
@@ -0,0 +1,98 @@
+getContainer();
+ $em = $this->getEntityManager();
+ /** @var Connection $connection */
+ $connection = $em->getConnection();
+
+ $kernel = $container->get('kernel');
+ $rootPath = $kernel->getProjectDir();
+
+ $userRepo = $container->get(UserRepository::class);
+
+ /** @var PersonalFileRepository $personalRepo */
+ $personalRepo = $container->get(PersonalFileRepository::class);
+
+ $q = $em->createQuery('SELECT s FROM Chamilo\CoreBundle\Entity\SocialPost s');
+
+ /** @var SocialPost $socialPost */
+ foreach ($q->toIterable() as $socialPost) {
+ $content = $socialPost->getContent();
+
+ // Define the regular expression pattern to match URLs containing "my_files/"
+ $pattern = '/(href|src)="[^"]*\/users\/(\d+)\/\d+\/my_files\/([^"]+)"/i';
+ preg_match_all($pattern, $content, $matches);
+
+ // Combine the URLs found in href and src attributes
+ $allUrls = array_merge($matches[0]);
+
+ if (!empty($allUrls)) {
+ foreach ($allUrls as $url) {
+
+ // Define a regular expression to search for the "/upload/users" part, numeric values, and filename in the URL
+ $pattern = '/\/upload\/users\/(\d+)\/(\d+)\/my_files\/([^\/"]+)/i';
+
+ // Perform the regular expression search in the URL
+ if (preg_match($pattern, $url, $matches)) {
+ $folderId = (int) $matches[1];
+ $userId = (int) $matches[2];
+ $filename = $matches[3];
+
+ // Get the full file path
+ $filePath = $rootPath . "/app/upload/users/{$folderId}/{$userId}/my_files/{$filename}";
+
+ // Check if the path corresponds to a file
+ if (is_file($filePath)) {
+ // Output the user id, folder id, and filename
+ error_log('User ID: ' . $userId . ', Folder ID: ' . $folderId . ', Filename: ' . $filename);
+ $user = $userRepo->find($userId);
+ $personalFile = $personalRepo->getResourceByCreatorFromTitle(
+ $filename,
+ $user,
+ $user->getResourceNode()
+ );
+
+ $newUrl = $personalRepo->getResourceFileUrl($personalFile);
+ if (!empty($newUrl)) {
+ // Perform the replacement of the old URL with the new URL in the content
+ $content = preg_replace('/(src|href)="[^"]*\/users\/(\d+)\/\d+\/my_files\/([^"]+)"/i', '$1="' . $newUrl . '"', $content);
+ }
+ }
+ }
+ }
+
+ // Set the updated content back to the social post entity
+ $socialPost->setContent($content);
+
+ // Persist the updated social post entity
+ $em->persist($socialPost);
+ $em->flush();
+
+ }
+ }
+ }
+
+}