Fixes bug when copying forums see #5462

skala
Julio Montoya 12 years ago
parent 18733592a1
commit 6e5e4ac528
  1. 3
      main/coursecopy/classes/CourseBuilder.class.php
  2. 9
      main/coursecopy/classes/CourseRecycler.class.php
  3. 31
      main/coursecopy/classes/CourseRestorer.class.php
  4. 72
      main/coursecopy/classes/CourseSelectForm.class.php
  5. 5
      main/coursecopy/copy_course.php

@ -306,8 +306,7 @@ class CourseBuilder {
$sql = "SELECT * FROM $table WHERE c_id = $course_id
ORDER BY thread_title ";
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
//$forum_topic = new ForumTopic($obj->thread_id, $obj->thread_title, $obj->thread_date, $obj->thread_poster_id, $obj->thread_poster_name, $obj->forum_id, $obj->thread_last_post, $obj->thread_replies, $obj->thread_views, $obj->thread_sticky, $obj->locked, $obj->thread_close_date, $obj->thread_weight, $obj->thread_title_qualify, $obj->thread_qualify_max);
while ($obj = Database::fetch_object($db_result)) {
$forum_topic = new ForumTopic($obj);
$this->course->add_resource($forum_topic);
$this->build_forum_posts($obj->thread_id, $obj->forum_id);

@ -54,7 +54,6 @@ class CourseRecycler
$this->recycle_thematic();
$this->recycle_attendance();
foreach ($this->course->resources as $type => $resources) {
foreach ($resources as $id => $resource) {
$sql = "DELETE FROM ".$table_linked_resources." WHERE c_id = ".$this->course_id." AND (source_type = '".$type."' AND source_id = '".$id."') OR (resource_type = '".$type."' AND resource_id = '".$id."') ";
@ -147,7 +146,7 @@ class CourseRecycler
$table_mail_queue = Database::get_course_table(TABLE_FORUM_MAIL_QUEUE);
$table_thread_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY);
$table_thread_qualify_log = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY_LOG);
if ($this->type == 'full_backup') {
$sql = "DELETE FROM ".$table_category." WHERE c_id = ".$this->course_id;
Database::query($sql);
@ -166,7 +165,11 @@ class CourseRecycler
$sql = "DELETE FROM ".$table_thread_qualify." WHERE c_id = ".$this->course_id;
Database::query($sql);
$sql = "DELETE FROM ".$table_thread_qualify_log." WHERE c_id = ".$this->course_id;
Database::query($sql);
Database::query($sql);
$sql = "DELETE FROM ".$table_thread_qualify_log." WHERE c_id = ".$this->course_id;
Database::query($sql);
}
if ($this->course->has_resources(RESOURCE_FORUMCATEGORY)) {

@ -304,7 +304,6 @@ class CourseRestorer
$resources = $this->course->resources;
foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) {
$path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/';
//$dirs = explode('/', dirname($document->path));
@ -721,7 +720,8 @@ class CourseRestorer
$resources = $this->course->resources;
foreach ($resources[RESOURCE_FORUM] as $id => $forum) {
$params = (array)$forum->obj;
$params = (array)$forum->obj;
if ($this->course->resources[RESOURCE_FORUMCATEGORY][$params['forum_category']]->destination_id == -1) {
$cat_id = $this->restore_forum_category($params['forum_category']);
} else {
@ -793,15 +793,13 @@ class CourseRestorer
/**
* Restore a forum-topic
*/
function restore_topic($id, $forum_id) {
$table = Database :: get_course_table(TABLE_FORUM_THREAD);
$resources = $this->course->resources;
$topic = $resources[RESOURCE_FORUMTOPIC][$id];
function restore_topic($thread_id, $forum_id) {
$table = Database :: get_course_table(TABLE_FORUM_THREAD);
$topic = $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id];
$params = (array)$topic->obj;
self::DBUTF8_array($params);
$params['c_id'] = $this->destination_course_id;
$params['c_id'] = $this->destination_course_id;
$params['forum_id'] = $forum_id;
$params['thread_poster_id'] = $this->first_teacher_id;
$params['thread_date'] = api_get_utc_datetime();
@ -809,16 +807,17 @@ class CourseRestorer
$params['thread_last_post'] = 0;
$params['thread_replies'] = 0;
$params['thread_views'] = 0;
unset($params['thread_id']);
unset($params['thread_id']);
$new_id = Database::insert($table, $params);
api_item_property_update($this->destination_course_info, TOOL_FORUM_THREAD, $new_id, 'ThreadAdded', api_get_user_id(), 0, 0, null, null);
$this->course->resources[RESOURCE_FORUMTOPIC][$id]->destination_id = $new_id;
$this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]->destination_id = $new_id;
$topic_replies = -1;
foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post){
if ($post->obj->thread_id == $id) {
foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post){
if ($post->obj->thread_id == $thread_id) {
$topic_replies++;
$this->restore_post($post_id, $new_id, $forum_id);
}
@ -880,6 +879,7 @@ class CourseRestorer
}
}
}
/**
* Restore tool intro
*/
@ -1151,8 +1151,7 @@ class CourseRestorer
}
$this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id;
$order = 0;
///var_dump($quiz->title);var_dump($quiz->question_ids);
$order = 0;
foreach ($quiz->question_ids as $index => $question_id) {
$qid = $this->restore_quiz_question($question_id);
$question_order = $quiz->question_orders[$index] ? $quiz->question_orders[$index] : ++$order;

@ -23,10 +23,8 @@ class CourseSelectForm
$resource_titles[RESOURCE_DOCUMENT] = get_lang('Documents');
$resource_titles[RESOURCE_LINK] = get_lang('Links');
$resource_titles[RESOURCE_COURSEDESCRIPTION] = get_lang('CourseDescription');
$resource_titles[RESOURCE_FORUM] = get_lang('Forums');
$resource_titles[RESOURCE_FORUMCATEGORY] = get_lang('ForumCategory');
$resource_titles[RESOURCE_FORUM] = get_lang('Forums');
$resource_titles[RESOURCE_FORUMCATEGORY] = get_lang('ForumCategory');
$resource_titles[RESOURCE_QUIZ] = get_lang('Tests');
$resource_titles[RESOURCE_LEARNPATH] = get_lang('Learnpaths');
$resource_titles[RESOURCE_SCORM] = 'SCORM';
@ -187,7 +185,7 @@ class CourseSelectForm
$forum_topics[$resource->obj->forum_id][$id] = $resource;
}
$element_count++;
break;
break;
case RESOURCE_LINKCATEGORY :
case RESOURCE_FORUMPOST :
case RESOURCE_QUIZQUESTION:
@ -210,7 +208,6 @@ class CourseSelectForm
}
echo '<blockquote>';
echo '<div class="btn-group">';
echo "<a class=\"btn\" href=\"javascript: void(0);\" onclick=\"javascript: setCheckbox('$type',true);\" >".get_lang('All')."</a>";
echo "<a class=\"btn\" href=\"javascript: void(0);\" onclick=\"javascript:setCheckbox('$type',false);\" >".get_lang('None')."</a>";
@ -300,14 +297,10 @@ class CourseSelectForm
}
echo '<hr/>';
}
echo '</ul>';
echo '</ul>';
echo '</div>';
echo '<script language="javascript">exp('."'$type'".')</script>';
echo '<script language="javascript">exp('."'$type'".')</script>';
}
if ($avoid_serialize) {
/*Documents are avoided due the huge amount of memory that the serialize php function "eats"
@ -351,7 +344,6 @@ class CourseSelectForm
echo '<input type="hidden" name="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" id="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" value="On" />';
}
break;
}
}
}
@ -382,10 +374,10 @@ class CourseSelectForm
*/
static function get_posted_course($from='', $session_id = 0, $course_code = '') {
$course = Course::unserialize(base64_decode($_POST['course']));
//Create the resource DOCUMENT objects
//Loading the results from the checkboxes of the javascript
$resource = $_POST['resource'][RESOURCE_DOCUMENT];
$resource = $_POST['resource'][RESOURCE_DOCUMENT];
$course_info = api_get_course_info($course_code);
$table_doc = Database::get_course_table(TABLE_DOCUMENT);
@ -430,21 +422,47 @@ class CourseSelectForm
}
}
}
if (is_array($course->resources)) {
foreach ($course->resources as $type => $resources) {
switch ($type) {
case RESOURCE_SURVEYQUESTION:
foreach($resources as $id => $obj) {
if(is_array($_POST['resource'][RESOURCE_SURVEY]) && !in_array($obj->survey_id,array_keys($_POST['resource'][RESOURCE_SURVEY]))) {
unset ($course->resources[$type][$id]);
if (is_array($_POST['resource'][RESOURCE_SURVEY]) && !in_array($obj->survey_id, array_keys($_POST['resource'][RESOURCE_SURVEY]))) {
unset($course->resources[$type][$id]);
}
}
break;
case RESOURCE_FORUMTOPIC:
case RESOURCE_FORUMPOST:
//Add post from topic
if ($type == RESOURCE_FORUMTOPIC) {
$posts_to_save = array();
$posts = $course->resources[RESOURCE_FORUMPOST];
foreach ($resources as $thread_id => $obj) {
if (!isset($_POST['resource'][RESOURCE_FORUMTOPIC][$thread_id])) {
unset($course->resources[RESOURCE_FORUMTOPIC][$thread_id]);
continue;
}
$forum_id = $obj->obj->forum_id;
$title = $obj->obj->thread_title;
foreach ($posts as $post_id => $post) {
if ($post->obj->thread_id == $thread_id && $forum_id == $post->obj->forum_id && $title == $post->obj->post_title) {
//unset($course->resources[RESOURCE_FORUMPOST][$post_id]);
$posts_to_save[] = $post_id;
}
}
}
if (!empty($posts)) {
foreach ($posts as $post_id => $post) {
if (!in_array($post_id, $posts_to_save)) {
unset($course->resources[RESOURCE_FORUMPOST][$post_id]);
}
}
}
}
break;
case RESOURCE_LINKCATEGORY :
case RESOURCE_FORUMCATEGORY :
case RESOURCE_FORUMPOST :
case RESOURCE_FORUMTOPIC :
case RESOURCE_FORUMCATEGORY :
case RESOURCE_QUIZQUESTION :
case RESOURCE_DOCUMENT:
// Mark folders to import which are not selected by the user to import,
@ -452,11 +470,11 @@ class CourseSelectForm
$documents = $_POST['resource'][RESOURCE_DOCUMENT];
if (is_array($resources))
foreach($resources as $id => $obj) {
if( $obj->file_type == 'folder' && ! isset($_POST['resource'][RESOURCE_DOCUMENT][$id]) && is_array($documents)) {
if ($obj->file_type == 'folder' && ! isset($_POST['resource'][RESOURCE_DOCUMENT][$id]) && is_array($documents)) {
foreach($documents as $id_to_check => $post_value) {
$obj_to_check = $resources[$id_to_check];
$shared_path_part = substr($obj_to_check->path,0,strlen($obj->path));
if($id_to_check != $id && $obj->path == $shared_path_part) {
if ($id_to_check != $id && $obj->path == $shared_path_part) {
$_POST['resource'][RESOURCE_DOCUMENT][$id] = 1;
break;
}
@ -470,19 +488,19 @@ class CourseSelectForm
// check if document is in a quiz (audio/video)
if ($type == RESOURCE_DOCUMENT && $course->has_resources(RESOURCE_QUIZ)) {
foreach($course->resources[RESOURCE_QUIZ] as $qid => $quiz) {
if($quiz->media == $id) {
if ($quiz->media == $id) {
$resource_is_used_elsewhere = true;
}
}
}
if (!isset($_POST['resource'][$type][$id]) && !$resource_is_used_elsewhere) {
unset ($course->resources[$type][$id]);
unset($course->resources[$type][$id]);
}
}
}
}
}
}
}
return $course;
}
@ -493,7 +511,7 @@ class CourseSelectForm
*/
function display_form_session_export($list_course, $hidden_fields = null, $avoid_serialize=false) {
?>
<script type="text/javascript">
<script>
function exp(item) {
el = document.getElementById('div_'+item);
if (el.style.display=='none'){

@ -34,7 +34,7 @@ if (function_exists('ini_set')) {
}
// Breadcrumbs
$interbreadcrumb[] = array ('url' => '../course_info/maintenance.php', 'name' => get_lang('Maintenance'));
$interbreadcrumb[] = array('url' => '../course_info/maintenance.php', 'name' => get_lang('Maintenance'));
// The section (for the tabs)
$this_section = SECTION_COURSES;
@ -48,13 +48,12 @@ echo Display::page_header(get_lang('CopyCourse'));
// If a CourseSelectForm is posted or we should copy all resources, then copy them
if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (isset($_POST['copy_option']) && $_POST['copy_option'] == 'full_copy')) {
if (isset($_POST['action']) && $_POST['action'] == 'course_select_form') {
$course = CourseSelectForm :: get_posted_course('copy_course');
$course = CourseSelectForm :: get_posted_course('copy_course');
} else {
$cb = new CourseBuilder();
$course = $cb->build();
}
$cr = new CourseRestorer($course);
$cr->set_file_option($_POST['same_file_name_option']);
$cr->restore($_POST['destination_course']);
Display::display_normal_message(get_lang('CopyFinished').': <a href="'.api_get_course_url($_POST['destination_course']).'">'.$_POST['destination_course'].'</a>',false);

Loading…
Cancel
Save