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
!1046
Issue
#3437409
ForbidCoreChangesValidator.php
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3437409
ForbidCoreChangesValidator.php
issue/automatic_updates-3437409:3437409-dont-allow-core
into
3.0.x
Overview
11
Commits
9
Pipelines
10
Changes
12
2 unresolved threads
Hide all comments
Merged
Ted Bowman
requested to merge
issue/automatic_updates-3437409:3437409-dont-allow-core
into
3.0.x
11 months ago
Overview
11
Commits
9
Pipelines
10
Changes
12
2 unresolved threads
Hide all comments
Expand
Closes
#3437409
0
0
Merge request reports
Viewing commit
d5b8d0ac
Prev
Next
Show latest version
12 files
+
234
−
2
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
12
Search (e.g. *.vue) (Ctrl+P)
d5b8d0ac
Merge branch '3.0.x' into 3437409-dont-allow-core
· d5b8d0ac
Ted Bowman
authored
11 months ago
automatic_updates_extensions/src/Validator/RequestedUpdateValidator.php
0 → 100644
+
105
−
0
Options
<?php
declare
(
strict_types
=
1
);
namespace
Drupal\automatic_updates_extensions\Validator
;
use
Composer\Semver\Semver
;
use
Drupal\automatic_updates_extensions
\ExtensionUpdateStage
;
use
Drupal\Core\StringTranslation\StringTranslationTrait
;
use
Drupal\package_manager
\ComposerInspector
;
use
Drupal\package_manager
\Event\PreApplyEvent
;
use
Drupal\package_manager
\Event\StatusCheckEvent
;
use
Drupal\package_manager
\PathLocator
;
use
Symfony\Component\EventDispatcher\EventSubscriberInterface
;
/**
* Validates that requested packages have been updated.
*
* @internal
* This is an internal part of Automatic Updates and may be changed or removed
* at any time without warning. External code should not interact with this
* class.
*/
final
class
RequestedUpdateValidator
implements
EventSubscriberInterface
{
use
StringTranslationTrait
;
/**
* Constructs a RequestedUpdateValidator object.
*
* @param \Drupal\package_manager\ComposerInspector $composerInspector
* The Composer inspector service.
* @param \Drupal\package_manager\PathLocator $pathLocator
* The path locator service.
*/
public
function
__construct
(
private
readonly
ComposerInspector
$composerInspector
,
private
readonly
PathLocator
$pathLocator
,
)
{}
/**
* Validates that requested packages have been updated to the right version.
*
* @param \Drupal\package_manager\Event\PreApplyEvent|\Drupal\package_manager\Event\StatusCheckEvent $event
* The pre-apply event.
*/
public
function
checkRequestedStagedVersion
(
PreApplyEvent
|
StatusCheckEvent
$event
):
void
{
$stage
=
$event
->
stage
;
if
(
$stage
->
getType
()
!==
'automatic_updates_extensions:attended'
||
!
$stage
->
stageDirectoryExists
())
{
return
;
}
$requested_package_versions
=
$stage
->
getPackageVersions
();
$active
=
$this
->
composerInspector
->
getInstalledPackagesList
(
$this
->
pathLocator
->
getProjectRoot
());
$staged
=
$this
->
composerInspector
->
getInstalledPackagesList
(
$event
->
stage
->
getStageDirectory
());
$changed_stage_packages
=
$staged
->
getPackagesWithDifferentVersionsIn
(
$active
)
->
getArrayCopy
();
if
(
empty
(
$changed_stage_packages
))
{
$event
->
addError
([
$this
->
t
(
'No updates detected in the staging area.'
)]);
return
;
}
// Check for all changed the packages if they are updated to the requested
// version.
foreach
([
'production'
,
'dev'
]
as
$package_type
)
{
foreach
(
$requested_package_versions
[
$package_type
]
as
$requested_package_name
=>
$requested_version
)
{
if
(
array_key_exists
(
$requested_package_name
,
$changed_stage_packages
))
{
$staged_version
=
$changed_stage_packages
[
$requested_package_name
]
->
version
;
if
(
!
Semver
::
satisfies
(
$staged_version
,
$requested_version
))
{
$event
->
addError
([
$this
->
t
(
"The requested update to '@requested_package_name' to version '@requested_version' does not match the actual staged update to '@staged_version'."
,
[
'@requested_package_name'
=>
$requested_package_name
,
'@requested_version'
=>
$requested_version
,
'@staged_version'
=>
$staged_version
,
]
),
]);
}
}
else
{
$event
->
addError
([
$this
->
t
(
"The requested update to '@requested_package_name' to version '@requested_version' was not performed."
,
[
'@requested_package_name'
=>
$requested_package_name
,
'@requested_version'
=>
$requested_version
,
]
),
]);
}
}
}
}
/**
* {@inheritdoc}
*/
public
static
function
getSubscribedEvents
():
array
{
$events
[
StatusCheckEvent
::
class
][]
=
[
'checkRequestedStagedVersion'
];
$events
[
PreApplyEvent
::
class
][]
=
[
'checkRequestedStagedVersion'
];
return
$events
;
}
}
Loading