|
|
|
@ -78,6 +78,7 @@ class CourseRestorer |
|
|
|
|
* |
|
|
|
|
**/ |
|
|
|
|
public $add_text_in_items = false; |
|
|
|
|
public $destination_course_id; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create a new CourseRestorer |
|
|
|
@ -149,7 +150,9 @@ class CourseRestorer |
|
|
|
|
$this->destination_course_id = $course_info['real_id']; |
|
|
|
|
|
|
|
|
|
//Getting first teacher (for the forums) |
|
|
|
|
$teacher_list = CourseManager::get_teacher_list_from_course_code($course_info['code']); |
|
|
|
|
$teacher_list = CourseManager::get_teacher_list_from_course_code( |
|
|
|
|
$course_info['code'] |
|
|
|
|
); |
|
|
|
|
$this->first_teacher_id = api_get_user_id(); |
|
|
|
|
|
|
|
|
|
if (!empty($teacher_list)) { |
|
|
|
@ -194,11 +197,12 @@ class CourseRestorer |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Restore the item properties |
|
|
|
|
$table = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
|
|
|
|
$table = Database::get_course_table(TABLE_ITEM_PROPERTY); |
|
|
|
|
|
|
|
|
|
foreach ($this->course->resources as $type => $resources) { |
|
|
|
|
if (is_array($resources)) { |
|
|
|
|
foreach ($resources as $id => $resource) { |
|
|
|
|
if (isset($resource->item_properties)) { |
|
|
|
|
foreach ($resource->item_properties as $property) { |
|
|
|
|
// First check if there isn't already a record for this resource |
|
|
|
|
$sql = "SELECT * FROM $table |
|
|
|
@ -219,17 +223,37 @@ class CourseRestorer |
|
|
|
|
the target course*/ |
|
|
|
|
|
|
|
|
|
$params['c_id'] = $this->destination_course_id; |
|
|
|
|
$params['tool'] = self::DBUTF8($property['tool']); |
|
|
|
|
$params['insert_user_id'] = self::DBUTF8($property['insert_user_id']); |
|
|
|
|
$params['insert_date'] = self::DBUTF8($property['insert_date']); |
|
|
|
|
$params['lastedit_date'] = self::DBUTF8($property['lastedit_date']); |
|
|
|
|
$params['tool'] = self::DBUTF8( |
|
|
|
|
$property['tool'] |
|
|
|
|
); |
|
|
|
|
$params['insert_user_id'] = self::DBUTF8( |
|
|
|
|
$property['insert_user_id'] |
|
|
|
|
); |
|
|
|
|
$params['insert_date'] = self::DBUTF8( |
|
|
|
|
$property['insert_date'] |
|
|
|
|
); |
|
|
|
|
$params['lastedit_date'] = self::DBUTF8( |
|
|
|
|
$property['lastedit_date'] |
|
|
|
|
); |
|
|
|
|
$params['ref'] = $resource->destination_id; |
|
|
|
|
$params['lastedit_type'] = self::DBUTF8($property['lastedit_type']); |
|
|
|
|
$params['lastedit_user_id'] = self::DBUTF8($property['lastedit_user_id']); |
|
|
|
|
$params['visibility'] = self::DBUTF8($property['visibility']); |
|
|
|
|
$params['start_visible'] = self::DBUTF8($property['start_visible']); |
|
|
|
|
$params['end_visible'] = self::DBUTF8($property['end_visible']); |
|
|
|
|
$params['to_user_id'] = self::DBUTF8($property['to_user_id']); |
|
|
|
|
$params['lastedit_type'] = self::DBUTF8( |
|
|
|
|
$property['lastedit_type'] |
|
|
|
|
); |
|
|
|
|
$params['lastedit_user_id'] = self::DBUTF8( |
|
|
|
|
$property['lastedit_user_id'] |
|
|
|
|
); |
|
|
|
|
$params['visibility'] = self::DBUTF8( |
|
|
|
|
$property['visibility'] |
|
|
|
|
); |
|
|
|
|
$params['start_visible'] = self::DBUTF8( |
|
|
|
|
$property['start_visible'] |
|
|
|
|
); |
|
|
|
|
$params['end_visible'] = self::DBUTF8( |
|
|
|
|
$property['end_visible'] |
|
|
|
|
); |
|
|
|
|
$params['to_user_id'] = self::DBUTF8( |
|
|
|
|
$property['to_user_id'] |
|
|
|
|
); |
|
|
|
|
//$params['to_group_id'] = 'NULL'; |
|
|
|
|
|
|
|
|
|
$id = Database::insert($table, $params); |
|
|
|
@ -243,6 +267,7 @@ class CourseRestorer |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Restore only harmless course settings: |
|
|
|
@ -868,7 +893,7 @@ class CourseRestorer |
|
|
|
|
|
|
|
|
|
$params = [ |
|
|
|
|
'c_id' => $this->destination_course_id, |
|
|
|
|
'path' => "/".self::DBUTF8escapestring(substr($new_file_name, 9)), |
|
|
|
|
'path' => "/".self::DBUTF8("/".substr($document->path, 9)), |
|
|
|
|
'comment'=> self::DBUTF8($document->comment), |
|
|
|
|
'title' => self::DBUTF8($document->title), |
|
|
|
|
'filetype' => self::DBUTF8($document->file_type), |
|
|
|
@ -1087,7 +1112,7 @@ class CourseRestorer |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if ($forum_cat && !$forum_cat->is_restored()) { |
|
|
|
|
$title = $forum_cat->obj->cat_title; |
|
|
|
|
/*$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. |
|
|
|
@ -1095,7 +1120,7 @@ class CourseRestorer |
|
|
|
|
$title = $title.' ('.$this->course->code.')'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}*/ |
|
|
|
|
$params = (array) $forum_cat->obj; |
|
|
|
|
$params['c_id'] = $this->destination_course_id; |
|
|
|
|
$params['cat_comment'] = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
|
|
|
@ -1237,9 +1262,14 @@ class CourseRestorer |
|
|
|
|
if ($this->course->has_resources(RESOURCE_LINK)) { |
|
|
|
|
$link_table = Database :: get_course_table(TABLE_LINK); |
|
|
|
|
$resources = $this->course->resources; |
|
|
|
|
|
|
|
|
|
foreach ($resources[RESOURCE_LINK] as $id => $link) { |
|
|
|
|
$cat_id = $this->restore_link_category($link->category_id, $session_id); |
|
|
|
|
$sql = "SELECT MAX(display_order) FROM $link_table |
|
|
|
|
$cat_id = $this->restore_link_category( |
|
|
|
|
$link->category_id, |
|
|
|
|
$session_id |
|
|
|
|
); |
|
|
|
|
$sql = "SELECT MAX(display_order) |
|
|
|
|
FROM $link_table |
|
|
|
|
WHERE |
|
|
|
|
c_id = ".$this->destination_course_id." AND |
|
|
|
|
category_id='" . intval($cat_id). "'"; |
|
|
|
@ -1264,9 +1294,21 @@ class CourseRestorer |
|
|
|
|
if ($id) { |
|
|
|
|
$sql = "UPDATE $link_table SET id = iid WHERE iid = $id"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
api_item_property_update( |
|
|
|
|
$this->destination_course_info, |
|
|
|
|
TOOL_LINK, |
|
|
|
|
$id, |
|
|
|
|
'LinkAdded', |
|
|
|
|
api_get_user_id() |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if (!isset($this->course->resources[RESOURCE_LINK][$id])) { |
|
|
|
|
$this->course->resources[RESOURCE_LINK][$id] = new stdClass(); |
|
|
|
|
} |
|
|
|
|
$this->course->resources[RESOURCE_LINK][$id]->destination_id = $id; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -1304,6 +1346,7 @@ class CourseRestorer |
|
|
|
|
if ($new_id) { |
|
|
|
|
$sql = "UPDATE $link_cat_table SET id = iid WHERE iid = $new_id"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
api_set_default_visibility($new_id, TOOL_LINK_CATEGORY); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$this->course->resources[RESOURCE_LINKCATEGORY][$id]->destination_id = $new_id; |
|
|
|
@ -1347,12 +1390,16 @@ class CourseRestorer |
|
|
|
|
if ($id) { |
|
|
|
|
$sql = "UPDATE $tool_intro_table SET id = iid WHERE iid = $id"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
|
|
if (!isset($this->course->resources[RESOURCE_TOOL_INTRO][$id])) { |
|
|
|
|
$this->course->resources[RESOURCE_TOOL_INTRO][$id] = new stdClass(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$this->course->resources[RESOURCE_TOOL_INTRO][$id]->destination_id = $id; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Restore events |
|
|
|
@ -1387,11 +1434,15 @@ class CourseRestorer |
|
|
|
|
if ($new_event_id) { |
|
|
|
|
$sql = "UPDATE $table SET id = iid WHERE iid = $new_event_id"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
|
|
if (!isset($this->course->resources[RESOURCE_EVENT][$id])) { |
|
|
|
|
$this->course->resources[RESOURCE_EVENT][$id] = new stdClass(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$this->course->resources[RESOURCE_EVENT][$id]->destination_id = $new_event_id; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//Copy event attachment |
|
|
|
|
// Copy event attachment |
|
|
|
|
|
|
|
|
|
$origin_path = $this->course->backup_path.'/upload/calendar/'; |
|
|
|
|
$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/calendar/'; |
|
|
|
|