Version20150528103216.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. * Session date changes
  8. */
  9. class Version20150528103216 extends AbstractMigrationChamilo
  10. {
  11. /**
  12. * @param Schema $schema
  13. */
  14. public function up(Schema $schema)
  15. {
  16. $this->addSql('ALTER TABLE session ADD COLUMN access_start_date datetime');
  17. $this->addSql('ALTER TABLE session ADD COLUMN access_end_date datetime');
  18. $this->addSql('ALTER TABLE session ADD COLUMN coach_access_start_date datetime');
  19. $this->addSql('ALTER TABLE session ADD COLUMN coach_access_end_date datetime');
  20. $this->addSql('ALTER TABLE session ADD COLUMN display_start_date datetime');
  21. $this->addSql('ALTER TABLE session ADD COLUMN display_end_date datetime');
  22. $this->addSql('UPDATE session SET access_start_date = date_start');
  23. $this->addSql("UPDATE session SET access_end_date = CONVERT(CONCAT(date_end, ' 23:59:59'), DATETIME)");
  24. $this->addSql('UPDATE session SET coach_access_start_date = CONVERT(DATE_SUB(date_start, INTERVAL nb_days_access_before_beginning DAY), DATETIME) ');
  25. $this->addSql('UPDATE session SET coach_access_start_date = NULL WHERE nb_days_access_before_beginning = 0');
  26. $this->addSql('UPDATE session SET coach_access_end_date = CONVERT(DATE_ADD(date_end, INTERVAL nb_days_access_after_end DAY), DATETIME) ');
  27. $this->addSql('UPDATE session SET coach_access_end_date = NULL WHERE nb_days_access_after_end = 0');
  28. $this->addSql('UPDATE session SET display_start_date = access_start_date');
  29. $this->addSql('UPDATE session SET display_end_date = access_end_date');
  30. // Set dates to NULL
  31. $this->addSql('UPDATE session SET access_start_date = NULL WHERE access_start_date = "0000-00-00 00:00:00"');
  32. $this->addSql('UPDATE session SET access_end_date = NULL WHERE access_end_date = "0000-00-00 00:00:00"');
  33. $this->addSql('UPDATE session SET access_start_date = NULL WHERE access_start_date = "0000-00-00 23:59:59"');
  34. $this->addSql('UPDATE session SET access_end_date = NULL WHERE access_end_date = "0000-00-00 23:59:59"');
  35. $this->addSql('UPDATE session SET coach_access_start_date = NULL WHERE coach_access_start_date = "0000-00-00 00:00:00"');
  36. $this->addSql('UPDATE session SET coach_access_end_date = NULL WHERE coach_access_end_date = "0000-00-00 00:00:00"');
  37. $this->addSql('UPDATE session SET coach_access_start_date = NULL WHERE coach_access_start_date = "0000-00-00 23:59:59"');
  38. $this->addSql('UPDATE session SET coach_access_end_date = NULL WHERE coach_access_end_date = "0000-00-00 23:59:59"');
  39. $this->addSql('UPDATE session SET display_start_date = NULL WHERE display_start_date = "0000-00-00 00:00:00"');
  40. $this->addSql('UPDATE session SET display_end_date = NULL WHERE display_end_date = "0000-00-00 00:00:00"');
  41. $this->addSql('UPDATE session SET display_start_date = NULL WHERE display_start_date = "0000-00-00 23:59:59"');
  42. $this->addSql('UPDATE session SET display_end_date = NULL WHERE display_end_date = "0000-00-00 23:59:59"');
  43. }
  44. /**
  45. * @param Schema $schema
  46. */
  47. public function down(Schema $schema)
  48. {
  49. $this->addSql('ALTER TABLE session CREATE date_start date NOT NULL');
  50. $this->addSql('ALTER TABLE session CREATE date_end date NOT NULL');
  51. $this->addSql('ALTER TABLE session CREATE nb_days_access_before_beginning TINYINT');
  52. $this->addSql('ALTER TABLE session CREATE nb_days_access_after_end TINYINT');
  53. $this->addSql('UPDATE session SET date_start = access_start_date');
  54. $this->addSql('UPDATE session SET date_end = access_end_date');
  55. $this->addSql('UPDATE session SET nb_days_access_before_beginning = DATEDIFF(access_start_date, coach_access_start_date) WHERE access_start_date != coach_access_start_date AND coach_access_start_date IS NOT NULL');
  56. $this->addSql('UPDATE session SET nb_days_access_after_end = DATEDIFF(coach_access_end_date, coach_access_end_date) WHERE access_end_date != coach_access_end_date AND coach_access_end_date IS NOT NULL');
  57. $this->addSql('UPDATE session SET nb_days_access_before_beginning = 0 WHERE access_start_date = coach_access_start_date OR coach_access_start_date IS NULL');
  58. $this->addSql('UPDATE session SET nb_days_access_after_end = 0 WHERE access_end_date = coach_access_end_date OR coach_access_end_date IS NULL');
  59. $this->addSql('ALTER TABLE session DROP access_start_date');
  60. $this->addSql('ALTER TABLE session DROP access_end_date');
  61. $this->addSql('ALTER TABLE session DROP coach_access_start_date');
  62. $this->addSql('ALTER TABLE session DROP coach_access_end_date');
  63. $this->addSql('ALTER TABLE session DROP display_start_date');
  64. $this->addSql('ALTER TABLE session DROP display_end_date');
  65. }
  66. }