scorm_migrate_hometools.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php //$id: $
  2. /**
  3. * Script handling the migration between an old Dokeos platform (<1.8.0) to
  4. * setup the course's tools so that they use the new code directory for SCORM
  5. * @package dokeos.scorm
  6. * @author Yannick Warnier <ywarnier@beeznest.org>
  7. */
  8. /**
  9. * Include mandatory libraries
  10. */
  11. require_once('back_compat.inc.php');
  12. $sql = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE)."";
  13. $res = api_sql_query($sql,__FILE__,__LINE__);
  14. while ($row = Database::fetch_array($res))
  15. {
  16. //TODO change this db name construction to use DB instead of configuration.php settings
  17. $course_pref = Database::get_course_table_prefix();
  18. $dbname = $row['db_name'].'.'.$course_pref;
  19. $courses_list[] = $row['db_name'];
  20. //TODO add check for learnpath element. If not exist, create one.
  21. $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST,$row['db_name']);
  22. $sql_t = "UPDATE $tbl_tool SET link = 'newscorm/lp_controller.php' WHERE name='learnpath'";
  23. $res_t = api_sql_query($sql_t,__FILE__,__LINE__);
  24. if(!$res_t){
  25. echo "SQL error with query: ".$sql_t." - ignoring<br/>\n";
  26. }
  27. $sql_s = "SELECT * FROM $tbl_tool WHERE link LIKE '%scorm/showinframes%'";
  28. $res_s = api_sql_query($sql_s,__FILE__,__LINE__);
  29. if(!$res_s){
  30. echo "SQL error with query: ".$sql_s." - ignoring<br/>\n";
  31. }else{
  32. $lp_id = 1; //distribute lp_ids at random, course tutors will modify links afterwards if needed
  33. while($row_s = Database::fetch_array($res_s)){
  34. error_log('YWUPDTOOL - '.$row['code'].' -'.$row_s['link'],0);
  35. $link = 'newscorm/lp_controller.php?cidReq='.$row['code'].'&action=view&lp_id='.$lp_id;
  36. $sql_r = "UPDATE $tbl_tool SET link = '$link' WHERE id=".$row_s['id'];
  37. //make sure we can revert by printing a list of updated links
  38. echo $sql_r." (AND link='".$row_s['link']."')<br/>\n";
  39. $res_r = api_sql_query($sql_r,__FILE__,__LINE__);
  40. if(!$res_r){
  41. echo "SQL error with query: ".$sql_r." - ignoring<br/>\n";
  42. }
  43. $lp_id++;
  44. }
  45. }
  46. }
  47. ?>