|
|
@ -78,6 +78,7 @@ class CourseRestorer |
|
|
|
* |
|
|
|
* |
|
|
|
**/ |
|
|
|
**/ |
|
|
|
public $add_text_in_items = false; |
|
|
|
public $add_text_in_items = false; |
|
|
|
|
|
|
|
public $destination_course_id; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a new CourseRestorer |
|
|
|
* Create a new CourseRestorer |
|
|
@ -149,7 +150,9 @@ class CourseRestorer |
|
|
|
$this->destination_course_id = $course_info['real_id']; |
|
|
|
$this->destination_course_id = $course_info['real_id']; |
|
|
|
|
|
|
|
|
|
|
|
//Getting first teacher (for the forums) |
|
|
|
//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(); |
|
|
|
$this->first_teacher_id = api_get_user_id(); |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($teacher_list)) { |
|
|
|
if (!empty($teacher_list)) { |
|
|
@ -194,48 +197,70 @@ class CourseRestorer |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Restore the item properties |
|
|
|
// 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) { |
|
|
|
foreach ($this->course->resources as $type => $resources) { |
|
|
|
if (is_array($resources)) { |
|
|
|
if (is_array($resources)) { |
|
|
|
foreach ($resources as $id => $resource) { |
|
|
|
foreach ($resources as $id => $resource) { |
|
|
|
foreach ($resource->item_properties as $property) { |
|
|
|
if (isset($resource->item_properties)) { |
|
|
|
// First check if there isn't already a record for this resource |
|
|
|
foreach ($resource->item_properties as $property) { |
|
|
|
$sql = "SELECT * FROM $table |
|
|
|
// First check if there isn't already a record for this resource |
|
|
|
WHERE |
|
|
|
$sql = "SELECT * FROM $table |
|
|
|
c_id = ".$this->destination_course_id." AND |
|
|
|
WHERE |
|
|
|
tool = '".$property['tool']."' AND |
|
|
|
c_id = ".$this->destination_course_id." AND |
|
|
|
ref = '".$resource->destination_id."'"; |
|
|
|
tool = '".$property['tool']."' AND |
|
|
|
|
|
|
|
ref = '".$resource->destination_id."'"; |
|
|
|
$params = []; |
|
|
|
|
|
|
|
if (!empty($session_id)) { |
|
|
|
|
|
|
|
$params['session_id'] = intval($session_id); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$res = Database::query($sql); |
|
|
|
$params = []; |
|
|
|
if (Database::num_rows($res) == 0) { |
|
|
|
if (!empty($session_id)) { |
|
|
|
/* The to_group_id and to_user_id are set to default |
|
|
|
$params['session_id'] = intval($session_id); |
|
|
|
values as users/groups possibly not exist in |
|
|
|
} |
|
|
|
the target course*/ |
|
|
|
|
|
|
|
|
|
|
|
$res = Database::query($sql); |
|
|
|
$params['c_id'] = $this->destination_course_id; |
|
|
|
if (Database::num_rows($res) == 0) { |
|
|
|
$params['tool'] = self::DBUTF8($property['tool']); |
|
|
|
/* The to_group_id and to_user_id are set to default |
|
|
|
$params['insert_user_id'] = self::DBUTF8($property['insert_user_id']); |
|
|
|
values as users/groups possibly not exist in |
|
|
|
$params['insert_date'] = self::DBUTF8($property['insert_date']); |
|
|
|
the target course*/ |
|
|
|
$params['lastedit_date'] = self::DBUTF8($property['lastedit_date']); |
|
|
|
|
|
|
|
$params['ref'] = $resource->destination_id; |
|
|
|
$params['c_id'] = $this->destination_course_id; |
|
|
|
$params['lastedit_type'] = self::DBUTF8($property['lastedit_type']); |
|
|
|
$params['tool'] = self::DBUTF8( |
|
|
|
$params['lastedit_user_id'] = self::DBUTF8($property['lastedit_user_id']); |
|
|
|
$property['tool'] |
|
|
|
$params['visibility'] = self::DBUTF8($property['visibility']); |
|
|
|
); |
|
|
|
$params['start_visible'] = self::DBUTF8($property['start_visible']); |
|
|
|
$params['insert_user_id'] = self::DBUTF8( |
|
|
|
$params['end_visible'] = self::DBUTF8($property['end_visible']); |
|
|
|
$property['insert_user_id'] |
|
|
|
$params['to_user_id'] = self::DBUTF8($property['to_user_id']); |
|
|
|
); |
|
|
|
//$params['to_group_id'] = 'NULL'; |
|
|
|
$params['insert_date'] = self::DBUTF8( |
|
|
|
|
|
|
|
$property['insert_date'] |
|
|
|
$id = Database::insert($table, $params); |
|
|
|
); |
|
|
|
if ($id) { |
|
|
|
$params['lastedit_date'] = self::DBUTF8( |
|
|
|
$sql = "UPDATE $table SET id = iid WHERE iid = $id"; |
|
|
|
$property['lastedit_date'] |
|
|
|
Database::query($sql); |
|
|
|
); |
|
|
|
|
|
|
|
$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['to_group_id'] = 'NULL'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$id = Database::insert($table, $params); |
|
|
|
|
|
|
|
if ($id) { |
|
|
|
|
|
|
|
$sql = "UPDATE $table SET id = iid WHERE iid = $id"; |
|
|
|
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -868,7 +893,7 @@ class CourseRestorer |
|
|
|
|
|
|
|
|
|
|
|
$params = [ |
|
|
|
$params = [ |
|
|
|
'c_id' => $this->destination_course_id, |
|
|
|
'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), |
|
|
|
'comment'=> self::DBUTF8($document->comment), |
|
|
|
'title' => self::DBUTF8($document->title), |
|
|
|
'title' => self::DBUTF8($document->title), |
|
|
|
'filetype' => self::DBUTF8($document->file_type), |
|
|
|
'filetype' => self::DBUTF8($document->file_type), |
|
|
@ -1087,7 +1112,7 @@ class CourseRestorer |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if ($forum_cat && !$forum_cat->is_restored()) { |
|
|
|
if ($forum_cat && !$forum_cat->is_restored()) { |
|
|
|
$title = $forum_cat->obj->cat_title; |
|
|
|
/*$title = $forum_cat->obj->cat_title; |
|
|
|
if (!empty($title)) { |
|
|
|
if (!empty($title)) { |
|
|
|
if (!preg_match('/.*\((.+)\)$/', $title, $matches)) { |
|
|
|
if (!preg_match('/.*\((.+)\)$/', $title, $matches)) { |
|
|
|
// This is for avoiding repetitive adding of training code after several backup/restore cycles. |
|
|
|
// 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.')'; |
|
|
|
$title = $title.' ('.$this->course->code.')'; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}*/ |
|
|
|
$params = (array) $forum_cat->obj; |
|
|
|
$params = (array) $forum_cat->obj; |
|
|
|
$params['c_id'] = $this->destination_course_id; |
|
|
|
$params['c_id'] = $this->destination_course_id; |
|
|
|
$params['cat_comment'] = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
|
|
|
$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)) { |
|
|
|
if ($this->course->has_resources(RESOURCE_LINK)) { |
|
|
|
$link_table = Database :: get_course_table(TABLE_LINK); |
|
|
|
$link_table = Database :: get_course_table(TABLE_LINK); |
|
|
|
$resources = $this->course->resources; |
|
|
|
$resources = $this->course->resources; |
|
|
|
|
|
|
|
|
|
|
|
foreach ($resources[RESOURCE_LINK] as $id => $link) { |
|
|
|
foreach ($resources[RESOURCE_LINK] as $id => $link) { |
|
|
|
$cat_id = $this->restore_link_category($link->category_id, $session_id); |
|
|
|
$cat_id = $this->restore_link_category( |
|
|
|
$sql = "SELECT MAX(display_order) FROM $link_table |
|
|
|
$link->category_id, |
|
|
|
|
|
|
|
$session_id |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
$sql = "SELECT MAX(display_order) |
|
|
|
|
|
|
|
FROM $link_table |
|
|
|
WHERE |
|
|
|
WHERE |
|
|
|
c_id = ".$this->destination_course_id." AND |
|
|
|
c_id = ".$this->destination_course_id." AND |
|
|
|
category_id='" . intval($cat_id). "'"; |
|
|
|
category_id='" . intval($cat_id). "'"; |
|
|
@ -1264,9 +1294,21 @@ class CourseRestorer |
|
|
|
if ($id) { |
|
|
|
if ($id) { |
|
|
|
$sql = "UPDATE $link_table SET id = iid WHERE iid = $id"; |
|
|
|
$sql = "UPDATE $link_table SET id = iid WHERE iid = $id"; |
|
|
|
Database::query($sql); |
|
|
|
Database::query($sql); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->course->resources[RESOURCE_LINK][$id]->destination_id = $id; |
|
|
|
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) { |
|
|
|
if ($new_id) { |
|
|
|
$sql = "UPDATE $link_cat_table SET id = iid WHERE iid = $new_id"; |
|
|
|
$sql = "UPDATE $link_cat_table SET id = iid WHERE iid = $new_id"; |
|
|
|
Database::query($sql); |
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
api_set_default_visibility($new_id, TOOL_LINK_CATEGORY); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$this->course->resources[RESOURCE_LINKCATEGORY][$id]->destination_id = $new_id; |
|
|
|
$this->course->resources[RESOURCE_LINKCATEGORY][$id]->destination_id = $new_id; |
|
|
@ -1347,9 +1390,13 @@ class CourseRestorer |
|
|
|
if ($id) { |
|
|
|
if ($id) { |
|
|
|
$sql = "UPDATE $tool_intro_table SET id = iid WHERE iid = $id"; |
|
|
|
$sql = "UPDATE $tool_intro_table SET id = iid WHERE iid = $id"; |
|
|
|
Database::query($sql); |
|
|
|
Database::query($sql); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->course->resources[RESOURCE_TOOL_INTRO][$id]->destination_id = $id; |
|
|
|
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; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1387,11 +1434,15 @@ class CourseRestorer |
|
|
|
if ($new_event_id) { |
|
|
|
if ($new_event_id) { |
|
|
|
$sql = "UPDATE $table SET id = iid WHERE iid = $new_event_id"; |
|
|
|
$sql = "UPDATE $table SET id = iid WHERE iid = $new_event_id"; |
|
|
|
Database::query($sql); |
|
|
|
Database::query($sql); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->course->resources[RESOURCE_EVENT][$id]->destination_id = $new_event_id; |
|
|
|
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/'; |
|
|
|
$origin_path = $this->course->backup_path.'/upload/calendar/'; |
|
|
|
$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/calendar/'; |
|
|
|
$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/calendar/'; |
|
|
|