class ReadOnlyFilesystem in Automatic Updates 8
Read only filesystem checker.
Hierarchy
- class \Drupal\automatic_updates\ReadinessChecker\Filesystem implements ReadinessCheckerInterface uses StringTranslationTrait
- class \Drupal\automatic_updates\ReadinessChecker\ReadOnlyFilesystem
Expanded class hierarchy of ReadOnlyFilesystem
1 file declares its use of ReadOnlyFilesystem
- ReadOnlyFilesystemTest.php in tests/
src/ Kernel/ ReadinessChecker/ ReadOnlyFilesystemTest.php
1 string reference to 'ReadOnlyFilesystem'
1 service uses ReadOnlyFilesystem
File
- src/
ReadinessChecker/ ReadOnlyFilesystem.php, line 13
Namespace
Drupal\automatic_updates\ReadinessCheckerView source
class ReadOnlyFilesystem extends Filesystem {
/**
* The logger.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* The file system service.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $fileSystem;
/**
* ReadOnlyFilesystem constructor.
*
* @param string $app_root
* The app root.
* @param \Psr\Log\LoggerInterface $logger
* The logger.
* @param \Drupal\Core\File\FileSystemInterface $file_system
* The file system service.
*/
public function __construct($app_root, LoggerInterface $logger, FileSystemInterface $file_system) {
parent::__construct($app_root);
$this->logger = $logger;
$this->fileSystem = $file_system;
}
/**
* {@inheritdoc}
*/
protected function doCheck() {
return $this
->readOnlyCheck();
}
/**
* Check if the filesystem is read only.
*
* @return array
* An array of translatable strings if any checks fail.
*/
protected function readOnlyCheck() {
$messages = [];
if ($this
->areSameLogicalDisk($this
->getRootPath(), $this
->getVendorPath())) {
$error = $this
->t('Logical disk at "@path" is read only. Updates to Drupal cannot be applied against a read only file system.', [
'@path' => $this->rootPath,
]);
$this
->doReadOnlyCheck($this
->getRootPath(), 'core/core.api.php', $messages, $error);
}
else {
$error = $this
->t('Drupal core filesystem at "@path" is read only. Updates to Drupal core cannot be applied against a read only file system.', [
'@path' => $this->rootPath . '/core',
]);
$this
->doReadOnlyCheck($this
->getRootPath(), implode(DIRECTORY_SEPARATOR, [
'core',
'core.api.php',
]), $messages, $error);
$error = $this
->t('Vendor filesystem at "@path" is read only. Updates to the site\'s code base cannot be applied against a read only file system.', [
'@path' => $this->vendorPath,
]);
$this
->doReadOnlyCheck($this
->getVendorPath(), 'composer/LICENSE', $messages, $error);
}
return $messages;
}
/**
* Do the read only check.
*
* @param string $file_path
* The filesystem to test.
* @param string $file
* The file path.
* @param array $messages
* The messages array of translatable strings.
* @param \Drupal\Component\Render\MarkupInterface $message
* The error message to add if the file is read only.
*/
protected function doReadOnlyCheck($file_path, $file, array &$messages, MarkupInterface $message) {
// Ignore check if the path doesn't exit.
if (!is_file($file_path . DIRECTORY_SEPARATOR . $file)) {
return;
}
try {
// If we can copy and delete a file, then we don't have a read only
// file system.
if ($this->fileSystem
->copy($file_path . DIRECTORY_SEPARATOR . $file, $file_path . DIRECTORY_SEPARATOR . "{$file}.automatic_updates", FileSystemInterface::EXISTS_REPLACE)) {
// Delete it after copying.
$this->fileSystem
->delete($file_path . DIRECTORY_SEPARATOR . "{$file}.automatic_updates");
}
else {
$this->logger
->error($message);
$messages[] = $message;
}
} catch (FileException $exception) {
$messages[] = $message;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Filesystem:: |
protected | property | The root file path. | |
Filesystem:: |
protected | property | The vendor file path. | |
Filesystem:: |
protected | function | Determine if the root and vendor file system are the same logical disk. | 2 |
Filesystem:: |
protected | function | Get the root file path. | |
Filesystem:: |
protected | function | Get the vendor file path. | |
Filesystem:: |
public | function |
Run check. Overrides ReadinessCheckerInterface:: |
|
ReadOnlyFilesystem:: |
protected | property | The file system service. | |
ReadOnlyFilesystem:: |
protected | property | The logger. | |
ReadOnlyFilesystem:: |
protected | function |
Perform checks. Overrides Filesystem:: |
|
ReadOnlyFilesystem:: |
protected | function | Do the read only check. | |
ReadOnlyFilesystem:: |
protected | function | Check if the filesystem is read only. | |
ReadOnlyFilesystem:: |
public | function |
ReadOnlyFilesystem constructor. Overrides Filesystem:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |