Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
BootData.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg;
4 
5 use Elgg\Database;
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->getTablePrefix()}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->getTablePrefix()}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->getTablePrefix()}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 = 40;
112  $set = implode(',', $guids);
113  $sql = "
114  SELECT entity_guid
115  FROM {$db->getTablePrefix()}private_settings
116  WHERE entity_guid IN ($set)
117  AND name NOT LIKE 'plugin:user_setting:%'
118  AND name NOT LIKE 'elgg:internal:%'
119  GROUP BY entity_guid
120  HAVING COUNT(*) > $limit
121  ";
122  $unsuitable_guids = $db->getData($sql, function ($row) {
123  return (int)$row->entity_guid;
124  });
125  $guids = array_values($guids);
126  $guids = array_diff($guids, $unsuitable_guids);
127 
128  if ($guids) {
129  // get the settings
130  $set = implode(',', $guids);
131  $rows = $db->getData("
132  SELECT entity_guid, `name`, `value`
133  FROM {$db->getTablePrefix()}private_settings
134  WHERE entity_guid IN ($set)
135  AND name NOT LIKE 'plugin:user_setting:%'
136  AND name NOT LIKE 'elgg:internal:%'
137  ORDER BY entity_guid
138  ");
139  // make sure we show all entities as loaded
140  $this->plugin_settings = array_fill_keys($guids, []);
141  foreach ($rows as $i => $row) {
142  $this->plugin_settings[$row->entity_guid][$row->name] = $row->value;
143  }
144  }
145  }
146 
152  public function getSite() {
153  return $this->site;
154  }
155 
161  public function getDatalistCache() {
162  return $this->datalist_cache;
163  }
164 
170  public function getConfigValues() {
171  return $this->config_values;
172  }
173 
179  public function getSubtypeData() {
180  return $this->subtype_data;
181  }
182 
188  public function getActivePlugins() {
189  return $this->active_plugins;
190  }
191 
197  public function getPluginSettings() {
198  return $this->plugin_settings;
199  }
200 }
$CONFIG site
The current site object.
Definition: config.php:79
$plugin
getSite()
Get the site entity.
Definition: BootData.php:152
getConfigValues()
Get config values to merge into $CONFIG.
Definition: BootData.php:170
getDatalistCache()
Get the datalists cache.
Definition: BootData.php:161
getData($query, $callback=null, array $params=[])
Retrieve rows from the database.
Definition: Database.php:209
$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:197
getActivePlugins()
Get active plugins.
Definition: BootData.php:188
getSubtypeData()
Get the subtype data.
Definition: BootData.php:179
$guids
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.