Skip to content

Commit

Permalink
index.php - Compatibility with HAN-C and HAN-D
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Jul 9, 2023
1 parent 1ba0aad commit 67e0365
Showing 1 changed file with 55 additions and 28 deletions.
83 changes: 55 additions & 28 deletions setup/res/index.php.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,66 @@ function invoke() {
}
}

if (file_exists('../data/civicrm.settings.php')) {
require_once '../vendor/autoload.php';
require_once '../data/civicrm.settings.php';
function findStandaloneSettings(): string {
return dirname($_SERVER['DOCUMENT_ROOT']) . '/data/civicrm.settings.php';
}

function findStandaloneCore(): ?string {
$candidates = [
implode(DIRECTORY_SEPARATOR, [$_SERVER['DOCUMENT_ROOT'], 'core']),
implode(DIRECTORY_SEPARATOR, [dirname($_SERVER['DOCUMENT_ROOT']), 'vendor', 'civicrm', 'civicrm-core']),
];
foreach ($candidates as $candidate) {
if (file_exists($candidate)) {
return $candidate;
}
}
return NULL;
}

function findStandaloneAutoload(): ?string {
$candidates = [
implode(DIRECTORY_SEPARATOR, [dirname($_SERVER['DOCUMENT_ROOT']), 'vendor', 'autoload.php']),
implode(DIRECTORY_SEPARATOR, [$_SERVER['DOCUMENT_ROOT'], 'core', 'vendor', 'autoload.php']),
];
foreach ($candidates as $candidate) {
if (file_exists($candidate)) {
return $candidate;
}
}
return NULL;
}

require_once findStandaloneAutoload();
$civiCorePath = findStandaloneCore();
$classLoader = implode(DIRECTORY_SEPARATOR, [$civiCorePath, 'CRM', 'Core', 'ClassLoader.php']);
require_once $classLoader;
CRM_Core_ClassLoader::singleton()->register();

if (file_exists(findStandaloneSettings())) {
require_once findStandaloneSettings();
invoke();
}
else {
$coreUrl = '/assets/civicrm/core';
// This is the path to the root of the composer project (as opposed to the web/doc root path, which would be this + /web/)
$projectRootPath = dirname(__DIR__);
$civiCorePath = implode(DIRECTORY_SEPARATOR, [$projectRootPath, 'vendor', 'civicrm', 'civicrm-core']);
$classLoader = implode(DIRECTORY_SEPARATOR, [$civiCorePath, 'CRM', 'Core', 'ClassLoader.php']);

if (file_exists($classLoader)) {
require_once $classLoader;
CRM_Core_ClassLoader::singleton()->register();
\Civi\Setup::assertProtocolCompatibility(1.0);
\Civi\Setup::assertProtocolCompatibility(1.0);

\Civi\Setup::init([
// This is just enough information to get going.
'cms' => 'Standalone',
'srcPath' => $civiCorePath,
]);
$ctrl = \Civi\Setup::instance()->createController()->getCtrl();
\Civi\Setup::init([
// This is just enough information to get going.
'cms' => 'Standalone',
'srcPath' => $civiCorePath,
]);
$ctrl = \Civi\Setup::instance()->createController()->getCtrl();

$ctrl->setUrls([
// The URL of this setup controller. May be used for POST-backs
'ctrl' => '/civicrm', /* @todo this had url('civicrm') ? */
// The base URL for loading resource files (images/javascripts) for this project. Includes trailing slash.
'res' => $coreUrl . '/setup/res/',
'jquery.js' => $coreUrl . '/bower_components/jquery/dist/jquery.min.js',
'font-awesome.css' => $coreUrl . '/bower_components/font-awesome/css/font-awesome.min.css',
]);
\Civi\Setup\BasicRunner::run($ctrl);
exit();
}
$ctrl->setUrls([
// The URL of this setup controller. May be used for POST-backs
'ctrl' => '/civicrm', /* @todo this had url('civicrm') ? */
// The base URL for loading resource files (images/javascripts) for this project. Includes trailing slash.
'res' => $coreUrl . '/setup/res/',
'jquery.js' => $coreUrl . '/bower_components/jquery/dist/jquery.min.js',
'font-awesome.css' => $coreUrl . '/bower_components/font-awesome/css/font-awesome.min.css',
]);
\Civi\Setup\BasicRunner::run($ctrl);
exit();
}

0 comments on commit 67e0365

Please sign in to comment.