class DrupalEncrypt in Backup and Migrate 5.0.x
@package Drupal\backup_migrate\Drupal\Filter
Hierarchy
- class \Drupal\backup_migrate\Core\Plugin\PluginBase implements ConfigurableInterface, PluginInterface uses ConfigurableTrait
- class \Drupal\backup_migrate\Drupal\Filter\DrupalEncrypt implements FileProcessorInterface uses FileProcessorTrait
Expanded class hierarchy of DrupalEncrypt
1 file declares its use of DrupalEncrypt
- backup_migrate.module in ./
backup_migrate.module - Primary hook implementations for Backup Migrate.
File
- src/
Drupal/ Filter/ DrupalEncrypt.php, line 18
Namespace
Drupal\backup_migrate\Drupal\FilterView source
class DrupalEncrypt extends PluginBase implements FileProcessorInterface {
use FileProcessorTrait;
/**
* {@inheritdoc}
*/
public function configSchema(array $params = []) {
$schema = [];
// Backup configuration.
if ($params['operation'] == 'backup' || $params['operation'] == 'restore') {
if (class_exists('\\Defuse\\Crypto\\File')) {
$schema['groups']['encrypt'] = [
'title' => 'Backup Encryption',
];
$schema['fields']['encrypt'] = [
'group' => 'encrypt',
'type' => 'boolean',
'title' => $params['operation'] == 'backup' ? $this
->t('Encrypt File') : $this
->t('Decrypt file'),
'description' => $this
->t('Password for encrypting / decrypting the file'),
];
$schema['fields']['encrypt_password'] = [
'group' => 'encrypt',
'type' => 'password',
'title' => $params['operation'] == 'backup' ? $this
->t('Encryption Password') : $this
->t('Decryption Password'),
];
}
else {
\Drupal::messenger()
->addMessage(t('In order to encrypt backup files, please install the Defuse PHP-encryption library via Composer with the following command: <code>composer require defuse/php-encryption</code>. See the <a href="@docs">Defuse PHP Encryption Documentation Page</a> for more information.', array(
'@docs' => 'https://www.drupal.org/node/3185484',
)), 'status');
}
}
return $schema;
}
/**
* Get the default values for the plugin.
*
* @return \Drupal\backup_migrate\Core\Config\Config
*/
public function configDefaults() {
return new Config([
'encrypt' => FALSE,
]);
}
/**
*
*/
protected function _encryptFile(BackupFileReadableInterface $from, BackupFileWritableInterface $to) {
$path = \Drupal::service('file_system')
->realpath($from
->realpath());
$out_path = \Drupal::service('file_system')
->realpath($to
->realpath());
try {
CryptoFile::encryptFileWithPassword($path, $out_path, $this
->confGet('encrypt_password'));
$fileszc = filesize(\Drupal::service('file_system')
->realpath($to
->realpath()));
$to
->setMeta('filesize', $fileszc);
return TRUE;
} catch (Exception $e) {
return FALSE;
}
}
/**
*
*/
protected function decryptFile(BackupFileReadableInterface $from, BackupFileWritableInterface $to) {
$path = \Drupal::service('file_system')
->realpath($from
->realpath());
$out_path = \Drupal::service('file_system')
->realpath($to
->realpath());
try {
CryptoFile::decryptFileWithPassword($path, $out_path, $this
->confGet('encrypt_password'));
return TRUE;
} catch (Exception $e) {
return FALSE;
}
}
/**
*
*/
public function beforeRestore(BackupFileReadableInterface $file) {
$type = $file
->getExtLast();
if ($type == 'ssl' && $this
->confGet('encrypt')) {
$out = $this
->getTempFileManager()
->popExt($file);
$success = $this
->decryptFile($file, $out);
if ($out && $success) {
return $out;
}
}
return $file;
}
/**
*
*/
public function supportedOps() {
return [
'getFileTypes' => [],
'backupSettings' => [],
'afterBackup' => [
'weight' => 1000,
],
'beforeRestore' => [
'weight' => -1000,
],
];
}
/**
*
*/
public function afterBackup(BackupFileReadableInterface $file) {
if ($this
->confGet('encrypt')) {
$out = $this
->getTempFileManager()
->pushExt($file, 'ssl');
$success = $this
->_encryptFile($file, $out);
if ($out && $success) {
return $out;
}
}
return $file;
}
}
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 any validation errors in the config. | |
ConfigurableTrait:: |
public | function | Set the configuration for all plugins. | 1 |
ConfigurableTrait:: |
public | function | 2 | |
DrupalEncrypt:: |
public | function | ||
DrupalEncrypt:: |
public | function | ||
DrupalEncrypt:: |
public | function |
Get the default values for the plugin. Overrides ConfigurableTrait:: |
|
DrupalEncrypt:: |
public | function |
Get a default (blank) schema. Overrides ConfigurableTrait:: |
|
DrupalEncrypt:: |
protected | function | ||
DrupalEncrypt:: |
public | function |
Get a list of supported operations and their weight. Overrides PluginBase:: |
|
DrupalEncrypt:: |
protected | function | ||
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:: |
|
TranslatableTrait:: |
protected | property | ||
TranslatableTrait:: |
public | function | ||
TranslatableTrait:: |
public | function | Translate the given string if there is a translator service available. |