migrations/Version20240726084344.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 Version20240726084344 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.         $this->addSql("
  19.                 SET @contenttype_menu_id = (SELECT `id` FROM `std_content_types` WHERE `machine_name` = 'menus');
  20.                 INSERT IGNORE INTO `std_content_types_skins` 
  21.                 (`content_type_id`, `machine_name`, `name`,  `is_active`, `created_by`, `created_date`, `updated_by`, `updated_date`) 
  22.                 VALUES 
  23.                 (@contenttype_menu_id, 'menumobilebottombar', 'Menu Mobile Bottom Bar', 1, 1, now(), 1, now());
  24.         ");
  25.         
  26.         $conn $this->connection;
  27.         //get all languages from std_languages
  28.         $sql "SELECT `language_code` FROM `std_languages`";
  29.         $stmt $conn->executeQuery($sql);
  30.         $languages $stmt->fetchAllAssociative();
  31.         //iterate through all the languages and create a menu config for each language        
  32.         foreach ($languages as $language) {
  33.             $languageCode $language['language_code'];           
  34.             $this->addSql("
  35.                 SET @order_value = (SELECT MAX(`order_value`) FROM `std_config` WHERE `parent_name` = 'Menus') + 1
  36.             ");            
  37.             $this->addSql("
  38.                 INSERT IGNORE INTO `std_config` 
  39.                 (`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`)
  40.                 VALUES ('mobilebottombar', 1, 1, '', 'mobilebottombar', 'mobilebottombar', 'Menus', 'SELECT', @order_value, 0, 1, now(), now(), 'Menu Mobile Bottom Bar', '{\"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');
  41.             ");
  42.             $this->addSql("
  43.                 INSERT IGNORE INTO `std_config` 
  44.                 (`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`)
  45.                 VALUES ('mobilebottombar_skin', 1, 1, 'menumobilebottombar', 'mobilebottombar_skin', 'mobilebottombar_skin', 'Menus', 'SELECT', @order_value+1, 0, 1, now(), now(), 'Menu Mobile Bottom Bar 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');
  46.             ");
  47.         }        
  48.     }
  49.     public function down(Schema $schema): void
  50.     {
  51.         // this down() migration is auto-generated, please modify it to your needs
  52.         $this->addSql("
  53.             DELETE FROM `std_config` WHERE `machine_name` = 'mobilebottombar';
  54.         ");
  55.         $this->addSql("
  56.             DELETE FROM `std_config` WHERE `machine_name` = 'mobilebottombar_skin';
  57.         ");
  58.         $this->addSql("
  59.             DELETE FROM `std_content_types_skins` WHERE `machine_name` = 'menumobilebottombar';
  60.         ");
  61.     }
  62. }