Merge pull request #5817 from christianbeeznest/rna-22042

Migration: Update old CKEditor image paths and convert .gif to .png in content - refs BT#22042
pull/5818/head
christianbeeznest 2 months ago committed by GitHub
commit ab78fd0cd7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. BIN
      public/img/legacy/angel_smile.png
  2. BIN
      public/img/legacy/angry_smile.png
  3. BIN
      public/img/legacy/broken_heart.png
  4. BIN
      public/img/legacy/confused_smile.png
  5. BIN
      public/img/legacy/cry_smile.png
  6. BIN
      public/img/legacy/devil_smile.png
  7. BIN
      public/img/legacy/embarrassed_smile.png
  8. BIN
      public/img/legacy/envelope.png
  9. BIN
      public/img/legacy/heart.png
  10. BIN
      public/img/legacy/kiss.png
  11. BIN
      public/img/legacy/lightbulb.png
  12. BIN
      public/img/legacy/omg_smile.png
  13. BIN
      public/img/legacy/regular_smile.png
  14. BIN
      public/img/legacy/sad_smile.png
  15. BIN
      public/img/legacy/shades_smile.png
  16. BIN
      public/img/legacy/teeth_smile.png
  17. BIN
      public/img/legacy/thumbs_down.png
  18. BIN
      public/img/legacy/thumbs_up.png
  19. BIN
      public/img/legacy/tongue_smile.png
  20. BIN
      public/img/legacy/whatchutalkingabout_smile.png
  21. BIN
      public/img/legacy/wink_smile.png
  22. 80
      src/CoreBundle/Migrations/Schema/V200/Version20240924120200.php

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 760 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 999 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1003 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 919 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 985 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 959 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

@ -0,0 +1,80 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;
final class Version20240924120200 extends AbstractMigrationChamilo
{
public function getDescription(): string
{
return 'Update HTML content blocks to replace old CKEditor image paths with new ones and convert .gif references to .png';
}
public function up(Schema $schema): void
{
$this->entityManager->clear();
// Define the content fields to update
$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_student_publication', 'field' => 'description'],
['table' => 'c_student_publication_comment', 'field' => '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'],
];
foreach ($updateConfigurations as $config) {
$this->updateContent($config);
}
}
private function updateContent(array $config): void
{
$fields = isset($config['field']) ? [$config['field']] : $config['fields'] ?? [];
foreach ($fields as $field) {
$sql = "SELECT iid, {$field} FROM {$config['table']}";
$result = $this->connection->executeQuery($sql);
$items = $result->fetchAllAssociative();
foreach ($items as $item) {
$originalText = $item[$field];
if (!empty($originalText)) {
$updatedText = $this->replaceGifWithPng($originalText);
if ($originalText !== $updatedText) {
$updateSql = "UPDATE {$config['table']} SET {$field} = :newText WHERE iid = :id";
$this->connection->executeQuery($updateSql, ['newText' => $updatedText, 'id' => $item['iid']]);
}
}
}
}
}
private function replaceGifWithPng(string $content): string
{
$pattern = '/(src=["\'])(https?:\/\/[^\/]+\/)?(\/?web\/assets\/ckeditor\/plugins\/smiley\/images\/([a-zA-Z0-9_\-]+))\.(gif|png)(["\'])/i';
$content = preg_replace_callback($pattern, function ($matches) {
$prefix = $matches[1];
$filename = $matches[4];
$extension = 'png';
return "{$prefix}/img/legacy/{$filename}.{$extension}{$matches[6]}";
}, $content);
return $content;
}
}
Loading…
Cancel
Save