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
!132
Issue
#3252126
: Detect DB updates and do not apply a update via cron if there is a DB update
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3252126
: Detect DB updates and do not apply a update via cron if there is a DB update
issue/automatic_updates-3252126:3252126-detect-db-updates
into
8.x-2.x
Overview
22
Commits
27
Pipelines
0
Changes
5
Merged
Ted Bowman
requested to merge
issue/automatic_updates-3252126:3252126-detect-db-updates
into
8.x-2.x
3 years ago
Overview
5
Commits
27
Pipelines
0
Changes
5
Expand
0
0
Merge request reports
Compare
8.x-2.x
version 24
bdc5d063
3 years ago
version 23
0ee5a152
3 years ago
version 22
949c6bb4
3 years ago
version 21
f902b6b2
3 years ago
version 20
7e862068
3 years ago
version 19
b36f1668
3 years ago
version 18
6a5c4d6d
3 years ago
version 17
5d7c0655
3 years ago
version 16
336950e1
3 years ago
version 15
46c5b367
3 years ago
version 14
fa226980
3 years ago
version 13
9fd8060d
3 years ago
version 12
b1d90e0d
3 years ago
version 11
a346cea8
3 years ago
version 10
72078348
3 years ago
version 9
ad0823d6
3 years ago
version 8
9ab187ac
3 years ago
version 7
b1f2e57d
3 years ago
version 6
b02d0828
3 years ago
version 5
cf427278
3 years ago
version 4
67a3a082
3 years ago
version 3
bb143a4f
3 years ago
version 2
43ccd94b
3 years ago
version 1
8f6d7bd9
3 years ago
8.x-2.x (base)
and
version 16
latest version
bdc5d063
27 commits,
3 years ago
version 24
bdc5d063
27 commits,
3 years ago
version 23
0ee5a152
26 commits,
3 years ago
version 22
949c6bb4
25 commits,
3 years ago
version 21
f902b6b2
24 commits,
3 years ago
version 20
7e862068
23 commits,
3 years ago
version 19
b36f1668
22 commits,
3 years ago
version 18
6a5c4d6d
21 commits,
3 years ago
version 17
5d7c0655
20 commits,
3 years ago
version 16
336950e1
19 commits,
3 years ago
version 15
46c5b367
18 commits,
3 years ago
version 14
fa226980
17 commits,
3 years ago
version 13
9fd8060d
16 commits,
3 years ago
version 12
b1d90e0d
15 commits,
3 years ago
version 11
a346cea8
13 commits,
3 years ago
version 10
72078348
11 commits,
3 years ago
version 9
ad0823d6
10 commits,
3 years ago
version 8
9ab187ac
9 commits,
3 years ago
version 7
b1f2e57d
8 commits,
3 years ago
version 6
b02d0828
7 commits,
3 years ago
version 5
cf427278
6 commits,
3 years ago
version 4
67a3a082
5 commits,
3 years ago
version 3
bb143a4f
3 commits,
3 years ago
version 2
43ccd94b
2 commits,
3 years ago
version 1
8f6d7bd9
1 commit,
3 years ago
5 files
+
327
−
32
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
src/Validator/StagedUpdateFunctionsValidator.php
0 → 100644
+
161
−
0
Options
<?php
namespace
Drupal\automatic_updates\Validator
;
use
Drupal\automatic_updates
\Updater
;
use
Drupal\Core\Extension\Extension
;
use
Drupal\Core\Extension\ModuleExtensionList
;
use
Drupal\Core\StringTranslation\StringTranslationTrait
;
use
Drupal\Core\StringTranslation\TranslationInterface
;
use
Drupal\package_manager
\Event\PreApplyEvent
;
use
Drupal\package_manager
\PathLocator
;
use
Symfony\Component\EventDispatcher\EventSubscriberInterface
;
/**
* Validates that staged update functions are unchanged.
*/
class
StagedUpdateFunctionsValidator
implements
EventSubscriberInterface
{
use
StringTranslationTrait
;
/**
* The path locator service.
*
* @var \Drupal\package_manager\PathLocator
*/
protected
$pathLocator
;
/**
* The module list service.
*
* @var \Drupal\Core\Extension\ModuleExtensionList
*/
protected
$moduleList
;
/**
* Constructs a StagedUpdateFunctionsValidator object.
*
* @param \Drupal\package_manager\PathLocator $path_locator
* The path locator service.
* @param \Drupal\Core\Extension\ModuleExtensionList $module_list
* The module list service.
* @param \Drupal\Core\StringTranslation\TranslationInterface $translation
* The string translation service.
*/
public
function
__construct
(
PathLocator
$path_locator
,
ModuleExtensionList
$module_list
,
TranslationInterface
$translation
)
{
$this
->
pathLocator
=
$path_locator
;
$this
->
moduleList
=
$module_list
;
$this
->
setStringTranslation
(
$translation
);
}
/**
* Checks that the staged update does not have changes to its install files.
*
* @param \Drupal\package_manager\Event\PreApplyEvent $event
* The event object.
*/
public
function
checkUpdateHooks
(
PreApplyEvent
$event
):
void
{
$stage
=
$event
->
getStage
();
if
(
!
$stage
instanceof
Updater
)
{
return
;
}
$active_dir
=
$this
->
pathLocator
->
getActiveDirectory
();
$stage_dir
=
$stage
->
getStageDirectory
();
$web_root
=
$this
->
pathLocator
->
getWebRoot
();
if
(
$web_root
)
{
$active_dir
.
=
DIRECTORY_SEPARATOR
.
$web_root
;
$stage_dir
.
=
DIRECTORY_SEPARATOR
.
$web_root
;
}
$invalid_modules
=
[];
// Although \Drupal\automatic_updates\Validator\StagedProjectsValidator
// should prevent non-core modules from being added, updated, or removed in
// the staging area, we check all installed modules so as not to rely on the
// presence of StagedProjectsValidator.
foreach
(
$this
->
moduleList
->
getAllInstalledInfo
()
as
$name
=>
$info
)
{
if
(
$this
->
hasStagedUpdates
(
$active_dir
,
$stage_dir
,
$this
->
moduleList
->
get
(
$name
)))
{
$invalid_modules
[]
=
$info
[
'name'
];
}
}
if
(
$invalid_modules
)
{
$event
->
addError
(
$invalid_modules
,
$this
->
t
(
'The update cannot proceed because possible database updates have been detected in the following modules.'
));
}
}
/**
* Determines if a staged extension has changed update functions.
*
* @param string $active_dir
* The path of the running Drupal code base.
* @param string $stage_dir
* The path of the staging area.
* @param \Drupal\Core\Extension\Extension $extension
* The extension to check.
*
* @return bool
* TRUE if the staged copy of the extension has changed update functions
* compared to the active copy, FALSE otherwise.
*
* @todo Use a more sophisticated method to detect changes in the staged
* extension. Right now, we just compare hashes of the .install and
* .post_update.php files in both copies of the given extension, but this
* will cause a false positives for changes to comments, whitespace, or
* runtime code like requirements checks. It would be preferable to use a
* static analyzer to detect new or changed functions that are actually
* executed during an update. In any event, it's critical that this method
* NEVER produce false negatives, since that could result in code which is
* incompatible with the current database schema being copied to the active
* directory.
*
* @see https://www.drupal.org/project/automatic_updates/issues/3253828
*/
protected
function
hasStagedUpdates
(
string
$active_dir
,
string
$stage_dir
,
Extension
$extension
):
bool
{
$active_hashes
=
$this
->
getHashes
(
$active_dir
,
$extension
);
$staged_hashes
=
$this
->
getHashes
(
$stage_dir
,
$extension
);
return
$active_hashes
!==
$staged_hashes
;
}
/**
* Returns hashes of the .install and .post-update.php files for a module.
*
* @param string $root_dir
* The root directory of the Drupal code base.
* @param \Drupal\Core\Extension\Extension $module
* The module to check.
*
* @return string[]
* The hashes of the module's .install and .post_update.php files, in that
* order, if they exist. The array will be keyed by file extension.
*/
protected
function
getHashes
(
string
$root_dir
,
Extension
$module
):
array
{
$path
=
implode
(
DIRECTORY_SEPARATOR
,
[
$root_dir
,
$module
->
getPath
(),
$module
->
getName
(),
]);
$hashes
=
[];
foreach
([
'.install'
,
'.post_update.php'
]
as
$suffix
)
{
$file
=
$path
.
$suffix
;
if
(
file_exists
(
$file
))
{
$hashes
[
$suffix
]
=
hash_file
(
'sha256'
,
$file
);
}
}
return
$hashes
;
}
/**
* {@inheritdoc}
*/
public
static
function
getSubscribedEvents
()
{
return
[
PreApplyEvent
::
class
=>
'checkUpdateHooks'
,
];
}
}
Loading