Elgg  Version 4.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 = false;
22 
26  private $active_plugins;
27 
31  private $plugin_settings = [];
32 
36  private $plugin_metadata = [];
37 
50  public function populate(Config $config, Database $db, EntityTable $entities, Plugins $plugins, $installed) {
51 
52  // get site entity
53  $this->site = $entities->get(1, 'site');
54  if (!$this->site && $installed) {
55  throw new InstallationException("Unable to handle this request. This site is not configured or the database is down.");
56  }
57 
58  // get plugins
59  $this->active_plugins = $plugins->find('active');
60 
61  // get plugin settings
62  if (empty($this->active_plugins)) {
63  return;
64  }
65 
66  // find GUIDs with not too many private settings
67  $guids = array_map(function (\ElggPlugin $plugin) {
68  return $plugin->guid;
69  }, $this->active_plugins);
70 
71  _elgg_services()->metadataCache->populateFromEntities($guids);
72 
73  foreach ($guids as $guid) {
74  $this->plugin_metadata[$guid] = _elgg_services()->metadataCache->getEntityMetadata($guid);
75  }
76 
77  // find plugin GUIDs with not too many settings
78  $limit = $config->bootdata_plugin_settings_limit;
79  if ($limit > 0) {
80  $qb = Select::fromTable('private_settings');
81  $qb->select('entity_guid')
82  ->where($qb->compare('entity_guid', 'in', $guids, ELGG_VALUE_GUID))
83  ->andWhere($qb->compare('name', 'not like', 'plugin:user_setting:%', ELGG_VALUE_STRING))
84  ->groupBy('entity_guid')
85  ->having("count(*) > {$limit}");
86 
87  $unsuitable_guids = $db->getData($qb, function ($row) {
88  return (int) $row->entity_guid;
89  });
90 
91  $guids = array_values($guids);
92  $guids = array_diff($guids, $unsuitable_guids);
93  }
94 
95  if (!empty($guids)) {
96  // get the settings
97  $qb = Select::fromTable('private_settings');
98  $qb->select('entity_guid', 'name', 'value')
99  ->where($qb->compare('entity_guid', 'in', $guids, ELGG_VALUE_GUID))
100  ->andWhere($qb->compare('name', 'not like', 'plugin:user_setting:%', ELGG_VALUE_STRING));
101 
102  $rows = $db->getData($qb);
103 
104  // make sure we show all entities as loaded
105  $this->plugin_settings = array_fill_keys($guids, []);
106  foreach ($rows as $row) {
107  $this->plugin_settings[$row->entity_guid][$row->name] = $row->value;
108  }
109  }
110  }
111 
117  public function getSite() {
118  return $this->site;
119  }
120 
126  public function getActivePlugins() {
127  return $this->active_plugins;
128  }
129 
135  public function getPluginSettings() {
136  return $this->plugin_settings;
137  }
138 
144  public function getPluginMetadata() {
145  return $this->plugin_metadata;
146  }
147 }
$plugin
$rows
Definition: redis.php:25
getSite()
Get the site entity.
Definition: BootData.php:117
The Elgg database.
Definition: Database.php:25
getPluginMetadata()
Get plugin metadata.
Definition: BootData.php:144
const ELGG_VALUE_GUID
Definition: constants.php:128
$plugins
Definition: categories.php:3
if($pagination &&($position== 'after'||$position== 'both')) $limit
Definition: list.php:108
$site
Definition: icons.php:5
$config
Advanced site settings, debugging section.
Definition: debugging.php:6
Updates the basic settings for the primary site object.
getData($query, $callback=null, array $params=[])
Retrieve rows from the database.
Definition: Database.php:210
foreach($recommendedExtensions as $extension) if(empty(ini_get('session.gc_probability'))||empty(ini_get('session.gc_divisor'))) $db
Thrown when there is a major problem with the installation.
populate(Config $config, Database $db, EntityTable $entities, Plugins $plugins, $installed)
Populate the boot data.
Definition: BootData.php:50
getPluginSettings()
Get the plugin settings (may not include all active plugins)
Definition: BootData.php:135
getActivePlugins()
Get active plugins.
Definition: BootData.php:126
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
const ELGG_VALUE_STRING
Definition: constants.php:127
Serializable collection of data used to boot Elgg.
Definition: BootData.php:16
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638
Persistent, installation-wide key-value storage.
Definition: Plugins.php:28
find(string $status= 'active')
Returns an ordered list of plugins.
Definition: Plugins.php:736
$qb
Definition: queue.php:11
Entity table database service.
Definition: EntityTable.php:26
$guid
Reset an ElggUpgrade.
Definition: reset.php:6