From eea5cfdfce71334f8ca7955bac9856ebed236f73 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 12 Oct 2020 09:41:47 +0200 Subject: [PATCH] Admin - Add duplicate_specific_session_content_on_session_copy WIP Add new action in session list to copy a session with its course-session content into another session BT#17832 --- main/inc/lib/api.lib.php | 51 ++-- main/inc/lib/course.lib.php | 20 +- main/inc/lib/document.lib.php | 2 +- main/inc/lib/sessionmanager.lib.php | 29 ++- main/install/configuration.dist.php | 3 + main/session/session_list.php | 31 ++- .../Component/CourseCopy/CourseRestorer.php | 220 ++++++++++++------ 7 files changed, 241 insertions(+), 115 deletions(-) diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php index f71206fda3..b1ed065243 100644 --- a/main/inc/lib/api.lib.php +++ b/main/inc/lib/api.lib.php @@ -5530,15 +5530,17 @@ function copyr($source, $dest, $exclude = [], $copied_files = []) } /** - * @todo: Using DIRECTORY_SEPARATOR is not recommended, this is an obsolete approach. - * Documentation header to be added here. - * * @param string $pathname * @param string $base_path_document * @param int $session_id + * @param array + * @param string * * @return mixed True if directory already exists, false if a file already exists at * the destination and null if everything goes according to plan + *@todo: Using DIRECTORY_SEPARATOR is not recommended, this is an obsolete approach. + * Documentation header to be added here. + * */ function copy_folder_course_session( $pathname, @@ -5546,14 +5548,12 @@ function copy_folder_course_session( $session_id, $course_info, $document, - $source_course_id + $source_course_id, + $originalFolderNameList = [], + $originalBaseName = '' ) { - $table = Database::get_course_table(TABLE_DOCUMENT); - $session_id = intval($session_id); - $source_course_id = intval($source_course_id); - // Check whether directory already exists. - if (is_dir($pathname) || empty($pathname)) { + if (empty($pathname) || is_dir($pathname)) { return true; } @@ -5564,18 +5564,29 @@ function copy_folder_course_session( return false; } + //error_log('checking:'); + //error_log(str_replace($base_path_document.DIRECTORY_SEPARATOR, '', $pathname)); + $baseNoDocument = str_replace('document', '', $originalBaseName); + $folderTitles = explode('/', $baseNoDocument); + $folderTitles = array_filter($folderTitles); + + //error_log($baseNoDocument);error_log(print_r($folderTitles, 1)); + + $table = Database::get_course_table(TABLE_DOCUMENT); + $session_id = (int) $session_id; + $source_course_id = (int) $source_course_id; $course_id = $course_info['real_id']; $folders = explode(DIRECTORY_SEPARATOR, str_replace($base_path_document.DIRECTORY_SEPARATOR, '', $pathname)); $new_pathname = $base_path_document; - $path = ''; - foreach ($folders as $folder) { + $path = ''; + foreach ($folders as $index => $folder) { $new_pathname .= DIRECTORY_SEPARATOR.$folder; $path .= DIRECTORY_SEPARATOR.$folder; if (!file_exists($new_pathname)) { $path = Database::escape_string($path); - + //error_log("path: $path"); $sql = "SELECT * FROM $table WHERE c_id = $source_course_id AND @@ -5587,17 +5598,29 @@ function copy_folder_course_session( if (0 == $num_rows) { mkdir($new_pathname, api_get_permissions_for_new_directories()); + $title = basename($new_pathname); + + if (isset($folderTitles[$index + 1])) { + $checkPath = $folderTitles[$index +1]; + //error_log("check $checkPath"); + if (isset($originalFolderNameList[$checkPath])) { + $title = $originalFolderNameList[$checkPath]; + //error_log('use this name: '.$title); + } + } // Insert new folder with destination session_id. $params = [ 'c_id' => $course_id, 'path' => $path, 'comment' => $document->comment, - 'title' => basename($new_pathname), + 'title' => $title, 'filetype' => 'folder', 'size' => '0', 'session_id' => $session_id, ]; + + //error_log("old $folder"); error_log("Add doc $title in $path"); $document_id = Database::insert($table, $params); if ($document_id) { $sql = "UPDATE $table SET id = iid WHERE iid = $document_id"; @@ -5618,7 +5641,7 @@ function copy_folder_course_session( } } } - } // en foreach + } } // TODO: chmodr() is a better name. Some corrections are needed. Documentation header to be added here. diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index 5b15aeac7c..9ec7603bc9 100755 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -4616,20 +4616,21 @@ class CourseManager $source_session_id, $destination_course_code, $destination_session_id, - $params = [] + $params = [], + $withBaseContent = true ) { $course_info = api_get_course_info($source_course_code); if (!empty($course_info)) { $cb = new CourseBuilder('', $course_info); - $course = $cb->build($source_session_id, $source_course_code, true); - $course_restorer = new CourseRestorer($course); - $course_restorer->skip_content = $params; - $course_restorer->restore( + $course = $cb->build($source_session_id, $source_course_code, $withBaseContent); + $restorer = new CourseRestorer($course); + $restorer->skip_content = $params; + $restorer->restore( $destination_course_code, $destination_session_id, true, - true + $withBaseContent ); return true; @@ -4646,6 +4647,7 @@ class CourseManager * @param int source session id * @param int destination session id * @param array $params + * @param bool $copySessionContent * * @return array */ @@ -4654,7 +4656,8 @@ class CourseManager $source_course_code, $source_session_id = 0, $destination_session_id = 0, - $params = [] + $params = [], + $copySessionContent = false ) { $source_course_info = api_get_course_info($source_course_code); if (!empty($source_course_info)) { @@ -4671,7 +4674,8 @@ class CourseManager $source_session_id, $new_course_info['code'], $destination_session_id, - $params + $params, + true ); if ($result) { return $new_course_info; diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php index b719827458..6ff6021672 100644 --- a/main/inc/lib/document.lib.php +++ b/main/inc/lib/document.lib.php @@ -2794,7 +2794,7 @@ class DocumentManager if ($type_url == 'abs' || $type_url == 'rel') { $document_file = strstr($real_orig_path, 'document'); - if (strpos($real_orig_path, $document_file) !== false) { + if ($document_file && strpos($real_orig_path, $document_file) !== false) { $origin_filepath = $orig_course_path.$document_file; $destination_filepath = $dest_course_path.$document_file; diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index 2c8bcfb418..81fe9cf0b6 100755 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -2576,10 +2576,7 @@ class SessionManager require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php'; } - $em = Database::getManager(); - - /** @var Session $session */ - $session = $em->find('ChamiloCoreBundle:Session', $sessionId); + $session = api_get_session_entity($sessionId); if (!$session) { return false; @@ -2779,7 +2776,7 @@ class SessionManager 'allow_text_assignment' => $work['allow_text_assignment'], ]; - $result = addDir( + addDir( $values, api_get_user_id(), $courseInfo, @@ -4511,6 +4508,7 @@ class SessionManager * @param bool $copyTeachersAndDrh * @param bool $create_new_courses New courses will be created * @param bool $set_exercises_lp_invisible Set exercises and LPs in the new session to invisible by default + * @param bool $copyWithSessionContent Copy course session content into the courses * * @return int The new session ID on success, 0 otherwise * @@ -4523,7 +4521,8 @@ class SessionManager $copy_courses = true, $copyTeachersAndDrh = true, $create_new_courses = false, - $set_exercises_lp_invisible = false + $set_exercises_lp_invisible = false, + $copyWithSessionContent = false ) { $id = (int) $id; $s = self::fetch($id); @@ -4574,7 +4573,6 @@ class SessionManager $extraFieldsValuesToCopy = []; if (!empty($extraFieldsValues)) { foreach ($extraFieldsValues as $extraFieldValue) { - //$extraFieldsValuesToCopy['extra_'.$extraFieldValue['variable']] = $extraFieldValue['value']; $extraFieldsValuesToCopy['extra_'.$extraFieldValue['variable']]['extra_'.$extraFieldValue['variable']] = $extraFieldValue['value']; } } @@ -4628,9 +4626,7 @@ class SessionManager foreach ($short_courses as $course_data) { $course_info = CourseManager::copy_course_simple( - $course_data['title'].' '.get_lang( - 'CopyLabelSuffix' - ), + $course_data['title'].' '.get_lang('CopyLabelSuffix'), $course_data['course_code'], $id, $sid, @@ -4677,6 +4673,19 @@ class SessionManager $short_courses = $new_short_courses; self::add_courses_to_session($sid, $short_courses, true); + if ($copyWithSessionContent) { + foreach ($courses as $course) { + CourseManager::copy_course( + $course['code'], + $id, + $course['code'], + $sid, + [], + false + ); + } + } + if ($create_new_courses === false && $copyTeachersAndDrh) { foreach ($short_courses as $courseItemId) { $coachList = self::getCoachesByCourseSession($id, $courseItemId); diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php index 11b6347548..afc575ee15 100755 --- a/main/install/configuration.dist.php +++ b/main/install/configuration.dist.php @@ -1638,6 +1638,9 @@ $_configuration['auth_password_links'] = [ // Shows a marker if the course was shared in other portals. //$_configuration['multiple_access_url_show_shared_course_marker'] = false; +// Add option to copy a session with its course-session content BT#17832 +//$_configuration['duplicate_specific_session_content_on_session_copy'] = false; + // KEEP THIS AT THE END // -------- Custom DB changes // Add user activation by confirmation email diff --git a/main/session/session_list.php b/main/session/session_list.php index d1ad8574b2..1a704df31b 100644 --- a/main/session/session_list.php +++ b/main/session/session_list.php @@ -18,6 +18,11 @@ $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null; $idChecked = isset($_REQUEST['idChecked']) ? $_REQUEST['idChecked'] : null; $idMultiple = isset($_REQUEST['id']) ? $_REQUEST['id'] : null; $listType = isset($_REQUEST['list_type']) ? Security::remove_XSS($_REQUEST['list_type']) : SessionManager::getDefaultSessionTab(); +$copySessionContent = isset($_REQUEST['copy_session_content']) ? true : false; +$addSessionContent = api_get_configuration_value('duplicate_specific_session_content_on_session_copy'); +if (false === $addSessionContent) { + $copySessionContent = false; +} switch ($action) { case 'delete_multiple': @@ -54,7 +59,14 @@ switch ($action) { exit(); break; case 'copy': - $result = SessionManager::copy($idChecked); + $result = SessionManager::copy( + $idChecked, + true, + true, + false, + false, + $copySessionContent + ); if ($result) { $sessionInfo = api_get_session_info($result); $url = Display::url( @@ -157,23 +169,22 @@ if (isset($_REQUEST['keyword'])) { $rule->data = Security::remove_XSS($_REQUEST['keyword']); $filter->rules[] = $rule; $filter->groupOp = 'OR'; - $filter = json_encode($filter); - $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&_force_search=true&rows=20&page=1&sidx=&sord=asc&filters='.$filter.'&searchField=s.name&searchString='.Security::remove_XSS($_REQUEST['keyword']).'&searchOper=in'; + $url = api_get_path(WEB_AJAX_PATH). + 'model.ajax.php?a=get_sessions&_force_search=true&rows=20&page=1&sidx=&sord=asc&filters='.$filter.'&searchField=s.name&searchString='.Security::remove_XSS($_REQUEST['keyword']).'&searchOper=in'; } if (isset($_REQUEST['id_category'])) { $sessionCategory = SessionManager::get_session_category($_REQUEST['id_category']); if (!empty($sessionCategory)) { - //Begin with see the searchOper param - $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&_force_search=true&rows=20&page=1&sidx=&sord=asc&filters=&searchField=sc.name&searchString='.Security::remove_XSS($sessionCategory['name']).'&searchOper=in'; + // Begin with see the searchOper param + $url = api_get_path(WEB_AJAX_PATH). + 'model.ajax.php?a=get_sessions&_force_search=true&rows=20&page=1&sidx=&sord=asc&filters=&searchField=sc.name&searchString='.Security::remove_XSS($sessionCategory['name']).'&searchOper=in'; } } $url .= '&list_type='.$listType; - $result = SessionManager::getGridColumns($listType); - $columns = $result['columns']; $column_model = $result['column_model']; $extra_params['autowidth'] = 'true'; @@ -196,6 +207,11 @@ if (!isset($_GET['keyword'])) { } $hideSearch = api_get_configuration_value('hide_search_form_in_session_list'); +$copySessionContentLink = ''; +if ($addSessionContent) { + $copySessionContentLink = ' '. + Display::return_icon('cd.png', get_lang('CopyWithSessionContent'), '', ICON_SIZE_SMALL).''; +} // With this function we can add actions to the jgrid (edit, delete, etc) $action_links = 'function action_formatter(cellvalue, options, rowObject) { @@ -207,6 +223,7 @@ $action_links = 'function action_formatter(cellvalue, options, rowObject) { Display::return_icon('courses_to_session.png', get_lang('SubscribeCoursesToSession'), '', ICON_SIZE_SMALL).''. ' '. Display::return_icon('copy.png', get_lang('Copy'), '', ICON_SIZE_SMALL).''. + $copySessionContentLink. ' '. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).''. '\'; diff --git a/src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php b/src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php index 874c19b0b8..f85642f5d6 100644 --- a/src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php +++ b/src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php @@ -151,7 +151,6 @@ class CourseRestorer $this->course->destination_path = $course_info['path']; } $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']); $this->first_teacher_id = api_get_user_id(); @@ -297,14 +296,19 @@ class CourseRestorer $table = Database::get_course_table(TABLE_DOCUMENT); $resources = $this->course->resources; $path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/'; - + $originalFolderNameList = []; foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) { - $my_session_id = empty($document->item_properties[0]['id_session']) ? 0 : $session_id; + $my_session_id = empty($document->item_properties[0]['session_id']) ? 0 : $session_id; + + if (false === $respect_base_content && $session_id) { + if (empty($my_session_id)) { + $my_session_id = $session_id; + } + } if ($document->file_type == FOLDER) { $visibility = isset($document->item_properties[0]['visibility']) ? $document->item_properties[0]['visibility'] : ''; $new = substr($document->path, 8); - $folderList = explode('/', $new); $tempFolder = ''; @@ -317,14 +321,16 @@ class CourseRestorer if (empty($folderToCreate)) { continue; } - $title = $document->title; + $originalFolderNameList[basename($document->path)] = $document->title; if (empty($title)) { $title = basename($sysFolderPath); } - + //error_log($title); error_log($sysFolderPath); // File doesn't exist in file system. if (!is_dir($sysFolderPath)) { + /*error_log('Creating directory'); + error_log("Creating $folderToCreate");*/ // Creating directory create_unexisting_directory( $course_info, @@ -344,37 +350,40 @@ class CourseRestorer $documentData = DocumentManager::get_document_id( $course_info, $folderToCreate, - $my_session_id + $session_id ); + //error_log("session_id $session_id"); if (empty($documentData)) { - /* This means the folder exists in the - filesystem but not in the DB, trying to fix it */ - add_document( - $course_info, - $folderToCreate, - 'folder', - 0, - $title, - null, - null, - false, - null, - $my_session_id, - 0, - false - ); + if (!is_dir($sysFolderPath)) { + //error_log('$documentData empty'); + //error_log('$folderToCreate '.$folderToCreate); + /* This means the folder exists in the + filesystem but not in the DB, trying to fix it */ + add_document( + $course_info, + $folderToCreate, + 'folder', + 0, + $title, + null, + null, + false, + null, + $session_id, + 0, + false + ); + } } else { $insertUserId = isset($document->item_properties[0]['insert_user_id']) ? $document->item_properties[0]['insert_user_id'] : api_get_user_id(); $insertUserId = $this->checkUserId($insertUserId); - // Check if user exists in platform $toUserId = isset($document->item_properties[0]['to_user_id']) ? $document->item_properties[0]['to_user_id'] : null; $toUserId = $this->checkUserId($toUserId, true); - $groupId = isset($document->item_properties[0]['to_group_id']) ? $document->item_properties[0]['to_group_id'] : null; $groupInfo = $this->checkGroupId($groupId); - + //error_log(" if folder exists then just refresh it"); // if folder exists then just refresh it api_item_property_update( $course_info, @@ -393,6 +402,7 @@ class CourseRestorer } elseif ($document->file_type == DOCUMENT) { // Checking if folder exists in the database otherwise we created it $dir_to_create = dirname($document->path); + $originalFolderNameList[basename($document->path)] = $document->title; if (!empty($dir_to_create) && $dir_to_create != 'document' && $dir_to_create != '/') { if (is_dir($path.dirname($document->path))) { $sql = "SELECT id FROM $table @@ -450,6 +460,7 @@ class CourseRestorer } } + //error_log(print_r($originalFolderNameList, 1)); if (file_exists($path.$document->path)) { switch ($this->file_option) { case FILE_OVERWRITE: @@ -600,6 +611,7 @@ class CourseRestorer $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id; break; case FILE_RENAME: + //error_log("Rename: ".$path.$document->path); $i = 1; $ext = explode('.', basename($document->path)); if (count($ext) > 1) { @@ -619,6 +631,8 @@ class CourseRestorer } if (!empty($session_id)) { + $originalPath = $document->path; + //error_log("document->path: ".$document->path); $document_path = explode('/', $document->path, 3); $course_path = $path; $orig_base_folder = $document_path[1]; @@ -628,7 +642,9 @@ class CourseRestorer $new_base_foldername = $orig_base_folder; $new_base_path = $orig_base_path; - if ($_SESSION['orig_base_foldername'] != $new_base_foldername) { + if (isset($_SESSION['orig_base_foldername']) && + $_SESSION['orig_base_foldername'] != $new_base_foldername + ) { unset($_SESSION['new_base_foldername']); unset($_SESSION['orig_base_foldername']); unset($_SESSION['new_base_path']); @@ -638,12 +654,14 @@ class CourseRestorer if ($folder_exists) { // e.g: carpeta1 in session $_SESSION['orig_base_foldername'] = $new_base_foldername; - $x = ''; + $x = 0; while ($folder_exists) { $x = $x + 1; $new_base_foldername = $document_path[1].'_'.$x; $new_base_path = $orig_base_path.'_'.$x; - if ($_SESSION['new_base_foldername'] == $new_base_foldername) { + if (isset($_SESSION['new_base_foldername']) && + $_SESSION['new_base_foldername'] == $new_base_foldername + ) { break; } $folder_exists = file_exists($new_base_path); @@ -662,13 +680,20 @@ class CourseRestorer $base_path_document = $course_path.$document_path[0]; // e.g: "/var/www/wiener/courses/CURSO4/document" $path_title = '/'.$new_base_foldername.'/'.$document_path[2]; + /*error_log("copy_folder_course_session"); + error_log("original: $orig_base_path"); + error_log($basedir_dest_path); + error_log($document->title);*/ + copy_folder_course_session( $basedir_dest_path, $base_path_document, $session_id, $course_info, $document, - $this->course_origin_id + $this->course_origin_id, + $originalFolderNameList, + $originalPath ); if (file_exists($course_path.$document->path)) { @@ -695,11 +720,16 @@ class CourseRestorer } } + $title = basename($path_title); + if (isset($originalFolderNameList[basename($path_title)])) { + $title = $originalFolderNameList[basename($path_title)]; + } + $params = [ 'path' => self::DBUTF8($path_title), 'c_id' => $this->destination_course_id, 'comment' => self::DBUTF8($document->comment), - 'title' => self::DBUTF8(basename($path_title)), + 'title' => self::DBUTF8($title), 'filetype' => self::DBUTF8($document->file_type), 'size' => self::DBUTF8($document->size), 'session_id' => $my_session_id, @@ -1086,10 +1116,7 @@ class CourseRestorer if (isset($this->course->resources[RESOURCE_FORUMCATEGORY]) && isset($this->course->resources[RESOURCE_FORUMCATEGORY][$params['forum_category']])) { if ($this->course->resources[RESOURCE_FORUMCATEGORY][$params['forum_category']]->destination_id == -1) { - $cat_id = $this->restore_forum_category( - $params['forum_category'], - $sessionId - ); + $cat_id = $this->restore_forum_category($params['forum_category'], $sessionId); } else { $cat_id = $this->course->resources[RESOURCE_FORUMCATEGORY][$params['forum_category']]->destination_id; } @@ -1132,11 +1159,15 @@ class CourseRestorer TOOL_FORUM, $new_id, 'ForumUpdated', - api_get_user_id() + api_get_user_id(), + null, + null, + null, + null, + $sessionId ); $this->course->resources[RESOURCE_FORUM][$id]->destination_id = $new_id; - $forum_topics = 0; if (isset($this->course->resources[RESOURCE_FORUMTOPIC]) && is_array($this->course->resources[RESOURCE_FORUMTOPIC]) @@ -1165,6 +1196,7 @@ class CourseRestorer { $forum_cat_table = Database::get_course_table(TABLE_FORUM_CATEGORY); $resources = $this->course->resources; + $sessionId = (int) $sessionId; if (!empty($resources[RESOURCE_FORUMCATEGORY])) { foreach ($resources[RESOURCE_FORUMCATEGORY] as $id => $forum_cat) { if (!empty($my_id)) { @@ -1182,7 +1214,7 @@ class CourseRestorer $this->course->backup_path, $this->course->info['path'] ); - $params['session_id'] = intval($sessionId); + $params['session_id'] = $sessionId; $params['cat_id'] = 0; unset($params['iid']); @@ -1198,7 +1230,12 @@ class CourseRestorer TOOL_FORUM_CATEGORY, $new_id, 'ForumCategoryUpdated', - api_get_user_id() + api_get_user_id(), + null, + null, + null, + null, + $sessionId ); $this->course->resources[RESOURCE_FORUMCATEGORY][$id]->destination_id = $new_id; } @@ -1223,7 +1260,9 @@ class CourseRestorer $table = Database::get_course_table(TABLE_FORUM_THREAD); $topic = $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]; + $sessionId = (int) $sessionId; $params = (array) $topic->obj; + $params = self::DBUTF8_array($params); $params['c_id'] = $this->destination_course_id; $params['forum_id'] = $forum_id; @@ -1233,7 +1272,7 @@ class CourseRestorer $params['thread_last_post'] = 0; $params['thread_replies'] = 0; $params['thread_views'] = 0; - $params['session_id'] = intval($sessionId); + $params['session_id'] = $sessionId; $params['thread_id'] = 0; unset($params['iid']); @@ -1334,15 +1373,12 @@ class CourseRestorer $resources = $this->course->resources; foreach ($resources[RESOURCE_LINK] as $oldLinkId => $link) { - $cat_id = $this->restore_link_category( - $link->category_id, - $session_id - ); + $cat_id = (int) $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)."'"; + category_id='".$cat_id."'"; $result = Database::query($sql); list($max_order) = Database::fetch_array($result); @@ -1371,7 +1407,12 @@ class CourseRestorer TOOL_LINK, $id, 'LinkAdded', - api_get_user_id() + api_get_user_id(), + null, + null, + null, + null, + $session_id ); if (!isset($this->course->resources[RESOURCE_LINK][$oldLinkId])) { @@ -1391,11 +1432,12 @@ class CourseRestorer * * @return bool */ - public function restore_link_category($id, $session_id = 0) + public function restore_link_category($id, $sessionId = 0) { $params = []; - if (!empty($session_id)) { - $params['session_id'] = $session_id; + $sessionId = (int) $sessionId; + if (!empty($sessionId)) { + $params['session_id'] = $sessionId; } if ($id == 0) { @@ -1429,13 +1471,19 @@ class CourseRestorer TOOL_LINK_CATEGORY, $new_id, 'LinkCategoryAdded', - api_get_user_id() + api_get_user_id(), + null, + null, + null, + null, + $sessionId ); api_set_default_visibility( $new_id, TOOL_LINK_CATEGORY, 0, - $courseInfo + $courseInfo, + $sessionId ); } @@ -2604,8 +2652,6 @@ class CourseRestorer /** * @param int $sessionId * @param bool $baseContent - * - * @throws \Doctrine\ORM\OptimisticLockException */ public function restore_learnpath_category($sessionId = 0, $baseContent = false) { @@ -2628,8 +2674,6 @@ class CourseRestorer $lpCategory = $item->object; if ($lpCategory) { - $categoryId = 0; - $existingLpCategory = Database::select( 'iid', $tblLpCategory, @@ -2675,7 +2719,8 @@ class CourseRestorer $resources = $this->course->resources; $origin_path = $this->course->backup_path.'/upload/learning_path/images/'; - $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/learning_path/images/'; + $destination_path = api_get_path(SYS_COURSE_PATH). + $this->course->destination_path.'/upload/learning_path/images/'; // Choose default visibility $toolVisibility = api_get_setting('tool_visible_by_default_at_creation'); @@ -2865,7 +2910,7 @@ class CourseRestorer // Dealing with path the same way as ref as some data has // been put into path when it's a local resource // Only fix the path for no scos - if ($item['item_type'] == 'sco') { + if ($item['item_type'] === 'sco') { $path = $item['path']; } else { $path = $this->get_new_id($item['item_type'], $item['path']); @@ -3085,16 +3130,16 @@ class CourseRestorer /** * Restore glossary. */ - public function restore_glossary($session_id = 0) + public function restore_glossary($sessionId = 0) { + $sessionId = (int) $sessionId; if ($this->course->has_resources(RESOURCE_GLOSSARY)) { $table_glossary = Database::get_course_table(TABLE_GLOSSARY); $resources = $this->course->resources; foreach ($resources[RESOURCE_GLOSSARY] as $id => $glossary) { $params = []; - if (!empty($session_id)) { - $session_id = (int) $session_id; - $params['session_id'] = $session_id; + if (!empty($sessionId)) { + $params['session_id'] = $sessionId; } // check resources inside html from ckeditor tool and copy correct urls into recipient course @@ -3121,7 +3166,12 @@ class CourseRestorer TOOL_GLOSSARY, $my_id, 'GlossaryAdded', - api_get_user_id() + api_get_user_id(), + null, + null, + null, + null, + $sessionId ); if (!isset($this->course->resources[RESOURCE_GLOSSARY][$id])) { @@ -3135,9 +3185,9 @@ class CourseRestorer } /** - * @param int $session_id + * @param int $sessionId */ - public function restore_wiki($session_id = 0) + public function restore_wiki($sessionId = 0) { if ($this->course->has_resources(RESOURCE_WIKI)) { // wiki table of the target course @@ -3169,7 +3219,7 @@ class CourseRestorer 'dtime' => self::DBUTF8($wiki->dtime), 'progress' => self::DBUTF8($wiki->progress), 'version' => intval($wiki->version), - 'session_id' => !empty($session_id) ? intval($session_id) : 0, + 'session_id' => !empty($sessionId) ? intval($sessionId) : 0, 'addlock' => 0, 'editlock' => 0, 'visibility' => 0, @@ -3221,9 +3271,9 @@ class CourseRestorer /** * Restore Thematics. * - * @param int $session_id + * @param int $sessionId */ - public function restore_thematic($session_id = 0) + public function restore_thematic($sessionId = 0) { if ($this->course->has_resources(RESOURCE_THEMATIC)) { $table_thematic = Database::get_course_table(TABLE_THEMATIC); @@ -3254,8 +3304,13 @@ class CourseRestorer $this->destination_course_info, 'thematic', $last_id, - "ThematicAdded", - api_get_user_id() + 'ThematicAdded', + api_get_user_id(), + null, + null, + null, + null, + $sessionId ); foreach ($thematic->thematic_advance_list as $thematic_advance) { @@ -3280,7 +3335,12 @@ class CourseRestorer 'thematic_advance', $my_id, 'ThematicAdvanceAdded', - api_get_user_id() + api_get_user_id(), + null, + null, + null, + null, + $sessionId ); } } @@ -3301,7 +3361,12 @@ class CourseRestorer 'thematic_plan', $my_id, 'ThematicPlanAdded', - api_get_user_id() + api_get_user_id(), + null, + null, + null, + null, + $sessionId ); } } @@ -3313,9 +3378,9 @@ class CourseRestorer /** * Restore Attendance. * - * @param int $session_id + * @param int $sessionId */ - public function restore_attendance($session_id = 0) + public function restore_attendance($sessionId = 0) { if ($this->course->has_resources(RESOURCE_ATTENDANCE)) { $table_attendance = Database::get_course_table(TABLE_ATTENDANCE); @@ -3347,8 +3412,13 @@ class CourseRestorer $this->destination_course_info, TOOL_ATTENDANCE, $last_id, - "AttendanceAdded", - api_get_user_id() + 'AttendanceAdded', + api_get_user_id(), + null, + null, + null, + null, + $sessionId ); foreach ($obj->attendance_calendar as $attendance_calendar) {