📄 courserestorer.class.php
字号:
if (file_exists($path.$document->path)) { switch ($this->file_option) { case FILE_OVERWRITE : rmdirr($path.$document->path); copyDirTo($this->course->backup_path.'/'.$document->path, $path.dirname($document->path), false); break; case FILE_SKIP : break; case FILE_RENAME : $i = 1; $ext = explode('.', basename($document->path)); if (count($ext) > 1) { $ext = array_pop($ext); $file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1)); $ext = '.'.$ext; } else { $ext = ''; $file_name_no_ext = $document->path; } $new_file_name = $file_name_no_ext.'_'.$i.$ext; $file_exists = file_exists($path.$new_file_name); while ($file_exists) { $i ++; $new_file_name = $file_name_no_ext.'_'.$i.$ext; $file_exists = file_exists($path.$new_file_name); } rename($this->course->backup_path.'/'.$document->path,$this->course->backup_path.'/'.$new_file_name); copyDirTo($this->course->backup_path.'/'.$new_file_name, $path.dirname($new_file_name), false); rename($this->course->backup_path.'/'.$new_file_name,$this->course->backup_path.'/'.$document->path); break; } // end switch } // end if file exists else { copyDirTo($this->course->backup_path.'/'.$document->path, $path.dirname($document->path), false); } } // end for each } } /** * Restore forums */ function restore_forums() { if ($this->course->has_resources(RESOURCE_FORUM)) { $table_forum = Database :: get_course_table(TABLE_FORUM, $this->course->destination_db); $table_topic = Database :: get_course_table(TABLE_FORUM_POST, $this->course->destination_db); $table_post = Database :: get_course_table(TABLE_FORUM_POST, $this->course->destination_db); $resources = $this->course->resources; foreach ($resources[RESOURCE_FORUM] as $id => $forum) { $cat_id = $this->restore_forum_category($forum->category_id); $sql = "INSERT INTO ".$table_forum." SET forum_name = '".Database::escape_string($forum->title)."', forum_desc = '".Database::escape_string($forum->description)."', cat_id = '".$cat_id."', forum_access='2'"; api_sql_query($sql, __FILE__, __LINE__); $new_id = Database::get_last_insert_id(); $this->course->resources[RESOURCE_FORUM][$id]->destination_id = $new_id; $forum_topics = 0; if (is_array($this->course->resources[RESOURCE_FORUMTOPIC])) { foreach ($this->course->resources[RESOURCE_FORUMTOPIC] as $topic_id => $topic) { if ($topic->forum_id == $id) { $this->restore_topic($topic_id, $new_id); $forum_topics ++; } } } if ($forum_topics > 0) { $last_post = $this->course->resources[RESOURCE_FORUMPOST][$forum->last_post]; $sql = "UPDATE ".$table_forum." SET forum_topics = ".$forum_topics.", forum_last_post_id = ".$last_post->destination_id." WHERE forum_id = '".$new_id."' "; api_sql_query($sql, __FILE__, __LINE__); } } } } /** * Restore forum-categories */ function restore_forum_category($id) { $forum_cat_table = Database :: get_course_table(TABLE_FORUM_CATEGORY, $this->course->destination_db); $resources = $this->course->resources; $forum_cat = $resources[RESOURCE_FORUMCATEGORY][$id]; if (!$forum_cat->is_restored()) { $sql = "INSERT INTO ".$forum_cat_table." SET cat_title = '".Database::escape_string($forum_cat->title.' ('.$this->course->code.')')."'"; api_sql_query($sql, __FILE__, __LINE__); $new_id = Database::get_last_insert_id(); $this->course->resources[RESOURCE_FORUMCATEGORY][$id]->destination_id = $new_id; return $new_id; } return $this->course->resources[RESOURCE_FORUMCATEGORY][$id]->destination_id; } /** * Restore a forum-topic */ function restore_topic($id, $forum_id) { $table = Database :: get_course_table(TABLE_FORUM_POST, $this->course->destination_db); $resources = $this->course->resources; $topic = $resources[RESOURCE_FORUMTOPIC][$id]; $sql = "INSERT INTO ".$table." SET topic_title = '".Database::escape_string($topic->title)."', topic_time = '".$topic->time."', nom = '".Database::escape_string($topic->lastname)."', prenom = '".Database::escape_string($topic->firstname)."', topic_notify = '".$topic->topic_notify."', forum_id = '".$forum_id."'"; api_sql_query($sql, __FILE__, __LINE__); $new_id = Database::get_last_insert_id(); $this->course->resources[RESOURCE_FORUMTOPIC][$id]->destination_id = $new_id; $topic_replies = -1; foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post) { if ($post->topic_id == $id) { $topic_replies ++; $this->restore_post($post_id, $new_id, $forum_id); } } if ($topic_replies >= 0) { $last_post = $this->course->resources[RESOURCE_FORUMPOST][$topic->last_post]; $sql = "UPDATE ".$table." SET topic_replies = '".$topic_replies."', topic_last_post_id = ".$last_post->destination_id; api_sql_query($sql, __FILE__, __LINE__); } return $new_id; } /** * restore a forum-post * @todo restore tree-structure of posts. */ function restore_post($id, $topic_id, $forum_id) { $table_post = Database :: get_course_table(TABLE_FORUM_POST, $this->course->destination_db); $table_posttext = Database :: get_course_table(TOOL_FORUM_POST_TEXT_TABLE, $this->course->destination_db); $resources = $this->course->resources; $post = $resources[RESOURCE_FORUMPOST][$id]; $sql = "INSERT INTO ".$table_post." SET topic_id = '".$topic_id."', post_time = '".$post->post_time."', forum_id = '".$forum_id."', nom = '".Database::escape_string($post->lastname)."', prenom = '".Database::escape_string($post->firstname)."', topic_notify = '".$post->topic_notify."', poster_ip = '".$post->poster_ip."'"; api_sql_query($sql, __FILE__, __LINE__); $new_id = Database::get_last_insert_id(); $this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id; $sql = "INSERT INTO ".$table_posttext." SET post_text = '".Database::escape_string($post->text)."', post_title = '".Database::escape_string($post->title)."', post_id = '".$new_id."'"; api_sql_query($sql, __FILE__, __LINE__); return $new_id; } /** * Restore links */ function restore_links() { if ($this->course->has_resources(RESOURCE_LINK)) { $link_table = Database :: get_course_table(TABLE_LINK, $this->course->destination_db); $resources = $this->course->resources; foreach ($resources[RESOURCE_LINK] as $id => $link) { $cat_id = $this->restore_link_category($link->category_id); $sql = "SELECT MAX(display_order) FROM $link_table WHERE category_id='" . Database::escape_string($cat_id). "'"; $result = api_sql_query($sql, __FILE__, __LINE__); list($max_order) = Database::fetch_array($result); $sql = "INSERT INTO ".$link_table." SET url = '".Database::escape_string($link->url)."', title = '".Database::escape_string($link->title)."', description = '".Database::escape_string($link->description)."', category_id='".$cat_id."', on_homepage = '".$link->on_homepage."', display_order='".($max_order+1)."'"; api_sql_query($sql, __FILE__, __LINE__); $this->course->resources[RESOURCE_LINK][$id]->destination_id = Database::get_last_insert_id(); } } } /** * Restore tool intro */ function restore_tool_intro() { if ($this->course->has_resources(RESOURCE_TOOL_INTRO)) { $tool_intro_table = Database :: get_course_table(TABLE_TOOL_INTRO, $this->course->destination_db); $resources = $this->course->resources; foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) { $sql = "DELETE FROM ".$tool_intro_table." WHERE id='".Database::escape_string($tool_intro->id)."'"; api_sql_query($sql, __FILE__, __LINE__); $sql = "INSERT INTO ".$tool_intro_table." SET id='".Database::escape_string($tool_intro->id)."', intro_text = '".Database::escape_string($tool_intro->intro_text)."'"; api_sql_query($sql, __FILE__, __LINE__); $this->course->resources[RESOURCE_TOOL_INTRO][$id]->destination_id = Database::get_last_insert_id(); } } } /** * Restore a link-category */ function restore_link_category($id) { if ($id == 0) return 0; $link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY, $this->course->destination_db); $resources = $this->course->resources; $link_cat = $resources[RESOURCE_LINKCATEGORY][$id]; if (is_object($link_cat) && !$link_cat->is_restored()) { $sql = "SELECT MAX(display_order) FROM $link_cat_table"; $result=api_sql_query($sql,__FILE__,__LINE__); list($orderMax)=Database::fetch_array($result,'NUM'); $display_order=$orderMax+1; $sql = "INSERT INTO ".$link_cat_table." SET category_title = '".Database::escape_string($link_cat->title)."', description='".Database::escape_string($link_cat->description)."', display_order='".$display_order."' "; api_sql_query($sql, __FILE__, __LINE__); $new_id = Database::get_last_insert_id(); $this->course->resources[RESOURCE_LINKCATEGORY][$id]->destination_id = $new_id; return $new_id; } return $this->course->resources[RESOURCE_LINKCATEGORY][$id]->destination_id; } /** * Restore events */ function restore_events() { if ($this->course->has_resources(RESOURCE_EVENT)) { $table = Database :: get_course_table(TABLE_AGENDA, $this->course->destination_db); $resources = $this->course->resources; foreach ($resources[RESOURCE_EVENT] as $id => $event) { $sql = "INSERT INTO ".$table." SET title = '".Database::escape_string($event->title)."', content = '".Database::escape_string($event->content)."', start_date = '".$event->start_date."', end_date = '".$event->end_date."'"; api_sql_query($sql, __FILE__, __LINE__); $this->course->resources[RESOURCE_EVENT][$id]->destination_id = Database::get_last_insert_id(); } } } /** * Restore course-description */ function restore_course_descriptions() { if ($this->course->has_resources(RESOURCE_COURSEDESCRIPTION)) { $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION, $this->course->destination_db); $resources = $this->course->resources; foreach ($resources[RESOURCE_COURSEDESCRIPTION] as $id => $cd) { $sql = "INSERT INTO ".$table." SET title = '".Database::escape_string($cd->title)."', content = '".Database::escape_string($cd->content)."'"; api_sql_query($sql, __FILE__, __LINE__); $this->course->resources[RESOURCE_COURSEDESCRIPTION][$id]->destination_id = Database::get_last_insert_id(); } } } /** * Restore announcements */ function restore_announcements() { if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) { $table = Database :: get_course_table(TABLE_ANNOUNCEMENT, $this->course->destination_db); $resources = $this->course->resources; foreach ($resources[RESOURCE_ANNOUNCEMENT] as $id => $announcement) { $sql = "INSERT INTO ".$table." " . "SET title = '".Database::escape_string($announcement->title)."'," . "content = '".Database::escape_string($announcement->content)."', " . "end_date = '".$announcement->date."', " . "display_order = '".$announcement->display_order."', " . "email_sent = '".$announcement->email_sent."'"; api_sql_query($sql, __FILE__, __LINE__); $this->course->resources[RESOURCE_ANNOUNCEMENT][$id]->destination_id = Database::get_last_insert_id(); } } } /** * Restore Quiz */ function restore_quizzes() { if ($this->course->has_resources(RESOURCE_QUIZ)) { $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST, $this->course->destination_db); $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION, $this->course->destination_db); $table_doc = Database :: get_course_table(TABLE_DOCUMENT, $this->course->destination_db); $resources = $this->course->resources; foreach ($resources[RESOURCE_QUIZ] as $id => $quiz) { $doc = '';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -