}
// grab a lock so other processes dont compete and do the same query
- $lock = Civi::service('lockManager')->acquire("data.core.group.{$groupID}");
+ $lock = Civi::lockManager()->acquire("data.core.group.{$groupID}");
if (!$lock->isAcquired()) {
// this can cause inconsistent results since we dont know if the other process
// will fill up the cache before our calling routine needs it.
// get a lock so that multiple ajax requests on the same page
// dont trample on each other
// CRM-11234
- $lock = Civi::service('lockManager')->acquire("cache.{$group}_{$path}._{$componentID}");
+ $lock = Civi::lockManager()->acquire("cache.{$group}_{$path}._{$componentID}");
if (!$lock->isAcquired()) {
CRM_Core_Error::fatal();
}
self::$_singleton->getRuntime()->initialize($loadFromDB);
if ($loadFromDB && self::$_singleton->getRuntime()->dsn) {
CRM_Core_DAO::init(self::$_singleton->getRuntime()->dsn);
+ }
+ \Civi\Core\Container::getBootServices();
+ if ($loadFromDB && self::$_singleton->getRuntime()->dsn) {
+ CRM_Extension_System::singleton();
+ \Civi\Core\Container::singleton();
$domain = \CRM_Core_BAO_Domain::getDomain();
\CRM_Core_BAO_ConfigSetting::applyLocale(\Civi::settings($domain->id), $domain->locales);
exit();
}
+ /**
+ * Create a unique identification code for this runtime.
+ *
+ * If two requests involve a different hostname, different
+ * port, different DSN, etc., then they should also have a
+ * different runtime ID.
+ *
+ * @return mixed
+ */
+ public static function getId() {
+ if (!isset(Civi::$statics[__CLASS__]['id'])) {
+ Civi::$statics[__CLASS__]['id'] = md5(implode(\CRM_Core_DAO::VALUE_SEPARATOR, array(
+ defined('CIVICRM_DOMAIN_ID') ? CIVICRM_DOMAIN_ID : 1, // e.g. one database, multi URL
+ parse_url(CIVICRM_DSN, PHP_URL_PATH), // e.g. one codebase, multi database
+ \CRM_Utils_Array::value('SCRIPT_FILENAME', $_SERVER, ''), // e.g. CMS vs extern vs installer
+ \CRM_Utils_Array::value('HTTP_HOST', $_SERVER, ''), // e.g. name-based vhosts
+ \CRM_Utils_Array::value('SERVER_PORT', $_SERVER, ''), // e.g. port-based vhosts
+ // Depending on deployment arch, these signals *could* be redundant, but who cares?
+ )));
+ }
+ return Civi::$statics[__CLASS__]['id'];
+ }
+
+
}
// check if we are using global locks
foreach ($lockArray as $lockID) {
- $cronLock = Civi::service('lockManager')->acquire("worker.mailing.send.{$lockID}");
+ $cronLock = Civi::lockManager()->acquire("worker.mailing.send.{$lockID}");
if ($cronLock->isAcquired()) {
$gotCronLock = TRUE;
break;
while ($job->fetch()) {
// still use job level lock for each child job
- $lock = Civi::service('lockManager')->acquire("data.mailing.job.{$job->id}");
+ $lock = Civi::lockManager()->acquire("data.mailing.job.{$job->id}");
if (!$lock->isAcquired()) {
continue;
}
// X Number of child jobs
while ($job->fetch()) {
// still use job level lock for each child job
- $lock = Civi::service('lockManager')->acquire("data.mailing.job.{$job->id}");
+ $lock = Civi::lockManager()->acquire("data.mailing.job.{$job->id}");
if (!$lock->isAcquired()) {
continue;
}
return Civi\Core\Container::singleton();
}
+ /**
+ * @return \Civi\Core\Lock\LockManager
+ */
+ public static function lockManager() {
+ return \Civi\Core\Container::getBootService('lockManager');
+ }
+
/**
* @return \Psr\Log\LoggerInterface
*/
* singletons, containers.
*/
public static function reset() {
- Civi\Core\Container::singleton(TRUE);
self::$statics = array();
+ Civi\Core\Container::getBootServices();
+ Civi\Core\Container::singleton(TRUE);
}
/**
* @return \Civi\Core\SettingsBag
*/
public static function settings($domainID = NULL) {
- return Civi\Core\Container::singleton()->get('settings_manager')->getBagByDomain($domainID);
+ return \Civi\Core\Container::getBootService('settings_manager')->getBagByDomain($domainID);
}
}
return $this->createContainer();
}
- $envId = md5(implode(\CRM_Core_DAO::VALUE_SEPARATOR, array(
- defined('CIVICRM_DOMAIN_ID') ? CIVICRM_DOMAIN_ID : 1, // e.g. one database, multi URL
- parse_url(CIVICRM_DSN, PHP_URL_PATH), // e.g. one codebase, multi database
- \CRM_Utils_Array::value('SCRIPT_FILENAME', $_SERVER, ''), // e.g. CMS vs extern vs installer
- \CRM_Utils_Array::value('HTTP_HOST', $_SERVER, ''), // e.g. name-based vhosts
- \CRM_Utils_Array::value('SERVER_PORT', $_SERVER, ''), // e.g. port-based vhosts
- // Depending on deployment arch, these signals *could* be redundant, but who cares?
- )));
+ $envId = \CRM_Core_Config_Runtime::getId();
$file = CIVICRM_TEMPLATE_COMPILEDIR . "/CachedCiviContainer.{$envId}.php";
$containerConfigCache = new ConfigCache($file, $cacheMode === 'auto');
-
if (!$containerConfigCache->isFresh()) {
$containerBuilder = $this->createContainer();
$containerBuilder->compile();
// }
// }
- $container->setDefinition('lockManager', new Definition(
- 'Civi\Core\Lock\LockManager',
- array()
- ))
- ->setFactoryService(self::SELF)->setFactoryMethod('createLockManager');
-
$container->setDefinition('angular', new Definition(
'Civi\Angular\Manager',
array()
$container->setDefinition('psr_log', new Definition('CRM_Core_Error_Log', array()));
- foreach (array('settings', 'js_strings', 'community_messages') as $cacheName) {
+ foreach (array('js_strings', 'community_messages') as $cacheName) {
$container->setDefinition("cache.{$cacheName}", new Definition(
'CRM_Utils_Cache_Interface',
array(
))->setFactoryClass('CRM_Utils_Cache')->setFactoryMethod('create');
}
- $container->setDefinition('settings_manager', new Definition(
- 'Civi\Core\SettingsManager',
- array(new Reference('cache.settings'))
- ));
-
$container->setDefinition('pear_mail', new Definition('Mail'))
->setFactoryClass('CRM_Utils_Mail')->setFactoryMethod('createMailer');
+ foreach (self::getBootServices() as $bootService => $def) {
+ $container->setDefinition($bootService, new Definition($def['class'], array($bootService)))
+ ->setFactoryClass(__CLASS__)
+ ->setFactoryMethod('getBootService');
+ }
+
// Expose legacy singletons as services in the container.
$singletons = array(
'resources' => 'CRM_Core_Resources',
/**
* @return LockManager
*/
- public function createLockManager() {
+ public static function createLockManager() {
// Ideally, downstream implementers could override any definitions in
// the container. For now, we'll make-do with some define()s.
$lm = new LockManager();
return $kernel;
}
+ /**
+ * Get a list of boot services.
+ *
+ * These are services which must be setup *before* the container can operate.
+ *
+ * @return array
+ * Ex: $result['serviceName'] = array('class' => $, 'obj' => $).
+ * @throws \CRM_Core_Exception
+ */
+ public static function getBootServices() {
+ if (!isset(\Civi::$statics['*boot*'])) {
+ \Civi::$statics['*boot*']['cache.settings'] = array(
+ 'class' => 'CRM_Utils_Cache_Interface',
+ 'obj' => \CRM_Utils_Cache::create(array(
+ 'name' => 'settings',
+ 'type' => array('*memory*', 'SqlGroup', 'ArrayCache'),
+ )),
+ );
+ \Civi::$statics['*boot*']['settings_manager'] = array(
+ 'class' => 'Civi\Core\SettingsManager',
+ 'obj' => new \Civi\Core\SettingsManager(\Civi::$statics['*boot*']['cache.settings']['obj']),
+ );
+ \Civi::$statics['*boot*']['lockManager'] = array(
+ 'class' => 'Civi\Core\Lock\LockManager',
+ 'obj' => self::createLockManager(),
+ );
+ }
+ return \Civi::$statics['*boot*'];
+ }
+
+ public static function getBootService($name) {
+ return \Civi::$statics['*boot*'][$name]['obj'];
+ }
+
}
// in that case (ie. makes it non-configurable via the UI). Another approach would be to set a default of 0
// in the _spec function - but since that is a deprecated value it seems more contentious than this approach
$params['rowCount'] = 0;
- $lock = Civi::service('lockManager')->acquire('worker.core.ActionSchedule');
+ $lock = Civi::lockManager()->acquire('worker.core.ActionSchedule');
if (!$lock->isAcquired()) {
return civicrm_api3_create_error('Could not acquire lock, another ActionSchedule process is running');
}
* @return array
*/
function civicrm_api3_job_fetch_bounces($params) {
- $lock = Civi::service('lockManager')->acquire('worker.mailing.EmailProcessor');
+ $lock = Civi::lockManager()->acquire('worker.mailing.EmailProcessor');
if (!$lock->isAcquired()) {
return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running');
}
* @return array
*/
function civicrm_api3_job_fetch_activities($params) {
- $lock = Civi::service('lockManager')->acquire('worker.mailing.EmailProcessor');
+ $lock = Civi::lockManager()->acquire('worker.mailing.EmailProcessor');
if (!$lock->isAcquired()) {
return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running');
}
* true if success, else false
*/
function civicrm_api3_job_process_membership($params) {
- $lock = Civi::service('lockManager')->acquire('worker.member.UpdateMembership');
+ $lock = Civi::lockManager()->acquire('worker.member.UpdateMembership');
if (!$lock->isAcquired()) {
return civicrm_api3_create_error('Could not acquire lock, another Membership Processing process is running');
}
* @throws \API_Exception
*/
function civicrm_api3_job_group_rebuild($params) {
- $lock = Civi::service('lockManager')->acquire('worker.core.GroupRebuild');
+ $lock = Civi::lockManager()->acquire('worker.core.GroupRebuild');
if (!$lock->isAcquired()) {
throw new API_Exception('Could not acquire lock, another EmailProcessor process is running');
}
//log the execution of script
CRM_Core_Error::debug_log_message('ContributionProcessor.php');
-$lock = Civi::service('lockManager')->acquire('worker.contribute.CiviContributeProcessor');
+$lock = Civi::lockManager()->acquire('worker.contribute.CiviContributeProcessor');
if ($lock->isAcquired()) {
// try to unset any time limits