From e1d8c0aadfd97bab3af23b4a2ab3dd429ee6cec1 Mon Sep 17 00:00:00 2001 From: Rich Lott / Artful Robot Date: Thu, 2 Feb 2023 17:30:46 +0000 Subject: [PATCH] standalone: merge other changes --- CRM/Utils/System/Standalone.php | 34 ++++++++++++++------ setup/plugins/init/Standalone.civi-setup.php | 12 ++++--- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/CRM/Utils/System/Standalone.php b/CRM/Utils/System/Standalone.php index 42932a86a2..17f038dbaa 100644 --- a/CRM/Utils/System/Standalone.php +++ b/CRM/Utils/System/Standalone.php @@ -212,7 +212,9 @@ class CRM_Utils_System_Standalone extends CRM_Utils_System_Base { } /** - * Bootstrap the non-existent CMS + * Bootstrap composer libs. + * + * This is used by cv and civix, but not I (artfulrobot) think, in the main http requests. * * @param array $params * Either uid, or name & pass. @@ -226,14 +228,30 @@ class CRM_Utils_System_Standalone extends CRM_Utils_System_Base { * @Todo Handle setting cleanurls configuration for CiviCRM? */ public function loadBootStrap($params = [], $loadUser = TRUE, $throwError = TRUE, $realPath = NULL) { - static $run_once = FALSE; - if ($run_once) { + static $runOnce; + if (!isset($runOnce)) { + $runOnce = TRUE; return TRUE; } - else { - $run_once = TRUE; + + if (!($root = $this->cmsRootPath())) { + // What does this guard against? + return FALSE; + } + chdir($root); + + // Create a mock $request object + require_once $root . '../vendor/autoload.php'; /* assumes $root to be the _web_ root path, not the project root path. */ + + if ($loadUser) { + // @todo + // if (!empty($params['uid']) && ...) { + // $this->loadUser($username); + // } + // elseif (!empty($params['name']) && !empty($params['pass']) && ...can authenticate...) { + // $this->loadUser($params['name']); + // } } - // @todo ? return TRUE; } @@ -265,9 +283,7 @@ class CRM_Utils_System_Standalone extends CRM_Utils_System_Base { if (!empty($civicrm_paths['cms.root']['path'])) { return $civicrm_paths['cms.root']['path']; } - - // @todo? - throw new \RuntimeException("Standalone requires that you set \$civicrm_paths['cms.root']['path'] in civicrm.settings.php"); + throw new \RuntimeException("Standalone requires the path is set for now. Set \$civicrm_paths['cms.root']['path'] in civicrm.settings.php to the webroot."); } /** diff --git a/setup/plugins/init/Standalone.civi-setup.php b/setup/plugins/init/Standalone.civi-setup.php index 6441d190a9..b895ef0b07 100644 --- a/setup/plugins/init/Standalone.civi-setup.php +++ b/setup/plugins/init/Standalone.civi-setup.php @@ -29,6 +29,10 @@ if (!defined('CIVI_SETUP')) { } \Civi\Setup::log()->info(sprintf('[%s] Handle %s', basename(__FILE__), 'init')); + // NOTE: in here, $model->webroot refers to the root of the *application*, not the actual webroot as reachable by http. + // Typically this means that $model->webroot might be like /var/www/example.org/ and the actual web root would be + // /var/www/example.org/web/ + // Compute settingsPath. // We use this structure: /var/www/standalone/data/{civicrm.settings.php,templates_c} // to reduce the number of directories that admins have to chmod @@ -37,10 +41,10 @@ if (!defined('CIVI_SETUP')) { // Compute DSN. $model->db = $model->cmsDb = [ - 'server' => 'localhost', - 'username' => '', - 'password' => '', - 'database' => '', + 'server' => 'mysql', + 'username' => 'loner', + 'password' => 'somepass', + 'database' => 'standalone_civicrm', ]; // Compute URLs (@todo?) -- 2.25.1