Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
automatic_updates
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
project
automatic_updates
Merge requests
!648
Issue
#3331310
: Exclude unknown paths in project base
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3331310
: Exclude unknown paths in project base
issue/automatic_updates-3331310:3331310-exclude-unknown-paths
into
8.x-2.x
Overview
50
Commits
20
Pipelines
1
Changes
3
Merged
Kunal Sachdev
requested to merge
issue/automatic_updates-3331310:3331310-exclude-unknown-paths
into
8.x-2.x
2 years ago
Overview
24
Commits
20
Pipelines
1
Changes
3
Expand
0
0
Merge request reports
Compare
8.x-2.x
version 17
5f965c8a
2 years ago
version 16
d6868efc
2 years ago
version 15
4712c903
2 years ago
version 14
01121c43
2 years ago
version 13
8e4b0c5d
2 years ago
version 12
e9f5995c
2 years ago
version 11
a245afe8
2 years ago
version 10
a3357bc5
2 years ago
version 9
d50f55f3
2 years ago
version 8
1e19c987
2 years ago
version 7
068db6e8
2 years ago
version 6
c598818c
2 years ago
version 5
937b552b
2 years ago
version 4
c17b5678
2 years ago
version 3
441aa1c1
2 years ago
version 2
c475f47d
2 years ago
version 1
5fba2666
2 years ago
8.x-2.x (base)
and
latest version
latest version
5f965c8a
20 commits,
2 years ago
version 17
5f965c8a
20 commits,
2 years ago
version 16
d6868efc
19 commits,
2 years ago
version 15
4712c903
17 commits,
2 years ago
version 14
01121c43
16 commits,
2 years ago
version 13
8e4b0c5d
15 commits,
2 years ago
version 12
e9f5995c
14 commits,
2 years ago
version 11
a245afe8
13 commits,
2 years ago
version 10
a3357bc5
11 commits,
2 years ago
version 9
d50f55f3
10 commits,
2 years ago
version 8
1e19c987
9 commits,
2 years ago
version 7
068db6e8
8 commits,
2 years ago
version 6
c598818c
7 commits,
2 years ago
version 5
937b552b
6 commits,
2 years ago
version 4
c17b5678
5 commits,
2 years ago
version 3
441aa1c1
4 commits,
2 years ago
version 2
c475f47d
1 commit,
2 years ago
version 1
5fba2666
1 commit,
2 years ago
3 files
+
265
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
package_manager/src/PathExcluder/UnknownPathExcluder.php
0 → 100644
+
99
−
0
Options
<?php
declare
(
strict_types
=
1
);
namespace
Drupal\package_manager\PathExcluder
;
use
Drupal\package_manager
\Event\CollectIgnoredPathsEvent
;
use
Drupal\package_manager
\PathLocator
;
use
Symfony\Component\EventDispatcher\EventSubscriberInterface
;
/**
* Excludes unknown paths from stage operations.
*
* Any paths in the root directory of the project that are NOT one of the
* following are considered unknown paths:
* 1. The vendor directory
* 2. The webroot
* 3. composer.json
* 4. composer.lock
* 5. Scaffold files as determined by the drupal/core-composer-scaffold plugin
* If web root and project root are same then nothing is excluded.
*
* @internal
* This is an internal part of Package Manager and may be changed or removed
* at any time without warning. External code should not interact with this
* class.
*/
final
class
UnknownPathExcluder
implements
EventSubscriberInterface
{
use
PathExclusionsTrait
;
/**
* Constructs a UnknownPathExcluder object.
*
* @param \Drupal\package_manager\PathLocator $path_locator
* The path locator service.
*/
public
function
__construct
(
PathLocator
$path_locator
)
{
$this
->
pathLocator
=
$path_locator
;
}
/**
* {@inheritdoc}
*/
public
static
function
getSubscribedEvents
():
array
{
return
[
CollectIgnoredPathsEvent
::
class
=>
'excludeUnknownPaths'
,
];
}
/**
* Excludes unknown paths from stage operations.
*
* @param \Drupal\package_manager\Event\CollectIgnoredPathsEvent $event
* The event object.
*/
public
function
excludeUnknownPaths
(
CollectIgnoredPathsEvent
$event
):
void
{
$project_root
=
$this
->
pathLocator
->
getProjectRoot
();
$web_root
=
$project_root
.
DIRECTORY_SEPARATOR
.
$this
->
pathLocator
->
getWebRoot
();
if
(
realpath
(
$web_root
)
===
$project_root
)
{
return
;
}
$vendor_dir
=
$this
->
pathLocator
->
getVendorDirectory
();
// @todo Refactor in https://www.drupal.org/project/automatic_updates/issues/3334994.
$core_packages
=
$event
->
getStage
()
->
getActiveComposer
()
->
getCorePackages
();
$scaffold_files_paths
=
$this
->
getScaffoldFiles
(
$core_packages
);
$paths_in_project_root
=
glob
(
"
$project_root
/*"
);
$paths
=
[];
$known_paths
=
array_merge
([
$vendor_dir
,
$web_root
,
"
$project_root
/composer.json"
,
"
$project_root
/composer.lock"
],
$scaffold_files_paths
);
foreach
(
$paths_in_project_root
as
$path_in_project_root
)
{
if
(
!
in_array
(
$path_in_project_root
,
$known_paths
,
TRUE
))
{
$paths
[]
=
$path_in_project_root
;
}
}
$this
->
excludeInProjectRoot
(
$event
,
$paths
);
}
/**
* Gets the path of scaffold files, for example 'index.php' and 'robots.txt'.
*
* @param string[] $core_packages
* The installed core packages.
*
* @return array
* The array of scaffold file paths.
*/
private
function
getScaffoldFiles
(
array
$core_packages
):
array
{
$scaffold_file_paths
=
[];
/** @var \Composer\Package\PackageInterface $package */
foreach
(
$core_packages
as
$package
)
{
$core_composer_extra
=
$package
->
getExtra
();
if
(
array_key_exists
(
'drupal-scaffold'
,
$core_composer_extra
))
{
$scaffold_file_paths
=
array_merge
(
$scaffold_file_paths
,
array_keys
(
$core_composer_extra
[
'drupal-scaffold'
][
'file-mapping'
]));
}
}
return
$scaffold_file_paths
;
}
}
Loading