Fixing course copy due c_id changes

skala
Julio Montoya 12 years ago
parent 643cb6745f
commit acad38137b
  1. 4
      main/coursecopy/classes/CourseBuilder.class.php
  2. 10
      main/coursecopy/classes/CourseRecycler.class.php
  3. 29
      main/coursecopy/classes/CourseRestorer.class.php
  4. 35
      main/coursecopy/classes/ForumCategory.class.php

@ -275,12 +275,9 @@ class CourseBuilder {
$sql .= " ORDER BY forum_title, forum_category";
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
//$forum = new Forum($obj->forum_id, $obj->forum_title, $obj->forum_comment, $obj->forum_category, $obj->forum_last_post, $obj->forum_threads, $obj->forum_posts, $obj->allow_anonymous, $obj->allow_edit, $obj->approval_direct_post, $obj->allow_attachements, $obj->allow_new_threads, $obj->default_view, $obj->forum_of_group, $obj->forum_group_public_private, $obj->forum_order, $obj->locked, $obj->session_id, $obj->forum_image);
$forum = new Forum($obj);
$this->course->add_resource($forum);
}
//$this->build_forum_topics();
//$this->build_forum_posts();
}
/**
@ -294,7 +291,6 @@ class CourseBuilder {
$sql = "SELECT * FROM $table WHERE c_id = $course_id ORDER BY cat_title";
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
//$forum_category = new ForumCategory($obj->cat_id, $obj->cat_title, $obj->cat_comment, $obj->cat_order, $obj->locked, $obj->session_id);
$forum_category = new ForumCategory($obj);
$this->course->add_resource($forum_category);
}

@ -208,14 +208,16 @@ class CourseRecycler
function recycle_forum_categories() {
$table_forum = Database :: get_course_table(TABLE_FORUM);
$table_forumcat = Database :: get_course_table(TABLE_FORUM_CATEGORY);
$sql = "SELECT fc.cat_id FROM ".$table_forumcat." fc LEFT JOIN ".$table_forum." f ON fc.cat_id=f.forum_category
WHERE fc.c_id = ".$this->course_id." AND f.c_id = ".$this->course_id." AND f.forum_id IS NULL";
$sql = "SELECT fc.cat_id FROM ".$table_forumcat." fc
LEFT JOIN ".$table_forum." f ON fc.cat_id=f.forum_category AND fc.c_id = ".$this->course_id." AND f.c_id = ".$this->course_id."
WHERE f.forum_id IS NULL";
$res = Database::query($sql);
while ($obj = Database::fetch_object($res)) {
$sql = "DELETE FROM ".$table_forumcat." WHERE c_id = ".$this->course_id." AND cat_id = ".$obj->cat_id;
Database::query($sql);
}
}
/**
* Delete link-categories
* Deletes all empty link-categories (=without links) from current course
@ -223,7 +225,9 @@ class CourseRecycler
function recycle_link_categories() {
$link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY);
$link_table = Database :: get_course_table(TABLE_LINK);
$sql = "SELECT lc.id FROM ".$link_cat_table." lc LEFT JOIN ".$link_table." l ON lc.id=l.category_id
$sql = "SELECT lc.id FROM ".$link_cat_table." lc
LEFT JOIN ".$link_table." l
ON lc.id=l.category_id AND lc.c_id = ".$this->course_id." AND l.c_id = ".$this->course_id."
WHERE l.id IS NULL";
$res = Database::query($sql);
while ($obj = Database::fetch_object($res)) {

@ -63,7 +63,7 @@ class CourseRestorer
'course_descriptions',
'documents',
'events',
// 'forum_category',
'forum_category',
'forums',
// 'forum_topics',
'glossary',
@ -751,12 +751,17 @@ class CourseRestorer
/**
* Restore forum-categories
*/
function restore_forum_category($id) {
function restore_forum_category($my_id = null) {
$forum_cat_table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
$resources = $this->course->resources;
$forum_cat = $resources[RESOURCE_FORUMCATEGORY][$id];
if ($forum_cat && !$forum_cat->is_restored()) {
foreach ($resources[RESOURCE_FORUMCATEGORY] as $id => $forum_cat) {
if (!empty($my_id)) {
if ($id != $my_id) {
continue;
}
}
if (!$forum_cat->is_restored()) {
$title = $forum_cat->obj->cat_title;
if (!empty($title)) {
if (!preg_match('/.*\((.+)\)$/', $title, $matches)) {
@ -771,19 +776,13 @@ class CourseRestorer
unset($params['cat_id']);
self::DBUTF8_array($params);
$new_id = Database::insert($forum_cat_table, $params);
/*
$sql = "INSERT INTO ".$forum_cat_table." SET
c_id = ".$this->destination_course_id." ,
cat_title = '".self::DBUTF8escapestring($title).
"', cat_comment = '".self::DBUTF8escapestring($forum_cat->description).
"', cat_order = ".(int)self::DBUTF8escapestring($forum_cat->order).
", locked = ".(int)self::DBUTF8escapestring($forum_cat->locked).
", session_id = ".(int)self::DBUTF8escapestring($forum_cat->session_id);
Database::query($sql);*/
$this->course->resources[RESOURCE_FORUMCATEGORY][$id]->destination_id = $new_id;
if (!empty($my_id)) {
return $new_id;
}
return $this->course->resources[RESOURCE_FORUMCATEGORY][$id]->destination_id;
$this->course->resources[RESOURCE_FORUMCATEGORY][$id]->destination_id = $new_id;
}
$this->course->resources[RESOURCE_FORUMCATEGORY][$id]->destination_id;
}
}
/**

@ -16,44 +16,12 @@ require_once 'Resource.class.php';
* @package chamilo.backup
*/
class ForumCategory extends Resource {
/**
* The title
*/
var $title;
/**
* The description
*/
var $description;
/**
* The order
*/
var $order;
/**
* Locked flag
*/
var $locked;
/**
* The session id
*/
var $session_id;
/**
* Create a new ForumCategory
*/
//function ForumCategory($id, $title, $description, $order, $locked, $session_id)
function ForumCategory($obj) {
parent::Resource($obj->cat_id, RESOURCE_FORUMCATEGORY);
$this->obj = $obj; /*
$this->title = $title;
$this->description = $description;
$this->order = $order;
$this->locked = $locked;
$this->session_id = $session_id; */
$this->obj = $obj;
}
/**
@ -63,5 +31,4 @@ class ForumCategory extends Resource {
parent::show();
echo $this->obj->cat_title;
}
}

Loading…
Cancel
Save