<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210326151638 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
// SEARCH
$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);");
$this->addSql("
SET @block_id=(SELECT id FROM std_blocks WHERE machine_name='B50_search');
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
('disabled_block', @block_id, 1, 1, 'Disabled block', 'CHECKBOX', 1, now(), now(), -1, NULL)
");
//Components
$this->addSql("
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
('search_label', @block_id, '1', '1', 'INPUT', NULL, 1, now(), now(), 'Search Label', 0),
('search_placeholder', @block_id, '1', '1', 'INPUT', NULL, 1, now(), now(), 'Search Placeholder', 0);
('search_page', @block_id, '1', '1', 'COMBO_PAGES', '{\"render\": false, \"content_type\": \"system\"}', 1, now(), now(), 'Search Page', 0);
");
// RESULTS
$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}');");
$this->addSql("
SET @block_id=(SELECT id FROM std_blocks WHERE machine_name='B51_search_results');
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
('disabled_block', @block_id, 1, 1, 'Disabled block', 'CHECKBOX', 1, now(), now(), -1, NULL);
");
//Components
$this->addSql("
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
('results_label', @block_id, '1', '1', 'INPUT', NULL, 1, now(), now(), 'Results Label', 0),
('results_placeholder', @block_id, '1', '1', 'INPUT', NULL, 1, now(), now(), 'Results Placeholder', 0),
('results_title', @block_id, '1', '1', 'INPUT', NULL, 1, now(), now(), 'Results Title', 0)
");
// Create page "Search"
$this->addSql("SET @id_content_type = (SELECT id FROM `std_content_types` WHERE `machine_name` = 'system');");
$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`)
VALUES (NULL, 1, 1, @id_content_type, 1, NOW(), NOW(), NULL, NOW(), NULL, 'Página de Pesquisa');");
$this->addSql("SET @id_page = (SELECT id FROM `std_pages` WHERE `content_type` = @id_content_type AND `name`='Página de Pesquisa');");
$arrayJsonContent = '{"fields":{
"1":{
"skin":"",
"block":"B02_title",
"isMaster":"0",
"settings":{},
"blockname":"",
"components":{
"title":"<h1>Página de Pesquisa</h1>"
},
"repeatable":[],
"templatesBlocksId":"0"
},
"2":{
"skin":"",
"block":"B51_search_results",
"isMaster":"0",
"settings":{},
"blockname":"",
"components":{
"results_label":"Página de Pesquisa",
"results_placeholder":"Resultados"
},
"repeatable":[],
"templatesBlocksId":"0"
}
}
}';
$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)."');");
$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);");
// config
$this->addSql("
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
('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\'\"}', '');
");
}
public function down(Schema $schema) : void
{
$this->addSql("SET @id_content_type = (SELECT id FROM `std_content_types` WHERE `machine_name` = 'system');");
$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');");
$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');");
$this->addSql("DELETE FROM `std_config` where machine_name= 'results_pages';");
$this->addSql("DELETE FROM `std_pages` WHERE `content_type`=@id_content_type AND `name`='Página de Pesquisa';");
// this down() migration is auto-generated, please modify it to your needs
//fazer código down
$this->addSql("
SET @block_id=(SELECT id FROM std_blocks WHERE machine_name='B51_search_results');
DELETE FROM `std_blocks_components` WHERE block_id = @block_id;
DELETE FROM `std_blocks_settings` WHERE block_id = @block_id;
DELETE FROM `std_blocks` where machine_name= 'B51_search_results';
");
$this->addSql("
SET @block_id=(SELECT id FROM std_blocks WHERE machine_name='B50_search');
DELETE FROM `std_blocks_components` WHERE block_id = @block_id;
DELETE FROM `std_blocks_settings` WHERE block_id = @block_id;
DELETE FROM `std_blocks` where machine_name= 'B50_search';
");
}
}