5 * Generate the civicrm.settings.php file.
8 if (!defined('CIVI_SETUP')) {
9 exit("Installation plugins must only be loaded by the installer.\n");
13 * Validate the $model.
15 \Civi\Setup
::dispatcher()
16 ->addListener('civi.setup.checkRequirements', function(\Civi\Setup\Event\CheckRequirementsEvent
$e) {
17 \Civi\Setup
::log()->info(sprintf('[%s] Handle %s', basename(__FILE__
), 'checkRequirements'));
20 * @var \Civi\Setup\Model $m
24 if (empty($m->settingsPath
)) {
25 $e->addError('system', 'settingsPath', sprintf('The settingsPath is undefined.'));
28 $e->addInfo('system', 'settingsPath', sprintf('The settingsPath is defined.'));
31 if (!\Civi\Setup\FileUtil
::isCreateable($m->settingsPath
)) {
32 $e->addError('system', 'settingsWritable', sprintf('The settings file "%s" cannot be created. Ensure the parent folder is writable.', $m->settingsPath
));
35 $e->addInfo('system', 'settingsWritable', sprintf('The settings file "%s" can be created.', $m->settingsPath
));
40 * Read the $model and create the "civicrm.settings.php".
42 \Civi\Setup
::dispatcher()
43 ->addListener('civi.setup.installFiles', function (\Civi\Setup\Event\InstallFilesEvent
$e) {
44 \Civi\Setup
::log()->info(sprintf('[%s] Handle %s', basename(__FILE__
), 'installFiles'));
47 * @var \Civi\Setup\Model $m
51 // Map from the logical $model to civicrm.settings.php variables.
53 $params['crmRoot'] = addslashes(rtrim($m->srcPath
, DIRECTORY_SEPARATOR
) . DIRECTORY_SEPARATOR
);
54 $params['templateCompileDir'] = addslashes($m->templateCompilePath
);
55 // ??why is frontEnd=0??
56 $params['frontEnd'] = 0;
57 $params['baseURL'] = addslashes(rtrim($m->cmsBaseUrl
, '/'));
58 $params['dbUser'] = addslashes($m->db
['username']);
59 $params['dbPass'] = addslashes($m->db
['password']);
60 $params['dbHost'] = addslashes($m->db
['server']);
61 $params['dbName'] = addslashes($m->db
['database']);
62 $params['cms'] = addslashes($m->cms
);
63 $params['CMSdbUser'] = addslashes($m->cmsDb
['username']);
64 $params['CMSdbPass'] = addslashes($m->cmsDb
['password']);
65 $params['CMSdbHost'] = addslashes($m->cmsDb
['server']);
66 $params['CMSdbName'] = addslashes($m->cmsDb
['database']);
67 $params['siteKey'] = addslashes($m->siteKey
);
69 $extraSettings = array();
71 foreach ($m->paths
as $key => $aspects) {
72 foreach ($aspects as $aspect => $value) {
73 $extraSettings[] = sprintf('$civicrm_paths[%s][%s] = %s;', var_export($key, 1), var_export($aspect, 1), var_export($value, 1));
77 foreach ($m->mandatorySettings
as $key => $value) {
78 $extraSettings[] = sprintf('$civicrm_setting[%s][%s] = %s;', '\'domain\'', var_export($key, 1), var_export($value, 1));
81 // FIXME $m->defaultSettings, $m->components, $m->extensions, $m->callbacks
84 $params['extraSettings'] = "Additional settings generated by installer:\n" . implode("\n", $extraSettings);
87 $params['extraSettings'] = "";
90 $parent = dirname($m->settingsPath
);
91 if (!file_exists($parent)) {
92 Civi\Setup
::log()->info('[InstallSettingsFile.civi-setup.php] mkdir "{path}"', ['path' => $parent]);
93 mkdir($parent, 0777, TRUE);
94 \Civi\Setup\FileUtil
::makeWebWriteable($parent);
98 $tplPath = implode(DIRECTORY_SEPARATOR
,
99 [$m->srcPath
, 'templates', 'CRM', 'common', 'civicrm.settings.php.template']
101 $str = file_get_contents($tplPath);
102 foreach ($params as $key => $value) {
103 $str = str_replace('%%' . $key . '%%', $value, $str);
105 $str = trim($str) . "\n";
106 file_put_contents($m->settingsPath
, $str);
108 }, \Civi\Setup
::PRIORITY_LATE
);