Fixing PHP warnings.

1.10.x
Julio Montoya 9 years ago
parent 00372ccfac
commit a17d52df4a
  1. 31
      main/coursecopy/classes/CourseRecycler.class.php
  2. 155
      main/coursecopy/classes/CourseRestorer.class.php

@ -46,9 +46,9 @@ class CourseRecycler
$this->type = $type; $this->type = $type;
$table_tool_intro = Database::get_course_table(TABLE_TOOL_INTRO); $table_tool_intro = Database::get_course_table(TABLE_TOOL_INTRO);
$table_linked_resources = Database::get_course_table(TABLE_LINKED_RESOURCES); $table_linked_resources = Database::get_course_table(TABLE_LINKED_RESOURCES);
$table_item_properties = Database::get_course_table(TABLE_ITEM_PROPERTY); $table_item_properties = Database::get_course_table(TABLE_ITEM_PROPERTY);
$this->recycle_links(); $this->recycle_links();
$this->recycle_link_categories(); $this->recycle_link_categories();
@ -117,7 +117,8 @@ class CourseRecycler
} }
$ids = implode(',', (array_keys($this->course->resources[RESOURCE_DOCUMENT]))); $ids = implode(',', (array_keys($this->course->resources[RESOURCE_DOCUMENT])));
$sql = "DELETE FROM $table WHERE c_id = ".$this->course_id." AND id IN(".$ids.")"; $sql = "DELETE FROM $table
WHERE c_id = ".$this->course_id." AND id IN(".$ids.")";
Database::query($sql); Database::query($sql);
} }
} }
@ -129,8 +130,8 @@ class CourseRecycler
public function recycle_wiki() public function recycle_wiki()
{ {
if ($this->course->has_resources(RESOURCE_WIKI)) { if ($this->course->has_resources(RESOURCE_WIKI)) {
$table_wiki = Database::get_course_table(TABLE_WIKI); $table_wiki = Database::get_course_table(TABLE_WIKI);
$table_wiki_conf = Database::get_course_table(TABLE_WIKI_CONF); $table_wiki_conf = Database::get_course_table(TABLE_WIKI_CONF);
$pages = array(); $pages = array();
foreach ($this->course->resources[RESOURCE_WIKI] as $resource) { foreach ($this->course->resources[RESOURCE_WIKI] as $resource) {
$pages[] = $resource->page_id; $pages[] = $resource->page_id;
@ -138,9 +139,11 @@ class CourseRecycler
$wiki_ids = implode(',', (array_keys($this->course->resources[RESOURCE_WIKI]))); $wiki_ids = implode(',', (array_keys($this->course->resources[RESOURCE_WIKI])));
$page_ids = implode(',', $pages); $page_ids = implode(',', $pages);
$sql = "DELETE FROM ".$table_wiki." WHERE c_id = ".$this->course_id." AND id IN(".$wiki_ids.")"; $sql = "DELETE FROM ".$table_wiki."
WHERE c_id = ".$this->course_id." AND id IN(".$wiki_ids.")";
Database::query($sql); Database::query($sql);
$sql = "DELETE FROM ".$table_wiki_conf." WHERE c_id = ".$this->course_id." AND page_id IN(".$page_ids.")"; $sql = "DELETE FROM ".$table_wiki_conf."
WHERE c_id = ".$this->course_id." AND page_id IN(".$page_ids.")";
Database::query($sql); Database::query($sql);
} }
} }
@ -279,7 +282,6 @@ class CourseRecycler
WHERE c_id = ".$this->course_id." AND forum_id IN(".$forum_ids.")"; WHERE c_id = ".$this->course_id." AND forum_id IN(".$forum_ids.")";
Database::query($sql); Database::query($sql);
} }
} }
/** /**
@ -374,10 +376,11 @@ class CourseRecycler
public function recycle_quizzes() public function recycle_quizzes()
{ {
if ($this->course->has_resources(RESOURCE_QUIZ)) { if ($this->course->has_resources(RESOURCE_QUIZ)) {
$table_qui_que = Database :: get_course_table(TABLE_QUIZ_QUESTION); $table_qui_que = Database :: get_course_table(TABLE_QUIZ_QUESTION);
$table_qui_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER); $table_qui_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
$table_qui = Database :: get_course_table(TABLE_QUIZ_TEST); $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
$table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION); $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
$table_qui_que_opt = Database :: get_course_table(TABLE_QUIZ_QUESTION_OPTION); $table_qui_que_opt = Database :: get_course_table(TABLE_QUIZ_QUESTION_OPTION);
$table_qui_que_cat = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); $table_qui_que_cat = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$table_qui_que_rel_cat = Database :: get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); $table_qui_que_rel_cat = Database :: get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
@ -617,7 +620,13 @@ class CourseRecycler
} }
$cond = array('id = ? AND c_id = ?'=>array($last_id, $this->course_id)); $cond = array('id = ? AND c_id = ?'=>array($last_id, $this->course_id));
Database::delete($table_attendance, $cond); Database::delete($table_attendance, $cond);
api_item_property_update($this->course_info, TOOL_ATTENDANCE, $last_id,'AttendanceDeleted', api_get_user_id()); api_item_property_update(
$this->course_info,
TOOL_ATTENDANCE,
$last_id,
'AttendanceDeleted',
api_get_user_id()
);
} }
} }
} }

@ -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/';

Loading…
Cancel
Save