class DrupalEncrypt in Backup and Migrate 8.4
Class DrupalEncrypt.
@package BackupMigrate\Drupal\Filter
Hierarchy
- class \BackupMigrate\Core\Plugin\PluginBase implements ConfigurableInterface, PluginInterface uses ConfigurableTrait
- class \BackupMigrate\Drupal\Filter\DrupalEncrypt implements FileProcessorInterface uses FileProcessorTrait
Expanded class hierarchy of DrupalEncrypt
File
- src/
Filter/ DrupalEncrypt.php, line 19
Namespace
BackupMigrate\Drupal\FilterView source
class DrupalEncrypt extends PluginBase implements FileProcessorInterface {
use FileProcessorTrait;
/**
* {@inheritdoc}
*/
public function configSchema($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_set_message($this
->t('Please install the Defuse PHP-encryption library via Composer to be able to encrypt backup files.'), 'warning');
}
}
return $schema;
}
/**
* Get the default values for the plugin.
*
* @return \BackupMigrate\Core\Config\Config
*/
public function configDefaults() {
return new Config([
'encrypt' => FALSE,
]);
}
protected function _encryptFile(BackupFileReadableInterface $from, BackupFileWritableInterface $to) {
$path = drupal_realpath($from
->realpath());
$out_path = drupal_realpath($to
->realpath());
try {
CryptoFile::encryptFileWithPassword($path, $out_path, $this
->confGet('encrypt_password'));
$fileszc = filesize(drupal_realpath($to
->realpath()));
$to
->setMeta('filesize', $fileszc);
return TRUE;
} catch (Exception $e) {
return FALSE;
}
}
protected function _decryptFile(BackupFileReadableInterface $from, BackupFileWritableInterface $to) {
$path = drupal_realpath($from
->realpath());
$out_path = drupal_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. These configuration options can be overriden by the config options but will not be overwritten. If the object is re-configured after construction any missing configuration options will revert to these values. | |
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:: |
public | function |
Get a list of supported operations and their weight. Overrides PluginBase:: |
|
DrupalEncrypt:: |
protected | function | ||
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. |