Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * Config handles all the run time configuration changes that the system needs to deal with. | |
8eedd10a | 14 | * |
6a488035 TO |
15 | * Typically we'll have different values for a user's sandbox, a qa sandbox and a production area. |
16 | * The default values in general, should reflect production values (minimizes chances of screwing up) | |
17 | * | |
18 | * @package CRM | |
ca5cec67 | 19 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
20 | */ |
21 | ||
df8de0eb | 22 | require_once 'Log.php'; |
6a488035 TO |
23 | require_once 'Mail.php'; |
24 | ||
25 | require_once 'api/api.php'; | |
72536736 | 26 | |
28518c90 EM |
27 | /** |
28 | * Class CRM_Core_Config | |
e367c7b0 CW |
29 | * |
30 | * @property CRM_Utils_System_Base $userSystem | |
6d054a8e | 31 | * @property CRM_Core_Permission_Base $userPermissionClass |
6b070fc0 CW |
32 | * @property array $enableComponents |
33 | * @property array $languageLimit | |
34 | * @property bool $debug | |
35 | * @property bool $doNotResetCache | |
36 | * @property string $maxFileSize | |
37 | * @property string $defaultCurrency | |
38 | * @property string $defaultCurrencySymbol | |
39 | * @property string $lcMessages | |
40 | * @property string $fieldSeparator | |
41 | * @property string $userFramework | |
42 | * @property string $verpSeparator | |
43 | * @property string $dateFormatFull | |
44 | * @property string $resourceBase | |
45 | * @property string $dsn | |
46 | * @property string $customTemplateDir | |
47 | * @property string $defaultContactCountry | |
48 | * @property string $defaultContactStateProvince | |
49 | * @property string $monetaryDecimalPoint | |
50 | * @property string $monetaryThousandSeparator | |
81716ddb | 51 | * @property array fiscalYearStart |
28518c90 | 52 | */ |
c0a1f187 | 53 | class CRM_Core_Config extends CRM_Core_Config_MagicMerge { |
4d66768d | 54 | |
6a488035 TO |
55 | /** |
56 | * The handle to the log that we are using | |
57 | * @var object | |
58 | */ | |
59 | private static $_log = NULL; | |
60 | ||
6a488035 TO |
61 | /** |
62 | * We only need one instance of this object. So we use the singleton | |
63 | * pattern and cache the instance in this variable | |
72536736 AH |
64 | * |
65 | * @var CRM_Core_Config | |
6a488035 TO |
66 | */ |
67 | private static $_singleton = NULL; | |
68 | ||
6a488035 TO |
69 | /** |
70 | * The constructor. Sets domain id if defined, otherwise assumes | |
71 | * single instance installation. | |
6a488035 | 72 | */ |
0acb7f15 | 73 | public function __construct() { |
c0a1f187 | 74 | parent::__construct(); |
6a488035 TO |
75 | } |
76 | ||
77 | /** | |
78 | * Singleton function used to manage this object. | |
79 | * | |
5a4f6742 CW |
80 | * @param bool $loadFromDB |
81 | * whether to load from the database. | |
82 | * @param bool $force | |
83 | * whether to force a reconstruction. | |
6a488035 | 84 | * |
5af8c999 | 85 | * @return CRM_Core_Config |
6a488035 | 86 | */ |
00be9182 | 87 | public static function &singleton($loadFromDB = TRUE, $force = FALSE) { |
6a488035 | 88 | if (self::$_singleton === NULL || $force) { |
d6347440 | 89 | $GLOBALS['civicrm_default_error_scope'] = CRM_Core_TemporaryErrorScope::create(['CRM_Core_Error', 'exceptionHandler'], 1); |
be2fb01f | 90 | $errorScope = CRM_Core_TemporaryErrorScope::create(['CRM_Core_Error', 'simpleHandler']); |
6a488035 | 91 | |
fc50f470 | 92 | self::$_singleton = new CRM_Core_Config(); |
7f835399 TO |
93 | \Civi\Core\Container::boot($loadFromDB); |
94 | if ($loadFromDB && self::$_singleton->dsn) { | |
c0a1f187 TO |
95 | $domain = \CRM_Core_BAO_Domain::getDomain(); |
96 | \CRM_Core_BAO_ConfigSetting::applyLocale(\Civi::settings($domain->id), $domain->locales); | |
6a488035 | 97 | |
fc50f470 | 98 | unset($errorScope); |
6a488035 | 99 | |
fc50f470 TO |
100 | CRM_Utils_Hook::config(self::$_singleton); |
101 | self::$_singleton->authenticate(); | |
23bb9c85 | 102 | |
fc50f470 TO |
103 | // Extreme backward compat: $config binds to active domain at moment of setup. |
104 | self::$_singleton->getSettings(); | |
23bb9c85 | 105 | |
fc50f470 | 106 | Civi::service('settings_manager')->useDefaults(); |
0085db83 C |
107 | |
108 | self::$_singleton->handleFirstRun(); | |
fc50f470 | 109 | } |
6a488035 TO |
110 | } |
111 | return self::$_singleton; | |
112 | } | |
113 | ||
6a488035 | 114 | /** |
d09edf64 | 115 | * Returns the singleton logger for the application. |
6a488035 | 116 | * |
c0a1f187 | 117 | * @deprecated |
6a488035 | 118 | * @return object |
c0a1f187 | 119 | * @see Civi::log() |
6a488035 | 120 | */ |
518fa0ee | 121 | public static function &getLog() { |
6a488035 TO |
122 | if (!isset(self::$_log)) { |
123 | self::$_log = Log::singleton('display'); | |
124 | } | |
125 | ||
126 | return self::$_log; | |
127 | } | |
128 | ||
6a488035 | 129 | /** |
d09edf64 | 130 | * Retrieve a mailer to send any mail from the application. |
6a488035 | 131 | * |
247eb841 TO |
132 | * @return Mail |
133 | * @deprecated | |
c0a1f187 | 134 | * @see Civi::service() |
6a488035 | 135 | */ |
247eb841 | 136 | public static function getMailer() { |
048222df | 137 | return Civi::service('pear_mail'); |
72ad6c1b TO |
138 | } |
139 | ||
6a488035 | 140 | /** |
d09edf64 | 141 | * Deletes the web server writable directories. |
6a488035 | 142 | * |
72536736 AH |
143 | * @param int $value |
144 | * 1: clean templates_c, 2: clean upload, 3: clean both | |
145 | * @param bool $rmdir | |
6a488035 TO |
146 | */ |
147 | public function cleanup($value, $rmdir = TRUE) { | |
148 | $value = (int ) $value; | |
149 | ||
150 | if ($value & 1) { | |
151 | // clean templates_c | |
152 | CRM_Utils_File::cleanDir($this->templateCompileDir, $rmdir); | |
153 | CRM_Utils_File::createDir($this->templateCompileDir); | |
154 | } | |
155 | if ($value & 2) { | |
156 | // clean upload dir | |
157 | CRM_Utils_File::cleanDir($this->uploadDir); | |
158 | CRM_Utils_File::createDir($this->uploadDir); | |
fea6131e TO |
159 | } |
160 | ||
161 | // Whether we delete/create or simply preserve directories, we should | |
162 | // certainly make sure the restrictions are enforced. | |
be2fb01f | 163 | foreach ([ |
518fa0ee SL |
164 | $this->templateCompileDir, |
165 | $this->uploadDir, | |
166 | $this->configAndLogDir, | |
167 | $this->customFileUploadDir, | |
168 | ] as $dir) { | |
fea6131e TO |
169 | if ($dir && is_dir($dir)) { |
170 | CRM_Utils_File::restrictAccess($dir); | |
171 | } | |
6a488035 TO |
172 | } |
173 | } | |
174 | ||
175 | /** | |
0880a9d0 | 176 | * Verify that the needed parameters are not null in the config. |
6a488035 | 177 | * |
8d7a9d07 CB |
178 | * @param CRM_Core_Config $config (reference) the system config object |
179 | * @param array $required (reference) the parameters that need a value | |
6a488035 | 180 | * |
8d7a9d07 | 181 | * @return bool |
6a488035 | 182 | */ |
00be9182 | 183 | public static function check(&$config, &$required) { |
6a488035 TO |
184 | foreach ($required as $name) { |
185 | if (CRM_Utils_System::isNull($config->$name)) { | |
186 | return FALSE; | |
187 | } | |
188 | } | |
189 | return TRUE; | |
190 | } | |
191 | ||
192 | /** | |
0880a9d0 | 193 | * Reset the serialized array and recompute. |
6a488035 | 194 | * use with care |
502b6747 TO |
195 | * |
196 | * @deprecated | |
6a488035 | 197 | */ |
00be9182 | 198 | public function reset() { |
502b6747 TO |
199 | // This is what it used to do. However, it hasn't meant anything since 4.6. |
200 | // $query = "UPDATE civicrm_domain SET config_backend = null"; | |
201 | // CRM_Core_DAO::executeQuery($query); | |
6a488035 TO |
202 | } |
203 | ||
546b78fa | 204 | /** |
0880a9d0 | 205 | * This method should initialize auth sources. |
546b78fa | 206 | */ |
635f0b86 TO |
207 | public function authenticate() { |
208 | // make sure session is always initialised | |
e8f14831 | 209 | $session = CRM_Core_Session::singleton(); |
635f0b86 TO |
210 | |
211 | // for logging purposes, pass the userID to the db | |
212 | $userID = $session->get('userID'); | |
213 | if ($userID) { | |
214 | CRM_Core_DAO::executeQuery('SET @civicrm_user_id = %1', | |
be2fb01f | 215 | [1 => [$userID, 'Integer']] |
635f0b86 TO |
216 | ); |
217 | } | |
218 | ||
e8f14831 DS |
219 | if ($session->get('userID') && !$session->get('authSrc')) { |
220 | $session->set('authSrc', CRM_Core_Permission::AUTH_SRC_LOGIN); | |
221 | } | |
222 | ||
223 | // checksum source | |
224 | CRM_Contact_BAO_Contact_Permission::initChecksumAuthSrc(); | |
225 | } | |
226 | ||
6a488035 | 227 | /** |
0880a9d0 | 228 | * One function to get domain ID. |
ad37ac8e | 229 | * |
230 | * @param int $domainID | |
231 | * @param bool $reset | |
232 | * | |
233 | * @return int|null | |
6a488035 | 234 | */ |
00be9182 | 235 | public static function domainID($domainID = NULL, $reset = FALSE) { |
6a488035 TO |
236 | static $domain; |
237 | if ($domainID) { | |
238 | $domain = $domainID; | |
239 | } | |
240 | if ($reset || empty($domain)) { | |
241 | $domain = defined('CIVICRM_DOMAIN_ID') ? CIVICRM_DOMAIN_ID : 1; | |
242 | } | |
243 | ||
322b59f0 | 244 | return (int) $domain; |
6a488035 TO |
245 | } |
246 | ||
f008885c E |
247 | /** |
248 | * Function to get environment. | |
249 | * | |
250 | * @param string $env | |
251 | * @param bool $reset | |
252 | * | |
253 | * @return string | |
254 | */ | |
255 | public static function environment($env = NULL, $reset = FALSE) { | |
f008885c E |
256 | if ($env) { |
257 | $environment = $env; | |
258 | } | |
259 | if ($reset || empty($environment)) { | |
8a078f99 | 260 | $environment = Civi::settings()->get('environment'); |
f008885c E |
261 | } |
262 | if (!$environment) { | |
263 | $environment = 'Production'; | |
264 | } | |
265 | return $environment; | |
266 | } | |
267 | ||
6a488035 | 268 | /** |
100fef9d | 269 | * Do general cleanup of caches, temp directories and temp tables |
0e480632 | 270 | * @see https://issues.civicrm.org/jira/browse/CRM-8739 |
ea3ddccf | 271 | * |
272 | * @param bool $sessionReset | |
6a488035 | 273 | */ |
00be9182 | 274 | public function cleanupCaches($sessionReset = TRUE) { |
6a488035 TO |
275 | // cleanup templates_c directory |
276 | $this->cleanup(1, FALSE); | |
277 | ||
1b50807d | 278 | // clear all caches |
6a488035 | 279 | self::clearDBCache(); |
0a12cd4a | 280 | Civi::cache('session')->clear(); |
1b50807d | 281 | CRM_Utils_System::flushCache(); |
6a488035 TO |
282 | |
283 | if ($sessionReset) { | |
284 | $session = CRM_Core_Session::singleton(); | |
285 | $session->reset(2); | |
286 | } | |
287 | } | |
288 | ||
289 | /** | |
290 | * Do general cleanup of module permissions. | |
291 | */ | |
00be9182 | 292 | public function cleanupPermissions() { |
6a488035 | 293 | $module_files = CRM_Extension_System::singleton()->getMapper()->getActiveModuleFiles(); |
7fccad46 TO |
294 | if ($this->userPermissionClass->isModulePermissionSupported()) { |
295 | // Can store permissions -- so do it! | |
0d8fc497 TO |
296 | $this->userPermissionClass->upgradePermissions( |
297 | CRM_Core_Permission::basicPermissions() | |
298 | ); | |
0db6c3e1 TO |
299 | } |
300 | else { | |
7fccad46 | 301 | // Cannot store permissions -- warn if any modules require them |
be2fb01f | 302 | $modules_with_perms = []; |
7fccad46 TO |
303 | foreach ($module_files as $module_file) { |
304 | $perms = $this->userPermissionClass->getModulePermissions($module_file['prefix']); | |
305 | if (!empty($perms)) { | |
306 | $modules_with_perms[] = $module_file['prefix']; | |
307 | } | |
308 | } | |
309 | if (!empty($modules_with_perms)) { | |
310 | CRM_Core_Session::setStatus( | |
be2fb01f | 311 | ts('Some modules define permissions, but the CMS cannot store them: %1', [1 => implode(', ', $modules_with_perms)]), |
7fccad46 TO |
312 | ts('Permission Error'), |
313 | 'error' | |
314 | ); | |
315 | } | |
6a488035 TO |
316 | } |
317 | } | |
318 | ||
319 | /** | |
0880a9d0 | 320 | * Flush information about loaded modules. |
6a488035 | 321 | */ |
00be9182 | 322 | public function clearModuleList() { |
6a488035 TO |
323 | CRM_Extension_System::singleton()->getCache()->flush(); |
324 | CRM_Utils_Hook::singleton(TRUE); | |
325 | CRM_Core_PseudoConstant::getModuleExtensions(TRUE); | |
326 | CRM_Core_Module::getAll(TRUE); | |
327 | } | |
328 | ||
329 | /** | |
0880a9d0 | 330 | * Clear db cache. |
6a488035 TO |
331 | */ |
332 | public static function clearDBCache() { | |
be2fb01f | 333 | $queries = [ |
6a488035 TO |
334 | 'TRUNCATE TABLE civicrm_acl_cache', |
335 | 'TRUNCATE TABLE civicrm_acl_contact_cache', | |
336 | 'TRUNCATE TABLE civicrm_cache', | |
337 | 'TRUNCATE TABLE civicrm_prevnext_cache', | |
338 | 'UPDATE civicrm_group SET cache_date = NULL', | |
339 | 'TRUNCATE TABLE civicrm_group_contact_cache', | |
340 | 'TRUNCATE TABLE civicrm_menu', | |
341 | 'UPDATE civicrm_setting SET value = NULL WHERE name="navigation" AND contact_id IS NOT NULL', | |
be2fb01f | 342 | ]; |
6a488035 TO |
343 | |
344 | foreach ($queries as $query) { | |
345 | CRM_Core_DAO::executeQuery($query); | |
346 | } | |
347 | ||
348 | // also delete all the import and export temp tables | |
349 | self::clearTempTables(); | |
350 | } | |
351 | ||
352 | /** | |
0880a9d0 | 353 | * Clear leftover temporary tables. |
0383ef73 EM |
354 | * |
355 | * This is called on upgrade, during tests and site move, from the cron and via clear caches in the UI. | |
356 | * | |
357 | * Currently the UI clear caches does not pass a time interval - which may need review as it does risk | |
358 | * ripping the tables out from underneath a current action. This was considered but | |
359 | * out-of-scope for CRM-16167 | |
360 | * | |
361 | * @param string|bool $timeInterval | |
362 | * Optional time interval for mysql date function.g '2 day'. This can be used to prevent | |
363 | * tables created recently from being deleted. | |
6a488035 | 364 | */ |
0383ef73 EM |
365 | public static function clearTempTables($timeInterval = FALSE) { |
366 | ||
367 | $dao = new CRM_Core_DAO(); | |
6a488035 | 368 | $query = " |
0383ef73 EM |
369 | SELECT TABLE_NAME as tableName |
370 | FROM INFORMATION_SCHEMA.TABLES | |
371 | WHERE TABLE_SCHEMA = %1 | |
372 | AND ( | |
373 | TABLE_NAME LIKE 'civicrm_import_job_%' | |
0383ef73 | 374 | OR TABLE_NAME LIKE 'civicrm_report_temp%' |
40c8b829 | 375 | OR TABLE_NAME LIKE 'civicrm_tmp_d%' |
0383ef73 EM |
376 | ) |
377 | "; | |
f7e48bad TO |
378 | // NOTE: Cannot find use-cases where "civicrm_report_temp" would be durable. Could probably remove. |
379 | ||
0383ef73 EM |
380 | if ($timeInterval) { |
381 | $query .= " AND CREATE_TIME < DATE_SUB(NOW(), INTERVAL {$timeInterval})"; | |
382 | } | |
383 | ||
be2fb01f CW |
384 | $tableDAO = CRM_Core_DAO::executeQuery($query, [1 => [$dao->database(), 'String']]); |
385 | $tables = []; | |
6a488035 TO |
386 | while ($tableDAO->fetch()) { |
387 | $tables[] = $tableDAO->tableName; | |
388 | } | |
389 | if (!empty($tables)) { | |
390 | $table = implode(',', $tables); | |
391 | // drop leftover temporary tables | |
392 | CRM_Core_DAO::executeQuery("DROP TABLE $table"); | |
393 | } | |
394 | } | |
395 | ||
396 | /** | |
0880a9d0 | 397 | * Check if running in upgrade mode. |
54957108 | 398 | * |
399 | * @param string $path | |
400 | * | |
401 | * @return bool | |
6a488035 | 402 | */ |
00be9182 | 403 | public static function isUpgradeMode($path = NULL) { |
6a488035 TO |
404 | if (defined('CIVICRM_UPGRADE_ACTIVE')) { |
405 | return TRUE; | |
406 | } | |
407 | ||
3ec0873b TO |
408 | $upgradeInProcess = CRM_Core_Session::singleton()->get('isUpgradePending'); |
409 | if ($upgradeInProcess) { | |
410 | return TRUE; | |
411 | } | |
412 | ||
6a488035 TO |
413 | if (!$path) { |
414 | // note: do not re-initialize config here, since this function is part of | |
415 | // config initialization itself | |
416 | $urlVar = 'q'; | |
417 | if (defined('CIVICRM_UF') && CIVICRM_UF == 'Joomla') { | |
418 | $urlVar = 'task'; | |
419 | } | |
420 | ||
9c1bc317 | 421 | $path = $_GET[$urlVar] ?? NULL; |
6a488035 TO |
422 | } |
423 | ||
424 | if ($path && preg_match('/^civicrm\/upgrade(\/.*)?$/', $path)) { | |
425 | return TRUE; | |
426 | } | |
427 | ||
428 | return FALSE; | |
429 | } | |
430 | ||
9be1374d EM |
431 | /** |
432 | * Is back office credit card processing enabled for this site - ie are there any installed processors that support | |
fbcb6fba | 433 | * it? |
52767de0 EM |
434 | * This function is used for determining whether to show the submit credit card link, not for determining which processors to show, hence |
435 | * it is a config var | |
9be1374d EM |
436 | * @return bool |
437 | */ | |
00be9182 | 438 | public static function isEnabledBackOfficeCreditCardPayments() { |
be2fb01f | 439 | return CRM_Financial_BAO_PaymentProcessor::hasPaymentProcessorSupporting(['BackOffice']); |
9be1374d | 440 | } |
96025800 | 441 | |
0acb7f15 TO |
442 | /** |
443 | * @deprecated | |
444 | */ | |
445 | public function addressSequence() { | |
9b118398 | 446 | CRM_Core_Error::deprecatedFunctionWarning('CRM_Utils_Address::sequence(Civi::settings()->get(\'address_format\')'); |
0acb7f15 TO |
447 | return CRM_Utils_Address::sequence(Civi::settings()->get('address_format')); |
448 | } | |
449 | ||
450 | /** | |
451 | * @deprecated | |
452 | */ | |
453 | public function defaultContactCountry() { | |
d14f0a66 | 454 | CRM_Core_Error::deprecatedFunctionWarning('CRM_Core_BAO_Country::defaultContactCountry'); |
0acb7f15 TO |
455 | return CRM_Core_BAO_Country::defaultContactCountry(); |
456 | } | |
457 | ||
458 | /** | |
459 | * @deprecated | |
460 | */ | |
461 | public function defaultContactCountryName() { | |
d14f0a66 | 462 | CRM_Core_Error::deprecatedFunctionWarning('CRM_Core_BAO_Country::defaultContactCountryName'); |
0acb7f15 TO |
463 | return CRM_Core_BAO_Country::defaultContactCountryName(); |
464 | } | |
465 | ||
466 | /** | |
467 | * @deprecated | |
ea3ddccf | 468 | * |
469 | * @param string $defaultCurrency | |
470 | * | |
471 | * @return string | |
0acb7f15 TO |
472 | */ |
473 | public function defaultCurrencySymbol($defaultCurrency = NULL) { | |
a5dfa653 | 474 | CRM_Core_Error::deprecatedFunctionWarning('CRM_Core_BAO_Country::defaultCurrencySymbol'); |
0acb7f15 TO |
475 | return CRM_Core_BAO_Country::defaultCurrencySymbol($defaultCurrency); |
476 | } | |
477 | ||
97b8e6b2 | 478 | /** |
479 | * Resets the singleton, so that the next call to CRM_Core_Config::singleton() | |
480 | * reloads completely. | |
481 | * | |
482 | * While normally we could call the singleton function with $force = TRUE, | |
483 | * this function addresses a very specific use-case in the CiviCRM installer, | |
484 | * where we cannot yet force a reload, but we want to make sure that the next | |
485 | * call to this object gets a fresh start (ex: to initialize the DAO). | |
486 | */ | |
487 | public function free() { | |
488 | self::$_singleton = NULL; | |
489 | } | |
c8ab0a65 | 490 | |
0085db83 C |
491 | /** |
492 | * Conditionally fire an event during the first page run. | |
493 | * | |
494 | * The install system is currently implemented several times, so it's hard to add | |
e047612e | 495 | * new installation logic. We use a makeshift method to detect the first run. |
0085db83 C |
496 | * |
497 | * Situations to test: | |
498 | * - New installation | |
499 | * - Upgrade from an old version (predating first-run tracker) | |
500 | * - Upgrade from an old version (with first-run tracking) | |
501 | */ | |
502 | public function handleFirstRun() { | |
503 | // Ordinarily, we prefetch settings en masse and find that the system is already installed. | |
504 | // No extra SQL queries required. | |
505 | if (Civi::settings()->get('installed')) { | |
506 | return; | |
507 | } | |
508 | ||
509 | // Q: How should this behave during testing? | |
510 | if (defined('CIVICRM_TEST')) { | |
511 | return; | |
512 | } | |
513 | ||
514 | // If schema hasn't been loaded yet, then do nothing. Don't want to interfere | |
515 | // with the existing installers. NOTE: If we change the installer pageflow, | |
516 | // then we may want to modify this behavior. | |
517 | if (!CRM_Core_DAO::checkTableExists('civicrm_domain')) { | |
518 | return; | |
519 | } | |
520 | ||
521 | // If we're handling an upgrade, then the system has already been used, so this | |
522 | // is not the first run. | |
523 | if (CRM_Core_Config::isUpgradeMode()) { | |
524 | return; | |
525 | } | |
526 | $dao = CRM_Core_DAO::executeQuery('SELECT version FROM civicrm_domain'); | |
527 | while ($dao->fetch()) { | |
528 | if ($dao->version && version_compare($dao->version, CRM_Utils_System::version(), '<')) { | |
529 | return; | |
530 | } | |
531 | } | |
532 | ||
533 | // The installation flag is stored in civicrm_setting, which is domain-aware. The | |
534 | // flag could have been stored under a different domain. | |
535 | $dao = CRM_Core_DAO::executeQuery(' | |
536 | SELECT domain_id, value FROM civicrm_setting | |
537 | WHERE is_domain = 1 AND name = "installed" | |
538 | '); | |
539 | while ($dao->fetch()) { | |
f24846d5 | 540 | $value = CRM_Utils_String::unserialize($dao->value); |
0085db83 C |
541 | if (!empty($value)) { |
542 | Civi::settings()->set('installed', 1); | |
543 | return; | |
544 | } | |
545 | } | |
546 | ||
547 | // OK, this looks new. | |
1d440215 | 548 | Civi::dispatcher()->dispatch('civi.core.install', new \Civi\Core\Event\SystemInstallEvent()); |
0085db83 C |
549 | Civi::settings()->set('installed', 1); |
550 | } | |
551 | ||
0626851e | 552 | /** |
553 | * Is the system permitted to flush caches at the moment. | |
554 | */ | |
518fa0ee | 555 | public static function isPermitCacheFlushMode() { |
0626851e | 556 | return !CRM_Core_Config::singleton()->doNotResetCache; |
557 | } | |
558 | ||
559 | /** | |
560 | * Set cache clearing to enabled or disabled. | |
561 | * | |
562 | * This might be enabled at the start of a long running process | |
563 | * such as an import in order to delay clearing caches until the end. | |
564 | * | |
565 | * @param bool $enabled | |
566 | * If true then caches can be cleared at this time. | |
567 | */ | |
518fa0ee | 568 | public static function setPermitCacheFlushMode($enabled) { |
0626851e | 569 | CRM_Core_Config::singleton()->doNotResetCache = $enabled ? 0 : 1; |
570 | } | |
571 | ||
6a488035 | 572 | } |