1 | <?php |
||
16 | class BootData { |
||
17 | |||
18 | /** |
||
19 | * @var \ElggSite|false |
||
20 | */ |
||
21 | private $site = false; |
||
22 | |||
23 | /** |
||
24 | * @var \stdClass[] |
||
25 | */ |
||
26 | private $subtype_data = []; |
||
27 | |||
28 | /** |
||
29 | * @var \ElggPlugin[] |
||
30 | */ |
||
31 | private $active_plugins = []; |
||
32 | |||
33 | /** |
||
34 | * @var array |
||
35 | */ |
||
36 | private $plugin_settings = []; |
||
37 | |||
38 | /** |
||
39 | * Populate the boot data |
||
40 | * |
||
41 | * @param Database $db Elgg database |
||
42 | * @param EntityTable $entities Entities service |
||
43 | * @param Plugins $plugins Plugins service |
||
44 | * @param bool $installed Is the site installed? |
||
45 | * |
||
46 | * @return void |
||
47 | * @throws \InstallationException |
||
48 | */ |
||
49 | 293 | public function populate(Database $db, EntityTable $entities, Plugins $plugins, $installed) { |
|
50 | |||
51 | // get subtypes |
||
52 | 293 | $rows = $db->getData(" |
|
53 | SELECT * |
||
54 | 293 | FROM {$db->prefix}entity_subtypes |
|
55 | "); |
||
56 | 293 | foreach ($rows as $row) { |
|
57 | 293 | $this->subtype_data[$row->id] = $row; |
|
58 | } |
||
59 | |||
60 | // get site entity |
||
61 | 293 | $this->site = $entities->get(1, 'site'); |
|
|
|||
62 | 293 | if (!$this->site && $installed) { |
|
63 | throw new \InstallationException("Unable to handle this request. This site is not configured or the database is down."); |
||
64 | } |
||
65 | |||
66 | // get plugins |
||
67 | 293 | $this->active_plugins = $plugins->find('active'); |
|
68 | |||
69 | // get plugin settings |
||
70 | 293 | if (!$this->active_plugins) { |
|
71 | 293 | return; |
|
72 | } |
||
73 | |||
74 | // find GUIDs with not too many private settings |
||
75 | $guids = array_map(function (\ElggPlugin $plugin) { |
||
76 | return $plugin->guid; |
||
77 | }, $this->active_plugins); |
||
78 | |||
79 | // find plugin GUIDs with not too many settings |
||
80 | $limit = 40; |
||
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 | if ($guids) { |
||
97 | // get the settings |
||
98 | $set = implode(',', $guids); |
||
99 | $rows = $db->getData(" |
||
100 | SELECT entity_guid, `name`, `value` |
||
101 | FROM {$db->prefix}private_settings |
||
102 | WHERE entity_guid IN ($set) |
||
103 | AND name NOT LIKE 'plugin:user_setting:%' |
||
104 | ORDER BY entity_guid |
||
105 | "); |
||
106 | // make sure we show all entities as loaded |
||
107 | $this->plugin_settings = array_fill_keys($guids, []); |
||
108 | foreach ($rows as $i => $row) { |
||
109 | $this->plugin_settings[$row->entity_guid][$row->name] = $row->value; |
||
110 | } |
||
111 | } |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Get the site entity |
||
116 | * |
||
117 | * @return \ElggSite|false False if not installed |
||
118 | */ |
||
119 | 293 | public function getSite() { |
|
122 | |||
123 | /** |
||
124 | * Get the subtype data |
||
125 | * |
||
126 | * @return \stdClass[] |
||
127 | */ |
||
128 | 293 | public function getSubtypeData() { |
|
131 | |||
132 | /** |
||
133 | * Get active plugins |
||
134 | * |
||
135 | * @return \ElggPlugin[] |
||
136 | */ |
||
137 | 293 | public function getActivePlugins() { |
|
140 | |||
141 | /** |
||
142 | * Get the plugin settings (may not include all active plugins) |
||
143 | * |
||
144 | * @return array |
||
145 | */ |
||
146 | 293 | public function getPluginSettings() { |
|
149 | } |
||
150 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.