Skip to content
Snippets Groups Projects
Commit 515d9d14 authored by Claudiu Cristea's avatar Claudiu Cristea
Browse files

ISAICP-9052: Move switch in private.

parent 70b05cdf
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env php
<?php
use Symfony\Component\Filesystem\Filesystem;
include_once __DIR__ . '/../vendor/autoload.php';
// Logs messages
$log = function (string $type, string $message): void {
$message = trim($message);
print match($type) {
'info' => "\033[36m$message\033[0m",
'warning' => "\033[33m$message\033[0m",
'error' => "\033[31m$message\033[0m",
};
print "\n";
if ($type === 'error') {
exit(1);
}
};
[, $switch, $operation] = $argv;
// Check command arguments.
$errors = [];
if (!in_array($switch, ['config-readonly', 'eu-oss-catalogue'])) {
$errors[] = "First argument should be 'config-readonly' or 'eu-oss-catalogue' but '$switch' given";
}
if (!in_array($operation, ['on', 'off'])) {
$errors[] = "Second argument should be 'on' or 'off' but '$operation' given";
}
if (($count = count($argv) -1 ) > 2) {
$errors[] = "This command only accepts 2 arguments but $count given";
}
if ($errors) {
$log('error', implode("\n", $errors));
}
$fileSystem = new Filesystem();
$path = getenv('DRUPAL_PRIVATE_FILE_SYSTEM');
if (empty($path)) {
$log('error', 'The DRUPAL_PRIVATE_FILE_SYSTEM environment variable is not set');
}
// Drupal expects the private filesystem path as relative to web root but in
// CI/CD it might be set as absolute. Convert to absolute path.
if (!$fileSystem->isAbsolutePath($path)) {
$dir = DRUPAL_ROOT . '/' . $path;
$path = realpath($dir);
if ($path === FALSE) {
$log('error', "The directory $dir doesn't exist");
}
}
$path .= '/killswitch';
if (!$fileSystem->exists($path)) {
// Create the directory if it's missing.
$fileSystem->mkdir($path);
$fileSystem->chmod($path, 0770);
}
// File used as kill-switch.
$killSwitch = "$path/disable-$switch";
if ($operation === 'on') {
if ($fileSystem->exists($killSwitch)) {
$fileSystem->remove($killSwitch);
}
if ($switch === 'config-readonly' && getenv('CONFIG_READONLY') === 'false') {
$log('warning', "Config read-only is permanently disabled because the CONFIG_READONLY environment\nvariable is set to 'false'");
}
else {
$log('info', "The $switch functionality has been enabled");
}
}
elseif ($operation === 'off') {
$fileSystem->touch($killSwitch);
$log('info', "The $switch functionality has been disabled");
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment