5 * Generate the site key.
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()->siteKey
)) {
23 elseif (function_exists('random_bytes')) {
24 $e->getModel()->siteKey
= $toAlphanum(random_bytes(32));
26 elseif (function_exists('openssl_random_pseudo_bytes')) {
27 $e->getModel()->siteKey
= $toAlphanum(openssl_random_pseudo_bytes(32));
30 throw new \
RuntimeException("Failed to generate a random site key");
33 \Civi\Setup
::log()->info(sprintf('[%s] Done %s', basename(__FILE__
), 'installFiles'));
35 }, \Civi\Setup
::PRIORITY_PREPARE
);