Commit | Line | Data |
---|---|---|
2ce5684a TO |
1 | <?php |
2 | /** | |
3 | * @file | |
4 | * | |
5 | * Generate the credential key(s). | |
6 | */ | |
7 | ||
8 | if (!defined('CIVI_SETUP')) { | |
9 | exit("Installation plugins must only be loaded by the installer.\n"); | |
10 | } | |
11 | ||
12 | \Civi\Setup::dispatcher() | |
13 | ->addListener('civi.setup.installFiles', function (\Civi\Setup\Event\InstallFilesEvent $e) { | |
14 | \Civi\Setup::log()->info(sprintf('[%s] Handle %s', basename(__FILE__), 'installFiles')); | |
15 | ||
16 | $toAlphanum = function($bits) { | |
17 | return preg_replace(';[^a-zA-Z0-9];', '', base64_encode($bits)); | |
18 | }; | |
19 | ||
20 | if (empty($e->getModel()->credKeys)) { | |
f44de8a5 | 21 | $e->getModel()->credKeys = ['aes-cbc:hkdf-sha256:' . $toAlphanum(random_bytes(37))]; |
2ce5684a TO |
22 | } |
23 | ||
24 | if (is_string($e->getModel()->credKeys)) { | |
25 | $e->getModel()->credKeys = [$e->getModel()->credKeys]; | |
26 | } | |
27 | ||
28 | \Civi\Setup::log()->info(sprintf('[%s] Done %s', basename(__FILE__), 'installFiles')); | |
29 | ||
30 | }, \Civi\Setup::PRIORITY_PREPARE); |