protected function InPlaceUpdate::checkModifiedFiles in Automatic Updates 8
Check if files are modified before applying updates.
Parameters
\Drupal\automatic_updates\UpdateMetadata $metadata: The update metadata.
\Drupal\Core\Archiver\ArchiverInterface $archive: The archive.
Return value
bool Return TRUE if modified files exist, FALSE otherwise.
1 call to InPlaceUpdate::checkModifiedFiles()
- InPlaceUpdate::update in src/
Services/ InPlaceUpdate.php - Update a project to the next release.
File
- src/
Services/ InPlaceUpdate.php, line 229
Class
- InPlaceUpdate
- Class to apply in-place updates.
Namespace
Drupal\automatic_updates\ServicesCode
protected function checkModifiedFiles(UpdateMetadata $metadata, ArchiverInterface $archive) {
if ($metadata
->getProjectType() === 'core') {
$metadata
->setProjectType('module');
}
$extensions = $this
->getInfos($metadata
->getProjectType());
/** @var \Drupal\automatic_updates\Services\ModifiedFilesInterface $modified_files */
$modified_files = \Drupal::service('automatic_updates.modified_files');
try {
$files = iterator_to_array($modified_files
->getModifiedFiles([
$extensions[$metadata
->getProjectName()],
]));
} catch (RequestException $exception) {
// While not strictly true that there are modified files, we can't be sure
// there aren't any. So assume the worst.
return TRUE;
}
$files = array_unique($files);
$archive_files = $archive
->listContents();
foreach ($archive_files as $index => &$archive_file) {
$skipped_files = [
self::DELETION_MANIFEST,
];
// Skip certain files and all directories.
if (in_array($archive_file, $skipped_files, TRUE) || substr($archive_file, -1) === '/') {
unset($archive_files[$index]);
continue;
}
$this
->stripFileDirectoryPath($archive_file);
}
unset($archive_file);
if ($intersection = array_intersect($files, $archive_files)) {
$this->logger
->error('Can not update because %count files are modified: %paths', [
'%count' => count($intersection),
'%paths' => implode(', ', $intersection),
]);
return TRUE;
}
return FALSE;
}