Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Save.php
Go to the documentation of this file.
1 <?php
9 
14 {
18  protected $encryptor;
19 
23  protected $change;
24 
28  protected $cache;
29 
36  public function __construct(
37  \Magento\Backend\App\Action\Context $context,
38  \Magento\Framework\Encryption\EncryptorInterface $encryptor,
39  \Magento\EncryptionKey\Model\ResourceModel\Key\Change $change,
40  \Magento\Framework\App\CacheInterface $cache
41  ) {
42  $this->encryptor = $encryptor;
43  $this->change = $change;
44  $this->cache = $cache;
45  parent::__construct($context);
46  }
47 
53  public function execute()
54  {
55  try {
56  $key = null;
57 
58  if (0 == $this->getRequest()->getPost('generate_random')) {
59  $key = $this->getRequest()->getPost('crypt_key');
60  if (empty($key)) {
61  throw new \Exception(__('Please enter an encryption key.'));
62  }
63  $this->encryptor->validateKey($key);
64  }
65 
66  $newKey = $this->change->changeEncryptionKey($key);
67  $this->messageManager->addSuccessMessage(__('The encryption key has been changed.'));
68 
69  if (!$key) {
70  $this->messageManager->addNoticeMessage(
71  __(
72  'This is your new encryption key: %1. ' .
73  'Be sure to write it down and take good care of it!',
74  $newKey
75  )
76  );
77  }
78  $this->cache->clean();
79  } catch (\Exception $e) {
80  $this->messageManager->addErrorMessage($e->getMessage());
81  $this->_session->setFormData(['crypt_key' => $key]);
82  }
83  $this->_redirect('adminhtml/*/');
84  }
85 }
__()
Definition: __.php:13
__construct(\Magento\Backend\App\Action\Context $context, \Magento\Framework\Encryption\EncryptorInterface $encryptor, \Magento\EncryptionKey\Model\ResourceModel\Key\Change $change, \Magento\Framework\App\CacheInterface $cache)
Definition: Save.php:36