Elgg  Version 2.3
BootData.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg;
4 
9 
16 class BootData {
17 
21  private $site;
22 
26  private $datalist_cache;
27 
31  private $config_values = [];
32 
36  private $subtype_data = [];
37 
41  private $active_plugins = [];
42 
46  private $plugin_settings = [];
47 
59  public function populate(\stdClass $config, Database $db, EntityTable $entities, Plugins $plugins) {
60  // get datalists
61  // do not store site key in cache. The others we've already fetched.
62  $rows = $db->getData("
63  SELECT *
64  FROM {$db->prefix}datalists
65  WHERE `name` NOT IN ('__site_secret__', 'default_site', 'dataroot')
66  ");
67  $this->datalist_cache = new InMemory();
68  foreach ($rows as $row) {
69  $this->datalist_cache->put($row->name, $row->value);
70  }
71 
72  // get subtypes
73  $rows = $db->getData("
74  SELECT *
75  FROM {$db->prefix}entity_subtypes
76  ");
77  foreach ($rows as $row) {
78  $this->subtype_data[$row->id] = $row;
79  }
80 
81  // get site entity
82  $this->site = $entities->get($config->site_guid, 'site');
83  if (!$this->site) {
84  throw new \InstallationException("Unable to handle this request. This site is not configured or the database is down.");
85  }
86 
87  // get config
88  $rows = $db->getData("
89  SELECT *
90  FROM {$db->prefix}config
91  WHERE site_guid = {$config->site_guid}
92  ");
93  foreach ($rows as $row) {
94  $this->config_values[$row->name] = unserialize($row->value);
95  }
96 
97  // get plugins
98  $this->active_plugins = $plugins->find('active', $config->site_guid);
99 
100  // get plugin settings
101  if (!$this->active_plugins) {
102  return;
103  }
104 
105  // find GUIDs with not too many private settings
106  $guids = array_map(function (\ElggPlugin $plugin) {
107  return $plugin->guid;
108  }, $this->active_plugins);
109 
110  // find plugin GUIDs with not too many settings
111  $limit = isset($config->bootdata_plugin_settings_limit) ? (int) $config->bootdata_plugin_settings_limit : 40;
112  if ($limit > 0) {
113  $set = implode(',', $guids);
114  $sql = "
115  SELECT entity_guid
116  FROM {$db->prefix}private_settings
117  WHERE entity_guid IN ($set)
118  AND name NOT LIKE 'plugin:user_setting:%'
119  AND name NOT LIKE 'elgg:internal:%'
120  GROUP BY entity_guid
121  HAVING COUNT(*) > $limit
122  ";
123  $unsuitable_guids = $db->getData($sql, function ($row) {
124  return (int)$row->entity_guid;
125  });
126  $guids = array_values($guids);
127  $guids = array_diff($guids, $unsuitable_guids);
128  }
129 
130  if ($guids) {
131  // get the settings
132  $set = implode(',', $guids);
133  $rows = $db->getData("
134  SELECT entity_guid, `name`, `value`
135  FROM {$db->prefix}private_settings
136  WHERE entity_guid IN ($set)
137  AND name NOT LIKE 'plugin:user_setting:%'
138  AND name NOT LIKE 'elgg:internal:%'
139  ORDER BY entity_guid
140  ");
141  // make sure we show all entities as loaded
142  $this->plugin_settings = array_fill_keys($guids, []);
143  foreach ($rows as $i => $row) {
144  $this->plugin_settings[$row->entity_guid][$row->name] = $row->value;
145  }
146  }
147  }
148 
154  public function getSite() {
155  return $this->site;
156  }
157 
163  public function getDatalistCache() {
164  return $this->datalist_cache;
165  }
166 
172  public function getConfigValues() {
173  return $this->config_values;
174  }
175 
181  public function getSubtypeData() {
182  return $this->subtype_data;
183  }
184 
190  public function getActivePlugins() {
191  return $this->active_plugins;
192  }
193 
199  public function getPluginSettings() {
200  return $this->plugin_settings;
201  }
202 }
$plugin
$CONFIG site
The current site object.
Definition: config.php:79
getSite()
Get the site entity.
Definition: BootData.php:154
The Elgg database.
Definition: Database.php:17
getConfigValues()
Get config values to merge into $CONFIG.
Definition: BootData.php:172
getDatalistCache()
Get the datalists cache.
Definition: BootData.php:163
getData($query, $callback=null, array $params=[])
Retrieve rows from the database.
Definition: Database.php:208
Save menu items.
$limit
Definition: userpicker.php:38
An in-memory implementation of a cache pool.
Definition: InMemory.php:18
find($status= 'active', $site_guid=null)
Returns an ordered list of plugins.
Definition: Plugins.php:409
populate(\stdClass $config, Database $db, EntityTable $entities, Plugins $plugins)
Populate the boot data.
Definition: BootData.php:59
getPluginSettings()
Get the plugin settings (may not include all active plugins)
Definition: BootData.php:199
getActivePlugins()
Get active plugins.
Definition: BootData.php:190
getSubtypeData()
Get the subtype data.
Definition: BootData.php:181
$guids
if(!is_file("$autoload_root/vendor/autoload.php"))
Interates through each element of an array and calls callback a function.
Definition: start.php:4
Serializable collection of data used to boot Elgg.
Definition: BootData.php:16
$row
$rows
Persistent, installation-wide key-value storage.
Definition: Plugins.php:18
get($guid, $type= '')
Loads and returns an entity object from a guid.
http free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:5