migrations/Version20240112170713.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20240112170713 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // this up() migration is auto-generated, please modify it to your needs
  18.         $conn $this->connection;
  19.         //get all languages from std_languages
  20.         $sql "SELECT `language_code` FROM `std_languages`";
  21.         $stmt $conn->executeQuery($sql);
  22.         $languages $stmt->fetchAllAssociative();
  23.         //iterate through all the languages and create a menu config for each language
  24.         foreach ($languages as $language) {
  25.             $languageCode $language['language_code'];
  26.             $this->addSql("set @menu=(select id from `std_pages_pages` WHERE `page_id`=(SELECT `id` FROM `std_pages` WHERE `name`='Side Menu - $languageCode'));");
  27.             $this->addSql("
  28.                 SET @order_value = (SELECT MAX(`order_value`) FROM `std_config` WHERE `parent_name` = 'Menus') + 1
  29.             ");
  30.             $this->addSql("
  31.                 INSERT IGNORE INTO `std_config` 
  32.                 (`machine_name`, `created_by`, `updated_by`, `value`, `description_machine_name`, `details_machine_name`, `parent_name`, `variable_type`, `order_value`, `is_hidden`, `is_active`, `created_date`, `updated_date`, `label`, `content`, `language_code`)
  33.                 VALUES ('menubottom', 1, 1, @menu, 'menubottom', 'menubottom', 'Menus', 'SELECT', @order_value, 0, 1, now(), now(), 'Menu Bottom', '{\"query\": \"select sp.name as label,spp.id as id from std_pages sp LEFT OUTER JOIN std_pages_pages spp ON sp.id = spp.page_id LEFT OUTER JOIN std_content_types sct ON sp.content_type = sct.id inner join std_pages_content spc on sp.id=spc.page_id and spc.language_code=\'$languageCode\' where sct.machine_name=\'menus\' AND spp.relation_id = 0\"}','$languageCode');
  34.             ");
  35.             $this->addSql("
  36.                 INSERT IGNORE INTO `std_config` 
  37.                 (`machine_name`, `created_by`, `updated_by`, `value`, `description_machine_name`, `details_machine_name`, `parent_name`, `variable_type`, `order_value`, `is_hidden`, `is_active`, `created_date`, `updated_date`, `label`, `content`, `language_code`)
  38.                 VALUES ('menubottom_skin', 1, 1, 'menubottom', 'menubottom_skin', 'menubottom_skin', 'Menus', 'SELECT', @order_value+1, 0, 1, now(), now(), 'Menu Bottom Skin', '{\"query\": \"select scts.name as label,scts.machine_name as id from std_content_types_skins scts LEFT OUTER JOIN std_content_types sct ON scts.content_type_id = sct.id WHERE sct.machine_name=\'menus\'\"}','$languageCode');
  39.             ");
  40.         }        
  41.     }
  42.     public function down(Schema $schema): void
  43.     {
  44.         // this down() migration is auto-generated, please modify it to your needs
  45.         $this->addSql("
  46.             DELETE FROM `std_config` WHERE `machine_name` = 'menubottom';
  47.         ");
  48.         $this->addSql("
  49.             DELETE FROM `std_config` WHERE `machine_name` = 'menubottom_skin';
  50.         ");
  51.     }
  52. }