Elgg  Version 3.0
BootService.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg;
4 
7 use ElggCache;
8 
15 class BootService {
16 
17  use Profilable;
18  use Cacheable;
19 
23  const DEFAULT_BOOT_CACHE_TTL = 3600;
24 
30  const DEFAULT_BOOTDATA_PLUGIN_SETTINGS_LIMIT = 40;
31 
37  public function __construct(ElggCache $cache) {
38  $this->cache = $cache;
39  }
40 
53  public function boot(ServiceProvider $services) {
54  $db = $services->db;
55  $config = $services->config;
56 
57  // set cookie values for session and remember me
58  $config->getCookieConfig();
59 
60  // defaults in case these aren't in config table
61  if ($config->boot_cache_ttl === null) {
62  $config->boot_cache_ttl = self::DEFAULT_BOOT_CACHE_TTL;
63  }
64  if ($config->bootdata_plugin_settings_limit === null) {
65  $config->bootdata_plugin_settings_limit = self::DEFAULT_BOOTDATA_PLUGIN_SETTINGS_LIMIT;
66  }
67  if ($config->simplecache_enabled === null) {
68  $config->simplecache_enabled = false;
69  }
70  if ($config->system_cache_enabled === null) {
71  $config->system_cache_enabled = false;
72  }
73  if ($config->simplecache_lastupdate === null) {
74  $config->simplecache_lastupdate = 0;
75  }
76  if ($config->min_password_length === null) {
77  $config->min_password_length = 6;
78  }
79  if ($config->minusername === null) {
80  $config->minusername = 4;
81  }
82  if ($config->batch_run_time_in_secs === null) {
83  $config->batch_run_time_in_secs = 4;
84  }
85 
86  // we were using NOTICE temporarily so we can't just check for null
87  if (!$config->hasInitialValue('debug') && !$config->debug) {
88  $config->debug = '';
89  }
90 
91  // copy all table values into config
92  $config->mergeValues($services->configTable->getAll());
93 
94  // needs to be set before [init, system] for links in html head
95  $config->lastcache = (int) $config->simplecache_lastupdate;
96 
97  if (!$config->elgg_config_set_secret) {
98  $site_secret = SiteSecret::fromConfig($config);
99  if ($site_secret) {
100  $services->setValue('siteSecret', $site_secret);
101  } else {
102  throw new \RuntimeException('The site secret is not set.');
103  }
104  }
105 
106  $installed = isset($config->installed);
107 
108  if ($this->timer) {
109  $this->timer->begin([__CLASS__ . '::getBootData']);
110  }
111 
112  // early config is done, now get the core boot data
113  $data = $this->getBootData($config, $db, $installed);
114 
115  $site = $data->getSite();
116  if (!$site) {
117  // must be set in config
118  $site = $config->site;
119  if (!$site instanceof \ElggSite) {
120  throw new \RuntimeException('Before installation, config->site must have an unsaved ElggSite.');
121  }
122  }
123 
124  $config->site = $site;
125  $config->sitename = $site->name;
126  $config->sitedescription = $site->description;
127 
128  $settings = $data->getPluginSettings();
129  foreach ($settings as $guid => $entity_settings) {
130  $services->privateSettingsCache->save($guid, $entity_settings);
131  }
132 
133  foreach ($data->getPluginMetadata() as $guid => $metadata) {
134  $services->dataCache->metadata->save($guid, $metadata);
135  }
136 
137  $services->plugins->setBootPlugins($data->getActivePlugins(), false);
138 
139  // use value in settings.php if available
140  $debug = $config->hasInitialValue('debug') ? $config->getInitialValue('debug') : $config->debug;
141  $services->logger->setLevel($debug);
142 
143  if ($config->system_cache_enabled) {
144  $config->system_cache_loaded = false;
145 
146  if ($services->views->configureFromCache($services->systemCache)) {
147  $config->system_cache_loaded = true;
148  }
149  }
150 
151  // we don't store langs in boot data because it varies by user
152  $services->translator->bootTranslations();
153  }
154 
160  public function invalidateCache() {
161  $this->cache->clear();
162  _elgg_services()->plugins->setBootPlugins(null);
163  _elgg_config()->system_cache_loaded = false;
164  _elgg_config()->_boot_cache_hit = false;
165  }
166 
181  private function getBootData(Config $config, Database $db, $installed) {
182  $config->_boot_cache_hit = false;
183 
184  $data = null;
185  if ($config->boot_cache_ttl > 0) {
186  $data = $this->cache->load('boot_data');
187  }
188 
189  if (!isset($data)) {
190  $data = new BootData();
191  $data->populate($config, $db, _elgg_services()->entityTable, _elgg_services()->plugins, $installed);
192  if ($config->boot_cache_ttl && $installed) {
193  $this->cache->save('boot_data', $data, $config->boot_cache_ttl);
194  }
195  } else {
196  $config->_boot_cache_hit = true;
197  }
198 
199  return $data;
200  }
201 
202 }
boot(ServiceProvider $services)
Boots the engine.
Definition: BootService.php:53
The Elgg database.
Definition: Database.php:21
if(!$enabled) if(PHP_SAPI!== 'cli')
Interates through each element of an array and calls callback a function.
if(elgg_trigger_plugin_hook('usersettings:save', 'user', $hooks_params, true)) foreach($request->validation() ->all() as $item) $data
Definition: save.php:57
$guid
Removes an admin notice.
invalidateCache()
Invalidate the cache item.
trait Profilable
Make an object accept a timer.
Definition: Profilable.php:10
$config
Advanced site settings, debugging section.
Definition: debugging.php:6
$metadata
Outputs object metadata $vars[&#39;metadata&#39;] Metadata/menu $vars[&#39;show_entity_menu&#39;] Show the entity m...
Definition: metadata.php:10
Configuration exception.
setValue($name, $value)
Set a value to be returned without modification.
Definition: DiContainer.php:92
__construct(ElggCache $cache)
Cache.
Definition: BootService.php:37
trait Cacheable
Utility trait for injecting cache.
Definition: Cacheable.php:11
_elgg_config()
Get the Elgg config service.
Boots Elgg and manages a cache of data needed during boot.
Definition: BootService.php:15
Serializable collection of data used to boot Elgg.
Definition: BootData.php:14
$site_secret
Definition: settings.php:168
_elgg_services()
Get the global service provider.
Definition: elgglib.php:1292
$settings
Definition: settings.php:3