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. 63
      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"; $sql .= " ORDER BY forum_title, forum_category";
$db_result = Database::query($sql); $db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) { 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); $forum = new Forum($obj);
$this->course->add_resource($forum); $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"; $sql = "SELECT * FROM $table WHERE c_id = $course_id ORDER BY cat_title";
$db_result = Database::query($sql); $db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) { 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); $forum_category = new ForumCategory($obj);
$this->course->add_resource($forum_category); $this->course->add_resource($forum_category);
} }

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

@ -63,7 +63,7 @@ class CourseRestorer
'course_descriptions', 'course_descriptions',
'documents', 'documents',
'events', 'events',
// 'forum_category', 'forum_category',
'forums', 'forums',
// 'forum_topics', // 'forum_topics',
'glossary', 'glossary',
@ -751,39 +751,38 @@ class CourseRestorer
/** /**
* Restore forum-categories * 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); $forum_cat_table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
$resources = $this->course->resources; $resources = $this->course->resources;
$forum_cat = $resources[RESOURCE_FORUMCATEGORY][$id];
foreach ($resources[RESOURCE_FORUMCATEGORY] as $id => $forum_cat) {
if ($forum_cat && !$forum_cat->is_restored()) { if (!empty($my_id)) {
$title = $forum_cat->obj->cat_title; if ($id != $my_id) {
if (!empty($title)) { continue;
if (!preg_match('/.*\((.+)\)$/', $title, $matches)) { }
// This is for avoiding repetitive adding of training code after several backup/restore cycles. }
if ($matches[1] != $this->course->code) { if (!$forum_cat->is_restored()) {
$title = $title.' ('.$this->course->code.')'; $title = $forum_cat->obj->cat_title;
} if (!empty($title)) {
} if (!preg_match('/.*\((.+)\)$/', $title, $matches)) {
} // This is for avoiding repetitive adding of training code after several backup/restore cycles.
$params = (array) $forum_cat->obj; if ($matches[1] != $this->course->code) {
$params['c_id'] = $this->destination_course_id; $title = $title.' ('.$this->course->code.')';
unset($params['cat_id']); }
self::DBUTF8_array($params); }
$new_id = Database::insert($forum_cat_table, $params); }
/* $params = (array) $forum_cat->obj;
$sql = "INSERT INTO ".$forum_cat_table." SET $params['c_id'] = $this->destination_course_id;
c_id = ".$this->destination_course_id." , unset($params['cat_id']);
cat_title = '".self::DBUTF8escapestring($title). self::DBUTF8_array($params);
"', cat_comment = '".self::DBUTF8escapestring($forum_cat->description). $new_id = Database::insert($forum_cat_table, $params);
"', cat_order = ".(int)self::DBUTF8escapestring($forum_cat->order). if (!empty($my_id)) {
", locked = ".(int)self::DBUTF8escapestring($forum_cat->locked). return $new_id;
", session_id = ".(int)self::DBUTF8escapestring($forum_cat->session_id); }
Database::query($sql);*/ $this->course->resources[RESOURCE_FORUMCATEGORY][$id]->destination_id = $new_id;
$this->course->resources[RESOURCE_FORUMCATEGORY][$id]->destination_id = $new_id; }
return $new_id; $this->course->resources[RESOURCE_FORUMCATEGORY][$id]->destination_id;
} }
return $this->course->resources[RESOURCE_FORUMCATEGORY][$id]->destination_id;
} }
/** /**

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

Loading…
Cancel
Save