@@ -894,7 +894,7 @@ public function restore_forums($sessionId = 0)
894
894
foreach ($ resources [RESOURCE_FORUM ] as $ id => $ forum ) {
895
895
$ params = (array )$ forum ->obj ;
896
896
if ($ this ->course ->resources [RESOURCE_FORUMCATEGORY ][$ params ['forum_category ' ]]->destination_id == -1 ) {
897
- $ cat_id = $ this ->restore_forum_category ($ params ['forum_category ' ]);
897
+ $ cat_id = $ this ->restore_forum_category ($ params ['forum_category ' ], $ sessionId );
898
898
} else {
899
899
$ cat_id = $ this ->course ->resources [RESOURCE_FORUMCATEGORY ][$ params ['forum_category ' ]]->destination_id ;
900
900
}
@@ -929,7 +929,7 @@ public function restore_forums($sessionId = 0)
929
929
if (is_array ($ this ->course ->resources [RESOURCE_FORUMTOPIC ])) {
930
930
foreach ($ this ->course ->resources [RESOURCE_FORUMTOPIC ] as $ topic_id => $ topic ) {
931
931
if ($ topic ->obj ->forum_id == $ id ) {
932
- $ this ->restore_topic ($ topic_id , $ new_id );
932
+ $ this ->restore_topic ($ topic_id , $ new_id, $ sessionId );
933
933
$ forum_topics ++;
934
934
}
935
935
}
@@ -946,7 +946,7 @@ public function restore_forums($sessionId = 0)
946
946
/**
947
947
* Restore forum-categories
948
948
*/
949
- public function restore_forum_category ($ my_id = null )
949
+ public function restore_forum_category ($ my_id = null , $ sessionId = 0 )
950
950
{
951
951
$ forum_cat_table = Database :: get_course_table (TABLE_FORUM_CATEGORY );
952
952
$ resources = $ this ->course ->resources ;
@@ -969,7 +969,14 @@ public function restore_forum_category($my_id = null)
969
969
}
970
970
$ params = (array ) $ forum_cat ->obj ;
971
971
$ params ['c_id ' ] = $ this ->destination_course_id ;
972
- $ params ['cat_comment ' ] = DocumentManager::replace_urls_inside_content_html_from_copy_course ($ params ['cat_comment ' ], $ this ->course ->code , $ this ->course ->destination_path , $ this ->course ->backup_path , $ this ->course ->info ['path ' ]);
972
+ $ params ['cat_comment ' ] = DocumentManager::replace_urls_inside_content_html_from_copy_course (
973
+ $ params ['cat_comment ' ],
974
+ $ this ->course ->code ,
975
+ $ this ->course ->destination_path ,
976
+ $ this ->course ->backup_path ,
977
+ $ this ->course ->info ['path ' ]
978
+ );
979
+ $ params ['session_id ' ] = intval ($ sessionId );
973
980
unset($ params ['cat_id ' ]);
974
981
$ params = self ::DBUTF8_array ($ params );
975
982
$ new_id = Database::insert ($ forum_cat_table , $ params );
@@ -985,34 +992,46 @@ public function restore_forum_category($my_id = null)
985
992
/**
986
993
* Restore a forum-topic
987
994
*/
988
- public function restore_topic ($ thread_id , $ forum_id )
995
+ public function restore_topic ($ thread_id , $ forum_id, $ sessionId = 0 )
989
996
{
990
997
$ table = Database :: get_course_table (TABLE_FORUM_THREAD );
991
998
$ topic = $ this ->course ->resources [RESOURCE_FORUMTOPIC ][$ thread_id ];
992
999
993
1000
$ params = (array )$ topic ->obj ;
994
1001
$ params = self ::DBUTF8_array ($ params );
995
- $ params ['c_id ' ] = $ this ->destination_course_id ;
1002
+ $ params ['c_id ' ] = $ this ->destination_course_id ;
996
1003
$ params ['forum_id ' ] = $ forum_id ;
997
1004
$ params ['thread_poster_id ' ] = $ this ->first_teacher_id ;
998
1005
$ params ['thread_date ' ] = api_get_utc_datetime ();
999
1006
$ params ['thread_close_date ' ] = '0000-00-00 00:00:00 ' ;
1000
1007
$ params ['thread_last_post ' ] = 0 ;
1001
1008
$ params ['thread_replies ' ] = 0 ;
1002
1009
$ params ['thread_views ' ] = 0 ;
1010
+ $ params ['session_id ' ] = intval ($ sessionId );
1003
1011
unset($ params ['thread_id ' ]);
1004
1012
1005
1013
$ new_id = Database::insert ($ table , $ params );
1006
- api_item_property_update ($ this ->destination_course_info , TOOL_FORUM_THREAD , $ new_id , 'ThreadAdded ' , api_get_user_id (), 0 , 0 , null , null );
1014
+ api_item_property_update (
1015
+ $ this ->destination_course_info ,
1016
+ TOOL_FORUM_THREAD ,
1017
+ $ new_id ,
1018
+ 'ThreadAdded ' ,
1019
+ api_get_user_id (),
1020
+ 0 ,
1021
+ 0 ,
1022
+ null ,
1023
+ null ,
1024
+ $ sessionId
1025
+ );
1007
1026
1008
1027
$ this ->course ->resources [RESOURCE_FORUMTOPIC ][$ thread_id ]->destination_id = $ new_id ;
1009
1028
1010
1029
$ topic_replies = -1 ;
1011
1030
1012
- foreach ($ this ->course ->resources [RESOURCE_FORUMPOST ] as $ post_id => $ post ){
1031
+ foreach ($ this ->course ->resources [RESOURCE_FORUMPOST ] as $ post_id => $ post ) {
1013
1032
if ($ post ->obj ->thread_id == $ thread_id ) {
1014
1033
$ topic_replies ++;
1015
- $ this ->restore_post ($ post_id , $ new_id , $ forum_id );
1034
+ $ this ->restore_post ($ post_id , $ new_id , $ forum_id, $ sessionId );
1016
1035
}
1017
1036
}
1018
1037
return $ new_id ;
@@ -1022,7 +1041,7 @@ public function restore_topic($thread_id, $forum_id)
1022
1041
* Restore a forum-post
1023
1042
* @TODO Restore tree-structure of posts. For example: attachments to posts.
1024
1043
*/
1025
- public function restore_post ($ id , $ topic_id , $ forum_id )
1044
+ public function restore_post ($ id , $ topic_id , $ forum_id, $ sessionId = 0 )
1026
1045
{
1027
1046
$ table_post = Database :: get_course_table (TABLE_FORUM_POST );
1028
1047
$ post = $ this ->course ->resources [RESOURCE_FORUMPOST ][$ id ];
@@ -1033,9 +1052,26 @@ public function restore_post($id, $topic_id, $forum_id)
1033
1052
$ params ['poster_id ' ] = $ this ->first_teacher_id ;
1034
1053
$ params ['post_date ' ] = api_get_utc_datetime ();
1035
1054
unset($ params ['post_id ' ]);
1036
- $ params ['post_text ' ] = DocumentManager::replace_urls_inside_content_html_from_copy_course ($ params ['post_text ' ], $ this ->course ->code , $ this ->course ->destination_path , $ this ->course ->backup_path , $ this ->course ->info ['path ' ]);
1055
+ $ params ['post_text ' ] = DocumentManager::replace_urls_inside_content_html_from_copy_course (
1056
+ $ params ['post_text ' ],
1057
+ $ this ->course ->code ,
1058
+ $ this ->course ->destination_path ,
1059
+ $ this ->course ->backup_path ,
1060
+ $ this ->course ->info ['path ' ]
1061
+ );
1037
1062
$ new_id = Database::insert ($ table_post , $ params );
1038
- api_item_property_update ($ this ->destination_course_info , TOOL_FORUM_POST , $ new_id , 'PostAdded ' , api_get_user_id (), 0 , 0 , null , null );
1063
+ api_item_property_update (
1064
+ $ this ->destination_course_info ,
1065
+ TOOL_FORUM_POST ,
1066
+ $ new_id ,
1067
+ 'PostAdded ' ,
1068
+ api_get_user_id (),
1069
+ 0 ,
1070
+ 0 ,
1071
+ null ,
1072
+ null ,
1073
+ $ sessionId
1074
+ );
1039
1075
$ this ->course ->resources [RESOURCE_FORUMPOST ][$ id ]->destination_id = $ new_id ;
1040
1076
return $ new_id ;
1041
1077
}
@@ -1050,7 +1086,8 @@ public function restore_links($session_id = 0)
1050
1086
$ resources = $ this ->course ->resources ;
1051
1087
foreach ($ resources [RESOURCE_LINK ] as $ id => $ link ) {
1052
1088
$ cat_id = $ this ->restore_link_category ($ link ->category_id , $ session_id );
1053
- $ sql = "SELECT MAX(display_order) FROM $ link_table WHERE c_id = " .$ this ->destination_course_id ." AND category_id=' " . self ::DBUTF8escapestring ($ cat_id ). "' " ;
1089
+ $ sql = "SELECT MAX(display_order) FROM $ link_table
1090
+ WHERE c_id = " .$ this ->destination_course_id ." AND category_id=' " . self ::DBUTF8escapestring ($ cat_id ). "' " ;
1054
1091
$ result = Database::query ($ sql );
1055
1092
list ($ max_order ) = Database::fetch_array ($ result );
1056
1093
@@ -1060,13 +1097,13 @@ public function restore_links($session_id = 0)
1060
1097
}
1061
1098
1062
1099
$ sql = "INSERT INTO " .$ link_table ." SET
1063
- c_id = " .$ this ->destination_course_id ." ,
1064
- url = ' " .self ::DBUTF8escapestring ($ link ->url )."',
1065
- title = ' " .self ::DBUTF8escapestring ($ link ->title )."',
1066
- description = ' " .self ::DBUTF8escapestring ($ link ->description )."',
1067
- category_id = ' " .$ cat_id ."',
1068
- on_homepage = ' " .$ link ->on_homepage ."',
1069
- display_order = ' " .($ max_order +1 )."' $ condition_session " ;
1100
+ c_id = " .$ this ->destination_course_id ." ,
1101
+ url = ' " .self ::DBUTF8escapestring ($ link ->url )."',
1102
+ title = ' " .self ::DBUTF8escapestring ($ link ->title )."',
1103
+ description = ' " .self ::DBUTF8escapestring ($ link ->description )."',
1104
+ category_id = ' " .$ cat_id ."',
1105
+ on_homepage = ' " .$ link ->on_homepage ."',
1106
+ display_order = ' " .($ max_order +1 )."' $ condition_session " ;
1070
1107
1071
1108
Database::query ($ sql );
1072
1109
$ this ->course ->resources [RESOURCE_LINK ][$ id ]->destination_id = Database::insert_id ();
@@ -2597,14 +2634,15 @@ public function restore_works($sessionId = 0)
2597
2634
api_get_user_id (),
2598
2635
$ this ->destination_course_info ,
2599
2636
0 ,
2600
- 0
2637
+ $ sessionId
2601
2638
);
2602
2639
} else {
2603
2640
$ workId = $ workData ['id ' ];
2604
2641
updateWork (
2605
2642
$ workId ,
2606
2643
$ obj ->params ,
2607
- $ this ->destination_course_info
2644
+ $ this ->destination_course_info ,
2645
+ $ sessionId
2608
2646
);
2609
2647
updatePublicationAssignment (
2610
2648
$ workId ,
0 commit comments