Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
digit-joinup-reference
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ec-europa
digit-joinup-reference
Commits
515d9d14
Commit
515d9d14
authored
7 months ago
by
Claudiu Cristea
Browse files
Options
Downloads
Patches
Plain Diff
ISAICP-9052: Move switch in private.
parent
70b05cdf
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/switch
+82
-0
82 additions, 0 deletions
scripts/switch
with
82 additions
and
0 deletions
scripts/switch
0 → 100755
+
82
−
0
View file @
515d9d14
#!/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
\n
variable 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"
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment