scorm_migrate_hometools_reverse.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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(MAIN_COURSE_TABLE)."";
  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 claro_main.conf 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(TOOL_LIST_TABLE,$row['db_name']);
  22. $sql_t = "UPDATE $tbl_tool SET link = 'scorm/scormdocument.php' WHERE name='learnpath'";
  23. $res_t = @mysql_query($sql_t);
  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 '%newscorm%'";
  28. $res_s = @mysql_query($sql_s);
  29. if(!$res_s){
  30. echo "SQL error with query: ".$sql_s." - ignoring<br/>\n";
  31. }else{
  32. $oldrow = mysql_fetch_array($res_s);
  33. $oldlink = $oldrow['link'];
  34. $match = preg_match('/lp_id=([0-9]{1,2})/',$oldlink);
  35. if($match){
  36. $lp_id = $match[1];
  37. }
  38. $sql_u = "SELECT path FROM lp WHERE id=".$lp_id;
  39. $res_u = @mysql_query($sql_u);
  40. $row_u = @mysql_fetch_array($res_u);
  41. $oldpath = $row_u['path'];
  42. $lp_id = 1; //distribute lp_ids at random, course tutors will modify links afterwards if needed
  43. while($row_s = Database::fetch_array($res_s)){
  44. error_log('YWUPDTOOL - '.$row['code'].' -'.$row_s['link'],0);
  45. $link = 'scorm/scormdocument.php?cidReq='.$row['code'].'&opendDir='.$oldpath;
  46. //$link = 'newscorm/lp_controller.php?cidReq='.$row['code'].'&action=view&lp_id='.$lp_id;
  47. $sql_r = "UPDATE $tbl_tool SET link = '$link' WHERE id=".$row_s['id'];
  48. $res_r = @mysql_query($sql_r);
  49. if(!$res_r){
  50. echo "SQL error with query: ".$sql_r." - ignoring<br/>\n";
  51. }
  52. $lp_id++;
  53. }
  54. }
  55. }
  56. /**
  57. * Update course description (intro page) to use new links instead of learnpath/learnpath_handler.php
  58. */
  59. ?>