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. 70
      src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php

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

@ -4,6 +4,7 @@
namespace Chamilo\CourseBundle\Component\CourseCopy; namespace Chamilo\CourseBundle\Component\CourseCopy;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\Asset; use Chamilo\CourseBundle\Component\CourseCopy\Resources\Asset;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\Document;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
/** /**
@ -108,12 +109,28 @@ class CourseArchiver
// Copy all documents to the temp-dir // Copy all documents to the temp-dir
if (isset($course->resources[RESOURCE_DOCUMENT]) && is_array($course->resources[RESOURCE_DOCUMENT])) { 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) { foreach ($course->resources[RESOURCE_DOCUMENT] as $document) {
if ($document->file_type == DOCUMENT) { if ($document->file_type == DOCUMENT) {
$doc_dir = $backup_dir.$document->path; $doc_dir = $backup_dir.$document->path;
@mkdir(dirname($doc_dir), $perm_dirs, true); @mkdir(dirname($doc_dir), $perm_dirs, true);
if (file_exists($course->path.$document->path)) { if (file_exists($course->path.$document->path)) {
copy($course->path.$document->path, $doc_dir); 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 { } else {
@mkdir($backup_dir.$document->path, $perm_dirs, true); @mkdir($backup_dir.$document->path, $perm_dirs, true);
@ -171,7 +188,6 @@ class CourseArchiver
copyDirTo($course->path.$asset->path, $doc_dir, false); copyDirTo($course->path.$asset->path, $doc_dir, false);
continue; continue;
} }
copy($course->path.$asset->path, $doc_dir); copy($course->path.$asset->path, $doc_dir);
} }
} }

@ -288,6 +288,7 @@ class CourseRestorer
return; return;
} }
$webEditorCss = api_get_path(WEB_CSS_PATH).'editor.css';
$table = Database::get_course_table(TABLE_DOCUMENT); $table = Database::get_course_table(TABLE_DOCUMENT);
$resources = $this->course->resources; $resources = $this->course->resources;
$path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/'; $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; $origin_path = $this->course->backup_path.'/'.$document->path;
if (file_exists($origin_path)) { if (file_exists($origin_path)) {
copy($origin_path, $path.$document->path); copy($origin_path, $path.$document->path);
$this->fixEditorHtmlContent($path.$document->path, $webEditorCss);
$sql = "SELECT id FROM $table $sql = "SELECT id FROM $table
WHERE WHERE
c_id = ".$this->destination_course_id." AND c_id = ".$this->destination_course_id." AND
@ -684,6 +686,7 @@ class CourseRestorer
$this->course->info['path'] $this->course->info['path']
); );
file_put_contents($dest_document_path, $content); file_put_contents($dest_document_path, $content);
$this->fixEditorHtmlContent($dest_document_path, $webEditorCss);
} }
} }
@ -702,31 +705,31 @@ class CourseRestorer
if ($document_id) { if ($document_id) {
$sql = "UPDATE $table SET id = iid WHERE iid = $document_id"; $sql = "UPDATE $table SET id = iid WHERE iid = $document_id";
Database::query($sql); Database::query($sql);
}
$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id; $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
$itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : ''; $itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : '';
$insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id(); $insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id();
$toGroupId = isset($itemProperty['to_group_id']) ? $itemProperty['to_group_id'] : 0; $toGroupId = isset($itemProperty['to_group_id']) ? $itemProperty['to_group_id'] : 0;
$toUserId = isset($itemProperty['to_user_id']) ? $itemProperty['to_user_id'] : null; $toUserId = isset($itemProperty['to_user_id']) ? $itemProperty['to_user_id'] : null;
$insertUserId = $this->checkUserId($insertUserId); $insertUserId = $this->checkUserId($insertUserId);
$toUserId = $this->checkUserId($toUserId, true); $toUserId = $this->checkUserId($toUserId, true);
$groupInfo = $this->checkGroupId($toGroupId); $groupInfo = $this->checkGroupId($toGroupId);
api_item_property_update( api_item_property_update(
$course_info, $course_info,
TOOL_DOCUMENT, TOOL_DOCUMENT,
$document_id, $document_id,
'DocumentAdded', 'DocumentAdded',
$insertUserId, $insertUserId,
$groupInfo, $groupInfo,
$toUserId, $toUserId,
null, null,
null, null,
$my_session_id $my_session_id
); );
}
} else { } else {
if (file_exists($path.$document->path)) { if (file_exists($path.$document->path)) {
copy($path.$document->path, $path.$new_file_name); copy($path.$document->path, $path.$new_file_name);
@ -747,6 +750,7 @@ class CourseRestorer
$this->course->info['path'] $this->course->info['path']
); );
file_put_contents($path.$new_file_name, $content); 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'] $this->course->info['path']
); );
file_put_contents($path.$new_file_name, $content); 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'] $this->course->info['path']
); );
file_put_contents($path.$document->path, $content); file_put_contents($path.$document->path, $content);
$this->fixEditorHtmlContent($path.$document->path, $webEditorCss);
} }
} }
@ -3568,4 +3574,26 @@ class CourseRestorer
return $userId; 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