migrations/Version20210326151638.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 Version20210326151638 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.         
  19.         //          SEARCH
  20.         $this->addSql("INSERT INTO `std_blocks` (`created_by`, `updated_by`, `machine_name`, `created_date`, `updated_date`, `name`, `settings`) VALUES ('1', '1', 'B50_search', now(), now(), 'Search', NULL);");
  21.         $this->addSql("
  22.             SET @block_id=(SELECT id FROM std_blocks WHERE machine_name='B50_search');    
  23.                 INSERT INTO `std_blocks_settings` (`machine_name`, `block_id`, `created_by`, `updated_by`, `name`, `setting_type`, `is_active`, `created_date`, `updated_date`, `order_value`, `settings`) VALUES 
  24.                 ('disabled_block', @block_id, 1, 1, 'Disabled block', 'CHECKBOX', 1, now(), now(), -1, NULL)
  25.             ");
  26.             //Components
  27.         $this->addSql("
  28.             INSERT INTO `std_blocks_components` (`machine_name`, `block_id`, `created_by`, `updated_by`, `component_type`, `settings`, `order_value`, `created_date`, `updated_date`, `name`, `is_repeatable`) VALUES 
  29.             ('search_label', @block_id, '1', '1', 'INPUT', NULL, 1, now(), now(), 'Search Label', 0),
  30.             ('search_placeholder', @block_id, '1', '1', 'INPUT', NULL, 1, now(), now(), 'Search Placeholder', 0);
  31.             ('search_page', @block_id, '1', '1', 'COMBO_PAGES', '{\"render\": false, \"content_type\": \"system\"}', 1, now(), now(), 'Search Page', 0);
  32.             ");
  33.             //      RESULTS
  34.         $this->addSql("INSERT INTO `std_blocks` (`created_by`, `updated_by`, `machine_name`, `created_date`, `updated_date`, `name`, `settings`) VALUES ('1', '1', 'B51_search_results', now(), now(), 'Results', '{\"isResultsBlock\": true}');");
  35.         $this->addSql("
  36.             SET @block_id=(SELECT id FROM std_blocks WHERE machine_name='B51_search_results');    
  37.                 INSERT INTO `std_blocks_settings` (`machine_name`, `block_id`, `created_by`, `updated_by`, `name`, `setting_type`, `is_active`, `created_date`, `updated_date`, `order_value`, `settings`) VALUES 
  38.                 ('disabled_block', @block_id, 1, 1, 'Disabled block', 'CHECKBOX', 1, now(), now(), -1, NULL);
  39.             ");
  40.             //Components
  41.         $this->addSql("
  42.             INSERT INTO `std_blocks_components` (`machine_name`, `block_id`, `created_by`, `updated_by`, `component_type`, `settings`, `order_value`, `created_date`, `updated_date`, `name`, `is_repeatable`) VALUES 
  43.             ('results_label', @block_id, '1', '1', 'INPUT', NULL, 1, now(), now(), 'Results Label', 0),
  44.             ('results_placeholder', @block_id, '1', '1', 'INPUT', NULL, 1, now(), now(), 'Results Placeholder', 0),
  45.             ('results_title', @block_id, '1', '1', 'INPUT', NULL, 1, now(), now(), 'Results Title', 0)
  46.             ");
  47.             // Create page "Search"
  48.             $this->addSql("SET @id_content_type = (SELECT id FROM `std_content_types` WHERE `machine_name` = 'system');");
  49.             $this->addSql("INSERT INTO `std_pages` (`template_id`, `created_by`, `updated_by`, `content_type`, `is_active`, `created_date`, `updated_date`, `order_value`, `publish_date`, `expire_date`, `name`)
  50.             VALUES (NULL, 1, 1, @id_content_type, 1, NOW(), NOW(), NULL, NOW(), NULL, 'Página de Pesquisa');");
  51.             $this->addSql("SET @id_page = (SELECT id FROM `std_pages` WHERE `content_type` = @id_content_type AND `name`='Página de Pesquisa');");
  52.             $arrayJsonContent '{"fields":{
  53.                 "1":{
  54.                     "skin":"",
  55.                     "block":"B02_title",
  56.                     "isMaster":"0",
  57.                     "settings":{},
  58.                     "blockname":"",
  59.                     "components":{
  60.                         "title":"<h1>P&aacute;gina de Pesquisa</h1>"
  61.                     },
  62.                     "repeatable":[],
  63.                     "templatesBlocksId":"0"
  64.                     },
  65.                 "2":{
  66.                     "skin":"",
  67.                     "block":"B51_search_results",
  68.                     "isMaster":"0",
  69.                     "settings":{},
  70.                     "blockname":"",
  71.                     "components":{
  72.                         "results_label":"Página de Pesquisa",
  73.                         "results_placeholder":"Resultados"
  74.                     },
  75.                     "repeatable":[],
  76.                     "templatesBlocksId":"0"
  77.                     }                        
  78.                 }
  79.                 }';
  80.             
  81.             $this->addSql("INSERT INTO `std_pages_content` (`page_id`, `language_code`, `created_by`, `updated_by`, `is_active`, `created_date`, `updated_date`, `title`, `url`, `canonical_url`, `meta_title`, `meta_keywords`, `meta_description`, `og_title`, `og_image`, `og_description`, `og_url`, `scripts_head`, `scripts_body`, `scripts_footer`, `content`) VALUES (@id_page, 'pt', 1, 1, 1, now(), now(), 'Página de Pesquisa', 'pesquisa', '/pt/pesquisa', '', '', '', '', '', '', '', '', '', '', '".str_replace(["\n","\r","\t"],"",$arrayJsonContent)."');");
  82.             $this->addSql("INSERT INTO `std_friendly_url` (`page_id`, `url`, `relation_tree`, `relation_id`, `language_code`, `is_canonical`) VALUES (@id_page, '/pt/pesquisa', '[]', NULL, 'pt', 1);");    
  83.             
  84.              // config
  85.             $this->addSql("
  86.             INSERT INTO `std_config` (`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`) VALUES 
  87.             ('results_pages', 1, 1, @id_page, 'results_pages', 'results_pages', 'System', 'SELECT', 2, 0, 1, now(), now(), 'Página de Pesquisa', '{\"query\": \"select p.`name` as label,p.id as id from std_pages p INNER JOIN std_content_types sct ON p.content_type = sct.id  where sct.machine_name LIKE \'system\'\"}', '');
  88.         ");
  89.     }
  90.     public function down(Schema $schema) : void
  91.     {
  92.         $this->addSql("SET @id_content_type = (SELECT id FROM `std_content_types` WHERE `machine_name` = 'system');");
  93.         
  94.         $this->addSql("DELETE FROM `std_friendly_url` WHERE page_id IN(SELECT id FROM std_pages WHERE `content_type`=@id_content_type AND `name`='Página de Pesquisa');");
  95.         $this->addSql("DELETE FROM `std_pages_content` WHERE page_id IN(SELECT id FROM std_pages WHERE `content_type`=@id_content_type AND `name`='Página de Pesquisa');");
  96.         $this->addSql("DELETE FROM `std_config` where machine_name= 'results_pages';");
  97.         $this->addSql("DELETE FROM `std_pages` WHERE `content_type`=@id_content_type AND `name`='Página de Pesquisa';");
  98.         
  99.         // this down() migration is auto-generated, please modify it to your needs
  100.         //fazer código down
  101.         $this->addSql("
  102.         SET @block_id=(SELECT id FROM std_blocks WHERE machine_name='B51_search_results'); 
  103.             DELETE FROM `std_blocks_components` WHERE block_id = @block_id;
  104.             DELETE FROM `std_blocks_settings` WHERE block_id = @block_id;
  105.             DELETE FROM `std_blocks` where machine_name= 'B51_search_results';
  106.         ");
  107.         $this->addSql("
  108.         SET @block_id=(SELECT id FROM std_blocks WHERE machine_name='B50_search'); 
  109.             DELETE FROM `std_blocks_components` WHERE block_id = @block_id;
  110.             DELETE FROM `std_blocks_settings` WHERE block_id = @block_id;
  111.             DELETE FROM `std_blocks` where machine_name= 'B50_search';
  112.         ");
  113.         
  114.         
  115.     }
  116. }