Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stud.IP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Marcus Eibrink-Lunzenauer
Stud.IP
Commits
95b8d817
Commit
95b8d817
authored
11 months ago
by
Jan-Hendrik Willms
Browse files
Options
Downloads
Patches
Plain Diff
remove cli command 'check:globalized-config', fixes
#4024
Closes
#4024
Merge request
!2878
parent
1c0302b5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cli/Commands/Checks/GlobalizedConfig.php
+0
-148
0 additions, 148 deletions
cli/Commands/Checks/GlobalizedConfig.php
cli/studip
+0
-1
0 additions, 1 deletion
cli/studip
with
0 additions
and
149 deletions
cli/Commands/Checks/GlobalizedConfig.php
deleted
100644 → 0
+
0
−
148
View file @
1c0302b5
<?php
namespace
Studip\Cli\Commands\Checks
;
use
Config
;
use
DirectoryIterator
;
use
FilesystemIterator
;
use
RecursiveDirectoryIterator
;
use
RecursiveIteratorIterator
;
use
RecursiveRegexIterator
;
use
RegexIterator
;
use
Studip\Cli\Commands\AbstractCommand
;
use
Symfony\Component\Console\Command\Command
;
use
Symfony\Component\Console\Input\InputArgument
;
use
Symfony\Component\Console\Input\InputInterface
;
use
Symfony\Component\Console\Input\InputOption
;
use
Symfony\Component\Console\Output\OutputInterface
;
final
class
GlobalizedConfig
extends
AbstractCommand
{
protected
static
$defaultName
=
'check:globalized-config'
;
protected
function
configure
():
void
{
$this
->
setDescription
(
'<href=https://develop.studip.de/trac/ticket/5671>TIC 5671</> scanner - Globalized config'
);
$this
->
setHelp
(
'Scans files for occurences of globalized config items (see <href=https://develop.studip.de/trac/ticket/5671>ticket 5671</> for more info)'
);
$this
->
addOption
(
'filenames'
,
'f'
,
InputOption
::
VALUE_NONE
,
'Display filenames only (excludes -m and -o)'
);
$this
->
addOption
(
'matches'
,
'm'
,
InputOption
::
VALUE_NONE
,
'Show matched config variables'
);
$this
->
addOption
(
'recursive'
,
'r'
,
InputOption
::
VALUE_NONE
|
InputOption
::
VALUE_NEGATABLE
,
'Do not scan recursively into subfolders'
);
$this
->
addOption
(
'occurences'
,
'o'
,
InputOption
::
VALUE_NONE
,
'Show occurences in files'
);
$this
->
addArgument
(
'folder'
,
InputArgument
::
IS_ARRAY
|
InputArgument
::
OPTIONAL
,
'Folder(s) to scan (pass the special value of "plugins" to scan the plugin folder)'
,
[
$GLOBALS
[
'STUDIP_BASE_PATH'
]]
);
}
protected
function
execute
(
InputInterface
$input
,
OutputInterface
$output
):
int
{
$only_filenames
=
(
bool
)
$input
->
getOption
(
'filenames'
);
$show_occurences
=
!
$only_filenames
&&
(
$output
->
isVerbose
()
||
$input
->
getOption
(
'occurences'
));
$show_matches
=
!
$only_filenames
&&
(
$show_occurences
||
$input
->
getOption
(
'matches'
));
$recursive
=
$input
->
getOption
(
'recursive'
)
??
true
;
$folders
=
$input
->
getArgument
(
'folder'
);
foreach
(
$folders
as
$index
=>
$folder
)
{
if
(
$folder
===
'plugins'
)
{
$folders
[
$index
]
=
$GLOBALS
[
'STUDIP_BASE_PATH'
]
.
'/public/plugins_packages/'
;
}
}
$folders
=
array_unique
(
$folders
);
$config
=
Config
::
get
()
->
getFields
(
'global'
);
$quoted
=
array_map
(
function
(
$item
)
{
return
preg_quote
(
$item
,
'/'
);
},
$config
);
$regexp
=
'/\$(?:GLOBALS\[["\']?)?('
.
implode
(
'|'
,
$quoted
)
.
')\b/S'
;
foreach
(
$folders
as
$folder
)
{
if
(
!
file_exists
(
$folder
)
||
!
is_dir
(
$folder
))
{
$output
->
writeln
(
"Skipping non-folder argument <fg=red>
{
$folder
}
</>"
,
OutputInterface
::
VERBOSITY_VERBOSE
);
continue
;
}
$output
->
writeln
(
"Scanning
{
$folder
}
"
,
OutputInterface
::
VERBOSITY_VERBOSE
);
foreach
(
$this
->
getFolderIterator
(
$folder
,
$recursive
,
[
'php'
,
'tpl'
,
'inc'
])
as
$file
)
{
$filename
=
$file
->
getPathName
();
$contents
=
file_get_contents
(
$filename
);
$output
->
writeln
(
sprintf
(
'Check <fg=magenta>%s</>'
,
$this
->
relativeFilePath
(
$filename
)
),
OutputInterface
::
VERBOSITY_VERBOSE
);
if
(
$matched
=
preg_match_all
(
$regexp
,
$contents
,
$matches
))
{
if
(
$only_filenames
)
{
$output
->
writeln
(
$filename
);
}
else
{
$output
->
writeln
(
sprintf
(
'%u matched variable(s) in <fg=green;options=bold>%s</>'
,
$matched
,
$this
->
shorten
(
$filename
)
)
);
if
(
$show_matches
)
{
$variables
=
array_unique
(
$matches
[
1
]);
foreach
(
$variables
as
$variable
)
{
$output
->
writeln
(
"> <fg=cyan>
{
$variable
}
</>"
);
if
(
$show_occurences
)
{
$output
->
writeln
(
$this
->
highlight
(
$contents
,
$variable
));
}
}
}
}
}
}
}
return
Command
::
SUCCESS
;
}
private
function
highlight
(
string
$content
,
string
$variable
):
string
{
$lines
=
explode
(
"
\n
"
,
$content
);
$result
=
[];
foreach
(
$lines
as
$index
=>
$line
)
{
if
(
mb_strpos
(
$line
,
$variable
)
===
false
)
{
continue
;
}
$result
[
$index
+
1
]
=
$line
;
}
if
(
!
$result
)
{
return
''
;
}
$max
=
max
(
array_map
(
'mb_strlen'
,
array_keys
(
$result
)));
foreach
(
$result
as
$index
=>
$line
)
{
$result
[
$index
]
=
sprintf
(
"<fg=yellow>:%0
{
$max
}
u:</> %s"
,
$index
,
str_replace
(
$variable
,
"<fg=black;bg=yellow>
{
$variable
}
</>"
,
$line
)
);
}
return
implode
(
"
\n
"
,
$result
);
}
}
This diff is collapsed.
Click to expand it.
cli/studip
+
0
−
1
View file @
95b8d817
...
@@ -15,7 +15,6 @@ $commands = [
...
@@ -15,7 +15,6 @@ $commands = [
Commands\Base\Dump
::
class
,
Commands\Base\Dump
::
class
,
Commands\Base\Tinker
::
class
,
Commands\Base\Tinker
::
class
,
Commands\Checks\Compatibility
::
class
,
Commands\Checks\Compatibility
::
class
,
Commands\Checks\GlobalizedConfig
::
class
,
Commands\Checks\HelpTours
::
class
,
Commands\Checks\HelpTours
::
class
,
Commands\Checks\HelpTours
::
class
,
Commands\Checks\HelpTours
::
class
,
Commands\CleanupAdmissionRules
::
class
,
Commands\CleanupAdmissionRules
::
class
,
...
...
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