Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #4500 to resolve config split recipe issues and #4501 for deprecated Twig code. #4502

Merged
merged 6 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions scripts/config-split/templates/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Deny all requests from Apache 2.4+.
<IfModule mod_authz_core.c>
Require all denied
</IfModule>

# Deny all requests from Apache 2.0-2.2.
<IfModule !mod_authz_core.c>
Deny from all
</IfModule>

# Turn off all options we don't need.
Options -Indexes -ExecCGI -Includes -MultiViews

# Set the catch-all handler to prevent scripts from being executed.
SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
<Files *>
# Override the handler again if we're run later in the evaluation list.
SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003
</Files>

# If we know how to do it safely, disable the PHP engine entirely.
<IfModule mod_php7.c>
php_flag engine off
</IfModule>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
uuid: {{ uuid }}
langcode: en
status: true
status: false
dependencies: { }
id: {{ id }}
label: {{ name }}
Expand Down
45 changes: 41 additions & 4 deletions src/Robo/Commands/Recipes/ConfigSplitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
namespace Acquia\Blt\Robo\Commands\Recipes;

use Acquia\Blt\Robo\BltTasks;
use Acquia\Blt\Robo\Common\YamlMunge;
use Acquia\Blt\Robo\Exceptions\BltException;
use Drupal\Component\Uuid\Php;
use Robo\Contract\VerbosityThresholdInterface;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;

/**
* Defines commands in the recipes:config:init:splits namespace.
Expand All @@ -20,7 +25,7 @@ class ConfigSplitCommand extends BltTasks {
/**
* An instance of the Twig template environment.
*
* @var \Twig_Environment
* @var \Twig\Environment
*/
protected $twig;

Expand All @@ -46,8 +51,8 @@ class ConfigSplitCommand extends BltTasks {
public function initialize() {
$this->uuidGenerator = new Php();
$template_dir = $this->getConfigValue('blt.root') . '/scripts/config-split/templates';
$loader = new \Twig_Loader_Filesystem($template_dir);
$this->twig = new \Twig_Environment($loader);
$loader = new FilesystemLoader($template_dir);
$this->twig = new Environment($loader);
$docroot = $this->getConfigValue('docroot');
$this->configSyncDir = $docroot . '/' . $this->getConfigValue('cm.core.dirs.sync.path');
$this->configSplitDir = $docroot . '/' . $this->getConfigValue('cm.core.path') . '/envs';
Expand All @@ -61,12 +66,33 @@ public function initialize() {
* @aliases rcis splits
*/
public function generateConfigSplits() {
$this->say("This command will generate configuration and directories for the following environment based splits: Local, CI, Dev, Stage, and Prod.");
$this->say("Creating config splits for the following environments: Local, CI, Dev, Stage, and Prod.");

$default_splits = ['Local', 'CI', 'Dev', 'Stage', 'Prod'];
foreach ($default_splits as $split) {
$this->createSplitConfig($split);
}

if (file_exists($this->configSyncDir . '/core.extension.yml')) {
// Automatically enable config split module.
$core_extensions = YamlMunge::parseFile($this->configSyncDir . '/core.extension.yml');
if (!array_key_exists("config_split", $core_extensions['module'])) {
$core_extensions['module']['config_split'] = 0;
}
if (!array_key_exists("config_filter", $core_extensions['module'])) {
$core_extensions['module']['config_filter'] = 0;
}
try {
ksort($core_extensions['module']);
YamlMunge::writeFile($this->configSyncDir . '/core.extension.yml', $core_extensions);
}
catch (\Exception $e) {
throw new BltException("Unable to update core.extension.yml");
}
}
else {
$this->say("No core.extension file found, skipping step to enable config split and config filter modules.");
}
}

/**
Expand Down Expand Up @@ -113,6 +139,17 @@ protected function createSplitDir($split) {
]);
file_put_contents($split_dir . '/README.md', $readme);
}
if (!file_exists($split_dir . '/.htaccess')) {
$result = $this->taskFilesystemStack()
->copy($this->getConfigValue('repo.root') . '/vendor/acquia/blt/scripts/config-split/templates/.htaccess', $split_dir . '/.htaccess', TRUE)
->stopOnFail()
->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE)
->run();

if (!$result->wasSuccessful()) {
throw new BltException("Could not place .htaccess file in $split_dir.");
}
}
}

/**
Expand Down
39 changes: 39 additions & 0 deletions tests/phpunit/src/ConfgSplitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Acquia\Blt\Tests;

/**
* Tests Config Split recipe.
*/
class ConfgSplitTest extends BltProjectTestBase {

/**
* Tests recipes:config:init:splits to validate split creation.
*/
public function testConfigSplitRecipe() {
$this->blt('recipes:config:init:splits');
$splits = $this->getSplits();
foreach ($splits as $split) {
$this->assertFileExists("$this->sandboxInstance/config/default/config_split.config_split.$split.yml");
$this->assertDirectoryExists("$this->sandboxInstance/config/envs/$split");
}
}

/**
* Defines the default BLT config splits.
*
* @return array
* An array of default config splits.
*/
public function getSplits() {
$splits = [
'local',
'dev',
'stage',
'prod',
'ci',
];
return $splits;
}

}