From 72bd25ec02e3d07a1ac3485293a692a1f54661fc Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 23 Jun 2023 19:28:08 -0700 Subject: [PATCH] Auto-enable `standaloneusers` when installing `Standalone` --- .../init/StandaloneUsers.civi-setup.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 setup/plugins/init/StandaloneUsers.civi-setup.php diff --git a/setup/plugins/init/StandaloneUsers.civi-setup.php b/setup/plugins/init/StandaloneUsers.civi-setup.php new file mode 100644 index 0000000000..98680b0897 --- /dev/null +++ b/setup/plugins/init/StandaloneUsers.civi-setup.php @@ -0,0 +1,39 @@ +addListener('civi.setup.init', function (\Civi\Setup\Event\InitEvent $e) { + if ($e->getModel()->cms !== 'Standalone') { + return; + } + + \Civi\Setup::log()->info(sprintf('[%s] Handle %s', basename(__FILE__), 'init')); + + $e->getModel()->extensions[] = 'standaloneusers'; + if (empty($e->getModel()->extras['adminPass'])) { + $toAlphanum = function ($bits) { + return preg_replace(';[^a-zA-Z0-9];', '', base64_encode($bits)); + }; + $e->getModel()->extras['adminPass'] = $toAlphanum(random_bytes(8)); + } + }); + +\Civi\Setup::dispatcher() + ->addListener('civi.setup.installDatabase', function (\Civi\Setup\Event\InstallDatabaseEvent $e) { + if (!in_array('standaloneusers', $e->getModel()->extensions)) { + return; + } + + \Civi\Setup::log()->info(sprintf('[%s] Handle %s', basename(__FILE__), 'installDatabase')); + + $security = \Civi\Standalone\Security::singleton(); + // $security->se + }, \Civi\Setup::PRIORITY_LATE); -- 2.25.1