Version20150505132304.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. * Extra fields changes
  8. */
  9. class Version20150505132304 extends AbstractMigrationChamilo
  10. {
  11. /**
  12. * @param Schema $schema
  13. */
  14. public function up(Schema $schema)
  15. {
  16. // Force table creation in order to do updates/insert later.
  17. $this->connection->executeQuery('CREATE TABLE IF NOT EXISTS extra_field (id INT AUTO_INCREMENT NOT NULL, extra_field_type INT NOT NULL, field_type INT NOT NULL, variable VARCHAR(64) NOT NULL, display_text VARCHAR(255) DEFAULT NULL, default_value LONGTEXT, field_order INT DEFAULT NULL, visible TINYINT(1) DEFAULT NULL, changeable TINYINT(1) DEFAULT NULL, filter TINYINT(1) DEFAULT NULL, created_at DATETIME NOT NULL, PRIMARY KEY(id))');
  18. $this->connection->executeQuery('CREATE TABLE IF NOT EXISTS extra_field_values (id INT AUTO_INCREMENT NOT NULL, value VARCHAR(255) DEFAULT NULL, field_id INT NOT NULL, item_id INT NOT NULL, comment LONGTEXT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(id))');
  19. $this->connection->executeQuery('CREATE TABLE IF NOT EXISTS extra_field_options (id INT AUTO_INCREMENT NOT NULL, field_id INT DEFAULT NULL, option_value LONGTEXT, display_text VARCHAR(64) DEFAULT NULL, option_order INT DEFAULT NULL, priority VARCHAR(255) DEFAULT NULL, priority_message VARCHAR(255) DEFAULT NULL, INDEX IDX_A572E3AE443707B0 (field_id), PRIMARY KEY(id))');
  20. if (!$schema->hasTable('extra_field_options')) {
  21. $this->connection->executeQuery(
  22. 'ALTER TABLE extra_field_options ADD CONSTRAINT FK_A572E3AE443707B0 FOREIGN KEY (field_id) REFERENCES extra_field (id)'
  23. );
  24. }
  25. $this->addSql('CREATE TABLE IF NOT EXISTS extra_field_option_rel_field_option (id INT AUTO_INCREMENT NOT NULL, field_id INT DEFAULT NULL, field_option_id INT DEFAULT NULL, related_field_option_id INT DEFAULT NULL, role_id INT DEFAULT NULL, UNIQUE INDEX idx (field_id, role_id, field_option_id, related_field_option_id), PRIMARY KEY(id))');
  26. /*
  27. $this->addSql('DROP TABLE course_field');
  28. $this->addSql('DROP TABLE course_field_options');
  29. $this->addSql('DROP TABLE course_field_values');
  30. $this->addSql('DROP TABLE session_field');
  31. $this->addSql('DROP TABLE session_field_options');
  32. $this->addSql('DROP TABLE session_field_values');
  33. $this->addSql('DROP TABLE user_field');
  34. $this->addSql('DROP TABLE user_field_options');
  35. $this->addSql('DROP TABLE user_field_values');
  36. */
  37. }
  38. /**
  39. * @param Schema $schema
  40. */
  41. public function postUp(Schema $schema)
  42. {
  43. }
  44. /**
  45. * @param Schema $schema
  46. */
  47. public function down(Schema $schema)
  48. {
  49. $this->addSql('ALTER TABLE extra_field_options DROP FOREIGN KEY FK_A572E3AE443707B0');
  50. $this->addSql('DROP TABLE extra_field_option_rel_field_option');
  51. $this->addSql('DROP TABLE extra_field_options');
  52. $this->addSql('DROP TABLE extra_field');
  53. $this->addSql('DROP TABLE extra_field_values');
  54. }
  55. }