fix_lp_items_not_found.php 1.5 KB

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