5 * Generate the credential key(s).
8 if (!defined('CIVI_SETUP')) {
9 exit("Installation plugins must only be loaded by the installer.\n");
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'));
16 $toAlphanum = function($bits) {
17 return preg_replace(';[^a-zA-Z0-9];', '', base64_encode($bits));
20 if (empty($e->getModel()->credKeys
)) {
21 $e->getModel()->credKeys
= ['aes-cbc:hkdf-sha256:' . $toAlphanum(random_bytes(37))];
24 if (is_string($e->getModel()->credKeys
)) {
25 $e->getModel()->credKeys
= [$e->getModel()->credKeys
];
28 \Civi\Setup
::log()->info(sprintf('[%s] Done %s', basename(__FILE__
), 'installFiles'));
30 }, \Civi\Setup
::PRIORITY_PREPARE
);