fix_lp_items_not_found.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * This script try to fix the lp items path for missing files
  4. * It's useful when the path field in c_lp_item table has a value like 'document/item_file.html'
  5. * Then this values is updated to 'document/learning_path/LP_DIRECTORY/item_file.html
  6. */
  7. exit;
  8. require_once '../../main/inc/global.inc.php';
  9. /** @var The course id $courseId */
  10. $courseId = 0;
  11. /** @var The LP id $lpId */
  12. $lpId = 0;
  13. $tblCLp = Database::get_course_table(TABLE_LP_MAIN);
  14. $tblCLpItem = Database::get_course_table(TABLE_LP_ITEM);
  15. $course = api_get_course_info_by_id($courseId);
  16. $lp = Database::fetch_assoc(
  17. Database::query("SELECT path FROM $tblCLp WHERE c_id = $courseId AND id = $lpId")
  18. );
  19. $items = Database::store_result(
  20. Database::query("SELECT id, c_id, lp_id, path FROM $tblCLpItem WHERE c_id = $courseId AND lp_id = $lpId"),
  21. 'ASSOC'
  22. );
  23. $scormDir = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/scorm/' . $lp['path'] . '/';
  24. /** @var array $item */
  25. foreach ($items as $item) {
  26. $fixedDirectory = "document/learning_path/{$lp['path']}/";
  27. $oldPath = $scormDir . $item['path'];
  28. $newPath = $scormDir . str_replace('document/', $fixedDirectory, $item['path']);
  29. if (!file_exists($oldPath) && file_exists($newPath)) {
  30. $sql = "
  31. UPDATE $tblCLpItem
  32. SET path = REPLACE(path, 'document/', '$fixedDirectory')
  33. WHERE c_id = {$item['c_id']} AND lp_id = {$item['lp_id']} AND id = {$item['id']}
  34. ";
  35. Database::query($sql);
  36. echo "Executing: $sql" . PHP_EOL;
  37. }
  38. }