detect_deleted_visible_documents.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Detects visible _DELETED_ visible files
  5. */
  6. exit;
  7. require __DIR__.'/../../main/inc/global.inc.php';
  8. api_protect_admin_script();
  9. // Define origin and destination courses' code
  10. $debug = true;
  11. $document = Database::get_course_table(TABLE_DOCUMENT);
  12. $itemProperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
  13. $sql = "SELECT i.* FROM $document d
  14. INNER JOIN $itemProperty i
  15. ON (d.c_id = i.c_id AND i.ref = d.id AND d.session_id = i.session_id)
  16. WHERE
  17. d.path LIKE '%_DELETED_%' AND
  18. i.visibility IN (1, 0) AND
  19. tool = 'document'
  20. ";
  21. $result = Database::query($sql);
  22. $docs = Database::store_result($result);
  23. if (!empty($docs)) {
  24. foreach ($docs as $doc) {
  25. $courseId = $doc['c_id'];
  26. $ref = $doc['ref'];
  27. $sessionId = $doc['id_session'];
  28. $sql = "UPDATE $itemProperty
  29. SET visibility = 2
  30. WHERE
  31. c_id = $courseId AND
  32. session_id = $sessionId AND
  33. ref = $ref AND
  34. tool = 'document'
  35. ";
  36. var_dump($sql);
  37. //Database::query($sql);
  38. }
  39. }