Version20150504182600.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. * Class Version20150504182600
  8. *
  9. * @package Application\Migrations\Schema\V110
  10. */
  11. class Version20150504182600 extends AbstractMigrationChamilo
  12. {
  13. /**
  14. * @param Schema $schema
  15. *
  16. * @throws \Doctrine\DBAL\Schema\SchemaException
  17. */
  18. public function up(Schema $schema)
  19. {
  20. // Set parent language to Spanish for all close-by languages. Same for Italian,
  21. // French, Portuguese and Chinese
  22. $connection = $this->connection;
  23. $sql = "SELECT id, english_name
  24. FROM language
  25. WHERE english_name IN ('spanish', 'italian', 'portuguese', 'simpl_chinese', 'french')";
  26. $result = $connection->executeQuery($sql);
  27. $dataList = $result->fetchAll();
  28. $languages = array();
  29. if (!empty($dataList)) {
  30. foreach ($dataList as $data) {
  31. $languages[$data['english_name']] = $data['id'];
  32. }
  33. }
  34. $this->addSql("
  35. UPDATE language SET parent_id = " . $languages['spanish'] . " WHERE english_name = 'quechua_cusco'
  36. ");
  37. $this->addSql("
  38. UPDATE language SET parent_id = " . $languages['spanish'] . " WHERE english_name = 'galician'
  39. ");
  40. $this->addSql("
  41. UPDATE language SET parent_id = " . $languages['spanish'] . " WHERE english_name = 'esperanto'
  42. ");
  43. $this->addSql("
  44. UPDATE language SET parent_id = " . $languages['spanish'] . " WHERE english_name = 'catalan'
  45. ");
  46. $this->addSql("
  47. UPDATE language SET parent_id = " . $languages['spanish'] . " WHERE english_name = 'asturian'
  48. ");
  49. $this->addSql("
  50. UPDATE language SET parent_id = " . $languages['spanish'] . " WHERE english_name = 'friulian'
  51. ");
  52. $this->addSql("
  53. UPDATE language SET parent_id = " . $languages['french'] . " WHERE english_name = 'occitan'
  54. ");
  55. $this->addSql("
  56. UPDATE language SET parent_id = " . $languages['portuguese'] . " WHERE english_name = 'brazilian'
  57. ");
  58. $this->addSql("
  59. UPDATE language SET parent_id = " . $languages['simpl_chinese'] . " WHERE english_name = 'trad_chinese'
  60. ");
  61. }
  62. /**
  63. * We don't allow downgrades yet
  64. * @param Schema $schema
  65. */
  66. public function down(Schema $schema)
  67. {
  68. $this->addSql("
  69. UPDATE language SET parent_id = 0 WHERE english_name IN ('trad_chinese', 'brazilian', 'occitan', 'friulian', 'asturian', 'catalan', 'esperanto', 'galician', 'quechua_cusco')
  70. ");
  71. }
  72. }