From 085d4b9b09819d932cbdef563e8e66253222616f Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Thu, 2 Aug 2007 06:38:20 +0200 Subject: [PATCH] [svn r12851] Removed deprecated scripts --- main/newscorm/learnpathItem.class.php | 37 +- main/newscorm/scorm_migrate_clean_db.php | 41 - .../scorm_migrate_clean_tracking_time.php | 32 - main/newscorm/scorm_migrate_db.php | 1145 ----------------- main/newscorm/scorm_migrate_db_one_course.php | 943 -------------- .../scorm_migrate_db_reimport_manifest.php | 44 - main/newscorm/scorm_migrate_hometools.php | 50 - .../scorm_migrate_hometools_reverse.php | 63 - main/newscorm/scorm_update_db.php | 166 --- main/newscorm/scorm_update_db_alter.php | 137 -- 10 files changed, 27 insertions(+), 2631 deletions(-) delete mode 100644 main/newscorm/scorm_migrate_clean_db.php delete mode 100755 main/newscorm/scorm_migrate_clean_tracking_time.php delete mode 100644 main/newscorm/scorm_migrate_db.php delete mode 100644 main/newscorm/scorm_migrate_db_one_course.php delete mode 100644 main/newscorm/scorm_migrate_db_reimport_manifest.php delete mode 100644 main/newscorm/scorm_migrate_hometools.php delete mode 100644 main/newscorm/scorm_migrate_hometools_reverse.php delete mode 100644 main/newscorm/scorm_update_db.php delete mode 100644 main/newscorm/scorm_update_db_alter.php diff --git a/main/newscorm/learnpathItem.class.php b/main/newscorm/learnpathItem.class.php index 0b35d64f45..49f7e3059c 100644 --- a/main/newscorm/learnpathItem.class.php +++ b/main/newscorm/learnpathItem.class.php @@ -1727,16 +1727,33 @@ class learnpathItem{ $res = api_sql_query($sql,__FILE__,__LINE__); $this->db_item_view_id = Database::get_last_insert_id(); }else{ - $sql = "UPDATE $item_view_table " . - "SET total_time = ".$this->get_total_time().", " . - " start_time = ".$this->get_current_start_time().", " . - " score = ".$this->get_score().", " . - " status = '".$this->get_status(false)."'," . - " suspend_data = '".Database::escape_string($this->current_data)."'," . - " lesson_location = '".$this->lesson_location."' " . - "WHERE lp_item_id = ".$this->db_id." " . - "AND lp_view_id = ".$this->view_id." " . - "AND view_count = ".$this->attempt_id; + $sql = ''; + if($this->type='hotpotatoes') + { //make an exception for HotPotatoes, don't update the score + //because it has been saved outside of this tool + $sql = "UPDATE $item_view_table " . + "SET total_time = ".$this->get_total_time().", " . + " start_time = ".$this->get_current_start_time().", " . + " status = '".$this->get_status(false)."'," . + " suspend_data = '".Database::escape_string($this->current_data)."'," . + " lesson_location = '".$this->lesson_location."' " . + "WHERE lp_item_id = ".$this->db_id." " . + "AND lp_view_id = ".$this->view_id." " . + "AND view_count = ".$this->attempt_id; + } + else + { //for all other content types... + $sql = "UPDATE $item_view_table " . + "SET total_time = ".$this->get_total_time().", " . + " start_time = ".$this->get_current_start_time().", " . + " score = ".$this->get_score().", " . + " status = '".$this->get_status(false)."'," . + " suspend_data = '".Database::escape_string($this->current_data)."'," . + " lesson_location = '".$this->lesson_location."' " . + "WHERE lp_item_id = ".$this->db_id." " . + "AND lp_view_id = ".$this->view_id." " . + "AND view_count = ".$this->attempt_id; + } if($this->debug>2){error_log('New LP - In learnpathItem::write_to_db() - Updating item_view: '.$sql,0);} $res = api_sql_query($sql,__FILE__,__LINE__); } diff --git a/main/newscorm/scorm_migrate_clean_db.php b/main/newscorm/scorm_migrate_clean_db.php deleted file mode 100644 index 73c40e89a9..0000000000 --- a/main/newscorm/scorm_migrate_clean_db.php +++ /dev/null @@ -1,41 +0,0 @@ -\n"; -$res = api_sql_query($sql,__FILE__,__LINE__); -while ($row = Database::fetch_array($res)) -{ - //TODO change this db name construction to use DB instead of configuration.php settings - $course_pref = Database::get_course_table_prefix(); - $dbname = $row['db_name'].'.'.$course_pref; - $courses_list[] = $row['db_name']; - $courses_id_list[$row['code']] = $row['db_name']; - $courses_dir_list[$row['code']] = $row['directory']; -} -foreach($courses_list as $db) -{ - echo "Using course db $db
\n"; - $lp = Database::get_course_table('lp',$db); - $sql = "TRUNCATE TABLE $lp"; - echo "$sql
\n"; - $res = @mysql_query($sql); - $lp = Database::get_course_table('lp_item',$db); - $sql = "TRUNCATE TABLE $lp"; - echo "$sql
\n"; - $res = @mysql_query($sql); - $lp = Database::get_course_table('lp_view',$db); - $sql = "TRUNCATE TABLE $lp"; - echo "$sql
\n"; - $res = @mysql_query($sql); - $lp = Database::get_course_table('lp_item_view',$db); - $sql = "TRUNCATE TABLE $lp"; - echo "$sql
\n"; - $res = @mysql_query($sql); -} -echo "All done"; -?> \ No newline at end of file diff --git a/main/newscorm/scorm_migrate_clean_tracking_time.php b/main/newscorm/scorm_migrate_clean_tracking_time.php deleted file mode 100755 index a91f5e22f2..0000000000 --- a/main/newscorm/scorm_migrate_clean_tracking_time.php +++ /dev/null @@ -1,32 +0,0 @@ -\n"; -$res = api_sql_query($sql,__FILE__,__LINE__); -while ($row = Database::fetch_array($res)) -{ - //TODO change this db name construction to use DB instead of configuration.php settings - $course_pref = Database::get_course_table_prefix(); - $dbname = $row['db_name'].'.'.$course_pref; - $courses_list[] = $row['db_name']; - $courses_id_list[$row['code']] = $row['db_name']; - $courses_dir_list[$row['code']] = $row['directory']; -} -foreach($courses_list as $db) -{ - echo "Using course db $db
\n"; - $lp = Database::get_course_table('lp_item_view',$db); - $sql = "UPDATE $lp SET start_time=0, total_time=0 WHERE total_time>7200 OR (total_time=0 AND start_time>0)"; - echo "$sql
\n"; - $res = mysql_query($sql); - $sql = "UPDATE $lp SET status='incomplete' WHERE status='Non complété'"; - echo "$sql
\n"; - $res = mysql_query($sql); -} -echo "All done"; -?> \ No newline at end of file diff --git a/main/newscorm/scorm_migrate_db.php b/main/newscorm/scorm_migrate_db.php deleted file mode 100644 index d9a03bb814..0000000000 --- a/main/newscorm/scorm_migrate_db.php +++ /dev/null @@ -1,1145 +0,0 @@ - - */ -//TODO change the install_db and update_db scripts to use this script -/** - * Include mandatory libraries - */ -require_once('back_compat.inc.php'); -require_once('learnpath.class.php'); -require_once('scorm.class.php'); - -ini_set('max_execution_time',7200); - -function my_get_time($time){ - $matches = array(); - if(preg_match('/(\d{1,4}):(\d{2})(:(\d{2})(\.\d*)?)?/',$time,$matches)){ - if(count($matches)==3){ - return ($matches[1]*60)+($matches[2]); - }else{ - return ($matches[1]*3600)+($matches[2]*60)+($matches[4]); - } - } - else return 0; -} - -//open log file -$fh = fopen('../garbage/newscorm_'.time().'.log','w'); -$fh_revert = fopen('../garbage/newscorm_'.time().'_revert.log','w'); -$fh_res = fopen('../garbage/newscorm_'.time().'_res.log','w'); -fwrite($fh,"-- Recording course homepages links changes to enable reverting\n"); -fwrite($fh_revert,"-- Recording reverted course homepages links changes to enable reverting\n"); -fwrite($fh_res,"-- Recording resulting course homepages links changes\n"); - -echo ""; - -/** - * New tables definition: - */ -$new_lp = 'lp'; -$new_lp_view = 'lp_view'; -$new_lp_item = 'lp_item'; -$new_lp_item_view = 'lp_item_view'; -$new_lp_type = 'lp_type'; - -$max_dsp_lp = 0; -$courses_list = array(); -$courses_id_list = array(); -$courses_dir_list = array(); -$sql = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE); -$res = api_sql_query($sql,__FILE__,__LINE__); -while ($row = Database::fetch_array($res)) -{ - //TODO change this db name construction to use DB instead of configuration.php settings - $course_pref = Database::get_course_table_prefix(); - $dbname = $row['db_name'].'.'.$course_pref; - $courses_list[] = $row['db_name']; - $courses_id_list[$row['code']] = $row['db_name']; - $courses_dir_list[$row['code']] = $row['directory']; -} -echo "Tables created/deleted for all courses
\n"; - -/** - * The migration needs to take all data from the original learnpath tables and add them to the new - * lp, lp_view, lp_item and lp_item_view tables - */ - //MIGRATING LEARNPATHS -//test only one course -//$courses_list = array('fadtest_BLA'); -foreach($courses_list as $db) -{ - $incoherences = 0; - echo "Now starting migration of learnpath tables from $db database...
\n"; - $lp_main = Database::get_course_table(TABLE_LEARNPATH_MAIN,$db); - $lp_ids = array(); - $lp_user = Database::get_course_learnpath_user_table($db); - $lp_users = array(); - $lp_chap = Database::get_course_learnpath_chapter_table($db); - $parent_chaps = array(); - $lp_chap_items = array(); - $ordered_chaps = array(); - $lp_item = Database::get_course_learnpath_item_table($db); - $lp_items = array(); - $lp_ordered_items = array(); - $parent_lps = array(); //keeps a track of chapter's learnpath ids - $my_new_lp = $db.$new_lp; - $my_new_lp_item = $db.$new_lp_item; - $my_new_lp_view = $db.$new_lp_view; - $my_new_lp_item_view = $db.$new_lp_item_view; - - //migrate learnpaths - $sql_test = "SELECT * FROM $my_new_lp"; - $res_test = mysql_query($sql_test); - $sql_lp = "SELECT * FROM $lp_main"; - echo "$sql_lp
\n"; - $res_lp = mysql_query($sql_lp);//using mysql_query to avoid dying on failure - if(!$res_lp or !$res_test){ - echo "+++Problem querying DB $lp_main+++ skipping (".mysql_error().")
\n"; - if(!$res_test){ - echo "This might be due to no existing table in the destination course
\n"; - } - continue; - } - $dsp_ord = 1; - while($row = Database::fetch_array($res_lp)) - { - //echo "Treating lp id : ".$row['learnpath_id']."
\n"; - $ins_lp_sql = "INSERT INTO $my_new_lp (lp_type,name,description,display_order,content_maker) " . - "VALUES (1," . - "'".mysql_real_escape_string($row['learnpath_name'])."'," . - "'".mysql_real_escape_string($row['learnpath_description'])."',$dsp_ord,'Dokeos')"; - $ins_lp_res = api_sql_query($ins_lp_sql); - $in_id = Database::get_last_insert_id(); - if(empty($in_id) or $in_id == false) die('Could not insert lp: '.$ins_lp_sql); - $lp_ids[$row['learnpath_id']] = $in_id; - $dsp_ord++; - $max_dsp_lp = $dsp_ord; - } - //echo "
lp_ids:".print_r($lp_ids,true)."
\n"; - - - //MIGRATING LEARNPATH CHAPTERS - - $sql_lp_chap = "SELECT * FROM $lp_chap ORDER BY parent_chapter_id, display_order"; - //echo "$sql_lp_chap
\n"; - $res_lp_chap = api_sql_query($sql_lp_chap); - while($row = Database::fetch_array($res_lp_chap)) - { - //echo "Treating chapter id : ".$row['id']."
\n"; - - //TODO build path for this chapter (although there is no real path for any chapter) - //TODO find out how to calculate the "next_item_id" with the "ordre" field - $my_lp_item = Database::get_course_table($new_lp_item); - $myname = mysql_real_escape_string($row['chapter_name']); - $mydesc = mysql_real_escape_string($row['chapter_description']); - $ins_lp_sql = "INSERT INTO $my_new_lp_item (" . - "lp_id," . - "item_type," . - "title," . - "description," . - "path, " . - "display_order, " . - "next_item_id) " . - "VALUES (" . - "'".$lp_ids[$row['learnpath_id']]."'," . //insert new learnpath ID - "'dokeos_chapter'," . - "'".$myname."'," . - "'".$mydesc."'," . - "''," . - $row['display_order'].", " . - "123456" . - ")"; - //echo $ins_lp_sql."
\n"; - $ins_res = api_sql_query($ins_lp_sql,__FILE__,__LINE__); - $in_id = Database::get_last_insert_id(); - //echo "  Inserted item $in_id
\n"; - if(empty($in_id) OR $in_id == false) die('Could not insert lp: '.$ins_sql); - $parent_chaps[$row['id']] = $row['parent_chapter_id']; - $lp_chap_items[$row['id']] = $in_id; - $parent_lps[$row['id']] = $row['learnpath_id']; - $ordered_chaps[$row['parent_chapter_id']][$row['display_order']]=$in_id; - $lp_chaps_list[$row['learnpath_id']][]=$in_id; - } - //echo "
parent_lps:".print_r($parent_lps,true)."
\n"; - //Now one loop to update the parent_chapter_ids - foreach($parent_chaps as $old_chap => $old_parent_chap){ - if($old_parent_chap != 0){ - $new_chap = $lp_chap_items[$old_chap]; - $new_parent = $lp_chap_items[$old_parent_chap]; - $sql_par_chap = "UPDATE $my_new_lp_item " . - "SET parent_item_id = $new_parent " . - "WHERE id = $new_chap"; - $res_par_chap = api_sql_query($sql_par_chap,__FILE__,__LINE__); - } - } - unset($parent_chaps); - //Now one loop to set the next_item_id and the previous_item_id - foreach($ordered_chaps as $parent_chap){ - $last = 0; - foreach($ordered_chaps[$parent_chap] as $order => $new_id){ - $sql_upd_chaps = "UPDATE $my_new_lp_item " . - "SET previous_item_id = $last " . - "WHERE id = $new_id"; - $res_upd_chaps = api_sql_query($sql_upd_chaps,__FILE__,__LINE__); - - $next = 0; - if(!empty($ordered_chaps[$parent_chap][$order+1])){ - $next = $ordered_chaps[$parent_chap][$order+1]; - } - $sql_upd_chaps = "UPDATE $my_new_lp_item " . - "SET next_item_id = $next " . - "WHERE id = $new_id"; - $res_upd_chaps = api_sql_query($sql_upd_chaps,__FILE__,__LINE__); - $last = $new_id; - } - } - unset($ordered_chaps); - - //migrate learnpath_items - //TODO define this array thanks to types defined in the learnpath_building scripts - //TODO set order correctly - $type_trans = array( - 'document' => TOOL_DOCUMENT, - 'exercise' => TOOL_QUIZ, - 'forum' => TOOL_FORUM, - 'Agenda' => TOOL_CALENDAR_EVENT, - 'Ad_Valvas' => TOOL_ANNOUNCEMENT, - 'Link' => TOOL_LINK, - 'Link _blank' => TOOL_LINK, - 'Exercise' => TOOL_QUIZ, - 'HotPotatoes'=> 'HotPotatoes', - 'Forum' => TOOL_FORUM, - 'Thread' => TOOL_THREAD, - 'Topic' => TOOL_THREAD, - 'Post' => TOOL_POST, - 'Document' => TOOL_DOCUMENT, - 'Assignments'=> 'Assignments', - 'Dropbox' => TOOL_DROPBOX, - 'Introduction_text'=> 'Introduction_text', - 'Course_description' => TOOL_COURSE_DESCRIPTION, - 'Groups' => TOOL_GROUP, - 'Users' => TOOL_USER, - - //'chapter' => 'dokeos_chapter', Chapters should all be in learnpath_chapter, no matter the nesting level - - ); - //MIGRATING LEARNPATH ITEMS - $sql_lp_item = "SELECT * FROM $lp_item ORDER BY chapter_id, display_order"; - //echo "$sql_lp_item
\n"; - $res_lp_item = api_sql_query($sql_lp_item,__FILE__,__LINE__); - while($row = Database::fetch_array($res_lp_item)) - { - //echo "Treating chapter ".$row['chapter_id'].", item ".$row['id']."
\n"; - $type = $type_trans[$row['item_type']]; - $ref = $row['item_id']; - //TODO build item path - //TODO calculate "next_item_id" with the "ordre" field - //prepare prereqs - //prerequisites in Dokeos 1.6 is only authorised on previous items, so - //we know that we are gonna talk about an item that has already been passed - //through here - if none found, print message - $prereq_id = ''; - if(!empty($row['prereq_id'])){ - switch($row['prereq_type']){ - case 'c': - //chapter-type prereq - $prereq_id = $lp_chap_items[$row['prereq_id']]; - if(empty($prereq_id)){echo "Could not find prereq chapter ".$row['prereq_id']."
\n";} - break; - case 'i': - default: - //item type prereq - $prereq_id = $lp_items[$parent_lps[$row['chapter_id']]][$row['prereq_id']]; - if(empty($prereq_id)){echo "Could not find prereq item ".$row['prereq_id']."
\n";} - break; - } - } - $my_lp_item = Database::get_course_table($new_lp_item); - $ins_lp_sql = "INSERT INTO $my_new_lp_item (" . - "lp_id," . - "item_type," . - "ref, " . - "title," . - "description," . - "path, " . - "parent_item_id," . - "prerequisite," . - "display_order" . - ") VALUES (" . - "'".$lp_ids[$parent_lps[$row['chapter_id']]]."'," . //insert new learnpath ID - "'$type'," . - "'$ref', " . - "'".mysql_real_escape_string($row['title'])."'," . - "'".mysql_real_escape_string($row['description'])."'," . - "'$ref'," . - "".$lp_chap_items[$row['chapter_id']]."," . - "'$prereq_id'," . - $row['display_order']." " . - ")"; - $ins_res = api_sql_query($ins_lp_sql,__FILE__,__LINE__); - $in_id = Database::get_last_insert_id(); - //echo "  Inserted item $in_id (".$row['title'].")
\n"; - if(empty($in_id) OR $in_id == false) die('Could not insert lp_item: '.$ins_sql); - $lp_items[$parent_lps[$row['chapter_id']]][$row['id']] = $in_id; - $lp_ordered_items[$parent_lps[$row['chapter_id']]][$row['chapter_id']][] = $in_id; - - } - //echo "
lp_items:".print_r($lp_items,true)."
\n"; - // complete next_item_id field by going through the new table and looking at parent_id and display_order - $my_lp_item = Database::get_course_table($new_lp_item); - $order_sql = "SELECT * FROM $my_new_lp_item ORDER by lp_id ASC, parent_item_id ASC, display_order ASC"; - //echo "$order_sql
\n"; - $order_res = api_sql_query($order_sql,__FILE__,__LINE__); - $order_item = array(); //this will contain a sequential list of item_id's, thus allowing to give a simple way to get next id... - $lp_id = 0; - //echo "
";
-	while($row = Database::fetch_array($order_res))
-	{
-		//print_r($row);
-		if($row['lp_id'] != $lp_id)
-		{
-			//apply changes to the database and clean tool arrays
-			$last = 0;
-			foreach($order_item as $order_id => $item_id){
-				$next = 0;
-				if(!empty($order_item[$order_id+1])){
-					$next = $order_item[$order_id+1];
-				}
-				$upd = "UPDATE $my_new_lp_item " .
-						"SET next_item_id = ".$next."," .
-						"    previous_item_id = ".$last." " .
-						"WHERE id = ".$item_id;
-				//echo "$upd
\n"; - api_sql_query($upd,__FILE__,__LINE__); - $last = $item_id; - } - $order_item = array(); - $lp_id = $row['lp_id']; - $order_item[] = $row['id']; - }else{ - $order_item[] = $row['id']; - } - } - //process the last LP stack - $last = 0; - foreach($order_item as $order_id => $item_id){ - $next = 0; - if(!empty($order_item[$order_id+1])){ - $next = $order_item[$order_id+1]; - } - $upd = "UPDATE $my_new_lp_item " . - "SET next_item_id = ".$next."," . - " previous_item_id = ".$last." " . - "WHERE id = ".$item_id; - //echo "$upd
\n"; - api_sql_query($upd,__FILE__,__LINE__); - $last = $item_id; - } - - //echo "
\n"; - - //MIGRATING THE learnpath_user TABLE (results) - $sql_lp_user = "SELECT * FROM $lp_user ORDER BY user_id, learnpath_id, learnpath_item_id"; - //echo "$sql_lp_user
\n"; - $res_lp_user = api_sql_query($sql_lp_user,__FILE__,__LINE__); - $user_id = 0; - $learnpath_id = 0; - $lp_view = 0; - while($row = Database::fetch_array($res_lp_user)) - { - if($row['user_id']!=$user_id OR $row['learnpath_id']!=$learnpath_id) //the user has changed or this is the first - { - //insert a new lp_view - $last = 0; - if(!empty($lp_chaps_list[$row['learnpath_id']][0])){ - $last = $lp_chaps_list[$row['learnpath_id']][0]; - } - if(empty($lp_ids[$row['learnpath_id']])){ - //this can be ignored as it means there was an LP before, this user - //used it, but now it's been removed - //echo "Somehow we also miss a lp_ids[".$row['learnpath_id']."] here
\n"; - $incoherences ++; - }else{ - $mylpid = $lp_ids[$row['learnpath_id']]; - $sql_ins_view = "INSERT INTO $my_new_lp_view(" . - "lp_id," . - "user_id," . - "view_count," . - "last_item" . - ")VALUES(" . - "".$mylpid."," . //new learnpath id - "".$row['user_id']."," . //user IDs stay the same - "1," . - "".$last."" . //use the first chapter from this learnpath - ")"; - //echo $sql_ins_view; - $res_ins_view = api_sql_query($sql_ins_view,__FILE__,__LINE__); - $in_id = Database::get_last_insert_id(); - $user_id = $row['user_id']; - $learnpath_id = $row['learnpath_id']; - $lp_view = $in_id; - } - } - //insert the record into lp_item_view - //TODO fix the whole in here (missing one item at least) - $my_new_lp_item_id = $lp_items[$learnpath_id][$row['learnpath_item_id']]; - if(empty($my_new_lp_item_id)){ - //this can be ignored safely as it just means a user used a learnpath_item - //before it was removed from items - maybe fix that in Dokeos? - //echo "Somehow we miss lp_items[".$learnpath_id."][".$row['learnpath_item_id']."] here...
"; - $incoherences ++; - }else{ - $start_time = 0; - $my_time = my_get_time($row['time']); - if($my_time>0){ - $start_time = time()-$my_time; - } - $sql_ins_iv = "INSERT INTO $my_new_lp_item_view(" . - "lp_item_id," . - "lp_view_id," . - "view_count," . - "start_time," . - "total_time," . - "score," . - "status" . - ")VALUES(" . - "".$lp_items[$learnpath_id][$row['learnpath_item_id']]."," . - "".$lp_view."," . - "1," . - "$start_time," . - "".$my_time."," . - "".$row['score']."," . - "'".$row['status']."'" . - ")"; - //echo $sql_ins_iv; - $res_ins_iv = api_sql_query($sql_ins_iv,__FILE__,__LINE__); - } - //UPDATE THE LP_VIEW progress - $sql = "SELECT count(distinct(lp_item_id)) FROM $my_new_lp_item_view WHERE lp_view_id = ".$lp_view." AND status IN ('passed','completed','succeeded','browsed','failed')"; - $myres = api_sql_query($sql,__FILE__,__LINE__); - $myrow = Database::fetch_array($myres); - $completed = $myrow[0]; - $mylpid = $lp_ids[$row['learnpath_id']]; - $sql = "SELECT count(*) FROM $my_new_lp_item WHERE lp_id = '".$mylpid."'"; - $myres = api_sql_query($sql,__FILE__,__LINE__); - $myrow = Database::fetch_array($myres); - $total = $myrow[0]; - $progress = ((float)$completed/(float)$total)*100; - $progress = number_format($progress,0); - $sql = "UPDATE $my_new_lp_view SET progress = '$progress' WHERE id = '$lp_view'"; - $myres = api_sql_query($sql,__FILE__,__LINE__); - } - - /** - * Move prerequisites - * TODO integrate prerequisites migration into learnpath_item migration - */ - - $msg = ''; - if($incoherences>0){ - $msg = "(found $incoherences incoherences between views and items - ignored)"; - } - /** - * Migrate links on the homepage as well now (look into the TABLE_TOOL_LIST table and - * update the links to newscorm/lp_controller.php?action=view&lp_id=x) - * Only normal learnpaths were visible from the homepage so we only need to update here - */ - //MIGRATING LEARNPATH LINKS ON COURSES HOMEPAGES - $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST,$db); - $sql_tool = "SELECT * FROM $tbl_tool WHERE image='scormbuilder.gif' AND link LIKE '%learnpath_handler%'"; - $res_tool = api_sql_query($sql_tool,__FILE__,__LINE__); - while($row_tool = Database::fetch_array($res_tool)){ - $name = $row_tool['name']; - $link = $row_tool['link']; - //get old lp_id from there - $matches = array(); - if(preg_match('/learnpath_id=(\d+)$/',$link,$matches)){ - $old_lp_id = $matches[1]; - $new_lp_id = $lp_ids[$old_lp_id]; - $sql_tool_upd = "UPDATE $tbl_tool " . - "SET link='newscorm/lp_controller.php?action=view&lp_id=$new_lp_id' " . - "WHERE id = ".$row_tool['id']; - error_log('New LP - Migration - Updating tool table: '.$sql_tool_upd,0); - //make sure there is a way of retrieving which links were updated (to revert) - fwrite($fh,$sql_tool_upd." AND link ='$link'"); - fwrite($fh_revert,"UPDATE $tbl_tool SET link='$link' WHERE id=".$row_tool['id']." AND link ='newscorm/lp_controller.php?action=view&lp_id=$new_lp_id';\n"); - //echo $sql_tool_upd." (and link='$link')
\n"; - $res_tool_upd = api_sql_query($sql_tool_upd,__FILE__,__LINE__); - } - } - /** - * Update course description (intro page) to use new links instead of learnpath/learnpath_handler.php - */ - $tbl_intro = Database::get_course_table(TABLE_TOOL_INTRO,$db); - $sql_i = "SELECT * FROM $tbl_intro WHERE id='course_homepage'"; - $res_i = api_sql_query($sql_i,__FILE__,__LINE__); - //$link_to_course1 = 'scorm/scormdocument.php'; - while($row_i = Database::fetch_array($res_i)){ - $intro = $row_i['intro_text']; - $update = 0; - $out = array(); - if(preg_match_all('/learnpath\/showinframes\.php([^\s"\']*)learnpath_id=(\d*)/',$intro,$out,PREG_SET_ORDER)){ - foreach($out as $results){ - //echo "---> replace ".'/learnpath\/showinframes\.php([^\s"\']*)learnpath_id='.$results[2].'/ by newscorm/lp_controller.php'.$results[1].'action=view&lp_id='.$lp_ids[$results[2]]; - $intro = preg_replace('/learnpath\/showinframes\.php([^\s"\']*)learnpath_id='.$results[2].'/','newscorm/lp_controller.php'.$results[1].'action=view&lp_id='.$lp_ids[$results[2]],$intro); - } - } - if($intrp != $row_i['intro_text']){ - //echo "
Replacing ".$row_i['intro_text']."\n by \n ".$intro."

\n"; - $sql_upd = "update $tbl_intro set intro_text = '".mysql_real_escape_string($intro)."' WHERE id = 'course_homepage' AND intro_text = '".mysql_real_escape_string($row_i['intro_text'])."'"; - //echo $sql_upd."
\n"; - fwrite($fh,"$sql_upd\n"); - fwrite($fh_revert,"UPDATE $tbl_intro set intro_text = '".$row_i['intro_text']."' WHERE id = 'course_homepage' AND intro_text = '$intro';\n"); - fwrite($fh_res,"$intro\n"); - api_sql_query($sql_upd,__FILE__,__LINE__); - } - } - - - - echo "Done!".$msg."
\n"; - flush(); - ob_flush(); -} -unset($lp_ids); -unset($lp_users); -unset($parent_chaps); -unset($lp_chap_items); -unset($ordered_chaps); -unset($lp_items); -unset($lp_ordered_items); -unset($parent_lps); - -fwrite($fh,"-- Recording course homepages links changes for SCORM to enable reverting\n"); -fwrite($fh_revert,"-- Recording reverted course homepages links changes for SCORM to enable reverting\n"); -fwrite($fh_res,"-- Recording resulting course homepages links changes for SCORM\n"); - -/** - * SCORM - * The migration needs to take all data from the scorm.scorm_main and scorm.scorm_sco_data tables - * and add them to the new lp, lp_view, lp_item and lp_item_view tables. - */ -echo "

Now starting migration of scorm tables from global SCORM database
\n"; -$scorm_main = Database::get_scorm_main_table($db); -$scorm_item = Database::get_scorm_sco_data_table($db); -$lp_main = Database::get_course_table(TABLE_LEARNPATH_MAIN,$db); -$course_pref = Database::get_course_table_prefix(); -$lp_ids = array(); -$lp_item_ids = array(); -$lp_item_refs = array(); -$lp_course = array(); -$lp_course_code = array(); -$scorm_lp_paths = array(); - -//avoid empty dokeosCourse fields as they potentially break the rest -$course_main = Database::get_main_table(TABLE_MAIN_COURSE); -$sql_crs = "SELECT * FROM $course_main WHERE target_course_code IS NULL"; -echo "$sql_crs
\n"; -$res_crs = api_sql_query($sql_crs,__FILE__,__LINE__); -$num = Database::num_rows($res_crs); - -//prepare an array that will contain course codes and for each course code a list of lps [by path prefixed by '/'] -$scorms =array(); -$course_code_swap = ''; -$scormdocuments_lps = array(); -while($course_row = Database::fetch_array($res_crs)){ - - echo "
\nNow dealing with course ".$course_row['code']."...
\n"; - //check the validity of this new course - $my_course_code = $course_row['code']; - - //reinit the scormdocuments list - //$scormdocuments_lps = array(); - $db_name = $courses_id_list[$my_course_code]; - $tblscodoc = Database::get_course_table(TABLE_SCORMDOC,$db_name); - $sql_scodoc = "SELECT path FROM $tblscodoc WHERE path IS NOT NULL AND path != ''"; - echo "$sql_scodoc
"; - $res_scodoc = api_sql_query($sql_scodoc,__FILE__,__LINE__); - while($row_scodoc = Database::fetch_array($res_scodoc)){ - - //check if there's more than one slash in total - if(strpos($row_scodoc['path'],'/',1)===false){ - $tmp_path = $row_scodoc['path']; - echo "++Now opening $tmp_path
"; - - //add a prefixing slash if there is none - if(substr($tmp_path,0,1)!='/'){ - $tmp_path = '/'.$tmp_path; - } - - //if the path is just a slash, empty it - if($tmp_path=='/'){ - $tmp_path=''; - } - - //there is only one 'slash' sign at the beginning, - //or none at all, so we assume - //it is a main directory that should be taken as path - $courses_dir = api_get_path(SYS_COURSE_PATH).''.$courses_dir_list[$my_course_code].'/scorm'.$tmp_path; - if(!is_dir($courses_dir)){ - //echo "Scormdocument path $my_content_id: $tmp_path doesn't exist in ".api_get_path(SYS_COURSE_PATH).$courses_dir_list[$my_course_code]."/scorm, skipping
\n"; - continue; - //avoid if contentTitle is not the name of an existing directory - }elseif(!is_file($courses_dir."/imsmanifest.xml")){ - //if the imsmanifest file was not found there - echo " !!imsmanifest.xml not found at scormdocument's $courses_dir/imsmanifest.xml, skipping
\n"; - //try subdirectories on one level depth - echo " Trying subdirectories...
"; - $dh = opendir($courses_dir); - while($entry = readdir($dh)){ - if(substr($entry,0,1)!='.'){ - if(is_dir($courses_dir."/".$entry)){ - if(is_file($courses_dir."/".$entry."/imsmanifest.xml")){ - echo ". .. and found $courses_dir/$entry/imsmanifest.xml!
"; - if(!in_array($tmp_path."/".$entry."/imsmanifest.xml",$scormdocuments_lps)){ - echo " Recording.
"; - $scormdocuments_lps[] = $tmp_path."/".$entry; - } - } - } - } - } - }else{ - echo " Found scormdocument $tmp_path in ".api_get_path(SYS_COURSE_PATH).$courses_dir_list[$my_course_code]."/scorm, treating it.
\n"; - $scormdocuments_lps[] = $tmp_path; - } - } - } - - //prepare the new course's space in the scorms array - $scorms[$my_course_code] = array(); - - $sql_paths = "SELECT * FROM $scorm_main WHERE dokeosCourse = '".$my_course_code."'"; - echo "$sql_paths
"; - $res_paths = api_sql_query($sql_paths,__FILE__,__LINE__); - $num = Database::num_rows($res_paths); - while($scorm_row = Database::fetch_array($res_paths)){ - //check if this is a new course - $my_content_id = $scorm_row['contentId']; - $my_path = $scorm_row['contentTitle']; - if(substr($my_path,0,1)!='/'){ - $my_path = '/'.$my_path; - } - if($my_path=='/'){ - $my_path=''; - } - echo "++++Now opening $my_path
"; - if(!is_dir($courses_dir = api_get_path(SYS_COURSE_PATH).''.$courses_dir_list[$my_course_code].'/scorm'.$my_path)){ - echo "Path $my_content_id: $my_path doesn't exist in ".api_get_path(SYS_COURSE_PATH).$courses_dir_list[$my_course_code]."/scorm, skipping
\n"; - continue; - //avoid if contentTitle is not the name of an existing directory - }elseif(!is_file(api_get_path(SYS_COURSE_PATH).$courses_dir_list[$my_course_code].'/scorm'.$my_path."/imsmanifest.xml")){ - echo "!!imsmanifest.xml not found at ".api_get_path(SYS_COURSE_PATH).$courses_dir_list[$my_course_code].'/scorm'.$my_path."/imsmanifest.xml, skipping
\n"; - continue; - }else{ - echo "Found $my_path in ".api_get_path(SYS_COURSE_PATH).$courses_dir_list[$my_course_code]."/scorm".$mypath."/imsmanifest.xml, keeping it.
\n"; - $scorms[$my_course_code][$my_path] = $my_content_id; - } - } - //check if all the lps from scormdocuments_lps are already in the course array, - //otherwise add them (and set ID of 0 so no tracking will be available) - foreach($scormdocuments_lps as $path){ - if(!in_array($path,array_keys($scorms[$my_course_code]))){ - //add it (-1 means no ID) - echo "** Scormdocument path $path wasn't recorded yet. Added.
\n"; - $scorms[$my_course_code][$path] = -1; - } - } - $course_code_swap = $my_course_code; - unset($scormdocuments_lps); -} - -//echo "
courses_id_list: ".print_r($courses_id_list,true)."
\n"; - -$my_count = 0; -foreach($scorms as $mycourse => $my_paths){ - $my_count += count($my_paths); -} -echo "
\n---- Scorms array now contains ".$mycount." paths to migrate. Starting migration...
\n"; - -/** - * Looping through the SCO_MAIN table for SCORM learnpath attached to courses - * Order by course to try and reuse the maximum data - */ -$i_count = 0; -foreach($scorms as $my_course_code => $paths_list ) -{ - $max_dsp_lp = 0; - $course_lp_done = array(); - $db_name = $courses_id_list[$my_course_code].'.'.$course_pref; - foreach($paths_list as $my_path => $old_id){ - echo "Migrating lp $my_path from course $my_course_code...
\n"; - $i_count ++; - //error_log('New LP - Migration script - Content '.$i_count.' on '.$num.' (course '.$scorm['dokeosCourse'].')',0); - //check if there is no embedded learnpaths into other learnpaths (one root-level and another embedded) - $embedded = false; - foreach($course_lp_done as $tmp_lp){ - if(empty($tmp_lp)){ - $tmp_lp = '/'; //allows finding the lp as a subitem, otherwise strstr returns false - } - if(strstr($my_path,$tmp_lp)===false){ - //let it be - }else{ - //this lp is embedded inside another lp who's imsmanifest exists, so prevent from parsing - echo "LP $my_path is embedded into $tmp_lp, ignoring...
\n"; - $embedded = true; - continue; - } - } - if($embedded){ - continue; - } - $course_lp_done[] = $my_path; - //echo "
scorm row: ".print_r($scorm,true)."
\n"; - $my_content_id = $old_id; - $my_path = $my_path; - $my_name = basename($my_path); - - echo "Try importing LP $my_path from imsmanifest first as it is more reliable
\n"; - - //Setup the ims path (path to the imsmanifest.xml file) - //echo "Looking for course with code ".$lp_course_code[$my_content_id]." (using $my_content_id)
\n"; - $courses_dir = api_get_path(SYS_COURSE_PATH).''.$courses_dir_list[$my_course_code]; - $sco_path_temp = ($my_path=='/')?'':$my_path; - $sco_middle_path = (empty($sco_path_temp)?'':(substr($sco_path_temp,0,1)=='/')?substr($sco_path_temp,1).'/':$sco_path_temp.'/'); //same thing as sco_path_temp but with reversed slashes - $ims = $courses_dir.'/scorm'.$sco_path_temp.'/imsmanifest.xml'; - - if(is_file($ims)){ - $oScorm = new scorm(); - //check if imsmanifest.xml exists at this location. If not, ignore the imsmanifest. - //That should have been done before already, now. - echo "Found imsmanifest ($ims), importing...
\n"; - if(!empty($sco_middle_path)){$oScorm->subdir = $sco_middle_path;} //this sets the subdir for the scorm package inside the scorm dir - //parse manifest file - $manifest = $oScorm->parse_manifest($ims); - //the title is already escaped in the method - $oScorm->import_manifest($my_course_code); - //TODO add code to update the path in that new lp created, as it probably uses / where - //$sco_path_temp should be used... - $lp_ids[$my_content_id] = $oScorm->lp_id; //contains the old LP ID => the new LP ID - echo " @@@ Created scorm lp ".$oScorm->lp_id." from imsmanifest [".$ims."] in course $my_course_code
\n"; - $lp_course[$my_content_id] = $courses_id_list[$my_course_code]; //contains the old learnpath ID => the course DB name - $lp_course_code[$my_content_id] = $my_course_code; - $max_dsp_lp++; - - /* - * QUERY SCORM ITEMS FROM SCORM_SCO_DATA - * The danger here is that we might have several users for the same data, and so - * we have to avoid entering the same elements twice - */ - $sql_items = "SELECT * FROM $scorm_item WHERE contentId = '".$my_content_id."' ORDER BY scoId"; - //echo "$sql_items
\n"; - $res_items = api_sql_query($sql_items,__FILE__,__LINE__); - while($scormItem = Database::fetch_array($res_items)) - { - $my_sco_id = $scormItem['scoId']; //the index for display??? (check that) - $my_identifier = $scormItem['scoIdentifier']; //the scorm item path/name - $my_title = mysql_real_escape_string($scormItem['scoTitle']); - $my_status = $scormItem['status']; - $my_student = $scormItem['studentId']; - $my_score = $scormItem['score']; - $my_time = my_get_time($scormItem['time']); - $my_type = 'sco'; - //$my_item_path = $scorm_lp_paths[$my_content_id]['path']; - $my_item_path = ''; - - //echo "  FOUND item belonging to old learnpath num $my_content_id so belongs to course ".$lp_course[$my_content_id]."
\n"; - $my_new_lp_item = $db_name.$new_lp_item; - $my_new_lp_view = $db_name.$new_lp_view; - $my_new_lp_item_view = $db_name.$new_lp_item_view; - - /* - * Check if a view is needed - */ - if($my_score != '' and $my_status != 'not attempted'){ - //it is worth creating an lp_view and an lp_item_view - otherwise not - $sel_sqlb = "SELECT * FROM $my_new_lp_view " . - "WHERE lp_id = ".$lp_ids[$my_content_id]." AND user_id = $my_student"; - $sel_resb = api_sql_query($sel_sqlb,__FILE__,__LINE__); - if(Database::num_rows($sel_resb)>0){ - //dont insert - $rowb = Database::fetch_array($sel_resb); - $view_insert_id = $rowb['id']; - }else{ - $ins_sql = "INSERT INTO $my_new_lp_view (" . - "lp_id," . - "user_id," . - "view_count" . - ") VALUES (" . - $lp_ids[$my_content_id].", " . - $my_student.", " . - "1" . - ")"; - //echo "$ins_sql
"; - $ins_res = api_sql_query($ins_sql,__FILE__,__LINE__); - $view_insert_id = Database::get_last_insert_id(); - } - $sel_sqlc = "SELECT * FROM $my_new_lp_item " . - "WHERE lp_id = ".$lp_ids[$my_content_id]." AND ref = '$my_identifier'"; - $sel_resc = api_sql_query($sel_sqlc,__FILE__,__LINE__); - if(Database::num_rows($sel_resc)>0){ - $my_item_id_row = Database::fetch_array($sel_resc); - $item_insert_id = $my_item_id_row['id']; - $ins_sql = "INSERT INTO $my_new_lp_item_view (" . - "lp_item_id, lp_view_id, view_count," . - "start_time, total_time, score," . - "status" . - ") VALUES (" . - "$item_insert_id, $view_insert_id, 1," . - "0, $my_time, $my_score," . - "'$my_status'" . - ")"; - //echo "$ins_sql
"; - $ins_res = api_sql_query($ins_sql,__FILE__,__LINE__); - }else{ - //echo " Didn't find corresponding item for $my_identifier in new tables
\n"; - } - } - } - - } - else{ - echo "This is a normal SCORM path
\n"; - $scorm_lp_paths[$my_content_id]['path'] = $my_path; - //$scorm_lp_paths[$my_content_id]['ims'] = ''; - $table_name = $db_name.$new_lp; - $sql_ins = "INSERT INTO $table_name (" . - "lp_type," . - "name," . - "description," . - "path," . - "force_commit, " . - "default_encoding," . - "display_order," . - "content_maker," . - "content_local," . - "js_lib" . - ") VALUES (" . - "2," . - "'$my_name'," . - "''," . - "'$my_path'," . - "0," . - "'UTF-8'," . - "".$max_dsp_lp."," . - "'Unknown'," . - "'Unknown'," . - "'scorm_api.php'" . - ")"; - echo "$sql_ins
\n"; - $sql_res = api_sql_query($sql_ins,__FILE__,__LINE__); - $in_id = Database::get_last_insert_id(); - if(empty($in_id) or $in_id == false) die('Could not insert scorm lp: '.$sql_ins); - //echo "  Inserted item $in_id
\n"; - $lp_ids[$my_content_id] = $in_id; //contains the old LP ID => the new LP ID - $lp_course[$my_content_id] = $courses_id_list[$my_course_code]; //contains the old learnpath ID => the course DB name - $lp_course_code[$my_content_id] = $my_course_code; - $max_dsp_lp++; - - //Setup the ims path (path to the imsmanifest.xml file) - //echo "Looking for course with code ".$lp_course_code[$my_content_id]." (using $my_content_id)
\n"; - $courses_dir = api_get_path(SYS_COURSE_PATH).''.$courses_dir_list[$lp_course_code[$my_content_id]]; - //$scorm_lp_paths[$my_content_id]['path'] = str_replace(' ','\\ ',$scorm_lp_paths[$my_content_id]['path']); - $sco_path_temp = ($scorm_lp_paths[$my_content_id]['path']=='/')?'':$scorm_lp_paths[$my_content_id]['path']; - $scorm_lp_paths[$my_content_id]['ims'] = $courses_dir.'/scorm'.$sco_path_temp.'/imsmanifest.xml'; - - //generate an imsmanifest object to get more info about the learnpath from the file - $oScorm = new scorm(); - //check if imsmanifest.xml exists at this location. If not, ignore the imsmanifest. - //That should have been done before already, now. - if(!is_file($scorm_lp_paths[$my_content_id]['ims'])){ - echo "!!! imsmanifest file not found at ".$scorm_lp_paths[$my_content_id]['ims'].' for old lp '.$my_content_id.' and new '.$lp_ids[$my_content_id]."
\n"; - $manifest = false; - }else{ - //echo "Parsing ".$scorm_lp_paths[$my_content_id]['ims']."
\n"; - //parse manifest file - $manifest = $oScorm->parse_manifest($scorm_lp_paths[$my_content_id]['ims']); - //the title is already escaped in the method - //$my_lp_title = mb_convert_encoding($oScorm->get_title(),'ISO-8859-1',$oScorm->manifest_encoding); - $my_lp_title = mb_convert_encoding($oScorm->get_title(),'ISO-8859-1','UTF-8'); - if(!empty($my_lp_title)){ - $my_new_lp = $db_name.$new_lp; - $my_sql = "UPDATE $my_new_lp " . - "SET name = '$my_lp_title', " . - "default_encoding = '".strtoupper($oScorm->manifest_encoding)."' " . - "WHERE id = ".$lp_ids[$my_content_id]; - echo "Updating title and encoding: ".$my_sql."
\n"; - $my_res = api_sql_query($my_sql,__FILE__,__LINE__); - } - } - - /* - * QUERY SCORM ITEMS FROM SCORM_SCO_DATA - * The danger here is that we might have several users for the same data, and so - * we have to avoid entering the same elements twice - */ - $sql_items = "SELECT * FROM $scorm_item WHERE contentId = '".$my_content_id."' ORDER BY scoId"; - //echo "$sql_items
\n"; - $res_items = api_sql_query($sql_items,__FILE__,__LINE__); - while($scormItem = Database::fetch_array($res_items)) - { - $my_sco_id = $scormItem['scoId']; //the index for display??? (check that) - $my_identifier = $scormItem['scoIdentifier']; //the scorm item path/name - $my_title = mysql_real_escape_string($scormItem['scoTitle']); - $my_status = $scormItem['status']; - $my_student = $scormItem['studentId']; - $my_score = $scormItem['score']; - $my_time = my_get_time($scormItem['time']); - $my_type = 'sco'; - //$my_item_path = $scorm_lp_paths[$my_content_id]['path']; - $my_item_path = ''; - - //echo "  FOUND item belonging to old learnpath num $my_content_id so belongs to course ".$lp_course[$my_content_id]."
\n"; - $my_new_lp_item = $db_name.$new_lp_item; - $my_new_lp_view = $db_name.$new_lp_view; - $my_new_lp_item_view = $db_name.$new_lp_item_view; - - /* - * Query items from the new table to check if it doesn't exist already - * Otherwise insert it - */ - $sel_sql = "SELECT * FROM $my_new_lp_item " . - "WHERE ref = '$my_identifier' " . - "AND lp_id = ".$lp_ids[$my_content_id].""; - //echo $sel_sql."
\n"; - $sel_res = api_sql_query($sel_sql,__FILE__,__LINE__); - if(Database::num_rows($sel_res)>0){ - //this item already exists, reuse - $row = Database::fetch_array($sel_res); - $item_insert_id = $row['lp_id']; - }else{ - $ins_sql = "INSERT INTO $my_new_lp_item (" . - "lp_id," . - "item_type," . - "ref," . - "title," . - "path" . - ") " . - "VALUES (" . - "'".$lp_ids[$my_content_id]."'," . //insert new learnpath ID - "'$my_type'," . - "'".$my_identifier."'," . - "'".$my_title."'," . - "'$my_item_path'" . - ")"; - $ins_res = api_sql_query($ins_sql,__FILE__,__LINE__); - $item_insert_id = Database::get_last_insert_id(); - $lp_item_ids[$lp_ids[$my_content_id]][$my_sco_id]=$item_insert_id; - $lp_item_refs[$lp_ids[$my_content_id]][$my_identifier]=$item_insert_id; - } - /* - * Check if a view is needed - */ - if($my_score != '' and $my_status != 'not attempted'){ - //it is worth creating an lp_view and an lp_item_view - otherwise not - $sel_sqlb = "SELECT * FROM $my_new_lp_view " . - "WHERE lp_id = ".$lp_ids[$my_content_id]." AND user_id = $my_student"; - $sel_resb = api_sql_query($sel_sqlb,__FILE__,__LINE__); - if(Database::num_rows($sel_resb)>0){ - //dont insert - $rowb = Database::fetch_array($sel_resb); - $view_insert_id = $rowb['id']; - }else{ - $ins_sql = "INSERT INTO $my_new_lp_view (" . - "lp_id," . - "user_id," . - "view_count" . - ") VALUES (" . - $lp_ids[$my_content_id].", " . - $my_student.", " . - "1" . - ")"; - $ins_res = api_sql_query($ins_sql,__FILE__,__LINE__); - $view_insert_id = Database::get_last_insert_id(); - } - $ins_sql = "INSERT INTO $my_new_lp_item_view (" . - "lp_item_id, lp_view_id, view_count," . - "start_time, total_time, score," . - "status" . - ") VALUES (" . - "$item_insert_id, $view_insert_id, 1," . - "0, $my_time, $my_score," . - "'$my_status'" . - ")"; - $ins_res = api_sql_query($ins_sql,__FILE__,__LINE__); - } - } - //UPDATE THE LP_VIEW progress - $sql = "SELECT count(distinct(lp_item_id)) FROM $my_new_lp_item_view WHERE lp_view_id = ".$view_insert_id." AND status IN ('passed','completed','succeeded','browsed','failed')"; - $myres = api_sql_query($sql,__FILE__,__LINE__); - $myrow = Database::fetch_array($myres); - $completed = $myrow[0]; - $mylpid = $lp_ids[$my_content_id]; - $sql = "SELECT count(*) FROM $my_new_lp_item WHERE lp_id = '".$mylpid."'"; - $myres = api_sql_query($sql,__FILE__,__LINE__); - $myrow = Database::fetch_array($myres); - $total = $myrow[0]; - $progress = ((float)$completed/(float)$total)*100; - $progress = number_format($progress,0); - $sql = "UPDATE $my_new_lp_view SET progress = '$progress' WHERE id = '$view_insert_id'"; - $myres = api_sql_query($sql,__FILE__,__LINE__); - - - /* - * Set all information that might be more correct coming from imsmanifest - */ - - //$my_new_lp = $db_name.$new_lp; - //$my_new_lp_item = $db_name.$new_lp_item; - //$my_new_lp_view = $db_name.$new_lp_view; - //$my_new_lp_item_view = $db_name.$new_lp_item_view; - //$sel_sql = "SELECT * FROM $my_new_lp WHERE id = $in_id"; - //$res = @mysql_query($sel_sql); - //if(!$res){ - // echo "Error selecting lp: $sel_sql - ".mysql_error()."
\n"; - //} - $lp_details = array(); - //while($row = Database::fetch_array($res)) - //{ - $ordered_list = array(); - $mylist = array(); - foreach($oScorm->organizations as $org){ - //There should be only one organization (generally) - //and if there are more, we are not supposed to have been - //able to manage them before the new tool, so ignore - if(count($ordered_list)>0){ - break; - } - $ordered_list = $org->get_flat_items_list(); - } - $previous = 0; - $stock = array(0); - $level=0; - $parent_id = 0; - foreach($ordered_list as $index => $subarray) - { - //$subarray is an array representing one item and that contains info like - //identifier, level, rel_order, prerequisites, title, masteryscore, etc. - //echo "
Lookin for ".$subarray['identifier']." ".print_r($lp_item_refs,true)."
\n"; - if(!empty($lp_item_refs[$in_id][$subarray['identifier']])){ - $new_id = $lp_item_refs[$in_id][$subarray['identifier']]; - $next = 0; - $dsp = $subarray['rel_order']; - if($subarray['level']>$level){ - //getting one level deeper, just consult - $parent_id = $previous; - array_push($stock,$previous); - $level = $subarray['level']; - }elseif($subarray['level']==$level){ - //we are on the same level, going to the next id - //array_pop($stock); - //array_push($stock,$new_id); - }else{ - //getting back from one level deeper - array_pop($stock); - $parent_id = array_pop($stock); - array_push($stock,$parent_id); - $level = $subarray['level']; - } - if(!empty($ordered_list[$index+1]['identifier']) && !empty($lp_item_refs[$in_id][$ordered_list[$index+1]['identifier']])){ - $next = $lp_item_refs[$in_id][$ordered_list[$index+1]['identifier']]; - } - $path = $oScorm->get_res_path($subarray['identifierref']); - $update_path = ''; - if(!empty($path)){ - //if new path is not empty, update - $update_path = "path = '$path', "; - } - $type = $oScorm->get_res_type($subarray['identifierref']); - $update_type = ''; - if(!empty($type)){ - //if type is defined, update - $update_type = "item_type = '$type', "; - } - if(empty($path)){ - //if path is empty, it is a dir anyway - $update_type = "item_type = 'dir', "; - } - $prereq = $subarray['prerequisites']; - $update_prereq = ''; - if(!empty($prereq)){ - $update_prereq = "prerequisite = '$prereq', "; - } - - //we had previous data about this element, update - $sql2 = "UPDATE $my_new_lp_item " . - "SET parent_item_id = $parent_id, " . - "previous_item_id = $previous, " . - "next_item_id = $next, " . - $update_path. - $update_type. - $update_prereq. - "display_order = $dsp " . - "WHERE lp_id = ".$in_id." AND id = ".$new_id; - //echo "$sql2
\n"; - $res2 = api_sql_query($sql2,__FILE__,__LINE__); - $previous = $new_id; - } - } - /** - * Migrate links on the homepage as well now (look into the TABLE_TOOL_LIST table and - * update the links to newscorm/lp_controller.php?action=view&lp_id=x) - * See scorm_migrate_hometools.php - */ - //} - //end of case where $my_content_id != -1 - - } - - /** - * Update course description (intro page) to use new links instead of learnpath/learnpath_handler.php - */ - $tbl_intro = $db_name.TABLE_TOOL_INTRO; - $sql_i = "SELECT * FROM $tbl_intro WHERE id='course_homepage'"; - $res_i = api_sql_query($sql_i,__FILE__,__LINE__); - //$link_to_course1 = 'scorm/scormdocument.php'; - while($row_i = Database::fetch_array($res_i)){ - $intro = $row_i['intro_text']; - $out = array(); - $enc_path = str_replace('/','%2F',$my_path); - $enc_path = str_replace(' ','\+',$enc_path); - //echo "Looking for path ".$enc_path."
\n"; - $pattern = ';scorm/scormdocument\.php([^\s"\']*)openDir='.$enc_path.'([\\"\'\s&]*);'; - if(preg_match_all($pattern,$intro,$out,PREG_SET_ORDER)){ - foreach($out as $results){ - //echo "---> replace ".'/'.$results[0].'/ by newscorm/lp_controller.php'.$results[1].'action=view&lp_id='.$lp_ids[$my_content_id]; - //$intro = preg_replace('/scorm\/scormdocument\.php([^\s"\']*)openDir='.$enc_path.'([\\"\'\s&])/','newscorm/lp_controller.php'.$results[1].'action=view&lp_id='.$lp_ids[$my_content_id],$intro); - $intro = preg_replace(';scorm/scormdocument\.php([^\s"\']*)openDir='.$enc_path.'([^\s"\']*);','newscorm/lp_controller.php'.$results[1].'action=view&lp_id='.$lp_ids[$my_content_id],$intro); - } - }else{ - //echo "No scorm link found in intro text
"; - } - $pattern = ';scorm/showinframes\.php([^\s"\']*)file=([^\s"\'&]*)'.$enc_path.';'; - if(preg_match_all($pattern,$intro,$out,PREG_SET_ORDER)){ - foreach($out as $results){ - //echo "---> replace ".'/'.$results[0].'/ by newscorm/lp_controller.php'.$results[1].'action=view&lp_id='.$lp_ids[$my_content_id]; - //$intro = preg_replace('/scorm\/showinframes\.php([^\s"\']*)file=([^\s"\']*)'.$enc_path.'/','newscorm/lp_controller.php'.$results[1].'action=view&lp_id='.$lp_ids[$my_content_id],$intro); - $intro = preg_replace(';scorm/showinframes\.php([^\s"\']*)file=([^\s"\'&]*)'.$enc_path.'([^\s"\']*);','newscorm/lp_controller.php'.$results[1].'action=view&lp_id='.$lp_ids[$my_content_id],$intro); - } - }else{ - //echo "No scorm link found in intro text
"; - } - if($intro != $row_i['intro_text']){ - //echo "
Replacing ".$row_i['intro_text']."\n by \n ".$intro."

\n"; - $sql_upd = "update $tbl_intro set intro_text = '".mysql_real_escape_string($intro)."' WHERE id = 'course_homepage' AND intro_text = '".mysql_real_escape_string($row_i['intro_text'])."'"; - //echo $sql_upd."
\n"; - fwrite($fh,$sql_upd."\n"); - fwrite($fh_revert,"UPDATE $tbl_intro set intro_text = '".$row_i['intro_text']."' WHERE id = 'course_homepage' AND intro_text = '$intro';\n"); - fwrite($fh_res,$intro."\n"); - api_sql_query($sql_upd,__FILE__,__LINE__); - } - } - - flush(); - } -} -echo "All done!"; -echo ""; -fclose($fh); -fclose($fh_revert); -fclose($fh_res); -?> diff --git a/main/newscorm/scorm_migrate_db_one_course.php b/main/newscorm/scorm_migrate_db_one_course.php deleted file mode 100644 index 9b2aac6ab3..0000000000 --- a/main/newscorm/scorm_migrate_db_one_course.php +++ /dev/null @@ -1,943 +0,0 @@ - - */ -//TODO change the install_db and update_db scripts to use this script -/** - * Include mandatory libraries - */ -require_once('back_compat.inc.php'); -require_once('learnpath.class.php'); -require_once('scorm.class.php'); - -ini_set('max_execution_time',7200); - -function my_get_time($time){ - $matches = array(); - if(preg_match('/(\d{2}):(\d{2}):(\d{2})(\.\d*)?/',$time,$matches)){ - return ($matches[1]*3600)+($matches[2]*60)+($matches[3]); - } - else return 0; -} - -//@todo shouldn't the dokeos header not be used here? -echo ""; - -/** - * New tables definition: - */ -$new_lp = 'lp'; -$new_lp_view = 'lp_view'; -$new_lp_item = 'lp_item'; -$new_lp_item_view = 'lp_item_view'; -$new_lp_type = 'lp_type'; - -//unique course to update -$course_code = mysql_real_escape_string($_GET['code']); -if(empty($course_code)){die('No course code provided, sorry');} - -$max_dsp_lp = 0; -$courses_list = array(); -$courses_id_list = array(); -$courses_dir_list = array(); -$sql = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE)." WHERE code='$course_code'"; -$res = api_sql_query($sql,__FILE__,__LINE__); -while ($row = Database::fetch_array($res)) -{ - //TODO change this db name construction to use DB instead of configuration.php settings - $course_pref = Database::get_course_table_prefix(); - $dbname = $row['db_name'].'.'.$course_pref; - $courses_list[] = $row['db_name']; - $courses_id_list[$row['code']] = $row['db_name']; - $courses_dir_list[$row['code']] = $row['directory']; -} -echo "Tables created/deleted for all courses
\n"; - -/** - * The migration needs to take all data from the original learnpath tables and add them to the new - * lp, lp_view, lp_item and lp_item_view tables - */ -//test only one course -//$courses_list = array('fadtest_BLA'); -foreach($courses_list as $db) -{ - $incoherences = 0; - echo "Now starting migration of learnpath tables from $db database...
\n"; - $lp_main = Database::get_course_table(TABLE_LEARNPATH_MAIN,$db); - $lp_ids = array(); - $lp_user = Database::get_course_learnpath_user_table($db); - $lp_users = array(); - $lp_chap = Database::get_course_learnpath_chapter_table($db); - $parent_chaps = array(); - $lp_chap_items = array(); - $ordered_chaps = array(); - $lp_item = Database::get_course_learnpath_item_table($db); - $lp_items = array(); - $lp_ordered_items = array(); - $parent_lps = array(); //keeps a track of chapter's learnpath ids - $course_pref = Database::get_course_table_prefix(); - $db_name = $db.'.'.$course_pref; - $my_new_lp = $db_name.$new_lp; - $my_new_lp_item = $db_name.$new_lp_item; - $my_new_lp_view = $db_name.$new_lp_view; - $my_new_lp_item_view = $db_name.$new_lp_item_view; - - //migrate learnpaths - $sql_test = "SELECT * FROM $my_new_lp"; - $res_test = mysql_query($sql_test); - $sql_lp = "SELECT * FROM $lp_main"; - echo "$sql_lp
\n"; - $res_lp = mysql_query($sql_lp);//using mysql_query to avoid dying on failure - if(!$res_lp or !$res_test){ - echo "+++Problem querying DB $lp_main+++ skipping (".mysql_error().")
\n"; - if(!$res_test){ - echo "This might be due to no existing table in the destination course
\n"; - } - continue; - } - $dsp_ord = 1; - while($row = Database::fetch_array($res_lp)) - { - //echo "Treating lp id : ".$row['learnpath_id']."
\n"; - $ins_lp_sql = "INSERT INTO $my_new_lp (lp_type,name,description,display_order,content_maker) " . - "VALUES (1," . - "'".mysql_real_escape_string($row['learnpath_name'])."'," . - "'".mysql_real_escape_string($row['learnpath_description'])."',$dsp_ord,'Dokeos')"; - $ins_lp_res = api_sql_query($ins_lp_sql); - $in_id = Database::get_last_insert_id(); - if(empty($in_id) or $in_id == false) die('Could not insert lp: '.$ins_lp_sql); - $lp_ids[$row['learnpath_id']] = $in_id; - $dsp_ord++; - $max_dsp_lp = $dsp_ord; - } - //echo "
lp_ids:".print_r($lp_ids,true)."
\n"; - - - //MIGRATING LEARNPATH CHAPTERS - - $sql_lp_chap = "SELECT * FROM $lp_chap ORDER BY parent_chapter_id, display_order"; - //echo "$sql_lp_chap
\n"; - $res_lp_chap = api_sql_query($sql_lp_chap); - while($row = Database::fetch_array($res_lp_chap)) - { - //echo "Treating chapter id : ".$row['id']."
\n"; - - //TODO build path for this chapter (although there is no real path for any chapter) - //TODO find out how to calculate the "next_item_id" with the "ordre" field - $my_lp_item = Database::get_course_table($new_lp_item); - $myname = mysql_real_escape_string($row['chapter_name']); - $mydesc = mysql_real_escape_string($row['chapter_description']); - $ins_lp_sql = "INSERT INTO $my_new_lp_item (" . - "lp_id," . - "item_type," . - "title," . - "description," . - "path, " . - "display_order, " . - "next_item_id) " . - "VALUES (" . - "'".$lp_ids[$row['learnpath_id']]."'," . //insert new learnpath ID - "'dokeos_chapter'," . - "'".$myname."'," . - "'".$mydesc."'," . - "''," . - $row['display_order'].", " . - "123456" . - ")"; - //echo $ins_lp_sql."
\n"; - $ins_res = api_sql_query($ins_lp_sql,__FILE__,__LINE__); - $in_id = Database::get_last_insert_id(); - //echo "  Inserted item $in_id
\n"; - if(empty($in_id) OR $in_id == false) die('Could not insert lp: '.$ins_sql); - $parent_chaps[$row['id']] = $row['parent_chapter_id']; - $lp_chap_items[$row['id']] = $in_id; - $parent_lps[$row['id']] = $row['learnpath_id']; - $ordered_chaps[$row['parent_chapter_id']][$row['display_order']]=$in_id; - $lp_chaps_list[$row['learnpath_id']][]=$in_id; - } - //echo "
parent_lps:".print_r($parent_lps,true)."
\n"; - //Now one loop to update the parent_chapter_ids - foreach($parent_chaps as $old_chap => $old_parent_chap){ - if($old_parent_chap != 0){ - $new_chap = $lp_chap_items[$old_chap]; - $new_parent = $lp_chap_items[$old_parent_chap]; - $sql_par_chap = "UPDATE $my_new_lp_item " . - "SET parent_item_id = $new_parent " . - "WHERE id = $new_chap"; - $res_par_chap = api_sql_query($sql_par_chap,__FILE__,__LINE__); - } - } - unset($parent_chaps); - //Now one loop to set the next_item_id and the previous_item_id - foreach($ordered_chaps as $parent_chap){ - $last = 0; - foreach($ordered_chaps[$parent_chap] as $order => $new_id){ - $sql_upd_chaps = "UPDATE $my_new_lp_item " . - "SET previous_item_id = $last " . - "WHERE id = $new_id"; - $res_upd_chaps = api_sql_query($sql_upd_chaps,__FILE__,__LINE__); - - $next = 0; - if(!empty($ordered_chaps[$parent_chap][$order+1])){ - $next = $ordered_chaps[$parent_chap][$order+1]; - } - $sql_upd_chaps = "UPDATE $my_new_lp_item " . - "SET next_item_id = $next " . - "WHERE id = $new_id"; - $res_upd_chaps = api_sql_query($sql_upd_chaps,__FILE__,__LINE__); - $last = $new_id; - } - } - unset($ordered_chaps); - - //migrate learnpath_items - //TODO define this array thanks to types defined in the learnpath_building scripts - //TODO set order correctly - $type_trans = array( - 'document' => TOOL_DOCUMENT, - 'exercise' => TOOL_QUIZ, - 'forum' => TOOL_FORUM, - 'Agenda' => TOOL_CALENDAR_EVENT, - 'Ad_Valvas' => TOOL_ANNOUNCEMENT, - 'Link' => TOOL_LINK, - 'Link _blank' => TOOL_LINK, - 'Exercise' => TOOL_QUIZ, - 'HotPotatoes'=> 'HotPotatoes', - 'Forum' => TOOL_FORUM, - 'Thread' => TOOL_THREAD, - 'Topic' => TOOL_THREAD, - 'Post' => TOOL_POST, - 'Document' => TOOL_DOCUMENT, - 'Assignments'=> 'Assignments', - 'Dropbox' => TOOL_DROPBOX, - 'Introduction_text'=> 'Introduction_text', - 'Course_description' => TOOL_COURSE_DESCRIPTION, - 'Groups' => TOOL_GROUP, - 'Users' => TOOL_USER, - - //'chapter' => 'dokeos_chapter', Chapters should all be in learnpath_chapter, no matter the nesting level - - ); - $sql_lp_item = "SELECT * FROM $lp_item ORDER BY chapter_id, display_order"; - //echo "$sql_lp_item
\n"; - $res_lp_item = api_sql_query($sql_lp_item,__FILE__,__LINE__); - while($row = Database::fetch_array($res_lp_item)) - { - //echo "Treating chapter ".$row['chapter_id'].", item ".$row['id']."
\n"; - $type = $type_trans[$row['item_type']]; - $ref = $row['item_id']; - //TODO build item path - //TODO calculate "next_item_id" with the "ordre" field - //prepare prereqs - //prerequisites in Dokeos 1.6 is only authorised on previous items, so - //we know that we are gonna talk about an item that has already been passed - //through here - if none found, print message - $prereq_id = ''; - if(!empty($row['prereq_id'])){ - switch($row['prereq_type']){ - case 'c': - //chapter-type prereq - $prereq_id = $lp_chap_items[$row['prereq_id']]; - if(empty($prereq_id)){echo "Could not find prereq chapter ".$row['prereq_id']."
\n";} - break; - case 'i': - default: - //item type prereq - $prereq_id = $lp_items[$parent_lps[$row['chapter_id']]][$row['prereq_id']]; - if(empty($prereq_id)){echo "Could not find prereq item ".$row['prereq_id']."
\n";} - break; - } - } - $my_lp_item = Database::get_course_table($new_lp_item); - $ins_lp_sql = "INSERT INTO $my_new_lp_item (" . - "lp_id," . - "item_type," . - "ref, " . - "title," . - "description," . - "path, " . - "parent_item_id," . - "prerequisite," . - "display_order" . - ") VALUES (" . - "'".$lp_ids[$parent_lps[$row['chapter_id']]]."'," . //insert new learnpath ID - "'$type'," . - "'$ref', " . - "'".mysql_real_escape_string($row['title'])."'," . - "'".mysql_real_escape_string($row['description'])."'," . - "''," . - "".$lp_chap_items[$row['chapter_id']]."," . - "'$prereq_id'," . - $row['display_order']." " . - ")"; - $ins_res = api_sql_query($ins_lp_sql,__FILE__,__LINE__); - $in_id = Database::get_last_insert_id(); - //echo "  Inserted item $in_id (".$row['title'].")
\n"; - if(empty($in_id) OR $in_id == false) die('Could not insert lp_item: '.$ins_sql); - $lp_items[$parent_lps[$row['chapter_id']]][$row['id']] = $in_id; - $lp_ordered_items[$parent_lps[$row['chapter_id']]][$row['chapter_id']][] = $in_id; - - } - //echo "
lp_items:".print_r($lp_items,true)."
\n"; - // complete next_item_id field by going through the new table and looking at parent_id and display_order - $my_lp_item = Database::get_course_table($new_lp_item); - $order_sql = "SELECT * FROM $my_new_lp_item ORDER by lp_id ASC, parent_item_id ASC, display_order ASC"; - //echo "$order_sql
\n"; - $order_res = api_sql_query($order_sql,__FILE__,__LINE__); - $order_item = array(); //this will contain a sequential list of item_id's, thus allowing to give a simple way to get next id... - $lp_id = 0; - //echo "
";
-	while($row = Database::fetch_array($order_res))
-	{
-		//print_r($row);
-		if($row['lp_id'] != $lp_id)
-		{
-			//apply changes to the database and clean tool arrays
-			$last = 0;
-			foreach($order_item as $order_id => $item_id){
-				$next = 0;
-				if(!empty($order_item[$order_id+1])){
-					$next = $order_item[$order_id+1];
-				}
-				$upd = "UPDATE $my_new_lp_item " .
-						"SET next_item_id = ".$next."," .
-						"    previous_item_id = ".$last." " .
-						"WHERE id = ".$item_id;
-				//echo "$upd
\n"; - api_sql_query($upd,__FILE__,__LINE__); - $last = $item_id; - } - $order_item = array(); - $lp_id = $row['lp_id']; - $order_item[] = $row['id']; - }else{ - $order_item[] = $row['id']; - } - } - //process the last LP stack - $last = 0; - foreach($order_item as $order_id => $item_id){ - $next = 0; - if(!empty($order_item[$order_id+1])){ - $next = $order_item[$order_id+1]; - } - $upd = "UPDATE $my_new_lp_item " . - "SET next_item_id = ".$next."," . - " previous_item_id = ".$last." " . - "WHERE id = ".$item_id; - //echo "$upd
\n"; - api_sql_query($upd,__FILE__,__LINE__); - $last = $item_id; - } - - //echo "
\n"; - //MIGRATING THE learnpath_user TABLE (results) - $sql_lp_user = "SELECT * FROM $lp_user ORDER BY user_id, learnpath_id, learnpath_item_id"; - //echo "$sql_lp_user
\n"; - $res_lp_user = api_sql_query($sql_lp_user,__FILE__,__LINE__); - $user_id = 0; - $learnpath_id = 0; - $lp_view = 0; - while($row = Database::fetch_array($res_lp_user)) - { - if($row['user_id']!=$user_id OR $row['learnpath_id']!=$learnpath_id) //the user has changed or this is the first - { - //insert a new lp_view - $last = 0; - if(!empty($lp_chaps_list[$row['learnpath_id']][0])){ - $last = $lp_chaps_list[$row['learnpath_id']][0]; - } - if(empty($lp_ids[$row['learnpath_id']])){ - //this can be ignored as it means there was an LP before, this user - //used it, but now it's been removed - //echo "Somehow we also miss a lp_ids[".$row['learnpath_id']."] here
\n"; - $incoherences ++; - }else{ - $mylpid = $lp_ids[$row['learnpath_id']]; - $sql_ins_view = "INSERT INTO $my_new_lp_view(" . - "lp_id," . - "user_id," . - "view_count," . - "last_item" . - ")VALUES(" . - "".$mylpid."," . //new learnpath id - "".$row['user_id']."," . //user IDs stay the same - "1," . - "".$last."" . //use the first chapter from this learnpath - ")"; - //echo $sql_ins_view; - $res_ins_view = api_sql_query($sql_ins_view,__FILE__,__LINE__); - $in_id = Database::get_last_insert_id(); - $user_id = $row['user_id']; - $learnpath_id = $row['learnpath_id']; - $lp_view = $in_id; - } - } - //insert the record into lp_item_view - //TODO fix the whole in here (missing one item at least) - $my_new_lp_item_id = $lp_items[$learnpath_id][$row['learnpath_item_id']]; - if(empty($my_new_lp_item_id)){ - //this can be ignored safely as it just means a user used a learnpath_item - //before it was removed from items - maybe fix that in Dokeos? - //echo "Somehow we miss lp_items[".$learnpath_id."][".$row['learnpath_item_id']."] here...
"; - $incoherences ++; - }else{ - $sql_ins_iv = "INSERT INTO $my_new_lp_item_view(" . - "lp_item_id," . - "lp_view_id," . - "view_count," . - "start_time," . - "total_time," . - "score," . - "status" . - ")VALUES(" . - "".$lp_items[$learnpath_id][$row['learnpath_item_id']]."," . - "".$lp_view."," . - "1," . - "".(time()-86400)."," . - "".my_get_time($row['time'])."," . - "".$row['score']."," . - "'".$row['status']."'" . - ")"; - //echo $sql_ins_iv; - $res_ins_iv = api_sql_query($sql_ins_iv,__FILE__,__LINE__); - } - - } - - /** - * Move prerequisites - * TODO integrate prerequisites migration into learnpath_item migration - */ - - $msg = ''; - if($incoherences>0){ - $msg = "(found $incoherences incoherences between views and items - ignored)"; - } - /** - * Migrate links on the homepage as well now (look into the TABLE_TOOL_LIST table and - * update the links to newscorm/lp_controller.php?action=view&lp_id=x) - * Only normal learnpaths were visible from the homepage so we only need to update here - */ - $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST,$db); - $sql_tool = "SELECT * FROM $tbl_tool WHERE image='scormbuilder.gif' AND link LIKE '%learnpath_handler%'"; - $res_tool = api_sql_query($sql_tool,__FILE__,__LINE__); - while($row_tool = Database::fetch_array($res_tool)){ - $name = $row_tool['name']; - $link = $row_tool['link']; - //get old lp_id from there - $matches = array(); - if(preg_match('/learnpath_id=(\d+)$/',$link,$matches)){ - $old_lp_id = $matches[1]; - $new_lp_id = $lp_ids[$old_lp_id]; - $sql_tool_upd = "UPDATE $tbl_tool " . - "SET link='newscorm/lp_controller.php?action=view&lp_id=$new_lp_id' " . - "WHERE id = ".$row_tool['id']; - error_log('New LP - Migration - Updating tool table: '.$sql_tool_upd,0); - $res_tool_upd = api_sql_query($sql_tool_upd,__FILE__,__LINE__); - } - } - - - echo "Done!".$msg."
\n"; - flush(); - ob_flush(); -} -unset($lp_ids); -unset($lp_users); -unset($parent_chaps); -unset($lp_chap_items); -unset($ordered_chaps); -unset($lp_items); -unset($lp_ordered_items); -unset($parent_lps); - -/** - * SCORM - * The migration needs to take all data from the scorm.scorm_main and scorm.scorm_sco_data tables - * and add them to the new lp, lp_view, lp_item and lp_item_view tables. - */ -echo '

'.get_lang('NowStartingMigration')."
\n"; - -// Database table definitions -$scorm_main = Database::get_scorm_main_table($db); -$scorm_item = Database::get_scorm_sco_data_table($db); -$lp_main = Database::get_course_table(TABLE_LEARNPATH_MAIN,$db); -$course_pref = Database::get_course_table_prefix(); - -// initialisations -$lp_ids = array(); -$lp_item_ids = array(); -$lp_item_refs = array(); -$lp_course = array(); -$lp_course_code = array(); -$scorm_lp_paths = array(); - -//avoid empty dokeosCourse fields as they potentially break the rest -$course_main = Database::get_main_table(TABLE_MAIN_COURSE); -$sql_crs = "SELECT * FROM $course_main WHERE target_course_code IS NULL AND code = '$course_code'"; -echo "$sql_crs
\n"; -$res_crs = api_sql_query($sql_crs,__FILE__,__LINE__); -$num = Database::num_rows($res_crs); - -//prepare an array that will contain course codes and for each course code a list of lps [by path prefixed by '/'] -$scorms =array(); -$course_code_swap = ''; -$scormdocuments_lps = array(); -while($course_row = Database::fetch_array($res_crs)){ - - echo "
\nNow dealing with course ".$course_row['code']."...
\n"; - //check the validity of this new course - $my_course_code = $course_row['code']; - - //reinit the scormdocuments list - //$scormdocuments_lps = array(); - $db_name = $courses_id_list[$my_course_code]; - $tblscodoc = Database::get_course_table(TABLE_SCORMDOC,$db_name); - $sql_scodoc = "SELECT path FROM $tblscodoc WHERE path IS NOT NULL AND path != ''"; - echo "$sql_scodoc
"; - $res_scodoc = api_sql_query($sql_scodoc,__FILE__,__LINE__); - while($row_scodoc = Database::fetch_array($res_scodoc)){ - - //check if there's more than one slash in total - if(strpos($row_scodoc['path'],'/',1)===false){ - $tmp_path = $row_scodoc['path']; - echo "++Now opening $tmp_path
"; - - //add a prefixing slash if there is none - if(substr($tmp_path,0,1)!='/'){ - $tmp_path = '/'.$tmp_path; - } - - //if the path is just a slash, empty it - if($tmp_path=='/'){ - $tmp_path=''; - } - - //there is only one 'slash' sign at the beginning, - //or none at all, so we assume - //it is a main directory that should be taken as path - $courses_dir = api_get_path(SYS_COURSE_PATH).''.$courses_dir_list[$my_course_code].'/scorm'.$tmp_path; - if(!is_dir($courses_dir)){ - //echo "Scormdocument path $my_content_id: $tmp_path doesn't exist in ".api_get_path(SYS_COURSE_PATH).$courses_dir_list[$my_course_code]."/scorm, skipping
\n"; - continue; - //avoid if contentTitle is not the name of an existing directory - }elseif(!is_file($courses_dir."/imsmanifest.xml")){ - //if the imsmanifest file was not found there - echo "!!imsmanifest.xml not found at scormdocument's $courses_dir/imsmanifest.xml, skipping
\n"; - //try subdirectories on one level depth - echo "Trying subdirectories...
"; - $dh = opendir($courses_dir); - while($entry = readdir($dh)){ - if(substr($entry,0,1)!='.'){ - if(is_dir($courses_dir."/".$entry)){ - if(is_file($courses_dir."/".$entry."/imsmanifest.xml")){ - echo "... and found $courses_dir/$entry/imsmanifest.xml!
"; - if(!in_array($tmp_path."/".$entry."/imsmanifest.xml",$scormdocuments_lps)){ - echo "Recording.
"; - $scormdocuments_lps[] = $tmp_path."/".$entry; - } - } - } - } - } - }else{ - echo "Found scormdocument $tmp_path in ".api_get_path(SYS_COURSE_PATH).$courses_dir_list[$my_course_code]."/scorm, treating it.
\n"; - $scormdocuments_lps[] = $tmp_path; - } - } - } - - //prepare the new course's space in the scorms array - $scorms[$my_course_code] = array(); - - $sql_paths = "SELECT * FROM $scorm_main WHERE dokeosCourse = '".$my_course_code."'"; - echo "$sql_paths
"; - $res_paths = api_sql_query($sql_paths,__FILE__,__LINE__); - $num = Database::num_rows($res_paths); - while($scorm_row = Database::fetch_array($res_paths)){ - //check if this is a new course - $my_content_id = $scorm_row['contentId']; - $my_path = $scorm_row['contentTitle']; - if(substr($my_path,0,1)!='/'){ - $my_path = '/'.$my_path; - } - if($my_path=='/'){ - $my_path=''; - } - echo "++++Now opening $my_path
"; - if(!is_dir($courses_dir = api_get_path(SYS_COURSE_PATH).''.$courses_dir_list[$my_course_code].'/scorm'.$my_path)){ - echo "Path $my_content_id: $my_path doesn't exist in ".api_get_path(SYS_COURSE_PATH).$courses_dir_list[$my_course_code]."/scorm, skipping
\n"; - continue; - //avoid if contentTitle is not the name of an existing directory - }elseif(!is_file(api_get_path(SYS_COURSE_PATH).$courses_dir_list[$my_course_code].'/scorm'.$my_path."/imsmanifest.xml")){ - echo "!!imsmanifest.xml not found at ".api_get_path(SYS_COURSE_PATH).$courses_dir_list[$my_course_code].'/scorm'.$my_path."/imsmanifest.xml, skipping
\n"; - continue; - }else{ - echo "Found $my_path in ".api_get_path(SYS_COURSE_PATH).$courses_dir_list[$my_course_code]."/scorm".$mypath."/imsmanifest.xml, keeping it.
\n"; - $scorms[$my_course_code][$my_path] = $my_content_id; - } - } - //check if all the lps from scormdocuments_lps are already in the course array, - //otherwise add them (and set ID of 0 so no tracking will be available) - foreach($scormdocuments_lps as $path){ - if(!in_array($path,array_keys($scorms[$my_course_code]))){ - //add it (-1 means no ID) - echo "** Scormdocument path $path wasn't recorded yet. Added.
\n"; - $scorms[$my_course_code][$path] = -1; - } - } - $course_code_swap = $my_course_code; - unset($scormdocuments_lps); -} - -//echo "
courses_id_list: ".print_r($courses_id_list,true)."
\n"; - -echo "
\n---- Scorms array now contains ".count($scorms)." paths to migrate. Starting migration...
\n"; - -/** - * Looping through the SCO_MAIN table for SCORM learnpath attached to courses - * Order by course to try and reuse the maximum data - */ -$i_count = 0; -foreach($scorms as $my_course_code => $paths_list ) -{ - $max_dsp_lp = 0; - $course_lp_done = array(); - foreach($paths_list as $my_path => $old_id){ - echo "Migrating lp $my_path from course $my_course_code...
\n"; - $i_count ++; - //error_log('New LP - Migration script - Content '.$i_count.' on '.$num.' (course '.$scorm['dokeosCourse'].')',0); - //check if there is no embedded learnpaths into other learnpaths (one root-level and another embedded) - $embedded = false; - foreach($course_lp_done as $tmp_lp){ - if(empty($tmp_lp)){ - $tmp_lp = '/'; //allows finding the lp as a subitem, otherwise strstr returns false - } - if(strstr($my_path,$tmp_lp)===false){ - //let it be - }else{ - //this lp is embedded inside another lp who's imsmanifest exists, so prevent from parsing - echo "LP $my_path is embedded into $tmp_lp, ignoring...
\n"; - $embedded = true; - continue; - } - } - if($embedded){ - continue; - } - $course_lp_done[] = $my_path; - //echo "
scorm row: ".print_r($scorm,true)."
\n"; - $my_content_id = $old_id; - $my_path = $my_path; - $my_name = basename($my_path); - - if($my_content_id != -1){ - echo "This is a normal SCORM path
\n"; - $db_name = $courses_id_list[$my_course_code].'.'.$course_pref; - $scorm_lp_paths[$my_content_id]['path'] = $my_path; - //$scorm_lp_paths[$my_content_id]['ims'] = ''; - $table_name = $db_name.$new_lp; - $sql_ins = "INSERT INTO $table_name (" . - "lp_type," . - "name," . - "description," . - "path," . - "force_commit, " . - "default_encoding," . - "display_order," . - "content_maker," . - "content_local," . - "js_lib" . - ") VALUES (" . - "2," . - "'$my_name'," . - "''," . - "'$my_path'," . - "1," . - "'UTF-8'," . - "".$max_dsp_lp."," . - "'Unknown'," . - "'Unknown'," . - "'scorm_api.php'" . - ")"; - //echo "$sql_ins
\n"; - $sql_res = api_sql_query($sql_ins,__FILE__,__LINE__); - $in_id = Database::get_last_insert_id(); - if(empty($in_id) or $in_id == false) die('Could not insert scorm lp: '.$sql_ins); - //echo "  Inserted item $in_id
\n"; - $lp_ids[$my_content_id] = $in_id; //contains the old LP ID => the new LP ID - $lp_course[$my_content_id] = $courses_id_list[$my_course_code]; //contains the old learnpath ID => the course DB name - $lp_course_code[$my_content_id] = $my_course_code; - $max_dsp_lp++; - - //Setup the ims path (path to the imsmanifest.xml file) - //echo "Looking for course with code ".$lp_course_code[$my_content_id]." (using $my_content_id)
\n"; - $courses_dir = api_get_path(SYS_COURSE_PATH).''.$courses_dir_list[$lp_course_code[$my_content_id]]; - //$scorm_lp_paths[$my_content_id]['path'] = str_replace(' ','\\ ',$scorm_lp_paths[$my_content_id]['path']); - $sco_path_temp = ($scorm_lp_paths[$my_content_id]['path']=='/')?'':$scorm_lp_paths[$my_content_id]['path']; - $scorm_lp_paths[$my_content_id]['ims'] = $courses_dir.'/scorm'.$sco_path_temp.'/imsmanifest.xml'; - - //generate an imsmanifest object to get more info about the learnpath from the file - $oScorm = new scorm(); - //check if imsmanifest.xml exists at this location. If not, ignore the imsmanifest. - //That should have been done before already, now. - if(!is_file($scorm_lp_paths[$my_content_id]['ims'])){ - echo "!!! imsmanifest file not found at ".$scorm_lp_paths[$my_content_id]['ims'].' for old lp '.$my_content_id.' and new '.$lp_ids[$my_content_id]."
\n"; - $manifest = false; - }else{ - //echo "Parsing ".$scorm_lp_paths[$my_content_id]['ims']."
\n"; - //parse manifest file - $manifest = $oScorm->parse_manifest($scorm_lp_paths[$my_content_id]['ims']); - //the title is already escaped in the method - //$my_lp_title = mb_convert_encoding($oScorm->get_title(),'ISO-8859-1',$oScorm->manifest_encoding); - $my_lp_title = mb_convert_encoding($oScorm->get_title(),'ISO-8859-1','UTF-8'); - if(!empty($my_lp_title)){ - $my_new_lp = $db_name.$new_lp; - $my_sql = "UPDATE $my_new_lp " . - "SET name = '$my_lp_title', " . - "default_encoding = '".strtoupper($oScorm->manifest_encoding)."' " . - "WHERE id = ".$lp_ids[$my_content_id]; - echo "Updating title and encoding: ".$my_sql."
\n"; - $my_res = api_sql_query($my_sql,__FILE__,__LINE__); - } - } - - /* - * QUERY SCORM ITEMS FROM SCORM_SCO_DATA - * The danger here is that we might have several users for the same data, and so - * we have to avoid entering the same elements twice - */ - $sql_items = "SELECT * FROM $scorm_item WHERE contentId = '".$my_content_id."' ORDER BY scoId"; - //echo "$sql_items
\n"; - $res_items = api_sql_query($sql_items,__FILE__,__LINE__); - while($scormItem = Database::fetch_array($res_items)) - { - $my_sco_id = $scormItem['scoId']; //the index for display??? (check that) - $my_identifier = $scormItem['scoIdentifier']; //the scorm item path/name - $my_title = mysql_real_escape_string($scormItem['scoTitle']); - $my_status = $scormItem['status']; - $my_student = $scormItem['studentId']; - $my_score = $scormItem['score']; - $my_time = my_get_time($scormItem['time']); - $my_type = 'sco'; - //$my_item_path = $scorm_lp_paths[$my_content_id]['path']; - $my_item_path = ''; - - //echo "  FOUND item belonging to old learnpath num $my_content_id so belongs to course ".$lp_course[$my_content_id]."
\n"; - $my_new_lp_item = $db_name.$new_lp_item; - $my_new_lp_view = $db_name.$new_lp_view; - $my_new_lp_item_view = $db_name.$new_lp_item_view; - - /* - * Query items from the new table to check if it doesn't exist already - * Otherwise insert it - */ - $sel_sql = "SELECT * FROM $my_new_lp_item " . - "WHERE ref = '$my_identifier' " . - "AND lp_id = ".$lp_ids[$my_content_id].""; - //echo $sel_sql."
\n"; - $sel_res = api_sql_query($sel_sql,__FILE__,__LINE__); - if(Database::num_rows($sel_res)>0){ - //this item already exists, reuse - $row = Database::fetch_array($sel_res); - $item_insert_id = $row['lp_id']; - }else{ - $ins_sql = "INSERT INTO $my_new_lp_item (" . - "lp_id," . - "item_type," . - "ref," . - "title," . - "path" . - ") " . - "VALUES (" . - "'".$lp_ids[$my_content_id]."'," . //insert new learnpath ID - "'$my_type'," . - "'".$my_identifier."'," . - "'".$my_title."'," . - "'$my_item_path'" . - ")"; - $ins_res = api_sql_query($ins_sql,__FILE__,__LINE__); - $item_insert_id = Database::get_last_insert_id(); - $lp_item_ids[$lp_ids[$my_content_id]][$my_sco_id]=$item_insert_id; - $lp_item_refs[$lp_ids[$my_content_id]][$my_identifier]=$item_insert_id; - } - /* - * Check if a view is needed - */ - if($my_score != '' and $my_status != 'not attempted'){ - //it is worth creating an lp_view and an lp_item_view - otherwise not - $sel_sqlb = "SELECT * FROM $my_new_lp_view " . - "WHERE lp_id = ".$lp_ids[$my_content_id]." AND user_id = $my_student"; - $sel_resb = api_sql_query($sel_sqlb,__FILE__,__LINE__); - if(Database::num_rows($sel_resb)>0){ - //dont insert - $rowb = Database::fetch_array($sel_resb); - $view_insert_id = $rowb['id']; - }else{ - $ins_sql = "INSERT INTO $my_new_lp_view (" . - "lp_id," . - "user_id," . - "view_count" . - ") VALUES (" . - $lp_ids[$my_content_id].", " . - $my_student.", " . - "1" . - ")"; - $ins_res = api_sql_query($ins_sql,__FILE__,__LINE__); - $view_insert_id = Database::get_last_insert_id(); - } - $ins_sql = "INSERT INTO $my_new_lp_item_view (" . - "lp_item_id, lp_view_id, view_count," . - "start_time, total_time, score," . - "status" . - ") VALUES (" . - "$item_insert_id, $view_insert_id, 1," . - "0, $my_time, $my_score," . - "'$my_status'" . - ")"; - $ins_res = api_sql_query($ins_sql,__FILE__,__LINE__); - } - } - /* - * Set all information that might be more correct coming from imsmanifest - */ - - //$my_new_lp = $db_name.$new_lp; - //$my_new_lp_item = $db_name.$new_lp_item; - //$my_new_lp_view = $db_name.$new_lp_view; - //$my_new_lp_item_view = $db_name.$new_lp_item_view; - //$sel_sql = "SELECT * FROM $my_new_lp WHERE id = $in_id"; - //$res = @mysql_query($sel_sql); - //if(!$res){ - // echo "Error selecting lp: $sel_sql - ".mysql_error()."
\n"; - //} - $lp_details = array(); - //while($row = Database::fetch_array($res)) - //{ - $ordered_list = array(); - $mylist = array(); - foreach($oScorm->organizations as $org){ - //There should be only one organization (generally) - //and if there are more, we are not supposed to have been - //able to manage them before the new tool, so ignore - if(count($ordered_list)>0){ - break; - } - $ordered_list = $org->get_flat_items_list(); - } - $previous = 0; - $stock = array(0); - $level=0; - $parent_id = 0; - foreach($ordered_list as $index => $subarray) - { - //$subarray is an array representing one item and that contains info like - //identifier, level, rel_order, prerequisites, title, masteryscore, etc. - //echo "
Lookin for ".$subarray['identifier']." ".print_r($lp_item_refs,true)."
\n"; - if(!empty($lp_item_refs[$in_id][$subarray['identifier']])){ - $new_id = $lp_item_refs[$in_id][$subarray['identifier']]; - $next = 0; - $dsp = $subarray['rel_order']; - if($subarray['level']>$level){ - //getting one level deeper, just consult - $parent_id = $previous; - array_push($stock,$previous); - $level = $subarray['level']; - }elseif($subarray['level']==$level){ - //we are on the same level, going to the next id - //array_pop($stock); - //array_push($stock,$new_id); - }else{ - //getting back from one level deeper - array_pop($stock); - $parent_id = array_pop($stock); - array_push($stock,$parent_id); - $level = $subarray['level']; - } - if(!empty($ordered_list[$index+1]['identifier']) && !empty($lp_item_refs[$in_id][$ordered_list[$index+1]['identifier']])){ - $next = $lp_item_refs[$in_id][$ordered_list[$index+1]['identifier']]; - } - $path = $oScorm->get_res_path($subarray['identifierref']); - $update_path = ''; - if(!empty($path)){ - //if new path is not empty, update - $update_path = "path = '$path', "; - } - $type = $oScorm->get_res_type($subarray['identifierref']); - $update_type = ''; - if(!empty($type)){ - //if type is defined, update - $update_type = "item_type = '$type', "; - } - if(empty($path)){ - //if path is empty, it is a dir anyway - $update_type = "item_type = 'dir', "; - } - $prereq = $subarray['prerequisites']; - $update_prereq = ''; - if(!empty($prereq)){ - $update_prereq = "prerequisite = '$prereq', "; - } - - //we had previous data about this element, update - $sql2 = "UPDATE $my_new_lp_item " . - "SET parent_item_id = $parent_id, " . - "previous_item_id = $previous, " . - "next_item_id = $next, " . - $update_path. - $update_type. - $update_prereq. - "display_order = $dsp " . - "WHERE lp_id = ".$in_id." AND id = ".$new_id; - //echo "$sql2
\n"; - $res2 = api_sql_query($sql2,__FILE__,__LINE__); - $previous = $new_id; - } - } - /** - * Migrate links on the homepage as well now (look into the TABLE_TOOL_LIST table and - * update the links to newscorm/lp_controller.php?action=view&lp_id=x) - * See scorm_migrate_hometools.php - */ - //} - //end of case where $my_content_id != -1 - }else{ - echo "Importing LP $my_path from imsmanifest as it was only found in scormdocument
\n"; - //if $my_content_id = -1, this means the scorm didn't have any details in the scorm_sco_data - //table. As such, we'd better re-import it completely from the imsmanifest.xml file - //generate an imsmanifest object to get more info about the learnpath from the file - - //Setup the ims path (path to the imsmanifest.xml file) - //echo "Looking for course with code ".$lp_course_code[$my_content_id]." (using $my_content_id)
\n"; - $courses_dir = api_get_path(SYS_COURSE_PATH).''.$courses_dir_list[$my_course_code]; - $sco_path_temp = ($my_path=='/')?'':$my_path; - $sco_middle_path = (empty($sco_path_temp)?'':(substr($sco_path_temp,0,1)=='/')?substr($sco_path_temp,1).'/':$sco_path_temp.'/'); //same thing as sco_path_temp but with reversed slashes - $ims = $courses_dir.'/scorm'.$sco_path_temp.'/imsmanifest.xml'; - - $oScorm = new scorm(); - //check if imsmanifest.xml exists at this location. If not, ignore the imsmanifest. - //That should have been done before already, now. - if(!is_file($ims)){ - echo "!!! imsmanifest file not found at ".$ims.' for old lp '.$my_path.' from scormdocument'."
\n"; - $manifest = false; - }else{ - echo "Found imsmanifest ($ims), importing...
\n"; - if(!empty($sco_middle_path)){$oScorm->subdir = $sco_middle_path;} //this sets the subdir for the scorm package inside the scorm dir - //parse manifest file - $manifest = $oScorm->parse_manifest($ims); - //the title is already escaped in the method - $oScorm->import_manifest($my_course_code); - //TODO add code to update the path in that new lp created, as it probably uses / where - //$sco_path_temp should be used... - } - } - flush(); - } -} -echo "All done!"; -echo ""; -?> diff --git a/main/newscorm/scorm_migrate_db_reimport_manifest.php b/main/newscorm/scorm_migrate_db_reimport_manifest.php deleted file mode 100644 index 0913dfbf26..0000000000 --- a/main/newscorm/scorm_migrate_db_reimport_manifest.php +++ /dev/null @@ -1,44 +0,0 @@ - - */ -/** - * Include mandatory libraries - */ -require_once('back_compat.inc.php'); -require_once('learnpathItem.class.php'); -require_once('learnpath.class.php'); -require_once('scormItem.class.php'); -require_once('scormResource.class.php'); -require_once('scormMetadata.class.php'); -require_once('scormOrganization.class.php'); -require_once('scorm.class.php'); - -ini_set('max_execution_time',7200); - -function my_get_time($time){ - $matches = array(); - if(preg_match('/(\d{2}):(\d{2}):(\d{2})(\.\d*)?/',$time,$matches)){ - return ($matches[1]*3600)+($matches[2]*60)+($matches[3]); - } - else return 0; -} - -echo ""; - -/** - * New tables definition: - */ - -//unique course to update -$lp_id = mysql_real_escape_string($_GET['lp']); -if(empty($lp_id)){die('No lp_id provided, sorry');} -else{ - scorm::reimport_manifest(api_get_course_id(),$lp_id); -} - -echo "All done!"; -echo ""; -?> diff --git a/main/newscorm/scorm_migrate_hometools.php b/main/newscorm/scorm_migrate_hometools.php deleted file mode 100644 index cd6274561d..0000000000 --- a/main/newscorm/scorm_migrate_hometools.php +++ /dev/null @@ -1,50 +0,0 @@ - - */ -/** - * Include mandatory libraries - */ -require_once('back_compat.inc.php'); - -$sql = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE).""; -$res = api_sql_query($sql,__FILE__,__LINE__); -while ($row = Database::fetch_array($res)) -{ - //TODO change this db name construction to use DB instead of configuration.php settings - $course_pref = Database::get_course_table_prefix(); - $dbname = $row['db_name'].'.'.$course_pref; - $courses_list[] = $row['db_name']; - - //TODO add check for learnpath element. If not exist, create one. - $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST,$row['db_name']); - $sql_t = "UPDATE $tbl_tool SET link = 'newscorm/lp_controller.php' WHERE name='learnpath'"; - $res_t = api_sql_query($sql_t,__FILE__,__LINE__); - if(!$res_t){ - echo "SQL error with query: ".$sql_t." - ignoring
\n"; - } - $sql_s = "SELECT * FROM $tbl_tool WHERE link LIKE '%scorm/showinframes%'"; - $res_s = api_sql_query($sql_s,__FILE__,__LINE__); - if(!$res_s){ - echo "SQL error with query: ".$sql_s." - ignoring
\n"; - }else{ - $lp_id = 1; //distribute lp_ids at random, course tutors will modify links afterwards if needed - while($row_s = Database::fetch_array($res_s)){ - error_log('YWUPDTOOL - '.$row['code'].' -'.$row_s['link'],0); - $link = 'newscorm/lp_controller.php?cidReq='.$row['code'].'&action=view&lp_id='.$lp_id; - $sql_r = "UPDATE $tbl_tool SET link = '$link' WHERE id=".$row_s['id']; - //make sure we can revert by printing a list of updated links - echo $sql_r." (AND link='".$row_s['link']."')
\n"; - $res_r = api_sql_query($sql_r,__FILE__,__LINE__); - if(!$res_r){ - echo "SQL error with query: ".$sql_r." - ignoring
\n"; - } - $lp_id++; - - } - } -} -?> \ No newline at end of file diff --git a/main/newscorm/scorm_migrate_hometools_reverse.php b/main/newscorm/scorm_migrate_hometools_reverse.php deleted file mode 100644 index 1946ba7b46..0000000000 --- a/main/newscorm/scorm_migrate_hometools_reverse.php +++ /dev/null @@ -1,63 +0,0 @@ - - */ -/** - * Include mandatory libraries - */ -require_once('back_compat.inc.php'); - -$sql = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE).""; -$res = api_sql_query($sql,__FILE__,__LINE__); -while ($row = Database::fetch_array($res)) -{ - //TODO change this db name construction to use DB instead of configuration.php settings - $course_pref = Database::get_course_table_prefix(); - $dbname = $row['db_name'].'.'.$course_pref; - $courses_list[] = $row['db_name']; - - //TODO add check for learnpath element. If not exist, create one. - $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST,$row['db_name']); - $sql_t = "UPDATE $tbl_tool SET link = 'scorm/scormdocument.php' WHERE name='learnpath'"; - $res_t = @mysql_query($sql_t); - if(!$res_t){ - echo "SQL error with query: ".$sql_t." - ignoring
\n"; - } - $sql_s = "SELECT * FROM $tbl_tool WHERE link LIKE '%newscorm%'"; - $res_s = @mysql_query($sql_s); - if(!$res_s){ - echo "SQL error with query: ".$sql_s." - ignoring
\n"; - }else{ - $oldrow = mysql_fetch_array($res_s); - $oldlink = $oldrow['link']; - $match = preg_match('/lp_id=([0-9]{1,2})/',$oldlink); - if($match){ - $lp_id = $match[1]; - } - $sql_u = "SELECT path FROM lp WHERE id=".$lp_id; - $res_u = @mysql_query($sql_u); - $row_u = @mysql_fetch_array($res_u); - $oldpath = $row_u['path']; - $lp_id = 1; //distribute lp_ids at random, course tutors will modify links afterwards if needed - while($row_s = Database::fetch_array($res_s)){ - error_log('YWUPDTOOL - '.$row['code'].' -'.$row_s['link'],0); - $link = 'scorm/scormdocument.php?cidReq='.$row['code'].'&opendDir='.$oldpath; - //$link = 'newscorm/lp_controller.php?cidReq='.$row['code'].'&action=view&lp_id='.$lp_id; - $sql_r = "UPDATE $tbl_tool SET link = '$link' WHERE id=".$row_s['id']; - $res_r = @mysql_query($sql_r); - if(!$res_r){ - echo "SQL error with query: ".$sql_r." - ignoring
\n"; - } - $lp_id++; - - } - } -} -/** - * Update course description (intro page) to use new links instead of learnpath/learnpath_handler.php - */ - -?> \ No newline at end of file diff --git a/main/newscorm/scorm_update_db.php b/main/newscorm/scorm_update_db.php deleted file mode 100644 index 91e0aa209d..0000000000 --- a/main/newscorm/scorm_update_db.php +++ /dev/null @@ -1,166 +0,0 @@ - - */ -/** - * Script - */ -require_once('back_compat.inc.php'); -require_once('learnpath.class.php'); -require_once('scorm.class.php'); -/** - * New tables definition: - */ -//table replacing learnpath_main -$new_lp = 'lp'; -$create_lp = "CREATE TABLE IF NOT EXISTS XXX_$new_lp (" . - "id int unsigned primary key auto_increment," . //unique ID, generated by MySQL - "lp_type smallint unsigned not null," . //lp_types can be found in the main database's lp_type table - "name tinytext not null," . //name is the text name of the learning path (e.g. Word 2000) - "ref tinytext null," . //ref for SCORM elements is the SCORM ID in imsmanifest. For other learnpath types, just ignore - "description text null,". //textual description - "path text not null," . //path, starting at the platforms root (so all paths should start with 'courses/...' for now) - "force_commit tinyint unsigned not null default 0, " . //stores the default behaviour regarding SCORM information - "default_view_mod char(32) not null default 'embedded'," .//stores the default view mode (embedded or fullscreen) - "default_encoding char(32) not null default 'ISO-8859-1', " . //stores the encoding detected at learning path reading - "display_order int unsigned not null default 0," . //order of learnpaths display in the learnpaths list - not really important - "content_maker tinytext not null default ''," . //content maker (ENI, Articulate, ...) - "content_local varchar(32) not null default 'local'," . //content localisation ('local' or 'distant') - "content_license text not null default ''," . //content license - "prevent_reinit tinyint unsigned not null default 1," . //stores the default behaviour regarding items re-initialisation when viewed a second time after success - "js_lib tinytext not null default ''," . //the JavaScript library to load for this lp - "debug tinyint unsigned not null default 0" . //stores the default behaviour regarding items re-initialisation when viewed a second time after success - ")"; -//new table, aimed at keeping track of attempts made to one learning path -//no row exists if nobody has opened any learning path yet. A row is only written when someone opens a learnpath -$new_lp_view = 'lp_view'; -$create_lp_view = "CREATE TABLE IF NOT EXISTS XXX_$new_lp_view (" . - "id int unsigned primary key auto_increment," . //unique ID from MySQL - "lp_id int unsigned not null," . //learnpath ID from 'lp' - "user_id int unsigned not null," . //user ID from main.user - "view_count smallint unsigned not null default 0," . //integer counting the amount of times this learning path has been attempted - "last_item int unsigned not null default 0," . //last item seen in this view - "progress int unsigned default 0" . - ")"; -//table replacing learnpath_item AND learnpath_chapter -$new_lp_item = 'lp_item'; -$create_lp_item = "CREATE TABLE IF NOT EXISTS XXX_$new_lp_item (" . - "id int unsigned primary key auto_increment," . //unique ID from MySQL - "lp_id int unsigned not null," . //lp_id from 'lp' - "item_type char(32) not null default 'dokeos_document'," . //can be dokeos_document, dokeos_chapter or scorm_asset, scorm_sco, scorm_chapter - "ref tinytext not null default ''," . //the ID given to this item in the imsmanifest file - "title tinytext not null," . //the title/name of this item (to display in the T.O.C.) - "description tinytext not null default ''," . //the description of this item (to display in the T.O.C.) - "path text not null," . //the path to that item, starting at 'courses/...' level - "min_score float unsigned not null default 0," . //min score allowed - "max_score float unsigned not null default 100," . //max score allowed - "mastery_score float unsigned null," . //minimum score to pass the test - "parent_item_id int unsigned not null default 0," . //the item one level higher - "previous_item_id int unsigned not null default 0," . //the item before this one in the sequential learning order (MySQL id) - "next_item_id int unsigned not null default 0," . //the item after this one in the sequential learning order (MySQL id) - "display_order int unsigned not null default 0," . //this is needed for ordering items under the same parent (previous_item_id doesn't give correct order after reordering) - "prerequisite char(64) null," . //prerequisites in AICC scripting language as defined in the SCORM norm (allow logical operators) - "launch_data text not null default '', " . //data from imsmanifest - "parameters text not null default ''" . //data from imsmanifest - ")"; -//table replacing the learnpath_user table -$new_lp_item_view = 'lp_item_view'; -$create_lp_item_view = "CREATE TABLE IF NOT EXISTS XXX_$new_lp_item_view (" . - "id bigint unsigned primary key auto_increment," . //unique ID - "lp_item_id int unsigned not null," . //item ID (MySQL id) - "lp_view_id int unsigned not null," . // learning path view id (attempt) - "view_count int unsigned not null default 0," . //how many times this item has been viewed in the current attempt (generally 0 or 1) - "start_time int unsigned not null," . //when did the user open it? - "total_time int unsigned not null default 0," . //after how many seconds did he close it? - "score float unsigned not null default 0," . //score returned by SCORM or other techs - "status char(32) not null default 'not attempted'," . //status for this item (SCORM) - "suspend_data text null default ''," . - "lesson_location text null default ''" . - ")"; -//table implementing item_view interactions -$new_lp_iv_interaction = 'lp_iv_interaction'; -$create_lp_iv_interaction = "CREATE TABLE IF NOT EXISTS XXX_$new_lp_iv_interaction (" . - "id bigint unsigned primary key auto_increment," . - "order_id smallint unsigned not null default 0,". //internal order (0->...) given by Dokeos but usable by sco - "lp_iv_id bigint unsigned not null," . //identifier of the related sco_view - "interaction_id varchar(255) not null default ''," . //sco-specific, given by the sco - "interaction_type varchar(255) not null default ''," . //literal values, SCORM-specific (see p.63 of SCORM 1.2 RTE) - "weighting double not null default 0," . - "completion_time varchar(16) not null default ''," . //completion time for the interaction (timestamp in a day's time) - expected output format is scorm time - "correct_responses text not null default ''," . //actually a serialised array. See p.65 os SCORM 1.2 RTE) - "student_response text not null default ''," . //student response (format depends on type) - "result varchar(255) not null default ''," . //textual result - "latency varchar(16) not null default ''" . //time necessary for completion of the interaction - ")"; -//table located in the main DB and holding a list of the possible learning paths types. -//so far we only have 'dokeos' and 'scorm' -$new_lp_type = 'lp_type'; -$create_lp_type = "CREATE TABLE IF NOT EXISTS YYY_$new_lp_type (" . - "id smallint unsigned primary key auto_increment," . - "name char(32) not null default 'dokeos'," . - "description char(255) null" . - ")"; -/** - * First create the lp, lp_view, lp_item and lp_item_view tables in each course's DB - */ -$main_db = Database::get_main_database(); -$sql = "SELECT * FROM $main_db.course"; -echo "$sql
\n"; -$res = api_sql_query($sql); -$create_table = str_replace('YYY_',$main_db.'.',$create_lp_type); -echo "$create_table
\n"; -api_sql_query($create_table); -$ins_elems = "INSERT INTO $main_db.$new_lp_type (id,name,description) VALUES (1,'dokeos','The default format of a learning path in Dokeos')"; -api_sql_query($ins_elems); -$ins_elems = "INSERT INTO $main_db.$new_lp_type (id,name,description) VALUES (2,'scorm','SCORM format')"; -api_sql_query($ins_elems); - -$courses_list = array(); -$courses_id_list = array(); -$courses_dir_list = array(); -while ($row = Database::fetch_array($res)) -{ - //TODO change this db name construction to use DB instead of configuration.php settings - $course_pref = Database::get_course_table_prefix(); - $dbname = $row['db_name'].'.'.$course_pref; - $courses_list[] = $row['db_name']; - $courses_id_list[$row['code']] = $row['db_name']; - $courses_dir_list[$row['code']] = $row['directory']; - if(empty($_GET['delete'])){ - echo "Creating tables for ".$row['db_name']."
\n"; - $create_table = str_replace('XXX_',$dbname,$create_lp); - echo "$create_table
\n"; - api_sql_query($create_table); - $create_table = str_replace('XXX_',$dbname,$create_lp_view); - echo "$create_table
\n"; - api_sql_query($create_table); - $create_table = str_replace('XXX_',$dbname,$create_lp_item); - echo "$create_table
\n"; - api_sql_query($create_table); - $create_table = str_replace('XXX_',$dbname,$create_lp_item_view); - echo "$create_table
\n"; - api_sql_query($create_table); - $create_table = str_replace('XXX_',$dbname,$create_lp_iv_interaction); - echo "$create_table
\n"; - api_sql_query($create_table); - echo "

\n"; - }else{ - echo "Deleting tables for ".$row['db_name']."
\n"; - $del_sql = "DROP TABLE ".$dbname.$new_lp; - echo "$del_sql
\n"; - $del_sql = "DROP TABLE ".$dbname.$new_lp_view; - echo "$del_sql
\n"; - $del_sql = "DROP TABLE ".$dbname.$new_lp_item; - echo "$del_sql
\n"; - $del_sql = "DROP TABLE ".$dbname.$new_lp_item_view; - echo "$del_sql
\n"; - $del_sql = "DROP TABLE ".$dbname.$new_lp_iv_interaction; - echo "$del_sql
\n"; - echo "

\n"; - } -} -echo "Tables created/deleted for all courses
\n"; - -?> diff --git a/main/newscorm/scorm_update_db_alter.php b/main/newscorm/scorm_update_db_alter.php deleted file mode 100644 index b7a2d1c7fb..0000000000 --- a/main/newscorm/scorm_update_db_alter.php +++ /dev/null @@ -1,137 +0,0 @@ - - */ -/** - * Script - */ -require_once('back_compat.inc.php'); -require_once('learnpath.class.php'); -require_once('scorm.class.php'); -/** - * New tables definition: - */ -//table replacing learnpath_main -$new_lp = 'lp'; -$alter_lp = "ALTER TABLE XXX_$new_lp ADD COLUMN (" . - "content_license text not null default ''" . //content license - ")"; -$alter_lp2 = "ALTER TABLE XXX_$new_lp ADD COLUMN (" . - "prevent_reinit tinyint unsigned not null default 1" . //stores the default behaviour regarding items re-initialisation when viewed a second time after success - ")"; -$alter_lp3 = "ALTER TABLE XXX_$new_lp ADD COLUMN (" . - "debug tinyint unsigned not null default 0" . //stores the default behaviour regarding items re-initialisation when viewed a second time after success - ")"; -//new table, aimed at keeping track of attempts made to one learning path -//no row exists if nobody has opened any learning path yet. A row is only written when someone opens a learnpath -$new_lp_view = 'lp_view'; -$alter_lp_view = "ALTER TABLE XXX_$new_lp_view ADD COLUMN " . - "progress int unsigned default 0" . - ""; -//table replacing the learnpath_user table -$new_lp_item = 'lp_item'; -$alter_lp_item = "ALTER TABLE XXX_$new_lp_item ADD COLUMN " . - "parameters text null default ''" . - ""; -//table replacing the learnpath_user table -$new_lp_item_view = 'lp_item_view'; -$alter_lp_item_view = "ALTER TABLE XXX_$new_lp_item_view ADD COLUMN " . - "lesson_location text null default ''" . - ""; - -$new_lp_iv_interaction = 'lp_iv_interaction'; -$alter_lp_iv_interaction = "CREATE TABLE XXX_$new_lp_iv_interaction(" . - "id bigint unsigned AUTO_INCREMENT PRIMARY KEY," . - "order_id smallint unsigned not null default 0,". //internal order (0->...) given by Dokeos - "lp_iv_id bigint unsigned not null," . //identifier of the related sco_view - "interaction_id varchar(255) not null default ''," . //sco-specific, given by the sco - "interaction_type varchar(255) not null default ''," . //literal values, SCORM-specific (see p.63 of SCORM 1.2 RTE) - "weighting double not null default 0," . - "completion_time varchar(16) not null default ''," . //completion time for the interaction (timestamp in a day's time) - expected output format is scorm time - "correct_responses text not null default ''," . //actually a serialised array. See p.65 os SCORM 1.2 RTE) - "student_response text not null default ''," . //student response (format depends on type) - "result varchar(255) not null default ''," . //textual result - "latency varchar(16) not null default ''" . //time necessary for completion of the interaction - ")"; -$alter_lp_iv_interaction2 = "ALTER TABLE XXX_$new_lp_iv_interaction CHANGE `time` completion_time VARCHAR(16) NOT NULL DEFAULT '0'"; -$alter_lp_iv_interaction3 = "ALTER TABLE XXX_$new_lp_iv_interaction CHANGE `type` interaction_type VARCHAR(255) NOT NULL DEFAULT ''"; - -/** - * First create the lp, lp_view, lp_item and lp_item_view tables in each course's DB - */ -$main_db = Database::get_main_database(); -$sql = "SELECT * FROM $main_db.course"; -echo "$sql
\n"; -$res = api_sql_query($sql); - -$courses_list = array(); -$courses_id_list = array(); -$courses_dir_list = array(); -while ($row = Database::fetch_array($res)) -{ - //TODO change this db name construction to use DB instead of configuration.php settings - $course_pref = Database::get_course_table_prefix(); - $dbname = $row['db_name'].'.'.$course_pref; - $courses_list[] = $row['db_name']; - $courses_id_list[$row['code']] = $row['db_name']; - $courses_dir_list[$row['code']] = $row['directory']; - if(empty($_GET['delete'])){ - echo "Updating tables for ".$row['db_name']."
\n"; - if (mysql_query("SELECT content_license FROM $new_lp")==false) - { - $create_table = str_replace('XXX_',$dbname,$alter_lp); - echo "$create_table
\n"; - api_sql_query($create_table); - } - if (mysql_query("SELECT prevent_reinit FROM $new_lp")==false) - { - $create_table = str_replace('XXX_',$dbname,$alter_lp2); - echo "$create_table
\n"; - api_sql_query($create_table); - } - if (mysql_query("SELECT debug FROM $new_lp")==false) - { - $create_table = str_replace('XXX_',$dbname,$alter_lp3); - echo "$create_table
\n"; - api_sql_query($create_table); - } - if (mysql_query("SELECT progress FROM $new_lp_view")==false) - { - $create_table = str_replace('XXX_',$dbname,$alter_lp_view); - echo "$create_table
\n"; - api_sql_query($create_table); - } - if (mysql_query("SELECT parameters FROM $new_lp_item")==false) - { - $create_table = str_replace('XXX_',$dbname,$alter_lp_item); - echo "$create_table
\n"; - api_sql_query($create_table); - } - if (mysql_query("SELECT lesson_location FROM $new_lp_item_view")==false) - { - $create_table = str_replace('XXX_',$dbname,$alter_lp_item_view); - echo "$create_table
\n"; - api_sql_query($create_table); - } - if(mysql_query("SELECT id FROM $new_lp_iv_interaction")==false){ - $create_table = str_replace('XXX_',$dbname,$alter_lp_iv_interaction); - echo "$create_table
\n"; - api_sql_query($create_table); - } - if(mysql_query("SELECT `type` FROM $new_lp_iv_interaction")==false){ - $create_table = str_replace('XXX_',$dbname,$alter_lp_iv_interaction2); - echo "$create_table
\n"; - api_sql_query($create_table); - } - if(mysql_query("SELECT `time` FROM $new_lp_iv_interaction")==false){ - $create_table = str_replace('XXX_',$dbname,$alter_lp_iv_interaction3); - echo "$create_table
\n"; - api_sql_query($create_table); - } - echo "

\n"; - } -} -echo "Tables updated for all courses
\n"; -?> \ No newline at end of file