Version20150522112023.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. * Usergroup changes
  8. */
  9. class Version20150522112023 extends AbstractMigrationChamilo
  10. {
  11. /**
  12. * @param Schema $schema
  13. */
  14. public function up(Schema $schema)
  15. {
  16. // Set 0 if there's no group category.
  17. $this->addSql('UPDATE c_group_info SET category_id = 0 WHERE category_id = 2');
  18. $this->addSql('ALTER TABLE usergroup ADD group_type INT NOT NULL, ADD created_at DATETIME NOT NULL, ADD updated_at DATETIME NOT NULL');
  19. $this->addSql('ALTER TABLE usergroup ADD picture VARCHAR(255) DEFAULT NULL, ADD url VARCHAR(255) DEFAULT NULL, ADD visibility VARCHAR(255) NOT NULL, ADD allow_members_leave_group INT NOT NULL, CHANGE description description LONGTEXT DEFAULT NULL');
  20. $this->addSql('CREATE TABLE usergroup_rel_usergroup (id INT AUTO_INCREMENT NOT NULL, group_id INT NOT NULL, subgroup_id INT NOT NULL, relation_type INT NOT NULL, PRIMARY KEY(id));');
  21. $this->addSql('ALTER TABLE usergroup_rel_user ADD relation_type INT');
  22. if (!$schema->hasTable('access_url_rel_usergroup')) {
  23. $this->addSql(
  24. 'CREATE TABLE access_url_rel_usergroup (id INT UNSIGNED AUTO_INCREMENT NOT NULL, access_url_id INT UNSIGNED NOT NULL, usergroup_id INT UNSIGNED NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
  25. );
  26. $sql = 'SELECT * FROM usergroup';
  27. $result = $this->connection->query($sql);
  28. $results = $result->fetchAll();
  29. foreach ($results as $result) {
  30. $groupId = $result['id'];
  31. $sql = "INSERT INTO access_url_rel_usergroup (access_url_id, usergroup_id) VALUES ('1', '$groupId')";
  32. $this->addSql($sql);
  33. }
  34. }
  35. }
  36. /**
  37. * @param Schema $schema
  38. */
  39. public function down(Schema $schema)
  40. {
  41. $this->addSql('DROP TABLE access_url_rel_usergroup');
  42. }
  43. }