Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Memorekall Member New
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Rekall
Memorekall Member New
Commits
3fcfe73f
Commit
3fcfe73f
authored
3 years ago
by
Sebastien
Browse files
Options
Downloads
Patches
Plain Diff
Refactoring of code for MR
parent
333e861d
No related branches found
No related tags found
1 merge request
!74
tuleap-190 : add command to update projects with latest version of capsule-prototype
Pipeline
#971
passed
3 years ago
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Command/UpdateAllProjects.php
+40
-30
40 additions, 30 deletions
src/Command/UpdateAllProjects.php
with
40 additions
and
30 deletions
src/Command/UpdateAllProjects.php
+
40
−
30
View file @
3fcfe73f
...
@@ -2,6 +2,9 @@
...
@@ -2,6 +2,9 @@
namespace
App\Command
;
namespace
App\Command
;
use
LogicException
;
use
phpDocumentor\Reflection\Types\Array_
;
use
phpDocumentor\Reflection\Types\Boolean
;
use
Symfony\Component\Console\Attribute\AsCommand
;
use
Symfony\Component\Console\Attribute\AsCommand
;
use
Symfony\Component\Console\Command\Command
;
use
Symfony\Component\Console\Command\Command
;
use
Symfony\Component\Console\Helper\ProgressBar
;
use
Symfony\Component\Console\Helper\ProgressBar
;
...
@@ -20,15 +23,19 @@ use Symfony\Component\HttpKernel\KernelInterface;
...
@@ -20,15 +23,19 @@ use Symfony\Component\HttpKernel\KernelInterface;
)]
)]
class
UpdateAllProjects
extends
Command
class
UpdateAllProjects
extends
Command
{
{
private
Filesystem
$filesystem
;
private
Filesystem
$file_system
;
private
KernelInterface
$kernel
;
private
KernelInterface
$kernel
;
private
string
$legacy_root
;
private
string
$capsule_prototype_root
;
/**
/**
* @var string[] $
black_list
* @var string[] $
BLACK_LIST files and directories that should not be taken into account for projects update
*/
*/
private
array
$black_list
=
private
static
array
$BLACK_LIST
=
[
'css'
,
'create.zip'
,
'favicon.ico'
,
'la-page-des-malins.php'
,
'js'
,
'php'
,
'shared'
,
'.'
,
'..'
];
[
'css'
,
'create.zip'
,
'favicon.ico'
,
'la-page-des-malins.php'
,
'js'
,
'php'
,
'shared'
,
'.'
,
'..'
];
private
static
string
$CAPSULE_PROTOTYPE_DIRECTORY_NAME
=
'capsule-prototype'
;
private
static
string
$LEGACY_DIRECTORY_NAME
=
'legacy'
;
public
function
__construct
(
Filesystem
$filesystem
,
KernelInterface
$kernel
)
public
function
__construct
(
Filesystem
$filesystem
,
KernelInterface
$kernel
)
...
@@ -38,8 +45,13 @@ class UpdateAllProjects extends Command
...
@@ -38,8 +45,13 @@ class UpdateAllProjects extends Command
// best practices recommend to call the parent constructor first and
// best practices recommend to call the parent constructor first and
// then set your own properties. That wouldn't work in this case
// then set your own properties. That wouldn't work in this case
// because configure() needs the properties set in this constructor
// because configure() needs the properties set in this constructor
$this
->
filesystem
=
$filesystem
;
$this
->
file
_
system
=
$filesystem
;
$this
->
kernel
=
$kernel
;
$this
->
kernel
=
$kernel
;
$this
->
legacy_root
=
Path
::
join
(
$this
->
kernel
->
getProjectDir
(),
self
::
$LEGACY_DIRECTORY_NAME
);
$this
->
capsule_prototype_root
=
Path
::
join
(
$this
->
kernel
->
getProjectDir
(),
self
::
$CAPSULE_PROTOTYPE_DIRECTORY_NAME
);
}
}
protected
function
configure
():
void
protected
function
configure
():
void
...
@@ -56,26 +68,21 @@ class UpdateAllProjects extends Command
...
@@ -56,26 +68,21 @@ class UpdateAllProjects extends Command
protected
function
execute
(
InputInterface
$input
,
OutputInterface
$output
):
int
protected
function
execute
(
InputInterface
$input
,
OutputInterface
$output
):
int
{
{
if
(
!
$output
instanceof
ConsoleOutputInterface
)
{
if
(
!
$output
instanceof
ConsoleOutputInterface
)
{
throw
new
\
LogicException
(
'This command accepts only an instance of "ConsoleOutputInterface".'
);
throw
new
LogicException
(
'This command accepts only an instance of "ConsoleOutputInterface".'
);
}
}
ProgressBar
::
setFormatDefinition
(
ProgressBar
::
setFormatDefinition
(
'project_update_message'
,
'project_update_message'
,
' %current%/%max% [%bar%] %percent%% : Updating project :%project% %elapsed%'
' %current%/%max% [%bar%] %percent%% : Updating project :%project% %elapsed%'
);
);
$output
->
writeln
(
"Updating all projects started"
);
$output
->
writeln
(
'Updating all projects started'
);
$legacy_root
=
$this
->
kernel
->
getProjectDir
()
.
'/legacy'
;
$capsule_prototype_root
=
'./capsule-prototype'
;
$
directory_files
=
scandir
(
$legacy_root
);
$
all_file_in_directory
=
$this
->
getProjectsDirectories
(
);
if
(
false
===
$directory
_files
)
{
if
(
false
===
$
all_file_in_
directory
)
{
return
Command
::
FAILURE
;
return
Command
::
FAILURE
;
}
}
$all_file_in_directory
=
$this
->
getProjectsDirectories
(
$directory_files
);
$php_files_count_per_projects
=
$this
->
getPhpFilesCountPerProjects
();
$php_files_count_per_projects
=
$this
->
getPhpFilesCountPerProjects
(
$capsule_prototype_root
);
$all_projects_progress_bar
=
new
ProgressBar
(
$output
->
section
());
$all_projects_progress_bar
=
new
ProgressBar
(
$output
->
section
());
$all_projects_progress_bar
->
setFormat
(
$all_projects_progress_bar
->
setFormat
(
...
@@ -85,9 +92,9 @@ class UpdateAllProjects extends Command
...
@@ -85,9 +92,9 @@ class UpdateAllProjects extends Command
$all_projects_progress_bar
->
start
();
$all_projects_progress_bar
->
start
();
foreach
(
$all_projects_progress_bar
->
iterate
(
$all_file_in_directory
)
as
$project_directory
)
{
foreach
(
$all_projects_progress_bar
->
iterate
(
$all_file_in_directory
)
as
$project_directory
)
{
$current_legacy_path
=
Path
::
normalize
(
$
legacy_root
.
'/'
.
$project_directory
);
$current_legacy_path
=
Path
::
join
(
$this
->
legacy_root
,
$project_directory
);
if
(
!
$this
->
filesystem
->
exists
(
$current_legacy_path
))
{
if
(
!
$this
->
file
_
system
->
exists
(
$current_legacy_path
))
{
continue
;
continue
;
}
}
...
@@ -95,7 +102,7 @@ class UpdateAllProjects extends Command
...
@@ -95,7 +102,7 @@ class UpdateAllProjects extends Command
continue
;
continue
;
}
}
if
(
in_array
(
$project_directory
,
$this
->
black_list
))
{
if
(
in_array
(
$project_directory
,
self
::
$BLACK_LIST
))
{
continue
;
continue
;
}
}
...
@@ -103,7 +110,7 @@ class UpdateAllProjects extends Command
...
@@ -103,7 +110,7 @@ class UpdateAllProjects extends Command
$output
,
$output
,
$php_files_count_per_projects
,
$php_files_count_per_projects
,
$current_legacy_path
,
$current_legacy_path
,
$capsule_prototype_root
$
this
->
capsule_prototype_root
);
);
$all_projects_progress_bar
->
advance
(
$php_files_count_per_projects
);
$all_projects_progress_bar
->
advance
(
$php_files_count_per_projects
);
}
}
...
@@ -114,21 +121,24 @@ class UpdateAllProjects extends Command
...
@@ -114,21 +121,24 @@ class UpdateAllProjects extends Command
}
}
/**
/**
* @param string[] $directory_files
* @return string[]|false
* @return string[] projects directories
*/
*/
private
function
getProjectsDirectories
(
array
$directory_files
):
array
private
function
getProjectsDirectories
():
array
|
false
{
{
return
array_diff
(
$directory_files
,
$this
->
black_list
);
$all_directories_and_files
=
scandir
(
$this
->
legacy_root
);
if
(
false
===
$all_directories_and_files
)
{
return
false
;
}
return
array_diff
(
$all_directories_and_files
,
self
::
$BLACK_LIST
);
}
}
/**
/**
* @param string $capsule_prototype_root
* @return int
* @return int
*/
*/
protected
function
getPhpFilesCountPerProjects
(
string
$capsule_prototype_root
):
int
protected
function
getPhpFilesCountPerProjects
():
int
{
{
$php_files
=
glob
(
$capsule_prototype_root
.
'/php/*.php'
);
$php_files
=
glob
(
$
this
->
capsule_prototype_root
.
'/php/*.php'
);
// add +1 for index.html file
// add +1 for index.html file
return
count
(
$php_files
?:
[])
+
1
;
return
count
(
$php_files
?:
[])
+
1
;
}
}
...
@@ -153,7 +163,7 @@ class UpdateAllProjects extends Command
...
@@ -153,7 +163,7 @@ class UpdateAllProjects extends Command
$progress_bar
->
start
();
$progress_bar
->
start
();
// override index.html
// override index.html
$this
->
filesystem
->
copy
(
$this
->
file
_
system
->
copy
(
Path
::
normalize
(
$capsule_prototype_root
.
'/index.html'
),
Path
::
normalize
(
$capsule_prototype_root
.
'/index.html'
),
Path
::
normalize
(
$current_legacy_path
.
'/index.html'
),
Path
::
normalize
(
$current_legacy_path
.
'/index.html'
),
true
true
...
@@ -161,9 +171,9 @@ class UpdateAllProjects extends Command
...
@@ -161,9 +171,9 @@ class UpdateAllProjects extends Command
$progress_bar
->
advance
();
$progress_bar
->
advance
();
// override php files
// override php files
$this
->
filesystem
->
mirror
(
$this
->
file
_
system
->
mirror
(
Path
::
normalize
(
$capsule_prototype_root
.
'
/
php'
),
Path
::
join
(
$capsule_prototype_root
,
'php'
),
Path
::
normalize
(
$current_legacy_path
.
'
/
php'
),
Path
::
join
(
$current_legacy_path
,
'php'
),
null
,
null
,
[
'override'
=>
true
,
'delete'
=>
true
]
[
'override'
=>
true
,
'delete'
=>
true
]
);
);
...
...
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