delete_orphan_questions.php 778 B

1234567891011121314151617181920212223242526
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. exit;
  4. require_once __DIR__ . '/../../main/inc/global.inc.php';
  5. $sql = 'SELECT iid, c_id, question
  6. FROM c_quiz_question
  7. WHERE iid not in (SELECT question_id from c_quiz_rel_question)
  8. ORDER BY iid';
  9. $result = Database::query($sql);
  10. $data = Database::store_result($result);
  11. $counter = 1;
  12. $totalQuestions = count($data);
  13. echo 'Questions to delete: '.$totalQuestions.PHP_EOL;
  14. foreach ($data as $row) {
  15. $courseInfo = api_get_course_info_by_id($row['c_id']);
  16. $question = Question::read($row['iid'], $courseInfo);
  17. if (empty($question->exerciseList)) {
  18. $question->delete(1);
  19. }
  20. echo 'Deleting question '.$counter.'/'.$totalQuestions.' - #'.$row['iid'].PHP_EOL;
  21. $counter++;
  22. }