Version20160727155600.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. namespace Application\Migrations\Schema\V111;
  4. use Application\Migrations\AbstractMigrationChamilo;
  5. use Doctrine\DBAL\Schema\Schema;
  6. use Chamilo\CoreBundle\Entity\BranchSync;
  7. /**
  8. * Class Version20160727155600
  9. * Add an initial branch_sync
  10. * @package Application\Migrations\Schema\V111
  11. */
  12. class Version20160727155600 extends AbstractMigrationChamilo
  13. {
  14. /**
  15. * @param Schema $schema
  16. */
  17. public function up(Schema $schema)
  18. {
  19. $sql = "SELECT COUNT(id) as count FROM branch_sync";
  20. $result = $this->connection->executeQuery($sql)->fetch();
  21. $count = $result['count'];
  22. if (!$count) {
  23. $unique = sha1(uniqid());
  24. $sql = "INSERT INTO branch_sync (branch_name, unique_id, access_url_id) VALUES ('localhost', '$unique', '1')";
  25. $this->addSql($sql);
  26. }
  27. }
  28. /**
  29. * @param Schema $schema
  30. */
  31. public function down(Schema $schema)
  32. {
  33. $em = $this->getEntityManager();
  34. $branchSync = $em
  35. ->getRepository('ChamiloCoreBundle:BranchSync')
  36. ->findOneBy([
  37. 'branchName' => 'localhost',
  38. 'accessUrlId' => 1
  39. ]);
  40. $em->remove($branchSync);
  41. $em->flush();
  42. }
  43. }