class DrupalDirectoryDestination in Backup and Migrate 5.0.x
@package Drupal\backup_migrate\Drupal\Destination
Hierarchy
- class \Drupal\backup_migrate\Core\Plugin\PluginBase implements ConfigurableInterface, PluginInterface uses ConfigurableTrait
- class \Drupal\backup_migrate\Core\Destination\DestinationBase implements ReadableDestinationInterface, WritableDestinationInterface
- class \Drupal\backup_migrate\Core\Destination\DirectoryDestination implements ConfigurableInterface, ListableDestinationInterface, ReadableDestinationInterface, FileProcessorInterface uses SidecarMetadataDestinationTrait
- class \Drupal\backup_migrate\Drupal\Destination\DrupalDirectoryDestination
- class \Drupal\backup_migrate\Core\Destination\DirectoryDestination implements ConfigurableInterface, ListableDestinationInterface, ReadableDestinationInterface, FileProcessorInterface uses SidecarMetadataDestinationTrait
- class \Drupal\backup_migrate\Core\Destination\DestinationBase implements ReadableDestinationInterface, WritableDestinationInterface
Expanded class hierarchy of DrupalDirectoryDestination
1 file declares its use of DrupalDirectoryDestination
- DrupalConfigHelper.php in src/
Drupal/ Config/ DrupalConfigHelper.php
File
- src/
Drupal/ Destination/ DrupalDirectoryDestination.php, line 17
Namespace
Drupal\backup_migrate\Drupal\DestinationView source
class DrupalDirectoryDestination extends DirectoryDestination {
/**
* Do the actual file save.
*
* This function is called to save the data file AND the metadata sidecar
* file.
*
* @param \Drupal\backup_migrate\Core\File\BackupFileReadableInterface $file
*
* @throws \Drupal\backup_migrate\Core\Exception\BackupMigrateException
*/
public function saveTheFile(BackupFileReadableInterface $file) {
// Check if the directory exists.
$this
->checkDirectory();
try {
\Drupal::service('file_system')
->move($file
->realpath(), $this
->idToPath($file
->getFullName()), FileSystemInterface::EXISTS_REPLACE);
} catch (FileException $e) {
return FALSE;
}
}
/**
* Check that the directory can be used for backup.
*
* @throws \Drupal\backup_migrate\Core\Exception\BackupMigrateException
*/
protected function checkDirectory() {
// @todo Figure out if the file is or might be accessible via the web.
$dir = $this
->confGet('directory');
$is_private = strpos($dir, 'private://') === 0;
// Attempt to create/prepare the directory if it is in the private
// directory.
if ($is_private) {
if (!PrivateStream::basePath()) {
throw new BackupMigrateException("The backup file could not be saved to '%dir' because your private files system path has not been set.", [
'%dir' => $dir,
]);
}
if (!\Drupal::service('file_system')
->prepareDirectory($dir, FileSystemInterface::CREATE_DIRECTORY && FileSystemInterface::MODIFY_PERMISSIONS)) {
throw new BackupMigrateException("The backup file could not be saved to '%dir' because the directory could not be created or cannot be written to. Please make sure your private files directory is writable by the web server.", [
'%dir' => $dir,
]);
}
}
else {
// If the file is local to the server.
$real = \Drupal::service('file_system')
->realpath($dir);
if ($real) {
// If the file is within the docroot.
$in_root = strpos($real, DRUPAL_ROOT) === 0;
if ($in_root) {
throw new BackupMigrateException("The backup file could not be saved to '%dir' because that directory may be publicly accessible via the web. Please save your backups to the private file directory or a directory outside of the web root.", [
'%dir' => $dir,
]);
}
}
}
// Do the regular exists/writable checks.
parent::checkDirectory();
// @todo Warn if the realpath cannot be resolved (because we cannot
// determine if the file is publicly accessible).
}
/**
* {@inheritdoc}
*/
public function queryFiles(array $filters = [], $sort = 'datestamp', $sort_direction = SORT_DESC, $count = 100, $start = 0) {
// Get the full list of files.
$out = $this
->listFiles($count + $start);
foreach ($out as $key => $file) {
$out[$key] = $this
->loadFileMetadata($file);
}
// Filter the output.
if ($filters) {
$out = array_filter($out, function ($file) use ($filters) {
foreach ($filters as $key => $value) {
if ($file
->getMeta($key) !== $value) {
return FALSE;
}
}
return TRUE;
});
}
// Sort the files.
if ($sort && $sort_direction) {
uasort($out, function ($a, $b) use ($sort, $sort_direction) {
if ($sort_direction == SORT_DESC) {
if ($sort == 'name') {
return $a
->getFullName() <=> $b
->getFullName();
}
// @todo fix this in core
return $a
->getMeta($sort) <=> $b
->getMeta($sort);
}
else {
if ($sort == 'name') {
return $b
->getFullName() <=> $a
->getFullName();
}
// @todo fix this in core
return $b
->getMeta($sort) <=> $a
->getMeta($sort);
}
});
}
// Slice the return array.
if ($count || $start) {
$out = array_slice($out, $start, $count);
}
return $out;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigurableTrait:: |
protected | property | The object's configuration object. | |
ConfigurableTrait:: |
protected | property | The initial configuration. | |
ConfigurableTrait:: |
public | function | Get a specific value from the configuration. | |
ConfigurableTrait:: |
public | function | Get the configuration object for this item. | |
ConfigurableTrait:: |
public | function | Get the default values for the plugin. | 10 |
ConfigurableTrait:: |
public | function | Get any validation errors in the config. | |
ConfigurableTrait:: |
public | function | Set the configuration for all plugins. | 1 |
ConfigurableTrait:: |
public | function | 2 | |
DestinationBase:: |
public | function | ||
DestinationBase:: |
public | function |
Load the metadata for the given file however it may be stored. Overrides ReadableDestinationInterface:: |
|
DestinationBase:: |
public | function |
Get a list of supported operations and their weight. Overrides PluginBase:: |
|
DirectoryDestination:: |
public | function |
Overrides DestinationBase:: |
|
DirectoryDestination:: |
public | function |
Get a definition for user-configurable settings. Overrides ConfigurableTrait:: |
|
DirectoryDestination:: |
public | function |
Overrides ListableDestinationInterface:: |
|
DirectoryDestination:: |
public | function |
Do the actual delete for a file. Overrides DestinationBase:: |
|
DirectoryDestination:: |
public | function |
Does the file with the given id (filename) exist in this destination. Overrides ReadableDestinationInterface:: |
|
DirectoryDestination:: |
protected | function | Get the entire file list from this destination. | |
DirectoryDestination:: |
public | function |
Get a file object representing the file with the given ID from the dest. Overrides ReadableDestinationInterface:: |
|
DirectoryDestination:: |
protected | function | Return a file path for the given file id. | |
DirectoryDestination:: |
public | function |
Return a list of files from the destination. Overrides ListableDestinationInterface:: |
|
DirectoryDestination:: |
public | function |
Load the file with the given ID from the destination. Overrides ReadableDestinationInterface:: |
|
DirectoryDestination:: |
public | function |
Save a file to the destination. Overrides DestinationBase:: |
|
DrupalDirectoryDestination:: |
protected | function |
Check that the directory can be used for backup. Overrides DirectoryDestination:: |
|
DrupalDirectoryDestination:: |
public | function |
Run a basic query with sort on the list of files. Overrides DirectoryDestination:: |
|
DrupalDirectoryDestination:: |
public | function |
Do the actual file save. Overrides DirectoryDestination:: |
|
FileProcessorTrait:: |
protected | property | ||
FileProcessorTrait:: |
public | function | Provide the file mime for the given file extension if known. | |
FileProcessorTrait:: |
public | function | Get the temp file manager. | |
FileProcessorTrait:: |
public | function | Inject the temp file manager. | |
PluginBase:: |
public | function |
What is the weight of the given operation for this plugin. Overrides PluginInterface:: |
|
PluginBase:: |
public | function |
Does this plugin implement the given operation. Overrides PluginInterface:: |
|
SidecarMetadataDestinationTrait:: |
protected | function | ||
SidecarMetadataDestinationTrait:: |
public | function | ||
SidecarMetadataDestinationTrait:: |
protected | function | Parse an INI file's contents. | |
SidecarMetadataDestinationTrait:: |
protected | function | ||
SidecarMetadataDestinationTrait:: |
protected | function | ||
TranslatableTrait:: |
protected | property | ||
TranslatableTrait:: |
public | function | ||
TranslatableTrait:: |
public | function | Translate the given string if there is a translator service available. |