Version20150522112023.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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');
  20. if (!$schema->hasTable('usergroup_rel_usergroup')) {
  21. $this->addSql(
  22. '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))'
  23. );
  24. }
  25. $this->addSql('ALTER TABLE usergroup_rel_user ADD relation_type INT');
  26. if (!$schema->hasTable('access_url_rel_usergroup')) {
  27. $this->addSql(
  28. 'CREATE TABLE access_url_rel_usergroup (id INT AUTO_INCREMENT NOT NULL, access_url_id INT NOT NULL, usergroup_id INT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
  29. );
  30. $sql = 'SELECT * FROM usergroup';
  31. $result = $this->connection->query($sql);
  32. $results = $result->fetchAll();
  33. foreach ($results as $result) {
  34. $groupId = $result['id'];
  35. $sql = "INSERT INTO access_url_rel_usergroup (access_url_id, usergroup_id) VALUES ('1', '$groupId')";
  36. $this->addSql($sql);
  37. }
  38. }
  39. }
  40. /**
  41. * @param Schema $schema
  42. */
  43. public function down(Schema $schema)
  44. {
  45. $this->addSql('DROP TABLE access_url_rel_usergroup');
  46. }
  47. }