fix_duplicate_tool_icons.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. require_once dirname(__FILE__).'/../../main/inc/global.inc.php';
  3. $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
  4. $tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  5. $sql = "SELECT * FROM $course_table ";
  6. $result = Database::query($sql);
  7. $course_list = Database::store_result($result);
  8. if (!empty($course_list)) {
  9. foreach ($course_list as $course) {
  10. $sql = "SELECT id, name FROM $tool_table WHERE c_id = {$course['id']} ";
  11. $tool_result = Database::query($sql);
  12. $all_tools = Database::store_result($tool_result);
  13. $tools_added = array();
  14. $deleted = false;
  15. if (!empty($all_tools)) {
  16. foreach ($all_tools as $tool) {
  17. if (isset($tools_added[$tool['name']])) {
  18. $sql = "DELETE FROM $tool_table WHERE c_id = {$course['id']} AND id = {$tool['id']}";
  19. Database::query($sql);
  20. $deleted = true;
  21. } else {
  22. $tools_added[$tool['name']] = true;
  23. }
  24. }
  25. if ($deleted) {
  26. error_log("Removing doubles tools from course {$course['id']}");
  27. } else {
  28. error_log("Nothing to delete from course {$course['id']}");
  29. }
  30. }
  31. }
  32. }