-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathconfigure.php
188 lines (165 loc) · 6.49 KB
/
configure.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
// escape early if called directly
defined('_JEXEC') or die('No direct access allowed');
global $civicrmUpgrade;
$civicrmUpgrade = FALSE;
/**
* If present, convert "admin/civicrm.zip" to "admin/civicrm/".
*
* @param string $adminPath
* @return void
*/
function civicrm_extract_code(string $adminPath) {
$archivename = $adminPath . DIRECTORY_SEPARATOR . 'civicrm.zip';
// a bit of support for the non-alternaive joomla install
if (file_exists($archivename)) {
// ensure that the site has native zip, else abort
if (
!function_exists('zip_open') ||
!function_exists('zip_read')
) {
echo "Your PHP version is missing zip functionality. Please ask your system administrator / hosting provider to recompile PHP with zip support.<p>";
echo "If this is a new install, you will need to uninstall CiviCRM from the Joomla Extension Manager.<p>";
exit();
}
$extractdir = $adminPath;
$archive = new Joomla\Archive\Archive();
$archive->extract($archivename, $extractdir);
}
$deletedFilesList = json_decode(file_get_contents($adminPath . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'deleted-files-list.json'));
foreach ($deletedFilesList as $deletedFile) {
$filePath = $adminPath . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . $deletedFile;
if (file_exists($filePath)) {
unlink($filePath);
}
}
}
function civicrm_main() {
global $civicrmUpgrade, $adminPath;
$civicrmUpgrade = civicrm_detect_upgrade();
// Check for php version and ensure its greater than minPhpVersion
$minPhpVersion = '7.4.0';
if (version_compare(PHP_VERSION, $minPhpVersion) < 0) {
echo "CiviCRM requires PHP version $minPhpVersion or greater. You are running PHP version " . PHP_VERSION . "<p>";
exit();
}
$adminPath = JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_civicrm';
civicrm_extract_code($adminPath);
$setup = civicrm_setup_instance($adminPath, $civicrmUpgrade);
civicrm_backend_config($setup->getModel()->settingsPath, $adminPath);
$setup->installFiles();
if (!$civicrmUpgrade) {
$setup->installDatabase();
}
}
/**
* Generate a "civicrm.config.php" file in the civicrm app-root.
* This (probably) allows backend tools like "extern/rest.php" or "bin/cli.php".
*
* @param string $configFile
* @param $adminPath
* @return string
*/
function civicrm_backend_config(string $configFile, $adminPath): string {
$string = "
<?php
define('CIVICRM_SETTINGS_PATH', '$configFile');
\$error = @include_once( '$configFile' );
if ( \$error == false ) {
echo \"Could not load the settings file at: {$configFile}\n\";
exit( );
}
// Load class loader
require_once \$civicrm_root . '/CRM/Core/ClassLoader.php';
CRM_Core_ClassLoader::singleton()->register();
";
$string = trim($string);
JFile::write($adminPath . DIRECTORY_SEPARATOR .
'civicrm' . DIRECTORY_SEPARATOR .
'civicrm.config.php',
$string
);
return $string;
}
/**
* @param string $adminPath
* @return \Civi\Setup
* @throws \Exception
*/
function civicrm_setup_instance(string $adminPath, bool $civicrmUpgrade): \Civi\Setup {
$civicrmCore = $adminPath . DIRECTORY_SEPARATOR . 'civicrm';
require_once implode(DIRECTORY_SEPARATOR, [$civicrmCore, 'CRM', 'Core', 'ClassLoader.php']);
CRM_Core_ClassLoader::singleton()->register();
\Civi\Setup::assertProtocolCompatibility(1.0);
\Civi\Setup::init([
'cms' => 'Joomla',
'srcPath' => $civicrmCore,
'db' => ['fixme'],
'settingsPath' => $adminPath . DIRECTORY_SEPARATOR . 'civicrm.settings.php',
]);
$setup = Civi\Setup::instance();
$model = $setup->getModel();
$jConfig = new JConfig();
$model->cmsBaseUrl = substr_replace(JURI::root(), '', -1, 1);
$model->cmsDb = [
'username' => $jConfig->user,
'password' => $jConfig->password,
'server' => $jConfig->host,
'database' => $jConfig->db,
];
$model->db = $model->cmsDb;
$model->templateCompilePath = implode(DIRECTORY_SEPARATOR, [JPATH_SITE, 'media', 'civicrm', 'templates_c']);
$model->lang = 'en_US'; /* Joomla installer historically only did `civicrm_data.mysql`. Should fix this... */
if ($civicrmUpgrade) {
require_once $setup->getModel()->settingsPath;
if (defined('CIVICRM_SITE_KEY')) {
$setup->getModel()->siteKey = CIVICRM_SITE_KEY;
}
if (defined('CIVICRM_CRED_KEYS')) {
$setup->getModel()->credKeys = explode(' ', CIVICRM_CRED_KEYS);
}
if (defined('CIVICRM_SIGN_KEYS')) {
$setup->getModel()->signKeys = explode(' ', CIVICRM_SIGN_KEYS);
}
}
return $setup;
}
/**
* @return bool
* TRUE if this installation operation is actually an upgrade.
*/
function civicrm_detect_upgrade(): bool {
$jConfig = new JConfig();
$db = JFactory::getDBO();
$db->setQuery(' SELECT count( * )
FROM information_schema.tables
WHERE table_name LIKE "civicrm_domain"
AND table_schema = "' . $jConfig->db . '" ');
$civicrmUpgrade = ($db->loadResult() == 0) ? FALSE : TRUE;
return $civicrmUpgrade;
}
set_time_limit(4000); /* Ex: ZIP extraction */
civicrm_main();