Version20151221150100.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. namespace Application\Migrations\Schema\V110;
  4. use Application\Migrations\AbstractMigrationChamilo;
  5. use Doctrine\DBAL\Schema\Schema;
  6. /**
  7. * Fix c_quiz_answer's correct field for id_auto
  8. */
  9. class Version20151221150100 extends AbstractMigrationChamilo
  10. {
  11. /**
  12. * @param Schema $schema
  13. */
  14. public function up(Schema $schema)
  15. {
  16. $this->addSql("ALTER TABLE c_quiz_answer ENGINE=InnoDB");
  17. $this->addSql("ALTER TABLE c_quiz_question ENGINE=InnoDB");
  18. $this->addSql("ALTER TABLE c_quiz_answer ADD INDEX idx_qa_question_id_temp (question_id)");
  19. $this->addSql("ALTER TABLE c_quiz_answer ADD INDEX idx_qa_id_temp (id)");
  20. $this->addSql("ALTER TABLE c_quiz_answer ADD INDEX idx_qa_correct_temp (correct)");
  21. $this->addSql("ALTER TABLE track_e_attempt CHANGE tms tms datetime default null");
  22. $this->addSql("UPDATE track_e_attempt SET tms = NULL WHERE tms = '0000-00-00 00:00:00'");
  23. $this->addSql("ALTER TABLE track_e_attempt ADD INDEX idx_tea_answer_temp (answer(6))");
  24. $this->addSql("ALTER TABLE c_quiz_question ADD INDEX idx_qq_id_temp (id)");
  25. $this->addSql("ALTER TABLE c_quiz_question ADD INDEX idx_qq_type_temp (type)");
  26. $this->addSql("
  27. UPDATE track_e_attempt a
  28. INNER JOIN c_quiz_answer qa
  29. ON (a.question_id = qa.question_id AND a.c_id = qa.c_id)
  30. INNER JOIN c_quiz_question q
  31. ON (qa.question_id = q.id AND qa.c_id = q.c_id)
  32. SET a.answer = qa.id_auto
  33. WHERE
  34. a.answer = qa.id AND
  35. q.c_id = a.c_id AND
  36. q.type IN (" . MATCHING . ", " . DRAGGABLE . ", " . MATCHING_DRAGGABLE . ")
  37. ");
  38. $this->addSql("
  39. UPDATE c_quiz_answer a
  40. INNER JOIN c_quiz_answer b
  41. ON (a.question_id = b.question_id AND b.c_id = a.c_id)
  42. INNER JOIN c_quiz_question q
  43. ON (b.question_id = q.id AND b.c_id = q.c_id)
  44. SET a.correct = b.id_auto
  45. WHERE
  46. a.correct = b.id AND
  47. q.c_id = a.c_id AND
  48. q.type IN (" . MATCHING . ", " . DRAGGABLE . ", " . MATCHING_DRAGGABLE . ")
  49. ");
  50. $this->addSql("ALTER TABLE c_quiz_answer DROP INDEX idx_qa_question_id_temp");
  51. $this->addSql("ALTER TABLE c_quiz_answer DROP INDEX idx_qa_id_temp");
  52. $this->addSql("ALTER TABLE c_quiz_answer DROP INDEX idx_qa_correct_temp");
  53. $this->addSql("ALTER TABLE track_e_attempt DROP INDEX idx_tea_answer_temp");
  54. $this->addSql("ALTER TABLE c_quiz_question DROP INDEX idx_qq_id_temp");
  55. $this->addSql("ALTER TABLE c_quiz_question DROP INDEX idx_qq_type_temp");
  56. }
  57. /**
  58. * @param Schema $schema
  59. */
  60. public function down(Schema $schema)
  61. {
  62. }
  63. }