Elgg  Version 3.0
BootData.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg;
4 
7 
14 class BootData {
15 
19  private $site = false;
20 
24  private $active_plugins;
25 
29  private $plugin_settings = [];
30 
34  private $plugin_metadata = [];
35 
51  public function populate(Config $config, Database $db, EntityTable $entities, Plugins $plugins, $installed) {
52 
53  // get site entity
54  $this->site = $entities->get(1, 'site');
55  if (!$this->site && $installed) {
56  throw new \InstallationException("Unable to handle this request. This site is not configured or the database is down.");
57  }
58 
59  // get plugins
60  $this->active_plugins = $plugins->find('active');
61 
62  // get plugin settings
63  if (empty($this->active_plugins)) {
64  return;
65  }
66 
67  // find GUIDs with not too many private settings
68  $guids = array_map(function (\ElggPlugin $plugin) {
69  return $plugin->guid;
70  }, $this->active_plugins);
71 
72  _elgg_services()->metadataCache->populateFromEntities($guids);
73 
74  foreach ($guids as $guid) {
75  $this->plugin_metadata[$guid] = _elgg_services()->metadataCache->getEntityMetadata($guid);
76  }
77 
78  // find plugin GUIDs with not too many settings
79  $limit = $config->bootdata_plugin_settings_limit;
80  if ($limit > 0) {
81  $set = implode(',', $guids);
82  $sql = "
83  SELECT entity_guid
84  FROM {$db->prefix}private_settings
85  WHERE entity_guid IN ($set)
86  AND name NOT LIKE 'plugin:user_setting:%'
87  GROUP BY entity_guid
88  HAVING COUNT(*) > $limit
89  ";
90  $unsuitable_guids = $db->getData($sql, function ($row) {
91  return (int) $row->entity_guid;
92  });
93  $guids = array_values($guids);
94  $guids = array_diff($guids, $unsuitable_guids);
95  }
96 
97  if (!empty($guids)) {
98  // get the settings
99  $set = implode(',', $guids);
100  $rows = $db->getData("
101  SELECT entity_guid, `name`, `value`
102  FROM {$db->prefix}private_settings
103  WHERE entity_guid IN ($set)
104  AND name NOT LIKE 'plugin:user_setting:%'
105  ORDER BY entity_guid
106  ");
107  // make sure we show all entities as loaded
108  $this->plugin_settings = array_fill_keys($guids, []);
109  foreach ($rows as $row) {
110  $this->plugin_settings[$row->entity_guid][$row->name] = $row->value;
111  }
112  }
113  }
114 
120  public function getSite() {
121  return $this->site;
122  }
123 
129  public function getActivePlugins() {
130  return $this->active_plugins;
131  }
132 
138  public function getPluginSettings() {
139  return $this->plugin_settings;
140  }
141 
147  public function getPluginMetadata() {
148  return $this->plugin_metadata;
149  }
150 }
$CONFIG site
The current site object.
Definition: config.php:73
$plugin
$rows
Definition: redis.php:20
getSite()
Get the site entity.
Definition: BootData.php:120
The Elgg database.
Definition: Database.php:21
getPluginMetadata()
Get plugin metadata.
Definition: BootData.php:147
$guid
Removes an admin notice.
$plugins
Definition: categories.php:3
find($status= 'active')
Returns an ordered list of plugins.
Definition: Plugins.php:777
$config
Advanced site settings, debugging section.
Definition: debugging.php:6
getData($query, $callback=null, array $params=[])
Retrieve rows from the database.
Definition: Database.php:191
Configuration exception.
$limit
Definition: userpicker.php:52
populate(Config $config, Database $db, EntityTable $entities, Plugins $plugins, $installed)
Populate the boot data.
Definition: BootData.php:51
getPluginSettings()
Get the plugin settings (may not include all active plugins)
Definition: BootData.php:138
getActivePlugins()
Get active plugins.
Definition: BootData.php:129
get($guid, $type=null, $subtype=null)
Loads and returns an entity object from a guid.
$guids
Activates all specified installed and inactive plugins.
Definition: activate_all.php:9
Serializable collection of data used to boot Elgg.
Definition: BootData.php:14
_elgg_services()
Get the global service provider.
Definition: elgglib.php:1292
Persistent, installation-wide key-value storage.
Definition: Plugins.php:36
WARNING: API IN FLUX.
Definition: EntityTable.php:38