Fix web/editor.css path when exporting/importing documents see BT#10885

pull/2500/head
jmontoyaa 8 years ago
parent 217a3b355c
commit 06eaf17619
  1. 2
      src/Chamilo/CourseBundle/Component/CourseCopy/Course.php
  2. 18
      src/Chamilo/CourseBundle/Component/CourseCopy/CourseArchiver.php
  3. 30
      src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php

@ -59,6 +59,8 @@ class Course
/**
* Add a resource from a given type to this course.
*
* @param Resource $resource
*/
public function add_resource(&$resource)
{

@ -4,6 +4,7 @@
namespace Chamilo\CourseBundle\Component\CourseCopy;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\Asset;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\Document;
use Symfony\Component\Filesystem\Filesystem;
/**
@ -108,12 +109,28 @@ class CourseArchiver
// Copy all documents to the temp-dir
if (isset($course->resources[RESOURCE_DOCUMENT]) && is_array($course->resources[RESOURCE_DOCUMENT])) {
$webEditorCss = api_get_path(WEB_CSS_PATH).'editor.css';
/** @var Document $document */
foreach ($course->resources[RESOURCE_DOCUMENT] as $document) {
if ($document->file_type == DOCUMENT) {
$doc_dir = $backup_dir.$document->path;
@mkdir(dirname($doc_dir), $perm_dirs, true);
if (file_exists($course->path.$document->path)) {
copy($course->path.$document->path, $doc_dir);
// Check if is html or htm
$extension = pathinfo(basename($document->path), PATHINFO_EXTENSION);
switch ($extension) {
case 'html':
case 'htm':
$contents = file_get_contents($doc_dir);
$contents = str_replace(
$webEditorCss,
'{{css_editor}}',
$contents
);
file_put_contents($doc_dir, $contents);
break;
}
}
} else {
@mkdir($backup_dir.$document->path, $perm_dirs, true);
@ -171,7 +188,6 @@ class CourseArchiver
copyDirTo($course->path.$asset->path, $doc_dir, false);
continue;
}
copy($course->path.$asset->path, $doc_dir);
}
}

@ -288,6 +288,7 @@ class CourseRestorer
return;
}
$webEditorCss = api_get_path(WEB_CSS_PATH).'editor.css';
$table = Database::get_course_table(TABLE_DOCUMENT);
$resources = $this->course->resources;
$path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/';
@ -450,6 +451,7 @@ class CourseRestorer
$origin_path = $this->course->backup_path.'/'.$document->path;
if (file_exists($origin_path)) {
copy($origin_path, $path.$document->path);
$this->fixEditorHtmlContent($path.$document->path, $webEditorCss);
$sql = "SELECT id FROM $table
WHERE
c_id = ".$this->destination_course_id." AND
@ -684,6 +686,7 @@ class CourseRestorer
$this->course->info['path']
);
file_put_contents($dest_document_path, $content);
$this->fixEditorHtmlContent($dest_document_path, $webEditorCss);
}
}
@ -702,7 +705,6 @@ class CourseRestorer
if ($document_id) {
$sql = "UPDATE $table SET id = iid WHERE iid = $document_id";
Database::query($sql);
}
$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
@ -727,6 +729,7 @@ class CourseRestorer
null,
$my_session_id
);
}
} else {
if (file_exists($path.$document->path)) {
copy($path.$document->path, $path.$new_file_name);
@ -747,6 +750,7 @@ class CourseRestorer
$this->course->info['path']
);
file_put_contents($path.$new_file_name, $content);
$this->fixEditorHtmlContent($path.$new_file_name, $webEditorCss);
}
}
@ -813,6 +817,7 @@ class CourseRestorer
$this->course->info['path']
);
file_put_contents($path.$new_file_name, $content);
$this->fixEditorHtmlContent($path.$new_file_name, $webEditorCss);
}
}
@ -887,6 +892,7 @@ class CourseRestorer
$this->course->info['path']
);
file_put_contents($path.$document->path, $content);
$this->fixEditorHtmlContent($path.$document->path, $webEditorCss);
}
}
@ -3568,4 +3574,26 @@ class CourseRestorer
return $userId;
}
/**
* @param string $documentPath
* @param string $webEditorCss
*/
public function fixEditorHtmlContent($documentPath, $webEditorCss = '')
{
$extension = pathinfo(basename($documentPath), PATHINFO_EXTENSION);
switch ($extension) {
case 'html':
case 'htm':
$contents = file_get_contents($documentPath);
$contents = str_replace(
'{{css_editor}}',
$webEditorCss,
$contents
);
file_put_contents($documentPath, $contents);
break;
}
}
}

Loading…
Cancel
Save