Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
automatic_updates-3449631
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
automatic_updates-3449631
Commits
648f8901
Commit
648f8901
authored
3 years ago
by
Adam G-H
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3229485
by phenaproxima, tedbow: Clean up some exclusion code
parent
faa96332
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
automatic_updates.services.yml
+1
-1
1 addition, 1 deletion
automatic_updates.services.yml
src/Updater.php
+47
-18
47 additions, 18 deletions
src/Updater.php
tests/src/Functional/ExclusionsTest.php
+74
-0
74 additions, 0 deletions
tests/src/Functional/ExclusionsTest.php
with
122 additions
and
19 deletions
automatic_updates.services.yml
+
1
−
1
View file @
648f8901
...
@@ -4,7 +4,7 @@ services:
...
@@ -4,7 +4,7 @@ services:
arguments
:
[
'
@keyvalue.expirable'
,
'
@datetime.time'
,
24
]
arguments
:
[
'
@keyvalue.expirable'
,
'
@datetime.time'
,
24
]
automatic_updates.updater
:
automatic_updates.updater
:
class
:
Drupal\automatic_updates\Updater
class
:
Drupal\automatic_updates\Updater
arguments
:
[
'
@state'
,
'
@string_translation'
,
'
@automatic_updates.beginner'
,
'
@automatic_updates.stager'
,
'
@automatic_updates.cleaner'
,
'
@automatic_updates.committer'
,
'
@file_system'
,
'
@event_dispatcher'
]
arguments
:
[
'
@state'
,
'
@string_translation'
,
'
@automatic_updates.beginner'
,
'
@automatic_updates.stager'
,
'
@automatic_updates.cleaner'
,
'
@automatic_updates.committer'
,
'
@file_system'
,
'
@event_dispatcher'
,
'
%app.root%'
,
'
%site.path%'
]
automatic_updates.staged_package_validator
:
automatic_updates.staged_package_validator
:
class
:
Drupal\automatic_updates\Validation\StagedProjectsValidation
class
:
Drupal\automatic_updates\Validation\StagedProjectsValidation
arguments
:
[
'
@string_translation'
,
'
@automatic_updates.updater'
]
arguments
:
[
'
@string_translation'
,
'
@automatic_updates.updater'
]
...
...
This diff is collapsed.
Click to expand it.
src/Updater.php
+
47
−
18
View file @
648f8901
...
@@ -79,6 +79,20 @@ class Updater {
...
@@ -79,6 +79,20 @@ class Updater {
*/
*/
protected
$eventDispatcher
;
protected
$eventDispatcher
;
/**
* The Drupal root.
*
* @var string
*/
protected
$appRoot
;
/**
* The current site directory, relative to the Drupal root.
*
* @var string
*/
protected
$sitePath
;
/**
/**
* Constructs an Updater object.
* Constructs an Updater object.
*
*
...
@@ -98,8 +112,12 @@ class Updater {
...
@@ -98,8 +112,12 @@ class Updater {
* The file system service.
* The file system service.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* The event dispatcher service.
* The event dispatcher service.
* @param string $app_root
* The Drupal root.
* @param string $site_path
* The current site directory, relative to the Drupal root.
*/
*/
public
function
__construct
(
StateInterface
$state
,
TranslationInterface
$translation
,
BeginnerInterface
$beginner
,
StagerInterface
$stager
,
CleanerInterface
$cleaner
,
CommitterInterface
$committer
,
FileSystemInterface
$file_system
,
EventDispatcherInterface
$event_dispatcher
)
{
public
function
__construct
(
StateInterface
$state
,
TranslationInterface
$translation
,
BeginnerInterface
$beginner
,
StagerInterface
$stager
,
CleanerInterface
$cleaner
,
CommitterInterface
$committer
,
FileSystemInterface
$file_system
,
EventDispatcherInterface
$event_dispatcher
,
string
$app_root
,
string
$site_path
)
{
$this
->
state
=
$state
;
$this
->
state
=
$state
;
$this
->
beginner
=
$beginner
;
$this
->
beginner
=
$beginner
;
$this
->
stager
=
$stager
;
$this
->
stager
=
$stager
;
...
@@ -108,6 +126,8 @@ class Updater {
...
@@ -108,6 +126,8 @@ class Updater {
$this
->
setStringTranslation
(
$translation
);
$this
->
setStringTranslation
(
$translation
);
$this
->
fileSystem
=
$file_system
;
$this
->
fileSystem
=
$file_system
;
$this
->
eventDispatcher
=
$event_dispatcher
;
$this
->
eventDispatcher
=
$event_dispatcher
;
$this
->
appRoot
=
$app_root
;
$this
->
sitePath
=
$site_path
;
}
}
/**
/**
...
@@ -171,34 +191,43 @@ class Updater {
...
@@ -171,34 +191,43 @@ class Updater {
* Gets the paths that should be excluded from the staging area.
* Gets the paths that should be excluded from the staging area.
*
*
* @return string[]
* @return string[]
* The paths relative to the active directory
to exclude
.
* The paths
to exclude,
relative to the active directory.
*/
*/
pr
ivate
function
getExclusions
():
array
{
pr
otected
function
getExclusions
():
array
{
$exclusions
=
[];
$exclusions
=
[];
$make_relative
=
function
(
$path
)
{
return
str_replace
(
static
::
getActiveDirectory
()
.
'/'
,
''
,
$path
);
};
if
(
$public
=
$this
->
fileSystem
->
realpath
(
'public://'
))
{
if
(
$public
=
$this
->
fileSystem
->
realpath
(
'public://'
))
{
$exclusions
[]
=
$make_relative
(
$public
)
;
$exclusions
[]
=
$public
;
}
}
if
(
$private
=
$this
->
fileSystem
->
realpath
(
'private://'
))
{
if
(
$private
=
$this
->
fileSystem
->
realpath
(
'private://'
))
{
$exclusions
[]
=
$make_relative
(
$private
)
;
$exclusions
[]
=
$private
;
}
}
/** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */
// If this module is a git clone, exclude it.
$module_handler
=
\Drupal
::
service
(
'module_handler'
);
if
(
is_dir
(
__DIR__
.
'/../.git'
))
{
$module_path
=
$this
->
fileSystem
->
realpath
(
$module_handler
->
getModule
(
'automatic_updates'
)
->
getPath
());
$exclusions
[]
=
$this
->
fileSystem
->
realpath
(
__DIR__
.
'/..'
);
if
(
is_dir
(
"
$module_path
/.git"
))
{
// If the current module is git clone. Don't copy it.
$exclusions
[]
=
$make_relative
(
$module_path
);
}
}
$settings_files
=
[
'settings.php'
,
'settings.local.php'
,
'services.yml'
];
// Exclude site-specific settings files.
$settings_files
=
[
'settings.php'
,
'settings.local.php'
,
'services.yml'
,
];
foreach
(
$settings_files
as
$settings_file
)
{
foreach
(
$settings_files
as
$settings_file
)
{
$file_path
=
"sites/default/
$settings_file
"
;
$file_path
=
implode
(
DIRECTORY_SEPARATOR
,
[
$this
->
appRoot
,
$this
->
sitePath
,
$settings_file
,
]);
$file_path
=
$this
->
fileSystem
->
realpath
(
$file_path
);
if
(
file_exists
(
$file_path
))
{
if
(
file_exists
(
$file_path
))
{
$exclusions
[]
=
$
make_relative
(
$this
->
fileSystem
->
realpath
(
"sites/default/
$settings_file
"
))
;
$exclusions
[]
=
$
file_path
;
}
}
}
}
return
$exclusions
;
$make_relative
=
function
(
string
$path
):
string
{
return
str_replace
(
$this
->
getActiveDirectory
()
.
'/'
,
''
,
$path
);
};
return
array_map
(
$make_relative
,
$exclusions
);
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
tests/src/Functional/ExclusionsTest.php
0 → 100644
+
74
−
0
View file @
648f8901
<?php
namespace
Drupal\Tests\automatic_updates\Functional
;
use
Drupal\Tests\BrowserTestBase
;
/**
* Tests exclusion of certain files and directories from the staging area.
*
* @group automatic_updates
*/
class
ExclusionsTest
extends
BrowserTestBase
{
/**
* {@inheritdoc}
*/
protected
static
$modules
=
[
'automatic_updates'
];
/**
* {@inheritdoc}
*/
protected
$defaultTheme
=
'stark'
;
/**
* The names of site-specific settings files to mock.
*
* @var string[]
*/
private
const
SETTINGS_FILES
=
[
'settings.php'
,
'settings.local.php'
,
'services.yml'
,
];
/**
* {@inheritdoc}
*/
protected
function
setUp
():
void
{
parent
::
setUp
();
foreach
(
static
::
SETTINGS_FILES
as
$settings_file
)
{
$settings_file
=
"
$this->siteDirectory
/
$settings_file
"
;
touch
(
$settings_file
);
$this
->
assertFileExists
(
$settings_file
);
}
}
/**
* Tests that certain files and directories are not staged.
*
* @covers \Drupal\automatic_updates\Updater::getExclusions
*/
public
function
testExclusions
():
void
{
/** @var \Drupal\automatic_updates\Updater $updater */
$updater
=
$this
->
container
->
get
(
'automatic_updates.updater'
);
$reflector
=
new
\ReflectionObject
(
$updater
);
$method
=
$reflector
->
getMethod
(
'getExclusions'
);
$method
->
setAccessible
(
TRUE
);
$exclusions
=
$method
->
invoke
(
$updater
);
$this
->
assertContains
(
"
$this->siteDirectory
/files"
,
$exclusions
);
$this
->
assertContains
(
"
$this->siteDirectory
/private"
,
$exclusions
);
foreach
(
static
::
SETTINGS_FILES
as
$settings_file
)
{
$this
->
assertContains
(
"
$this->siteDirectory
/
$settings_file
"
,
$exclusions
);
}
if
(
is_dir
(
__DIR__
.
'/../../../.git'
))
{
$module_path
=
$this
->
container
->
get
(
'extension.list.module'
)
->
getPath
(
'automatic_updates'
);
$this
->
assertContains
(
$module_path
,
$exclusions
);
}
}
}
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