@@ -4,27 +4,27 @@ |
||
4 | 4 | * Configuration array for Elgg installation on Travis |
5 | 5 | */ |
6 | 6 | return [ |
7 | - // database parameters |
|
8 | - 'dbuser' => 'root', |
|
9 | - 'dbpassword' => 'password', |
|
10 | - 'dbname' => 'elgg', |
|
7 | + // database parameters |
|
8 | + 'dbuser' => 'root', |
|
9 | + 'dbpassword' => 'password', |
|
10 | + 'dbname' => 'elgg', |
|
11 | 11 | |
12 | - // We use a wonky dbprefix to catch any cases where folks hardcode "elgg_" |
|
13 | - // instead of using config->dbprefix |
|
14 | - 'dbprefix' => 't_i_elgg_', |
|
12 | + // We use a wonky dbprefix to catch any cases where folks hardcode "elgg_" |
|
13 | + // instead of using config->dbprefix |
|
14 | + 'dbprefix' => 't_i_elgg_', |
|
15 | 15 | |
16 | - // site settings |
|
17 | - 'sitename' => 'Elgg Travis Site', |
|
18 | - 'siteemail' => '[email protected]', |
|
19 | - 'wwwroot' => 'http://localhost:8888/', |
|
20 | - 'dataroot' => getenv('HOME') . '/elgg_data/', |
|
16 | + // site settings |
|
17 | + 'sitename' => 'Elgg Travis Site', |
|
18 | + 'siteemail' => '[email protected]', |
|
19 | + 'wwwroot' => 'http://localhost:8888/', |
|
20 | + 'dataroot' => getenv('HOME') . '/elgg_data/', |
|
21 | 21 | |
22 | - // admin account |
|
23 | - 'displayname' => 'Administrator', |
|
24 | - 'email' => '[email protected]', |
|
25 | - 'username' => 'admin', |
|
26 | - 'password' => 'fancypassword', |
|
22 | + // admin account |
|
23 | + 'displayname' => 'Administrator', |
|
24 | + 'email' => '[email protected]', |
|
25 | + 'username' => 'admin', |
|
26 | + 'password' => 'fancypassword', |
|
27 | 27 | |
28 | - // timezone |
|
29 | - 'timezone' => 'UTC' |
|
28 | + // timezone |
|
29 | + 'timezone' => 'UTC' |
|
30 | 30 | ]; |
31 | 31 | \ No newline at end of file |
@@ -17,7 +17,7 @@ |
||
17 | 17 | 'sitename' => 'Elgg Travis Site', |
18 | 18 | 'siteemail' => '[email protected]', |
19 | 19 | 'wwwroot' => 'http://localhost:8888/', |
20 | - 'dataroot' => getenv('HOME') . '/elgg_data/', |
|
20 | + 'dataroot' => getenv('HOME').'/elgg_data/', |
|
21 | 21 | |
22 | 22 | // admin account |
23 | 23 | 'displayname' => 'Administrator', |
@@ -34,1414 +34,1414 @@ |
||
34 | 34 | */ |
35 | 35 | class ElggInstaller { |
36 | 36 | |
37 | - private $steps = [ |
|
38 | - 'welcome', |
|
39 | - 'requirements', |
|
40 | - 'database', |
|
41 | - 'settings', |
|
42 | - 'admin', |
|
43 | - 'complete', |
|
44 | - ]; |
|
45 | - |
|
46 | - private $has_completed = [ |
|
47 | - 'config' => false, |
|
48 | - 'database' => false, |
|
49 | - 'settings' => false, |
|
50 | - 'admin' => false, |
|
51 | - ]; |
|
52 | - |
|
53 | - private $is_action = false; |
|
54 | - |
|
55 | - private $autoLogin = true; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var ServiceProvider |
|
59 | - */ |
|
60 | - private $services; |
|
61 | - |
|
62 | - /** |
|
63 | - * @var Config |
|
64 | - */ |
|
65 | - private $config; |
|
66 | - |
|
67 | - /** |
|
68 | - * @var Application |
|
69 | - */ |
|
70 | - private $app; |
|
71 | - |
|
72 | - /** |
|
73 | - * Dispatches a request to one of the step controllers |
|
74 | - * |
|
75 | - * @return void |
|
76 | - * @throws InstallationException |
|
77 | - */ |
|
78 | - public function run() { |
|
79 | - $this->getApp(); |
|
80 | - |
|
81 | - $this->is_action = $this->services->request->getMethod() === 'POST'; |
|
82 | - |
|
83 | - $step = get_input('step', 'welcome'); |
|
84 | - |
|
85 | - if (!in_array($step, $this->getSteps())) { |
|
86 | - $msg = elgg_echo('InstallationException:UnknownStep', [$step]); |
|
87 | - throw new InstallationException($msg); |
|
88 | - } |
|
89 | - |
|
90 | - $this->determineInstallStatus(); |
|
37 | + private $steps = [ |
|
38 | + 'welcome', |
|
39 | + 'requirements', |
|
40 | + 'database', |
|
41 | + 'settings', |
|
42 | + 'admin', |
|
43 | + 'complete', |
|
44 | + ]; |
|
45 | + |
|
46 | + private $has_completed = [ |
|
47 | + 'config' => false, |
|
48 | + 'database' => false, |
|
49 | + 'settings' => false, |
|
50 | + 'admin' => false, |
|
51 | + ]; |
|
52 | + |
|
53 | + private $is_action = false; |
|
54 | + |
|
55 | + private $autoLogin = true; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var ServiceProvider |
|
59 | + */ |
|
60 | + private $services; |
|
61 | + |
|
62 | + /** |
|
63 | + * @var Config |
|
64 | + */ |
|
65 | + private $config; |
|
66 | + |
|
67 | + /** |
|
68 | + * @var Application |
|
69 | + */ |
|
70 | + private $app; |
|
71 | + |
|
72 | + /** |
|
73 | + * Dispatches a request to one of the step controllers |
|
74 | + * |
|
75 | + * @return void |
|
76 | + * @throws InstallationException |
|
77 | + */ |
|
78 | + public function run() { |
|
79 | + $this->getApp(); |
|
80 | + |
|
81 | + $this->is_action = $this->services->request->getMethod() === 'POST'; |
|
82 | + |
|
83 | + $step = get_input('step', 'welcome'); |
|
84 | + |
|
85 | + if (!in_array($step, $this->getSteps())) { |
|
86 | + $msg = elgg_echo('InstallationException:UnknownStep', [$step]); |
|
87 | + throw new InstallationException($msg); |
|
88 | + } |
|
89 | + |
|
90 | + $this->determineInstallStatus(); |
|
91 | 91 | |
92 | - $this->checkInstallCompletion($step); |
|
93 | - |
|
94 | - // check if this is an install being resumed |
|
95 | - $this->resumeInstall($step); |
|
96 | - |
|
97 | - $this->finishBootstrapping($step); |
|
98 | - |
|
99 | - $params = $this->services->request->request->all(); |
|
100 | - |
|
101 | - $method = "run" . ucwords($step); |
|
102 | - $this->$method($params); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Build the application needed by the installer |
|
107 | - * |
|
108 | - * @return Application |
|
109 | - * @throws InstallationException |
|
110 | - */ |
|
111 | - protected function getApp() { |
|
112 | - if ($this->app) { |
|
113 | - return $this->app; |
|
114 | - } |
|
115 | - |
|
116 | - $config = new Config(); |
|
117 | - $config->elgg_config_locks = false; |
|
118 | - $config->installer_running = true; |
|
119 | - $config->dbencoding = 'utf8mb4'; |
|
120 | - |
|
121 | - $this->config = $config; |
|
122 | - $this->services = new ServiceProvider($config); |
|
123 | - |
|
124 | - $app = Application::factory([ |
|
125 | - 'service_provider' => $this->services, |
|
126 | - 'handle_exceptions' => false, |
|
127 | - 'handle_shutdown' => false, |
|
128 | - ]); |
|
129 | - |
|
130 | - // Don't set global $CONFIG, because loading the settings file may require it to write to |
|
131 | - // it, and it can have array sets (e.g. cookie config) that fail when using a proxy for |
|
132 | - // the config service. |
|
133 | - //$app->setGlobalConfig(); |
|
134 | - |
|
135 | - Application::setInstance($app); |
|
136 | - $app->loadCore(); |
|
137 | - $this->app = $app; |
|
138 | - |
|
139 | - $this->services->setValue('session', \ElggSession::getMock()); |
|
140 | - $this->services->views->setViewtype('installation'); |
|
141 | - $this->services->views->registerPluginViews(Paths::elgg()); |
|
142 | - $this->services->translator->registerTranslations(Paths::elgg() . "install/languages/", true); |
|
143 | - |
|
144 | - return $this->app; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Set the auto login flag |
|
149 | - * |
|
150 | - * @param bool $flag Auto login |
|
151 | - * |
|
152 | - * @return void |
|
153 | - */ |
|
154 | - public function setAutoLogin($flag) { |
|
155 | - $this->autoLogin = (bool) $flag; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * A batch install of Elgg |
|
160 | - * |
|
161 | - * All required parameters must be passed in as an associative array. See |
|
162 | - * $requiredParams for a list of them. This creates the necessary files, |
|
163 | - * loads the database, configures the site settings, and creates the admin |
|
164 | - * account. If it fails, an exception is thrown. It does not check any of |
|
165 | - * the requirements as the multiple step web installer does. |
|
166 | - * |
|
167 | - * @param array $params Array of key value pairs |
|
168 | - * @param bool $create_htaccess Should .htaccess be created |
|
169 | - * |
|
170 | - * @return void |
|
171 | - * @throws InstallationException |
|
172 | - */ |
|
173 | - public function batchInstall(array $params, $create_htaccess = false) { |
|
174 | - $this->getApp(); |
|
175 | - |
|
176 | - $defaults = [ |
|
177 | - 'dbhost' => 'localhost', |
|
178 | - 'dbprefix' => 'elgg_', |
|
179 | - 'language' => 'en', |
|
180 | - 'siteaccess' => ACCESS_PUBLIC, |
|
181 | - ]; |
|
182 | - $params = array_merge($defaults, $params); |
|
183 | - |
|
184 | - $required_params = [ |
|
185 | - 'dbuser', |
|
186 | - 'dbpassword', |
|
187 | - 'dbname', |
|
188 | - 'sitename', |
|
189 | - 'wwwroot', |
|
190 | - 'dataroot', |
|
191 | - 'displayname', |
|
192 | - 'email', |
|
193 | - 'username', |
|
194 | - 'password', |
|
195 | - ]; |
|
196 | - foreach ($required_params as $key) { |
|
197 | - if (empty($params[$key])) { |
|
198 | - $msg = elgg_echo('install:error:requiredfield', [$key]); |
|
199 | - throw new InstallationException($msg); |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - // password is passed in once |
|
204 | - $params['password1'] = $params['password2'] = $params['password']; |
|
205 | - |
|
206 | - if ($create_htaccess) { |
|
207 | - $rewrite_tester = new ElggRewriteTester(); |
|
208 | - if (!$rewrite_tester->createHtaccess($params['wwwroot'])) { |
|
209 | - throw new InstallationException(elgg_echo('install:error:htaccess')); |
|
210 | - } |
|
211 | - } |
|
212 | - |
|
213 | - $this->determineInstallStatus(); |
|
214 | - |
|
215 | - if (!$this->has_completed['config']) { |
|
216 | - if (!$this->createSettingsFile($params)) { |
|
217 | - throw new InstallationException(elgg_echo('install:error:settings')); |
|
218 | - } |
|
219 | - } |
|
220 | - |
|
221 | - $this->loadSettingsFile(); |
|
222 | - |
|
223 | - // Make sure settings file matches parameters |
|
224 | - $config = $this->config; |
|
225 | - $config_keys = [ |
|
226 | - // param key => config key |
|
227 | - 'dbhost' => 'dbhost', |
|
228 | - 'dbuser' => 'dbuser', |
|
229 | - 'dbpassword' => 'dbpass', |
|
230 | - 'dbname' => 'dbname', |
|
231 | - 'dataroot' => 'dataroot', |
|
232 | - 'dbprefix' => 'dbprefix', |
|
233 | - ]; |
|
234 | - foreach ($config_keys as $params_key => $config_key) { |
|
235 | - if ($params[$params_key] !== $config->$config_key) { |
|
236 | - throw new InstallationException(elgg_echo('install:error:settings_mismatch', [$config_key])); |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - if (!$this->connectToDatabase()) { |
|
241 | - throw new InstallationException(elgg_echo('install:error:databasesettings')); |
|
242 | - } |
|
243 | - |
|
244 | - if (!$this->has_completed['database']) { |
|
245 | - if (!$this->installDatabase()) { |
|
246 | - throw new InstallationException(elgg_echo('install:error:cannotloadtables')); |
|
247 | - } |
|
248 | - } |
|
249 | - |
|
250 | - // load remaining core libraries |
|
251 | - $this->finishBootstrapping('settings'); |
|
252 | - |
|
253 | - if (!$this->saveSiteSettings($params)) { |
|
254 | - throw new InstallationException(elgg_echo('install:error:savesitesettings')); |
|
255 | - } |
|
256 | - |
|
257 | - if (!$this->createAdminAccount($params)) { |
|
258 | - throw new InstallationException(elgg_echo('install:admin:cannot_create')); |
|
259 | - } |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Renders the data passed by a controller |
|
264 | - * |
|
265 | - * @param string $step The current step |
|
266 | - * @param array $vars Array of vars to pass to the view |
|
267 | - * |
|
268 | - * @return void |
|
269 | - */ |
|
270 | - protected function render($step, $vars = []) { |
|
271 | - $vars['next_step'] = $this->getNextStep($step); |
|
272 | - |
|
273 | - $title = elgg_echo("install:$step"); |
|
274 | - $body = elgg_view("install/pages/$step", $vars); |
|
92 | + $this->checkInstallCompletion($step); |
|
93 | + |
|
94 | + // check if this is an install being resumed |
|
95 | + $this->resumeInstall($step); |
|
96 | + |
|
97 | + $this->finishBootstrapping($step); |
|
98 | + |
|
99 | + $params = $this->services->request->request->all(); |
|
100 | + |
|
101 | + $method = "run" . ucwords($step); |
|
102 | + $this->$method($params); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Build the application needed by the installer |
|
107 | + * |
|
108 | + * @return Application |
|
109 | + * @throws InstallationException |
|
110 | + */ |
|
111 | + protected function getApp() { |
|
112 | + if ($this->app) { |
|
113 | + return $this->app; |
|
114 | + } |
|
115 | + |
|
116 | + $config = new Config(); |
|
117 | + $config->elgg_config_locks = false; |
|
118 | + $config->installer_running = true; |
|
119 | + $config->dbencoding = 'utf8mb4'; |
|
120 | + |
|
121 | + $this->config = $config; |
|
122 | + $this->services = new ServiceProvider($config); |
|
123 | + |
|
124 | + $app = Application::factory([ |
|
125 | + 'service_provider' => $this->services, |
|
126 | + 'handle_exceptions' => false, |
|
127 | + 'handle_shutdown' => false, |
|
128 | + ]); |
|
129 | + |
|
130 | + // Don't set global $CONFIG, because loading the settings file may require it to write to |
|
131 | + // it, and it can have array sets (e.g. cookie config) that fail when using a proxy for |
|
132 | + // the config service. |
|
133 | + //$app->setGlobalConfig(); |
|
134 | + |
|
135 | + Application::setInstance($app); |
|
136 | + $app->loadCore(); |
|
137 | + $this->app = $app; |
|
138 | + |
|
139 | + $this->services->setValue('session', \ElggSession::getMock()); |
|
140 | + $this->services->views->setViewtype('installation'); |
|
141 | + $this->services->views->registerPluginViews(Paths::elgg()); |
|
142 | + $this->services->translator->registerTranslations(Paths::elgg() . "install/languages/", true); |
|
143 | + |
|
144 | + return $this->app; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Set the auto login flag |
|
149 | + * |
|
150 | + * @param bool $flag Auto login |
|
151 | + * |
|
152 | + * @return void |
|
153 | + */ |
|
154 | + public function setAutoLogin($flag) { |
|
155 | + $this->autoLogin = (bool) $flag; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * A batch install of Elgg |
|
160 | + * |
|
161 | + * All required parameters must be passed in as an associative array. See |
|
162 | + * $requiredParams for a list of them. This creates the necessary files, |
|
163 | + * loads the database, configures the site settings, and creates the admin |
|
164 | + * account. If it fails, an exception is thrown. It does not check any of |
|
165 | + * the requirements as the multiple step web installer does. |
|
166 | + * |
|
167 | + * @param array $params Array of key value pairs |
|
168 | + * @param bool $create_htaccess Should .htaccess be created |
|
169 | + * |
|
170 | + * @return void |
|
171 | + * @throws InstallationException |
|
172 | + */ |
|
173 | + public function batchInstall(array $params, $create_htaccess = false) { |
|
174 | + $this->getApp(); |
|
175 | + |
|
176 | + $defaults = [ |
|
177 | + 'dbhost' => 'localhost', |
|
178 | + 'dbprefix' => 'elgg_', |
|
179 | + 'language' => 'en', |
|
180 | + 'siteaccess' => ACCESS_PUBLIC, |
|
181 | + ]; |
|
182 | + $params = array_merge($defaults, $params); |
|
183 | + |
|
184 | + $required_params = [ |
|
185 | + 'dbuser', |
|
186 | + 'dbpassword', |
|
187 | + 'dbname', |
|
188 | + 'sitename', |
|
189 | + 'wwwroot', |
|
190 | + 'dataroot', |
|
191 | + 'displayname', |
|
192 | + 'email', |
|
193 | + 'username', |
|
194 | + 'password', |
|
195 | + ]; |
|
196 | + foreach ($required_params as $key) { |
|
197 | + if (empty($params[$key])) { |
|
198 | + $msg = elgg_echo('install:error:requiredfield', [$key]); |
|
199 | + throw new InstallationException($msg); |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + // password is passed in once |
|
204 | + $params['password1'] = $params['password2'] = $params['password']; |
|
205 | + |
|
206 | + if ($create_htaccess) { |
|
207 | + $rewrite_tester = new ElggRewriteTester(); |
|
208 | + if (!$rewrite_tester->createHtaccess($params['wwwroot'])) { |
|
209 | + throw new InstallationException(elgg_echo('install:error:htaccess')); |
|
210 | + } |
|
211 | + } |
|
212 | + |
|
213 | + $this->determineInstallStatus(); |
|
214 | + |
|
215 | + if (!$this->has_completed['config']) { |
|
216 | + if (!$this->createSettingsFile($params)) { |
|
217 | + throw new InstallationException(elgg_echo('install:error:settings')); |
|
218 | + } |
|
219 | + } |
|
220 | + |
|
221 | + $this->loadSettingsFile(); |
|
222 | + |
|
223 | + // Make sure settings file matches parameters |
|
224 | + $config = $this->config; |
|
225 | + $config_keys = [ |
|
226 | + // param key => config key |
|
227 | + 'dbhost' => 'dbhost', |
|
228 | + 'dbuser' => 'dbuser', |
|
229 | + 'dbpassword' => 'dbpass', |
|
230 | + 'dbname' => 'dbname', |
|
231 | + 'dataroot' => 'dataroot', |
|
232 | + 'dbprefix' => 'dbprefix', |
|
233 | + ]; |
|
234 | + foreach ($config_keys as $params_key => $config_key) { |
|
235 | + if ($params[$params_key] !== $config->$config_key) { |
|
236 | + throw new InstallationException(elgg_echo('install:error:settings_mismatch', [$config_key])); |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + if (!$this->connectToDatabase()) { |
|
241 | + throw new InstallationException(elgg_echo('install:error:databasesettings')); |
|
242 | + } |
|
243 | + |
|
244 | + if (!$this->has_completed['database']) { |
|
245 | + if (!$this->installDatabase()) { |
|
246 | + throw new InstallationException(elgg_echo('install:error:cannotloadtables')); |
|
247 | + } |
|
248 | + } |
|
249 | + |
|
250 | + // load remaining core libraries |
|
251 | + $this->finishBootstrapping('settings'); |
|
252 | + |
|
253 | + if (!$this->saveSiteSettings($params)) { |
|
254 | + throw new InstallationException(elgg_echo('install:error:savesitesettings')); |
|
255 | + } |
|
256 | + |
|
257 | + if (!$this->createAdminAccount($params)) { |
|
258 | + throw new InstallationException(elgg_echo('install:admin:cannot_create')); |
|
259 | + } |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Renders the data passed by a controller |
|
264 | + * |
|
265 | + * @param string $step The current step |
|
266 | + * @param array $vars Array of vars to pass to the view |
|
267 | + * |
|
268 | + * @return void |
|
269 | + */ |
|
270 | + protected function render($step, $vars = []) { |
|
271 | + $vars['next_step'] = $this->getNextStep($step); |
|
272 | + |
|
273 | + $title = elgg_echo("install:$step"); |
|
274 | + $body = elgg_view("install/pages/$step", $vars); |
|
275 | 275 | |
276 | - echo elgg_view_page( |
|
277 | - $title, |
|
278 | - $body, |
|
279 | - 'default', |
|
280 | - [ |
|
281 | - 'step' => $step, |
|
282 | - 'steps' => $this->getSteps(), |
|
283 | - ] |
|
284 | - ); |
|
285 | - exit; |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Step controllers |
|
290 | - */ |
|
291 | - |
|
292 | - /** |
|
293 | - * Welcome controller |
|
294 | - * |
|
295 | - * @param array $vars Not used |
|
296 | - * |
|
297 | - * @return void |
|
298 | - */ |
|
299 | - protected function runWelcome($vars) { |
|
300 | - $this->render('welcome'); |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * Requirements controller |
|
305 | - * |
|
306 | - * Checks version of php, libraries, permissions, and rewrite rules |
|
307 | - * |
|
308 | - * @param array $vars Vars |
|
309 | - * |
|
310 | - * @return void |
|
311 | - */ |
|
312 | - protected function runRequirements($vars) { |
|
313 | - |
|
314 | - $report = []; |
|
315 | - |
|
316 | - // check PHP parameters and libraries |
|
317 | - $this->checkPHP($report); |
|
318 | - |
|
319 | - // check URL rewriting |
|
320 | - $this->checkRewriteRules($report); |
|
321 | - |
|
322 | - // check for existence of settings file |
|
323 | - if ($this->checkSettingsFile($report) != true) { |
|
324 | - // no file, so check permissions on engine directory |
|
325 | - $this->isInstallDirWritable($report); |
|
326 | - } |
|
327 | - |
|
328 | - // check the database later |
|
329 | - $report['database'] = [[ |
|
330 | - 'severity' => 'info', |
|
331 | - 'message' => elgg_echo('install:check:database') |
|
332 | - ]]; |
|
333 | - |
|
334 | - // any failures? |
|
335 | - $numFailures = $this->countNumConditions($report, 'failure'); |
|
336 | - |
|
337 | - // any warnings |
|
338 | - $numWarnings = $this->countNumConditions($report, 'warning'); |
|
339 | - |
|
340 | - |
|
341 | - $params = [ |
|
342 | - 'report' => $report, |
|
343 | - 'num_failures' => $numFailures, |
|
344 | - 'num_warnings' => $numWarnings, |
|
345 | - ]; |
|
346 | - |
|
347 | - $this->render('requirements', $params); |
|
348 | - } |
|
349 | - |
|
350 | - /** |
|
351 | - * Database set up controller |
|
352 | - * |
|
353 | - * Creates the settings.php file and creates the database tables |
|
354 | - * |
|
355 | - * @param array $submissionVars Submitted form variables |
|
356 | - * |
|
357 | - * @return void |
|
358 | - */ |
|
359 | - protected function runDatabase($submissionVars) { |
|
360 | - |
|
361 | - $formVars = [ |
|
362 | - 'dbuser' => [ |
|
363 | - 'type' => 'text', |
|
364 | - 'value' => '', |
|
365 | - 'required' => true, |
|
366 | - ], |
|
367 | - 'dbpassword' => [ |
|
368 | - 'type' => 'password', |
|
369 | - 'value' => '', |
|
370 | - 'required' => false, |
|
371 | - ], |
|
372 | - 'dbname' => [ |
|
373 | - 'type' => 'text', |
|
374 | - 'value' => '', |
|
375 | - 'required' => true, |
|
376 | - ], |
|
377 | - 'dbhost' => [ |
|
378 | - 'type' => 'text', |
|
379 | - 'value' => 'localhost', |
|
380 | - 'required' => true, |
|
381 | - ], |
|
382 | - 'dbprefix' => [ |
|
383 | - 'type' => 'text', |
|
384 | - 'value' => 'elgg_', |
|
385 | - 'required' => true, |
|
386 | - ], |
|
387 | - 'dataroot' => [ |
|
388 | - 'type' => 'text', |
|
389 | - 'value' => '', |
|
390 | - 'required' => true, |
|
391 | - ], |
|
392 | - 'wwwroot' => [ |
|
393 | - 'type' => 'url', |
|
394 | - 'value' => _elgg_services()->config->wwwroot, |
|
395 | - 'required' => true, |
|
396 | - ], |
|
397 | - 'timezone' => [ |
|
398 | - 'type' => 'dropdown', |
|
399 | - 'value' => 'UTC', |
|
400 | - 'options' => \DateTimeZone::listIdentifiers(), |
|
401 | - 'required' => true |
|
402 | - ] |
|
403 | - ]; |
|
404 | - |
|
405 | - if ($this->checkSettingsFile()) { |
|
406 | - // user manually created settings file so we fake out action test |
|
407 | - $this->is_action = true; |
|
408 | - } |
|
409 | - |
|
410 | - if ($this->is_action) { |
|
411 | - call_user_func(function () use ($submissionVars, $formVars) { |
|
412 | - // only create settings file if it doesn't exist |
|
413 | - if (!$this->checkSettingsFile()) { |
|
414 | - if (!$this->validateDatabaseVars($submissionVars, $formVars)) { |
|
415 | - // error so we break out of action and serve same page |
|
416 | - return; |
|
417 | - } |
|
418 | - |
|
419 | - if (!$this->createSettingsFile($submissionVars)) { |
|
420 | - return; |
|
421 | - } |
|
422 | - } |
|
423 | - |
|
424 | - // check db version and connect |
|
425 | - if (!$this->connectToDatabase()) { |
|
426 | - return; |
|
427 | - } |
|
428 | - |
|
429 | - if (!$this->installDatabase()) { |
|
430 | - return; |
|
431 | - } |
|
432 | - |
|
433 | - system_message(elgg_echo('install:success:database')); |
|
434 | - |
|
435 | - $this->continueToNextStep('database'); |
|
436 | - }); |
|
437 | - } |
|
438 | - |
|
439 | - $formVars = $this->makeFormSticky($formVars, $submissionVars); |
|
440 | - |
|
441 | - $params = ['variables' => $formVars,]; |
|
442 | - |
|
443 | - if ($this->checkSettingsFile()) { |
|
444 | - // settings file exists and we're here so failed to create database |
|
445 | - $params['failure'] = true; |
|
446 | - } |
|
447 | - |
|
448 | - $this->render('database', $params); |
|
449 | - } |
|
450 | - |
|
451 | - /** |
|
452 | - * Site settings controller |
|
453 | - * |
|
454 | - * Sets the site name, URL, data directory, etc. |
|
455 | - * |
|
456 | - * @param array $submissionVars Submitted vars |
|
457 | - * |
|
458 | - * @return void |
|
459 | - */ |
|
460 | - protected function runSettings($submissionVars) { |
|
461 | - $formVars = [ |
|
462 | - 'sitename' => [ |
|
463 | - 'type' => 'text', |
|
464 | - 'value' => 'My New Community', |
|
465 | - 'required' => true, |
|
466 | - ], |
|
467 | - 'siteemail' => [ |
|
468 | - 'type' => 'email', |
|
469 | - 'value' => '', |
|
470 | - 'required' => false, |
|
471 | - ], |
|
472 | - 'siteaccess' => [ |
|
473 | - 'type' => 'access', |
|
474 | - 'value' => ACCESS_PUBLIC, |
|
475 | - 'required' => true, |
|
476 | - ], |
|
477 | - ]; |
|
478 | - |
|
479 | - if ($this->is_action) { |
|
480 | - call_user_func(function () use ($submissionVars, $formVars) { |
|
481 | - if (!$this->validateSettingsVars($submissionVars, $formVars)) { |
|
482 | - return; |
|
483 | - } |
|
484 | - |
|
485 | - if (!$this->saveSiteSettings($submissionVars)) { |
|
486 | - return; |
|
487 | - } |
|
488 | - |
|
489 | - system_message(elgg_echo('install:success:settings')); |
|
490 | - |
|
491 | - $this->continueToNextStep('settings'); |
|
492 | - }); |
|
493 | - } |
|
494 | - |
|
495 | - $formVars = $this->makeFormSticky($formVars, $submissionVars); |
|
496 | - |
|
497 | - $this->render('settings', ['variables' => $formVars]); |
|
498 | - } |
|
499 | - |
|
500 | - /** |
|
501 | - * Admin account controller |
|
502 | - * |
|
503 | - * Creates an admin user account |
|
504 | - * |
|
505 | - * @param array $submissionVars Submitted vars |
|
506 | - * |
|
507 | - * @return void |
|
508 | - */ |
|
509 | - protected function runAdmin($submissionVars) { |
|
510 | - $formVars = [ |
|
511 | - 'displayname' => [ |
|
512 | - 'type' => 'text', |
|
513 | - 'value' => '', |
|
514 | - 'required' => true, |
|
515 | - ], |
|
516 | - 'email' => [ |
|
517 | - 'type' => 'email', |
|
518 | - 'value' => '', |
|
519 | - 'required' => true, |
|
520 | - ], |
|
521 | - 'username' => [ |
|
522 | - 'type' => 'text', |
|
523 | - 'value' => '', |
|
524 | - 'required' => true, |
|
525 | - ], |
|
526 | - 'password1' => [ |
|
527 | - 'type' => 'password', |
|
528 | - 'value' => '', |
|
529 | - 'required' => true, |
|
530 | - 'pattern' => '.{6,}', |
|
531 | - ], |
|
532 | - 'password2' => [ |
|
533 | - 'type' => 'password', |
|
534 | - 'value' => '', |
|
535 | - 'required' => true, |
|
536 | - ], |
|
537 | - ]; |
|
538 | - |
|
539 | - if ($this->is_action) { |
|
540 | - call_user_func(function () use ($submissionVars, $formVars) { |
|
541 | - if (!$this->validateAdminVars($submissionVars, $formVars)) { |
|
542 | - return; |
|
543 | - } |
|
544 | - |
|
545 | - if (!$this->createAdminAccount($submissionVars, $this->autoLogin)) { |
|
546 | - return; |
|
547 | - } |
|
548 | - |
|
549 | - system_message(elgg_echo('install:success:admin')); |
|
550 | - |
|
551 | - $this->continueToNextStep('admin'); |
|
552 | - }); |
|
553 | - } |
|
554 | - |
|
555 | - // Bit of a hack to get the password help to show right number of characters |
|
556 | - // We burn the value into the stored translation. |
|
557 | - $lang = $this->services->translator->getCurrentLanguage(); |
|
558 | - $translations = $this->services->translator->getLoadedTranslations(); |
|
559 | - $this->services->translator->addTranslation($lang, [ |
|
560 | - 'install:admin:help:password1' => sprintf( |
|
561 | - $translations[$lang]['install:admin:help:password1'], |
|
562 | - $this->config->min_password_length |
|
563 | - ), |
|
564 | - ]); |
|
565 | - |
|
566 | - $formVars = $this->makeFormSticky($formVars, $submissionVars); |
|
567 | - |
|
568 | - $this->render('admin', ['variables' => $formVars]); |
|
569 | - } |
|
570 | - |
|
571 | - /** |
|
572 | - * Controller for last step |
|
573 | - * |
|
574 | - * @return void |
|
575 | - */ |
|
576 | - protected function runComplete() { |
|
577 | - |
|
578 | - // nudge to check out settings |
|
579 | - $link = elgg_format_element([ |
|
580 | - '#tag_name' => 'a', |
|
581 | - '#text' => elgg_echo('install:complete:admin_notice:link_text'), |
|
582 | - 'href' => elgg_normalize_url('admin/settings/basic'), |
|
583 | - ]); |
|
584 | - $notice = elgg_echo('install:complete:admin_notice', [$link]); |
|
585 | - elgg_add_admin_notice('fresh_install', $notice); |
|
586 | - |
|
587 | - $this->render('complete'); |
|
588 | - } |
|
589 | - |
|
590 | - /** |
|
591 | - * Step management |
|
592 | - */ |
|
593 | - |
|
594 | - /** |
|
595 | - * Get an array of steps |
|
596 | - * |
|
597 | - * @return array |
|
598 | - */ |
|
599 | - protected function getSteps() { |
|
600 | - return $this->steps; |
|
601 | - } |
|
602 | - |
|
603 | - /** |
|
604 | - * Forwards the browser to the next step |
|
605 | - * |
|
606 | - * @param string $currentStep Current installation step |
|
607 | - * |
|
608 | - * @return void |
|
609 | - */ |
|
610 | - protected function continueToNextStep($currentStep) { |
|
611 | - $this->is_action = false; |
|
612 | - forward($this->getNextStepUrl($currentStep)); |
|
613 | - } |
|
614 | - |
|
615 | - /** |
|
616 | - * Get the next step as a string |
|
617 | - * |
|
618 | - * @param string $currentStep Current installation step |
|
619 | - * |
|
620 | - * @return string |
|
621 | - */ |
|
622 | - protected function getNextStep($currentStep) { |
|
623 | - $index = 1 + array_search($currentStep, $this->steps); |
|
624 | - if (isset($this->steps[$index])) { |
|
625 | - return $this->steps[$index]; |
|
626 | - } else { |
|
627 | - return null; |
|
628 | - } |
|
629 | - } |
|
630 | - |
|
631 | - /** |
|
632 | - * Get the URL of the next step |
|
633 | - * |
|
634 | - * @param string $currentStep Current installation step |
|
635 | - * |
|
636 | - * @return string |
|
637 | - */ |
|
638 | - protected function getNextStepUrl($currentStep) { |
|
639 | - $nextStep = $this->getNextStep($currentStep); |
|
640 | - return $this->config->wwwroot . "install.php?step=$nextStep"; |
|
641 | - } |
|
642 | - |
|
643 | - /** |
|
644 | - * Updates $this->has_completed according to the current installation |
|
645 | - * |
|
646 | - * @return void |
|
647 | - * @throws InstallationException |
|
648 | - */ |
|
649 | - protected function determineInstallStatus() { |
|
650 | - $path = Paths::settingsFile(); |
|
651 | - if (!is_file($path) || !is_readable($path)) { |
|
652 | - return; |
|
653 | - } |
|
654 | - |
|
655 | - $this->loadSettingsFile(); |
|
656 | - |
|
657 | - $this->has_completed['config'] = true; |
|
658 | - |
|
659 | - // must be able to connect to database to jump install steps |
|
660 | - $dbSettingsPass = $this->checkDatabaseSettings( |
|
661 | - $this->config->dbuser, |
|
662 | - $this->config->dbpass, |
|
663 | - $this->config->dbname, |
|
664 | - $this->config->dbhost |
|
665 | - ); |
|
666 | - |
|
667 | - if (!$dbSettingsPass) { |
|
668 | - return; |
|
669 | - } |
|
670 | - |
|
671 | - $db = $this->services->db; |
|
672 | - |
|
673 | - // check that the config table has been created |
|
674 | - $result = $db->getData("SHOW TABLES"); |
|
675 | - if ($result) { |
|
676 | - foreach ($result as $table) { |
|
677 | - $table = (array) $table; |
|
678 | - if (in_array("{$db->prefix}config", $table)) { |
|
679 | - $this->has_completed['database'] = true; |
|
680 | - } |
|
681 | - } |
|
682 | - if ($this->has_completed['database'] == false) { |
|
683 | - return; |
|
684 | - } |
|
685 | - } else { |
|
686 | - // no tables |
|
687 | - return; |
|
688 | - } |
|
689 | - |
|
690 | - // check that the config table has entries |
|
691 | - $query = "SELECT COUNT(*) AS total FROM {$db->prefix}config"; |
|
692 | - $result = $db->getData($query); |
|
693 | - if ($result && $result[0]->total > 0) { |
|
694 | - $this->has_completed['settings'] = true; |
|
695 | - } else { |
|
696 | - return; |
|
697 | - } |
|
698 | - |
|
699 | - // check that the users entity table has an entry |
|
700 | - $query = "SELECT COUNT(*) AS total FROM {$db->prefix}users_entity"; |
|
701 | - $result = $db->getData($query); |
|
702 | - if ($result && $result[0]->total > 0) { |
|
703 | - $this->has_completed['admin'] = true; |
|
704 | - } else { |
|
705 | - return; |
|
706 | - } |
|
707 | - } |
|
708 | - |
|
709 | - /** |
|
710 | - * Security check to ensure the installer cannot be run after installation |
|
711 | - * has finished. If this is detected, the viewer is sent to the front page. |
|
712 | - * |
|
713 | - * @param string $step Installation step to check against |
|
714 | - * |
|
715 | - * @return void |
|
716 | - */ |
|
717 | - protected function checkInstallCompletion($step) { |
|
718 | - if ($step != 'complete') { |
|
719 | - if (!in_array(false, $this->has_completed)) { |
|
720 | - // install complete but someone is trying to view an install page |
|
721 | - forward(); |
|
722 | - } |
|
723 | - } |
|
724 | - } |
|
725 | - |
|
726 | - /** |
|
727 | - * Check if this is a case of a install being resumed and figure |
|
728 | - * out where to continue from. Returns the best guess on the step. |
|
729 | - * |
|
730 | - * @param string $step Installation step to resume from |
|
731 | - * |
|
732 | - * @return string |
|
733 | - */ |
|
734 | - protected function resumeInstall($step) { |
|
735 | - // only do a resume from the first step |
|
736 | - if ($step !== 'welcome') { |
|
737 | - return; |
|
738 | - } |
|
739 | - |
|
740 | - if ($this->has_completed['database'] == false) { |
|
741 | - return; |
|
742 | - } |
|
743 | - |
|
744 | - if ($this->has_completed['settings'] == false) { |
|
745 | - forward("install.php?step=settings"); |
|
746 | - } |
|
747 | - |
|
748 | - if ($this->has_completed['admin'] == false) { |
|
749 | - forward("install.php?step=admin"); |
|
750 | - } |
|
751 | - |
|
752 | - // everything appears to be set up |
|
753 | - forward("install.php?step=complete"); |
|
754 | - } |
|
755 | - |
|
756 | - /** |
|
757 | - * Bootstrapping |
|
758 | - */ |
|
759 | - |
|
760 | - /** |
|
761 | - * Load remaining engine libraries and complete bootstrapping |
|
762 | - * |
|
763 | - * @param string $step Which step to boot strap for. Required because |
|
764 | - * boot strapping is different until the DB is populated. |
|
765 | - * |
|
766 | - * @return void |
|
767 | - * @throws InstallationException |
|
768 | - */ |
|
769 | - protected function finishBootstrapping($step) { |
|
770 | - |
|
771 | - $index_db = array_search('database', $this->getSteps()); |
|
772 | - $index_settings = array_search('settings', $this->getSteps()); |
|
773 | - $index_admin = array_search('admin', $this->getSteps()); |
|
774 | - $index_complete = array_search('complete', $this->getSteps()); |
|
775 | - $index_step = array_search($step, $this->getSteps()); |
|
776 | - |
|
777 | - // To log in the user, we need to use the Elgg core session handling. |
|
778 | - // Otherwise, use default php session handling |
|
779 | - $use_elgg_session = ($index_step == $index_admin && $this->is_action) || ($index_step == $index_complete); |
|
780 | - if (!$use_elgg_session) { |
|
781 | - $session = ElggSession::fromFiles($this->config); |
|
782 | - $session->setName('Elgg_install'); |
|
783 | - $this->services->setValue('session', $session); |
|
784 | - } |
|
785 | - |
|
786 | - if ($index_step > $index_db) { |
|
787 | - // once the database has been created, load rest of engine |
|
788 | - |
|
789 | - // dummy site needed to boot |
|
790 | - $this->config->site = new ElggSite(); |
|
791 | - |
|
792 | - $this->app->bootCore(); |
|
793 | - } |
|
794 | - } |
|
795 | - |
|
796 | - /** |
|
797 | - * Load settings |
|
798 | - * |
|
799 | - * @return void |
|
800 | - * @throws InstallationException |
|
801 | - */ |
|
802 | - protected function loadSettingsFile() { |
|
803 | - try { |
|
804 | - $config = Config::fromFile(Paths::settingsFile()); |
|
805 | - $this->config->mergeValues($config->getValues()); |
|
806 | - |
|
807 | - // in case the DB instance is already captured in services, we re-inject its settings. |
|
808 | - $this->services->db->resetConnections(DbConfig::fromElggConfig($this->config)); |
|
809 | - } catch (\Exception $e) { |
|
810 | - $msg = elgg_echo('InstallationException:CannotLoadSettings'); |
|
811 | - throw new InstallationException($msg, 0, $e); |
|
812 | - } |
|
813 | - } |
|
814 | - |
|
815 | - /** |
|
816 | - * Action handling methods |
|
817 | - */ |
|
818 | - |
|
819 | - /** |
|
820 | - * If form is reshown, remember previously submitted variables |
|
821 | - * |
|
822 | - * @param array $formVars Vars int he form |
|
823 | - * @param array $submissionVars Submitted vars |
|
824 | - * |
|
825 | - * @return array |
|
826 | - */ |
|
827 | - protected function makeFormSticky($formVars, $submissionVars) { |
|
828 | - foreach ($submissionVars as $field => $value) { |
|
829 | - $formVars[$field]['value'] = $value; |
|
830 | - } |
|
831 | - return $formVars; |
|
832 | - } |
|
833 | - |
|
834 | - /* Requirement checks support methods */ |
|
835 | - |
|
836 | - /** |
|
837 | - * Indicates whether the webserver can add settings.php on its own or not. |
|
838 | - * |
|
839 | - * @param array $report The requirements report object |
|
840 | - * |
|
841 | - * @return bool |
|
842 | - */ |
|
843 | - protected function isInstallDirWritable(&$report) { |
|
844 | - if (!is_writable(Paths::projectConfig())) { |
|
845 | - $msg = elgg_echo('install:check:installdir', [Paths::PATH_TO_CONFIG]); |
|
846 | - $report['settings'] = [ |
|
847 | - [ |
|
848 | - 'severity' => 'failure', |
|
849 | - 'message' => $msg, |
|
850 | - ] |
|
851 | - ]; |
|
852 | - return false; |
|
853 | - } |
|
854 | - |
|
855 | - return true; |
|
856 | - } |
|
857 | - |
|
858 | - /** |
|
859 | - * Check that the settings file exists |
|
860 | - * |
|
861 | - * @param array $report The requirements report array |
|
862 | - * |
|
863 | - * @return bool |
|
864 | - */ |
|
865 | - protected function checkSettingsFile(&$report = []) { |
|
866 | - if (!is_file(Paths::settingsFile())) { |
|
867 | - return false; |
|
868 | - } |
|
869 | - |
|
870 | - if (!is_readable(Paths::settingsFile())) { |
|
871 | - $report['settings'] = [ |
|
872 | - [ |
|
873 | - 'severity' => 'failure', |
|
874 | - 'message' => elgg_echo('install:check:readsettings'), |
|
875 | - ] |
|
876 | - ]; |
|
877 | - } |
|
276 | + echo elgg_view_page( |
|
277 | + $title, |
|
278 | + $body, |
|
279 | + 'default', |
|
280 | + [ |
|
281 | + 'step' => $step, |
|
282 | + 'steps' => $this->getSteps(), |
|
283 | + ] |
|
284 | + ); |
|
285 | + exit; |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Step controllers |
|
290 | + */ |
|
291 | + |
|
292 | + /** |
|
293 | + * Welcome controller |
|
294 | + * |
|
295 | + * @param array $vars Not used |
|
296 | + * |
|
297 | + * @return void |
|
298 | + */ |
|
299 | + protected function runWelcome($vars) { |
|
300 | + $this->render('welcome'); |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * Requirements controller |
|
305 | + * |
|
306 | + * Checks version of php, libraries, permissions, and rewrite rules |
|
307 | + * |
|
308 | + * @param array $vars Vars |
|
309 | + * |
|
310 | + * @return void |
|
311 | + */ |
|
312 | + protected function runRequirements($vars) { |
|
313 | + |
|
314 | + $report = []; |
|
315 | + |
|
316 | + // check PHP parameters and libraries |
|
317 | + $this->checkPHP($report); |
|
318 | + |
|
319 | + // check URL rewriting |
|
320 | + $this->checkRewriteRules($report); |
|
321 | + |
|
322 | + // check for existence of settings file |
|
323 | + if ($this->checkSettingsFile($report) != true) { |
|
324 | + // no file, so check permissions on engine directory |
|
325 | + $this->isInstallDirWritable($report); |
|
326 | + } |
|
327 | + |
|
328 | + // check the database later |
|
329 | + $report['database'] = [[ |
|
330 | + 'severity' => 'info', |
|
331 | + 'message' => elgg_echo('install:check:database') |
|
332 | + ]]; |
|
333 | + |
|
334 | + // any failures? |
|
335 | + $numFailures = $this->countNumConditions($report, 'failure'); |
|
336 | + |
|
337 | + // any warnings |
|
338 | + $numWarnings = $this->countNumConditions($report, 'warning'); |
|
339 | + |
|
340 | + |
|
341 | + $params = [ |
|
342 | + 'report' => $report, |
|
343 | + 'num_failures' => $numFailures, |
|
344 | + 'num_warnings' => $numWarnings, |
|
345 | + ]; |
|
346 | + |
|
347 | + $this->render('requirements', $params); |
|
348 | + } |
|
349 | + |
|
350 | + /** |
|
351 | + * Database set up controller |
|
352 | + * |
|
353 | + * Creates the settings.php file and creates the database tables |
|
354 | + * |
|
355 | + * @param array $submissionVars Submitted form variables |
|
356 | + * |
|
357 | + * @return void |
|
358 | + */ |
|
359 | + protected function runDatabase($submissionVars) { |
|
360 | + |
|
361 | + $formVars = [ |
|
362 | + 'dbuser' => [ |
|
363 | + 'type' => 'text', |
|
364 | + 'value' => '', |
|
365 | + 'required' => true, |
|
366 | + ], |
|
367 | + 'dbpassword' => [ |
|
368 | + 'type' => 'password', |
|
369 | + 'value' => '', |
|
370 | + 'required' => false, |
|
371 | + ], |
|
372 | + 'dbname' => [ |
|
373 | + 'type' => 'text', |
|
374 | + 'value' => '', |
|
375 | + 'required' => true, |
|
376 | + ], |
|
377 | + 'dbhost' => [ |
|
378 | + 'type' => 'text', |
|
379 | + 'value' => 'localhost', |
|
380 | + 'required' => true, |
|
381 | + ], |
|
382 | + 'dbprefix' => [ |
|
383 | + 'type' => 'text', |
|
384 | + 'value' => 'elgg_', |
|
385 | + 'required' => true, |
|
386 | + ], |
|
387 | + 'dataroot' => [ |
|
388 | + 'type' => 'text', |
|
389 | + 'value' => '', |
|
390 | + 'required' => true, |
|
391 | + ], |
|
392 | + 'wwwroot' => [ |
|
393 | + 'type' => 'url', |
|
394 | + 'value' => _elgg_services()->config->wwwroot, |
|
395 | + 'required' => true, |
|
396 | + ], |
|
397 | + 'timezone' => [ |
|
398 | + 'type' => 'dropdown', |
|
399 | + 'value' => 'UTC', |
|
400 | + 'options' => \DateTimeZone::listIdentifiers(), |
|
401 | + 'required' => true |
|
402 | + ] |
|
403 | + ]; |
|
404 | + |
|
405 | + if ($this->checkSettingsFile()) { |
|
406 | + // user manually created settings file so we fake out action test |
|
407 | + $this->is_action = true; |
|
408 | + } |
|
409 | + |
|
410 | + if ($this->is_action) { |
|
411 | + call_user_func(function () use ($submissionVars, $formVars) { |
|
412 | + // only create settings file if it doesn't exist |
|
413 | + if (!$this->checkSettingsFile()) { |
|
414 | + if (!$this->validateDatabaseVars($submissionVars, $formVars)) { |
|
415 | + // error so we break out of action and serve same page |
|
416 | + return; |
|
417 | + } |
|
418 | + |
|
419 | + if (!$this->createSettingsFile($submissionVars)) { |
|
420 | + return; |
|
421 | + } |
|
422 | + } |
|
423 | + |
|
424 | + // check db version and connect |
|
425 | + if (!$this->connectToDatabase()) { |
|
426 | + return; |
|
427 | + } |
|
428 | + |
|
429 | + if (!$this->installDatabase()) { |
|
430 | + return; |
|
431 | + } |
|
432 | + |
|
433 | + system_message(elgg_echo('install:success:database')); |
|
434 | + |
|
435 | + $this->continueToNextStep('database'); |
|
436 | + }); |
|
437 | + } |
|
438 | + |
|
439 | + $formVars = $this->makeFormSticky($formVars, $submissionVars); |
|
440 | + |
|
441 | + $params = ['variables' => $formVars,]; |
|
442 | + |
|
443 | + if ($this->checkSettingsFile()) { |
|
444 | + // settings file exists and we're here so failed to create database |
|
445 | + $params['failure'] = true; |
|
446 | + } |
|
447 | + |
|
448 | + $this->render('database', $params); |
|
449 | + } |
|
450 | + |
|
451 | + /** |
|
452 | + * Site settings controller |
|
453 | + * |
|
454 | + * Sets the site name, URL, data directory, etc. |
|
455 | + * |
|
456 | + * @param array $submissionVars Submitted vars |
|
457 | + * |
|
458 | + * @return void |
|
459 | + */ |
|
460 | + protected function runSettings($submissionVars) { |
|
461 | + $formVars = [ |
|
462 | + 'sitename' => [ |
|
463 | + 'type' => 'text', |
|
464 | + 'value' => 'My New Community', |
|
465 | + 'required' => true, |
|
466 | + ], |
|
467 | + 'siteemail' => [ |
|
468 | + 'type' => 'email', |
|
469 | + 'value' => '', |
|
470 | + 'required' => false, |
|
471 | + ], |
|
472 | + 'siteaccess' => [ |
|
473 | + 'type' => 'access', |
|
474 | + 'value' => ACCESS_PUBLIC, |
|
475 | + 'required' => true, |
|
476 | + ], |
|
477 | + ]; |
|
478 | + |
|
479 | + if ($this->is_action) { |
|
480 | + call_user_func(function () use ($submissionVars, $formVars) { |
|
481 | + if (!$this->validateSettingsVars($submissionVars, $formVars)) { |
|
482 | + return; |
|
483 | + } |
|
484 | + |
|
485 | + if (!$this->saveSiteSettings($submissionVars)) { |
|
486 | + return; |
|
487 | + } |
|
488 | + |
|
489 | + system_message(elgg_echo('install:success:settings')); |
|
490 | + |
|
491 | + $this->continueToNextStep('settings'); |
|
492 | + }); |
|
493 | + } |
|
494 | + |
|
495 | + $formVars = $this->makeFormSticky($formVars, $submissionVars); |
|
496 | + |
|
497 | + $this->render('settings', ['variables' => $formVars]); |
|
498 | + } |
|
499 | + |
|
500 | + /** |
|
501 | + * Admin account controller |
|
502 | + * |
|
503 | + * Creates an admin user account |
|
504 | + * |
|
505 | + * @param array $submissionVars Submitted vars |
|
506 | + * |
|
507 | + * @return void |
|
508 | + */ |
|
509 | + protected function runAdmin($submissionVars) { |
|
510 | + $formVars = [ |
|
511 | + 'displayname' => [ |
|
512 | + 'type' => 'text', |
|
513 | + 'value' => '', |
|
514 | + 'required' => true, |
|
515 | + ], |
|
516 | + 'email' => [ |
|
517 | + 'type' => 'email', |
|
518 | + 'value' => '', |
|
519 | + 'required' => true, |
|
520 | + ], |
|
521 | + 'username' => [ |
|
522 | + 'type' => 'text', |
|
523 | + 'value' => '', |
|
524 | + 'required' => true, |
|
525 | + ], |
|
526 | + 'password1' => [ |
|
527 | + 'type' => 'password', |
|
528 | + 'value' => '', |
|
529 | + 'required' => true, |
|
530 | + 'pattern' => '.{6,}', |
|
531 | + ], |
|
532 | + 'password2' => [ |
|
533 | + 'type' => 'password', |
|
534 | + 'value' => '', |
|
535 | + 'required' => true, |
|
536 | + ], |
|
537 | + ]; |
|
538 | + |
|
539 | + if ($this->is_action) { |
|
540 | + call_user_func(function () use ($submissionVars, $formVars) { |
|
541 | + if (!$this->validateAdminVars($submissionVars, $formVars)) { |
|
542 | + return; |
|
543 | + } |
|
544 | + |
|
545 | + if (!$this->createAdminAccount($submissionVars, $this->autoLogin)) { |
|
546 | + return; |
|
547 | + } |
|
548 | + |
|
549 | + system_message(elgg_echo('install:success:admin')); |
|
550 | + |
|
551 | + $this->continueToNextStep('admin'); |
|
552 | + }); |
|
553 | + } |
|
554 | + |
|
555 | + // Bit of a hack to get the password help to show right number of characters |
|
556 | + // We burn the value into the stored translation. |
|
557 | + $lang = $this->services->translator->getCurrentLanguage(); |
|
558 | + $translations = $this->services->translator->getLoadedTranslations(); |
|
559 | + $this->services->translator->addTranslation($lang, [ |
|
560 | + 'install:admin:help:password1' => sprintf( |
|
561 | + $translations[$lang]['install:admin:help:password1'], |
|
562 | + $this->config->min_password_length |
|
563 | + ), |
|
564 | + ]); |
|
565 | + |
|
566 | + $formVars = $this->makeFormSticky($formVars, $submissionVars); |
|
567 | + |
|
568 | + $this->render('admin', ['variables' => $formVars]); |
|
569 | + } |
|
570 | + |
|
571 | + /** |
|
572 | + * Controller for last step |
|
573 | + * |
|
574 | + * @return void |
|
575 | + */ |
|
576 | + protected function runComplete() { |
|
577 | + |
|
578 | + // nudge to check out settings |
|
579 | + $link = elgg_format_element([ |
|
580 | + '#tag_name' => 'a', |
|
581 | + '#text' => elgg_echo('install:complete:admin_notice:link_text'), |
|
582 | + 'href' => elgg_normalize_url('admin/settings/basic'), |
|
583 | + ]); |
|
584 | + $notice = elgg_echo('install:complete:admin_notice', [$link]); |
|
585 | + elgg_add_admin_notice('fresh_install', $notice); |
|
586 | + |
|
587 | + $this->render('complete'); |
|
588 | + } |
|
589 | + |
|
590 | + /** |
|
591 | + * Step management |
|
592 | + */ |
|
593 | + |
|
594 | + /** |
|
595 | + * Get an array of steps |
|
596 | + * |
|
597 | + * @return array |
|
598 | + */ |
|
599 | + protected function getSteps() { |
|
600 | + return $this->steps; |
|
601 | + } |
|
602 | + |
|
603 | + /** |
|
604 | + * Forwards the browser to the next step |
|
605 | + * |
|
606 | + * @param string $currentStep Current installation step |
|
607 | + * |
|
608 | + * @return void |
|
609 | + */ |
|
610 | + protected function continueToNextStep($currentStep) { |
|
611 | + $this->is_action = false; |
|
612 | + forward($this->getNextStepUrl($currentStep)); |
|
613 | + } |
|
614 | + |
|
615 | + /** |
|
616 | + * Get the next step as a string |
|
617 | + * |
|
618 | + * @param string $currentStep Current installation step |
|
619 | + * |
|
620 | + * @return string |
|
621 | + */ |
|
622 | + protected function getNextStep($currentStep) { |
|
623 | + $index = 1 + array_search($currentStep, $this->steps); |
|
624 | + if (isset($this->steps[$index])) { |
|
625 | + return $this->steps[$index]; |
|
626 | + } else { |
|
627 | + return null; |
|
628 | + } |
|
629 | + } |
|
630 | + |
|
631 | + /** |
|
632 | + * Get the URL of the next step |
|
633 | + * |
|
634 | + * @param string $currentStep Current installation step |
|
635 | + * |
|
636 | + * @return string |
|
637 | + */ |
|
638 | + protected function getNextStepUrl($currentStep) { |
|
639 | + $nextStep = $this->getNextStep($currentStep); |
|
640 | + return $this->config->wwwroot . "install.php?step=$nextStep"; |
|
641 | + } |
|
642 | + |
|
643 | + /** |
|
644 | + * Updates $this->has_completed according to the current installation |
|
645 | + * |
|
646 | + * @return void |
|
647 | + * @throws InstallationException |
|
648 | + */ |
|
649 | + protected function determineInstallStatus() { |
|
650 | + $path = Paths::settingsFile(); |
|
651 | + if (!is_file($path) || !is_readable($path)) { |
|
652 | + return; |
|
653 | + } |
|
654 | + |
|
655 | + $this->loadSettingsFile(); |
|
656 | + |
|
657 | + $this->has_completed['config'] = true; |
|
658 | + |
|
659 | + // must be able to connect to database to jump install steps |
|
660 | + $dbSettingsPass = $this->checkDatabaseSettings( |
|
661 | + $this->config->dbuser, |
|
662 | + $this->config->dbpass, |
|
663 | + $this->config->dbname, |
|
664 | + $this->config->dbhost |
|
665 | + ); |
|
666 | + |
|
667 | + if (!$dbSettingsPass) { |
|
668 | + return; |
|
669 | + } |
|
670 | + |
|
671 | + $db = $this->services->db; |
|
672 | + |
|
673 | + // check that the config table has been created |
|
674 | + $result = $db->getData("SHOW TABLES"); |
|
675 | + if ($result) { |
|
676 | + foreach ($result as $table) { |
|
677 | + $table = (array) $table; |
|
678 | + if (in_array("{$db->prefix}config", $table)) { |
|
679 | + $this->has_completed['database'] = true; |
|
680 | + } |
|
681 | + } |
|
682 | + if ($this->has_completed['database'] == false) { |
|
683 | + return; |
|
684 | + } |
|
685 | + } else { |
|
686 | + // no tables |
|
687 | + return; |
|
688 | + } |
|
689 | + |
|
690 | + // check that the config table has entries |
|
691 | + $query = "SELECT COUNT(*) AS total FROM {$db->prefix}config"; |
|
692 | + $result = $db->getData($query); |
|
693 | + if ($result && $result[0]->total > 0) { |
|
694 | + $this->has_completed['settings'] = true; |
|
695 | + } else { |
|
696 | + return; |
|
697 | + } |
|
698 | + |
|
699 | + // check that the users entity table has an entry |
|
700 | + $query = "SELECT COUNT(*) AS total FROM {$db->prefix}users_entity"; |
|
701 | + $result = $db->getData($query); |
|
702 | + if ($result && $result[0]->total > 0) { |
|
703 | + $this->has_completed['admin'] = true; |
|
704 | + } else { |
|
705 | + return; |
|
706 | + } |
|
707 | + } |
|
708 | + |
|
709 | + /** |
|
710 | + * Security check to ensure the installer cannot be run after installation |
|
711 | + * has finished. If this is detected, the viewer is sent to the front page. |
|
712 | + * |
|
713 | + * @param string $step Installation step to check against |
|
714 | + * |
|
715 | + * @return void |
|
716 | + */ |
|
717 | + protected function checkInstallCompletion($step) { |
|
718 | + if ($step != 'complete') { |
|
719 | + if (!in_array(false, $this->has_completed)) { |
|
720 | + // install complete but someone is trying to view an install page |
|
721 | + forward(); |
|
722 | + } |
|
723 | + } |
|
724 | + } |
|
725 | + |
|
726 | + /** |
|
727 | + * Check if this is a case of a install being resumed and figure |
|
728 | + * out where to continue from. Returns the best guess on the step. |
|
729 | + * |
|
730 | + * @param string $step Installation step to resume from |
|
731 | + * |
|
732 | + * @return string |
|
733 | + */ |
|
734 | + protected function resumeInstall($step) { |
|
735 | + // only do a resume from the first step |
|
736 | + if ($step !== 'welcome') { |
|
737 | + return; |
|
738 | + } |
|
739 | + |
|
740 | + if ($this->has_completed['database'] == false) { |
|
741 | + return; |
|
742 | + } |
|
743 | + |
|
744 | + if ($this->has_completed['settings'] == false) { |
|
745 | + forward("install.php?step=settings"); |
|
746 | + } |
|
747 | + |
|
748 | + if ($this->has_completed['admin'] == false) { |
|
749 | + forward("install.php?step=admin"); |
|
750 | + } |
|
751 | + |
|
752 | + // everything appears to be set up |
|
753 | + forward("install.php?step=complete"); |
|
754 | + } |
|
755 | + |
|
756 | + /** |
|
757 | + * Bootstrapping |
|
758 | + */ |
|
759 | + |
|
760 | + /** |
|
761 | + * Load remaining engine libraries and complete bootstrapping |
|
762 | + * |
|
763 | + * @param string $step Which step to boot strap for. Required because |
|
764 | + * boot strapping is different until the DB is populated. |
|
765 | + * |
|
766 | + * @return void |
|
767 | + * @throws InstallationException |
|
768 | + */ |
|
769 | + protected function finishBootstrapping($step) { |
|
770 | + |
|
771 | + $index_db = array_search('database', $this->getSteps()); |
|
772 | + $index_settings = array_search('settings', $this->getSteps()); |
|
773 | + $index_admin = array_search('admin', $this->getSteps()); |
|
774 | + $index_complete = array_search('complete', $this->getSteps()); |
|
775 | + $index_step = array_search($step, $this->getSteps()); |
|
776 | + |
|
777 | + // To log in the user, we need to use the Elgg core session handling. |
|
778 | + // Otherwise, use default php session handling |
|
779 | + $use_elgg_session = ($index_step == $index_admin && $this->is_action) || ($index_step == $index_complete); |
|
780 | + if (!$use_elgg_session) { |
|
781 | + $session = ElggSession::fromFiles($this->config); |
|
782 | + $session->setName('Elgg_install'); |
|
783 | + $this->services->setValue('session', $session); |
|
784 | + } |
|
785 | + |
|
786 | + if ($index_step > $index_db) { |
|
787 | + // once the database has been created, load rest of engine |
|
788 | + |
|
789 | + // dummy site needed to boot |
|
790 | + $this->config->site = new ElggSite(); |
|
791 | + |
|
792 | + $this->app->bootCore(); |
|
793 | + } |
|
794 | + } |
|
795 | + |
|
796 | + /** |
|
797 | + * Load settings |
|
798 | + * |
|
799 | + * @return void |
|
800 | + * @throws InstallationException |
|
801 | + */ |
|
802 | + protected function loadSettingsFile() { |
|
803 | + try { |
|
804 | + $config = Config::fromFile(Paths::settingsFile()); |
|
805 | + $this->config->mergeValues($config->getValues()); |
|
806 | + |
|
807 | + // in case the DB instance is already captured in services, we re-inject its settings. |
|
808 | + $this->services->db->resetConnections(DbConfig::fromElggConfig($this->config)); |
|
809 | + } catch (\Exception $e) { |
|
810 | + $msg = elgg_echo('InstallationException:CannotLoadSettings'); |
|
811 | + throw new InstallationException($msg, 0, $e); |
|
812 | + } |
|
813 | + } |
|
814 | + |
|
815 | + /** |
|
816 | + * Action handling methods |
|
817 | + */ |
|
818 | + |
|
819 | + /** |
|
820 | + * If form is reshown, remember previously submitted variables |
|
821 | + * |
|
822 | + * @param array $formVars Vars int he form |
|
823 | + * @param array $submissionVars Submitted vars |
|
824 | + * |
|
825 | + * @return array |
|
826 | + */ |
|
827 | + protected function makeFormSticky($formVars, $submissionVars) { |
|
828 | + foreach ($submissionVars as $field => $value) { |
|
829 | + $formVars[$field]['value'] = $value; |
|
830 | + } |
|
831 | + return $formVars; |
|
832 | + } |
|
833 | + |
|
834 | + /* Requirement checks support methods */ |
|
835 | + |
|
836 | + /** |
|
837 | + * Indicates whether the webserver can add settings.php on its own or not. |
|
838 | + * |
|
839 | + * @param array $report The requirements report object |
|
840 | + * |
|
841 | + * @return bool |
|
842 | + */ |
|
843 | + protected function isInstallDirWritable(&$report) { |
|
844 | + if (!is_writable(Paths::projectConfig())) { |
|
845 | + $msg = elgg_echo('install:check:installdir', [Paths::PATH_TO_CONFIG]); |
|
846 | + $report['settings'] = [ |
|
847 | + [ |
|
848 | + 'severity' => 'failure', |
|
849 | + 'message' => $msg, |
|
850 | + ] |
|
851 | + ]; |
|
852 | + return false; |
|
853 | + } |
|
854 | + |
|
855 | + return true; |
|
856 | + } |
|
857 | + |
|
858 | + /** |
|
859 | + * Check that the settings file exists |
|
860 | + * |
|
861 | + * @param array $report The requirements report array |
|
862 | + * |
|
863 | + * @return bool |
|
864 | + */ |
|
865 | + protected function checkSettingsFile(&$report = []) { |
|
866 | + if (!is_file(Paths::settingsFile())) { |
|
867 | + return false; |
|
868 | + } |
|
869 | + |
|
870 | + if (!is_readable(Paths::settingsFile())) { |
|
871 | + $report['settings'] = [ |
|
872 | + [ |
|
873 | + 'severity' => 'failure', |
|
874 | + 'message' => elgg_echo('install:check:readsettings'), |
|
875 | + ] |
|
876 | + ]; |
|
877 | + } |
|
878 | 878 | |
879 | - return true; |
|
880 | - } |
|
879 | + return true; |
|
880 | + } |
|
881 | 881 | |
882 | - /** |
|
883 | - * Check version of PHP, extensions, and variables |
|
884 | - * |
|
885 | - * @param array $report The requirements report array |
|
886 | - * |
|
887 | - * @return void |
|
888 | - */ |
|
889 | - protected function checkPHP(&$report) { |
|
890 | - $phpReport = []; |
|
891 | - |
|
892 | - $min_php_version = '5.6.0'; |
|
893 | - if (version_compare(PHP_VERSION, $min_php_version, '<')) { |
|
894 | - $phpReport[] = [ |
|
895 | - 'severity' => 'failure', |
|
896 | - 'message' => elgg_echo('install:check:php:version', [$min_php_version, PHP_VERSION]) |
|
897 | - ]; |
|
898 | - } |
|
899 | - |
|
900 | - $this->checkPhpExtensions($phpReport); |
|
901 | - |
|
902 | - $this->checkPhpDirectives($phpReport); |
|
903 | - |
|
904 | - if (count($phpReport) == 0) { |
|
905 | - $phpReport[] = [ |
|
906 | - 'severity' => 'pass', |
|
907 | - 'message' => elgg_echo('install:check:php:success') |
|
908 | - ]; |
|
909 | - } |
|
910 | - |
|
911 | - $report['php'] = $phpReport; |
|
912 | - } |
|
913 | - |
|
914 | - /** |
|
915 | - * Check the server's PHP extensions |
|
916 | - * |
|
917 | - * @param array $phpReport The PHP requirements report array |
|
918 | - * |
|
919 | - * @return void |
|
920 | - */ |
|
921 | - protected function checkPhpExtensions(&$phpReport) { |
|
922 | - $extensions = get_loaded_extensions(); |
|
923 | - $requiredExtensions = [ |
|
924 | - 'pdo_mysql', |
|
925 | - 'json', |
|
926 | - 'xml', |
|
927 | - 'gd', |
|
928 | - ]; |
|
929 | - foreach ($requiredExtensions as $extension) { |
|
930 | - if (!in_array($extension, $extensions)) { |
|
931 | - $phpReport[] = [ |
|
932 | - 'severity' => 'failure', |
|
933 | - 'message' => elgg_echo('install:check:php:extension', [$extension]) |
|
934 | - ]; |
|
935 | - } |
|
936 | - } |
|
937 | - |
|
938 | - $recommendedExtensions = [ |
|
939 | - 'mbstring', |
|
940 | - ]; |
|
941 | - foreach ($recommendedExtensions as $extension) { |
|
942 | - if (!in_array($extension, $extensions)) { |
|
943 | - $phpReport[] = [ |
|
944 | - 'severity' => 'warning', |
|
945 | - 'message' => elgg_echo('install:check:php:extension:recommend', [$extension]) |
|
946 | - ]; |
|
947 | - } |
|
948 | - } |
|
949 | - } |
|
950 | - |
|
951 | - /** |
|
952 | - * Check PHP parameters |
|
953 | - * |
|
954 | - * @param array $phpReport The PHP requirements report array |
|
955 | - * |
|
956 | - * @return void |
|
957 | - */ |
|
958 | - protected function checkPhpDirectives(&$phpReport) { |
|
959 | - if (ini_get('open_basedir')) { |
|
960 | - $phpReport[] = [ |
|
961 | - 'severity' => 'warning', |
|
962 | - 'message' => elgg_echo("install:check:php:open_basedir") |
|
963 | - ]; |
|
964 | - } |
|
965 | - |
|
966 | - if (ini_get('safe_mode')) { |
|
967 | - $phpReport[] = [ |
|
968 | - 'severity' => 'warning', |
|
969 | - 'message' => elgg_echo("install:check:php:safe_mode") |
|
970 | - ]; |
|
971 | - } |
|
972 | - |
|
973 | - if (ini_get('arg_separator.output') !== '&') { |
|
974 | - $separator = htmlspecialchars(ini_get('arg_separator.output')); |
|
975 | - $msg = elgg_echo("install:check:php:arg_separator", [$separator]); |
|
976 | - $phpReport[] = [ |
|
977 | - 'severity' => 'failure', |
|
978 | - 'message' => $msg, |
|
979 | - ]; |
|
980 | - } |
|
981 | - |
|
982 | - if (ini_get('register_globals')) { |
|
983 | - $phpReport[] = [ |
|
984 | - 'severity' => 'failure', |
|
985 | - 'message' => elgg_echo("install:check:php:register_globals") |
|
986 | - ]; |
|
987 | - } |
|
988 | - |
|
989 | - if (ini_get('session.auto_start')) { |
|
990 | - $phpReport[] = [ |
|
991 | - 'severity' => 'failure', |
|
992 | - 'message' => elgg_echo("install:check:php:session.auto_start") |
|
993 | - ]; |
|
994 | - } |
|
995 | - } |
|
996 | - |
|
997 | - /** |
|
998 | - * Confirm that the rewrite rules are firing |
|
999 | - * |
|
1000 | - * @param array $report The requirements report array |
|
1001 | - * |
|
1002 | - * @return void |
|
1003 | - */ |
|
1004 | - protected function checkRewriteRules(&$report) { |
|
1005 | - $tester = new ElggRewriteTester(); |
|
1006 | - $url = $this->config->wwwroot; |
|
1007 | - $url .= Request::REWRITE_TEST_TOKEN . '?' . http_build_query([ |
|
1008 | - Request::REWRITE_TEST_TOKEN => '1', |
|
1009 | - ]); |
|
1010 | - $report['rewrite'] = [$tester->run($url, Paths::project())]; |
|
1011 | - } |
|
1012 | - |
|
1013 | - /** |
|
1014 | - * Count the number of failures in the requirements report |
|
1015 | - * |
|
1016 | - * @param array $report The requirements report array |
|
1017 | - * @param string $condition 'failure' or 'warning' |
|
1018 | - * |
|
1019 | - * @return int |
|
1020 | - */ |
|
1021 | - protected function countNumConditions($report, $condition) { |
|
1022 | - $count = 0; |
|
1023 | - foreach ($report as $category => $checks) { |
|
1024 | - foreach ($checks as $check) { |
|
1025 | - if ($check['severity'] === $condition) { |
|
1026 | - $count++; |
|
1027 | - } |
|
1028 | - } |
|
1029 | - } |
|
1030 | - |
|
1031 | - return $count; |
|
1032 | - } |
|
1033 | - |
|
1034 | - |
|
1035 | - /** |
|
1036 | - * Database support methods |
|
1037 | - */ |
|
1038 | - |
|
1039 | - /** |
|
1040 | - * Validate the variables for the database step |
|
1041 | - * |
|
1042 | - * @param array $submissionVars Submitted vars |
|
1043 | - * @param array $formVars Vars in the form |
|
1044 | - * |
|
1045 | - * @return bool |
|
1046 | - */ |
|
1047 | - protected function validateDatabaseVars($submissionVars, $formVars) { |
|
1048 | - |
|
1049 | - foreach ($formVars as $field => $info) { |
|
1050 | - if ($info['required'] == true && !$submissionVars[$field]) { |
|
1051 | - $name = elgg_echo("install:database:label:$field"); |
|
1052 | - register_error(elgg_echo('install:error:requiredfield', [$name])); |
|
1053 | - return false; |
|
1054 | - } |
|
1055 | - } |
|
1056 | - |
|
1057 | - // check that data root is absolute path |
|
1058 | - if (stripos(PHP_OS, 'win') === 0) { |
|
1059 | - if (strpos($submissionVars['dataroot'], ':') !== 1) { |
|
1060 | - $msg = elgg_echo('install:error:relative_path', [$submissionVars['dataroot']]); |
|
1061 | - register_error($msg); |
|
1062 | - return false; |
|
1063 | - } |
|
1064 | - } else { |
|
1065 | - if (strpos($submissionVars['dataroot'], '/') !== 0) { |
|
1066 | - $msg = elgg_echo('install:error:relative_path', [$submissionVars['dataroot']]); |
|
1067 | - register_error($msg); |
|
1068 | - return false; |
|
1069 | - } |
|
1070 | - } |
|
1071 | - |
|
1072 | - // check that data root exists |
|
1073 | - if (!is_dir($submissionVars['dataroot'])) { |
|
1074 | - $msg = elgg_echo('install:error:datadirectoryexists', [$submissionVars['dataroot']]); |
|
1075 | - register_error($msg); |
|
1076 | - return false; |
|
1077 | - } |
|
1078 | - |
|
1079 | - // check that data root is writable |
|
1080 | - if (!is_writable($submissionVars['dataroot'])) { |
|
1081 | - $msg = elgg_echo('install:error:writedatadirectory', [$submissionVars['dataroot']]); |
|
1082 | - register_error($msg); |
|
1083 | - return false; |
|
1084 | - } |
|
1085 | - |
|
1086 | - if (!$this->config->data_dir_override) { |
|
1087 | - // check that data root is not subdirectory of Elgg root |
|
1088 | - if (stripos($submissionVars['dataroot'], $this->config->path) === 0) { |
|
1089 | - $msg = elgg_echo('install:error:locationdatadirectory', [$submissionVars['dataroot']]); |
|
1090 | - register_error($msg); |
|
1091 | - return false; |
|
1092 | - } |
|
1093 | - } |
|
1094 | - |
|
1095 | - // according to postgres documentation: SQL identifiers and key words must |
|
1096 | - // begin with a letter (a-z, but also letters with diacritical marks and |
|
1097 | - // non-Latin letters) or an underscore (_). Subsequent characters in an |
|
1098 | - // identifier or key word can be letters, underscores, digits (0-9), or dollar signs ($). |
|
1099 | - // Refs #4994 |
|
1100 | - if (!preg_match("/^[a-zA-Z_][\w]*$/", $submissionVars['dbprefix'])) { |
|
1101 | - register_error(elgg_echo('install:error:database_prefix')); |
|
1102 | - return false; |
|
1103 | - } |
|
1104 | - |
|
1105 | - return $this->checkDatabaseSettings( |
|
1106 | - $submissionVars['dbuser'], |
|
1107 | - $submissionVars['dbpassword'], |
|
1108 | - $submissionVars['dbname'], |
|
1109 | - $submissionVars['dbhost'] |
|
1110 | - ); |
|
1111 | - } |
|
1112 | - |
|
1113 | - /** |
|
1114 | - * Confirm the settings for the database |
|
1115 | - * |
|
1116 | - * @param string $user Username |
|
1117 | - * @param string $password Password |
|
1118 | - * @param string $dbname Database name |
|
1119 | - * @param string $host Host |
|
1120 | - * |
|
1121 | - * @return bool |
|
1122 | - */ |
|
1123 | - protected function checkDatabaseSettings($user, $password, $dbname, $host) { |
|
1124 | - $config = new DbConfig((object) [ |
|
1125 | - 'dbhost' => $host, |
|
1126 | - 'dbuser' => $user, |
|
1127 | - 'dbpass' => $password, |
|
1128 | - 'dbname' => $dbname, |
|
1129 | - 'dbencoding' => 'utf8mb4', |
|
1130 | - ]); |
|
1131 | - $db = new \Elgg\Database($config); |
|
1132 | - |
|
1133 | - try { |
|
1134 | - $db->getDataRow("SELECT 1"); |
|
1135 | - } catch (DatabaseException $e) { |
|
1136 | - if (0 === strpos($e->getMessage(), "Elgg couldn't connect")) { |
|
1137 | - register_error(elgg_echo('install:error:databasesettings')); |
|
1138 | - } else { |
|
1139 | - register_error(elgg_echo('install:error:nodatabase', [$dbname])); |
|
1140 | - } |
|
1141 | - return false; |
|
1142 | - } |
|
1143 | - |
|
1144 | - // check MySQL version |
|
1145 | - $version = $db->getServerVersion(DbConfig::READ_WRITE); |
|
1146 | - if (version_compare($version, '5.5.3', '<')) { |
|
1147 | - register_error(elgg_echo('install:error:oldmysql2', [$version])); |
|
1148 | - return false; |
|
1149 | - } |
|
1150 | - |
|
1151 | - return true; |
|
1152 | - } |
|
1153 | - |
|
1154 | - /** |
|
1155 | - * Writes the settings file to the engine directory |
|
1156 | - * |
|
1157 | - * @param array $params Array of inputted params from the user |
|
1158 | - * |
|
1159 | - * @return bool |
|
1160 | - */ |
|
1161 | - protected function createSettingsFile($params) { |
|
1162 | - $template = Application::elggDir()->getContents("elgg-config/settings.example.php"); |
|
1163 | - if (!$template) { |
|
1164 | - register_error(elgg_echo('install:error:readsettingsphp')); |
|
1165 | - return false; |
|
1166 | - } |
|
1167 | - |
|
1168 | - foreach ($params as $k => $v) { |
|
1169 | - $template = str_replace("{{" . $k . "}}", $v, $template); |
|
1170 | - } |
|
1171 | - |
|
1172 | - $result = file_put_contents(Paths::settingsFile(), $template); |
|
1173 | - if ($result === false) { |
|
1174 | - register_error(elgg_echo('install:error:writesettingphp')); |
|
1175 | - return false; |
|
1176 | - } |
|
1177 | - |
|
1178 | - return true; |
|
1179 | - } |
|
1180 | - |
|
1181 | - /** |
|
1182 | - * Bootstrap database connection before entire engine is available |
|
1183 | - * |
|
1184 | - * @return bool |
|
1185 | - */ |
|
1186 | - protected function connectToDatabase() { |
|
1187 | - try { |
|
1188 | - $this->services->db->setupConnections(); |
|
1189 | - } catch (DatabaseException $e) { |
|
1190 | - register_error($e->getMessage()); |
|
1191 | - return false; |
|
1192 | - } |
|
1193 | - |
|
1194 | - return true; |
|
1195 | - } |
|
1196 | - |
|
1197 | - /** |
|
1198 | - * Create the database tables |
|
1199 | - * |
|
1200 | - * @return bool |
|
1201 | - */ |
|
1202 | - protected function installDatabase() { |
|
1203 | - $ret = \Elgg\Application::migrate(); |
|
1204 | - if ($ret) { |
|
1205 | - init_site_secret(); |
|
1206 | - } |
|
1207 | - return $ret; |
|
1208 | - } |
|
1209 | - |
|
1210 | - /** |
|
1211 | - * Site settings support methods |
|
1212 | - */ |
|
1213 | - |
|
1214 | - /** |
|
1215 | - * Create the data directory if requested |
|
1216 | - * |
|
1217 | - * @param array $submissionVars Submitted vars |
|
1218 | - * @param array $formVars Variables in the form |
|
1219 | - * |
|
1220 | - * @return bool |
|
1221 | - */ |
|
1222 | - protected function createDataDirectory(&$submissionVars, $formVars) { |
|
1223 | - // did the user have option of Elgg creating the data directory |
|
1224 | - if ($formVars['dataroot']['type'] != 'combo') { |
|
1225 | - return true; |
|
1226 | - } |
|
1227 | - |
|
1228 | - // did the user select the option |
|
1229 | - if ($submissionVars['dataroot'] != 'dataroot-checkbox') { |
|
1230 | - return true; |
|
1231 | - } |
|
1232 | - |
|
1233 | - $dir = sanitise_filepath($submissionVars['path']) . 'data'; |
|
1234 | - if (file_exists($dir) || mkdir($dir, 0700)) { |
|
1235 | - $submissionVars['dataroot'] = $dir; |
|
1236 | - if (!file_exists("$dir/.htaccess")) { |
|
1237 | - $htaccess = "Order Deny,Allow\nDeny from All\n"; |
|
1238 | - if (!file_put_contents("$dir/.htaccess", $htaccess)) { |
|
1239 | - return false; |
|
1240 | - } |
|
1241 | - } |
|
1242 | - return true; |
|
1243 | - } |
|
1244 | - |
|
1245 | - return false; |
|
1246 | - } |
|
1247 | - |
|
1248 | - /** |
|
1249 | - * Validate the site settings form variables |
|
1250 | - * |
|
1251 | - * @param array $submissionVars Submitted vars |
|
1252 | - * @param array $formVars Vars in the form |
|
1253 | - * |
|
1254 | - * @return bool |
|
1255 | - */ |
|
1256 | - protected function validateSettingsVars($submissionVars, $formVars) { |
|
1257 | - foreach ($formVars as $field => $info) { |
|
1258 | - $submissionVars[$field] = trim($submissionVars[$field]); |
|
1259 | - if ($info['required'] == true && $submissionVars[$field] === '') { |
|
1260 | - $name = elgg_echo("install:settings:label:$field"); |
|
1261 | - register_error(elgg_echo('install:error:requiredfield', [$name])); |
|
1262 | - return false; |
|
1263 | - } |
|
1264 | - } |
|
1265 | - |
|
1266 | - // check that email address is email address |
|
1267 | - if ($submissionVars['siteemail'] && !is_email_address($submissionVars['siteemail'])) { |
|
1268 | - $msg = elgg_echo('install:error:emailaddress', [$submissionVars['siteemail']]); |
|
1269 | - register_error($msg); |
|
1270 | - return false; |
|
1271 | - } |
|
1272 | - |
|
1273 | - // @todo check that url is a url |
|
1274 | - // @note filter_var cannot be used because it doesn't work on international urls |
|
1275 | - |
|
1276 | - return true; |
|
1277 | - } |
|
1278 | - |
|
1279 | - /** |
|
1280 | - * Initialize the site including site entity, plugins, and configuration |
|
1281 | - * |
|
1282 | - * @param array $submissionVars Submitted vars |
|
1283 | - * |
|
1284 | - * @return bool |
|
1285 | - */ |
|
1286 | - protected function saveSiteSettings($submissionVars) { |
|
1287 | - $site = new ElggSite(); |
|
1288 | - $site->name = strip_tags($submissionVars['sitename']); |
|
1289 | - $site->access_id = ACCESS_PUBLIC; |
|
1290 | - $site->email = $submissionVars['siteemail']; |
|
1291 | - |
|
1292 | - $guid = $site->save(); |
|
1293 | - if ($guid !== 1) { |
|
1294 | - register_error(elgg_echo('install:error:createsite')); |
|
1295 | - return false; |
|
1296 | - } |
|
1297 | - |
|
1298 | - $this->config->site = $site; |
|
1299 | - |
|
1300 | - // new installations have run all the upgrades |
|
1301 | - $upgrades = elgg_get_upgrade_files(Paths::elgg() . "engine/lib/upgrades/"); |
|
1302 | - |
|
1303 | - $sets = [ |
|
1304 | - 'installed' => time(), |
|
1305 | - 'version' => elgg_get_version(), |
|
1306 | - 'simplecache_enabled' => 1, |
|
1307 | - 'system_cache_enabled' => 1, |
|
1308 | - 'simplecache_lastupdate' => time(), |
|
1309 | - 'processed_upgrades' => $upgrades, |
|
1310 | - 'language' => 'en', |
|
1311 | - 'default_access' => $submissionVars['siteaccess'], |
|
1312 | - 'allow_registration' => false, |
|
1313 | - 'walled_garden' => false, |
|
1314 | - 'allow_user_default_access' => '', |
|
1315 | - 'default_limit' => 10, |
|
1316 | - 'security_protect_upgrade' => true, |
|
1317 | - 'security_notify_admins' => true, |
|
1318 | - 'security_notify_user_password' => true, |
|
1319 | - 'security_email_require_password' => true, |
|
1320 | - ]; |
|
1321 | - foreach ($sets as $key => $value) { |
|
1322 | - elgg_save_config($key, $value); |
|
1323 | - } |
|
1324 | - |
|
1325 | - // Enable a set of default plugins |
|
1326 | - _elgg_generate_plugin_entities(); |
|
1327 | - |
|
1328 | - foreach (elgg_get_plugins('any') as $plugin) { |
|
1329 | - if ($plugin->getManifest()) { |
|
1330 | - if ($plugin->getManifest()->getActivateOnInstall()) { |
|
1331 | - $plugin->activate(); |
|
1332 | - } |
|
1333 | - if (in_array('theme', $plugin->getManifest()->getCategories())) { |
|
1334 | - $plugin->setPriority('last'); |
|
1335 | - } |
|
1336 | - } |
|
1337 | - } |
|
1338 | - |
|
1339 | - return true; |
|
1340 | - } |
|
1341 | - |
|
1342 | - /** |
|
1343 | - * Admin account support methods |
|
1344 | - */ |
|
1345 | - |
|
1346 | - /** |
|
1347 | - * Validate account form variables |
|
1348 | - * |
|
1349 | - * @param array $submissionVars Submitted vars |
|
1350 | - * @param array $formVars Form vars |
|
1351 | - * |
|
1352 | - * @return bool |
|
1353 | - */ |
|
1354 | - protected function validateAdminVars($submissionVars, $formVars) { |
|
1355 | - |
|
1356 | - foreach ($formVars as $field => $info) { |
|
1357 | - if ($info['required'] == true && !$submissionVars[$field]) { |
|
1358 | - $name = elgg_echo("install:admin:label:$field"); |
|
1359 | - register_error(elgg_echo('install:error:requiredfield', [$name])); |
|
1360 | - return false; |
|
1361 | - } |
|
1362 | - } |
|
1363 | - |
|
1364 | - if ($submissionVars['password1'] !== $submissionVars['password2']) { |
|
1365 | - register_error(elgg_echo('install:admin:password:mismatch')); |
|
1366 | - return false; |
|
1367 | - } |
|
1368 | - |
|
1369 | - if (trim($submissionVars['password1']) == "") { |
|
1370 | - register_error(elgg_echo('install:admin:password:empty')); |
|
1371 | - return false; |
|
1372 | - } |
|
1373 | - |
|
1374 | - $minLength = $this->services->configTable->get('min_password_length'); |
|
1375 | - if (strlen($submissionVars['password1']) < $minLength) { |
|
1376 | - register_error(elgg_echo('install:admin:password:tooshort')); |
|
1377 | - return false; |
|
1378 | - } |
|
1379 | - |
|
1380 | - // check that email address is email address |
|
1381 | - if ($submissionVars['email'] && !is_email_address($submissionVars['email'])) { |
|
1382 | - $msg = elgg_echo('install:error:emailaddress', [$submissionVars['email']]); |
|
1383 | - register_error($msg); |
|
1384 | - return false; |
|
1385 | - } |
|
1386 | - |
|
1387 | - return true; |
|
1388 | - } |
|
1389 | - |
|
1390 | - /** |
|
1391 | - * Create a user account for the admin |
|
1392 | - * |
|
1393 | - * @param array $submissionVars Submitted vars |
|
1394 | - * @param bool $login Login in the admin user? |
|
1395 | - * |
|
1396 | - * @return bool |
|
1397 | - */ |
|
1398 | - protected function createAdminAccount($submissionVars, $login = false) { |
|
1399 | - try { |
|
1400 | - $guid = register_user( |
|
1401 | - $submissionVars['username'], |
|
1402 | - $submissionVars['password1'], |
|
1403 | - $submissionVars['displayname'], |
|
1404 | - $submissionVars['email'] |
|
1405 | - ); |
|
1406 | - } catch (Exception $e) { |
|
1407 | - register_error($e->getMessage()); |
|
1408 | - return false; |
|
1409 | - } |
|
1410 | - |
|
1411 | - if (!$guid) { |
|
1412 | - register_error(elgg_echo('install:admin:cannot_create')); |
|
1413 | - return false; |
|
1414 | - } |
|
1415 | - |
|
1416 | - $user = get_entity($guid); |
|
1417 | - if (!$user instanceof ElggUser) { |
|
1418 | - register_error(elgg_echo('install:error:loadadmin')); |
|
1419 | - return false; |
|
1420 | - } |
|
1421 | - |
|
1422 | - $ia = elgg_set_ignore_access(true); |
|
1423 | - if ($user->makeAdmin() == false) { |
|
1424 | - register_error(elgg_echo('install:error:adminaccess')); |
|
1425 | - } else { |
|
1426 | - $this->services->configTable->set('admin_registered', 1); |
|
1427 | - } |
|
1428 | - elgg_set_ignore_access($ia); |
|
1429 | - |
|
1430 | - // add validation data to satisfy user validation plugins |
|
1431 | - $user->validated = 1; |
|
1432 | - $user->validated_method = 'admin_user'; |
|
1433 | - |
|
1434 | - if (!$login) { |
|
1435 | - return true; |
|
1436 | - } |
|
1437 | - |
|
1438 | - $session = ElggSession::fromDatabase($this->config, $this->services->db); |
|
1439 | - $session->start(); |
|
1440 | - $this->services->setValue('session', $session); |
|
1441 | - if (login($user) == false) { |
|
1442 | - register_error(elgg_echo('install:error:adminlogin')); |
|
1443 | - } |
|
1444 | - |
|
1445 | - return true; |
|
1446 | - } |
|
882 | + /** |
|
883 | + * Check version of PHP, extensions, and variables |
|
884 | + * |
|
885 | + * @param array $report The requirements report array |
|
886 | + * |
|
887 | + * @return void |
|
888 | + */ |
|
889 | + protected function checkPHP(&$report) { |
|
890 | + $phpReport = []; |
|
891 | + |
|
892 | + $min_php_version = '5.6.0'; |
|
893 | + if (version_compare(PHP_VERSION, $min_php_version, '<')) { |
|
894 | + $phpReport[] = [ |
|
895 | + 'severity' => 'failure', |
|
896 | + 'message' => elgg_echo('install:check:php:version', [$min_php_version, PHP_VERSION]) |
|
897 | + ]; |
|
898 | + } |
|
899 | + |
|
900 | + $this->checkPhpExtensions($phpReport); |
|
901 | + |
|
902 | + $this->checkPhpDirectives($phpReport); |
|
903 | + |
|
904 | + if (count($phpReport) == 0) { |
|
905 | + $phpReport[] = [ |
|
906 | + 'severity' => 'pass', |
|
907 | + 'message' => elgg_echo('install:check:php:success') |
|
908 | + ]; |
|
909 | + } |
|
910 | + |
|
911 | + $report['php'] = $phpReport; |
|
912 | + } |
|
913 | + |
|
914 | + /** |
|
915 | + * Check the server's PHP extensions |
|
916 | + * |
|
917 | + * @param array $phpReport The PHP requirements report array |
|
918 | + * |
|
919 | + * @return void |
|
920 | + */ |
|
921 | + protected function checkPhpExtensions(&$phpReport) { |
|
922 | + $extensions = get_loaded_extensions(); |
|
923 | + $requiredExtensions = [ |
|
924 | + 'pdo_mysql', |
|
925 | + 'json', |
|
926 | + 'xml', |
|
927 | + 'gd', |
|
928 | + ]; |
|
929 | + foreach ($requiredExtensions as $extension) { |
|
930 | + if (!in_array($extension, $extensions)) { |
|
931 | + $phpReport[] = [ |
|
932 | + 'severity' => 'failure', |
|
933 | + 'message' => elgg_echo('install:check:php:extension', [$extension]) |
|
934 | + ]; |
|
935 | + } |
|
936 | + } |
|
937 | + |
|
938 | + $recommendedExtensions = [ |
|
939 | + 'mbstring', |
|
940 | + ]; |
|
941 | + foreach ($recommendedExtensions as $extension) { |
|
942 | + if (!in_array($extension, $extensions)) { |
|
943 | + $phpReport[] = [ |
|
944 | + 'severity' => 'warning', |
|
945 | + 'message' => elgg_echo('install:check:php:extension:recommend', [$extension]) |
|
946 | + ]; |
|
947 | + } |
|
948 | + } |
|
949 | + } |
|
950 | + |
|
951 | + /** |
|
952 | + * Check PHP parameters |
|
953 | + * |
|
954 | + * @param array $phpReport The PHP requirements report array |
|
955 | + * |
|
956 | + * @return void |
|
957 | + */ |
|
958 | + protected function checkPhpDirectives(&$phpReport) { |
|
959 | + if (ini_get('open_basedir')) { |
|
960 | + $phpReport[] = [ |
|
961 | + 'severity' => 'warning', |
|
962 | + 'message' => elgg_echo("install:check:php:open_basedir") |
|
963 | + ]; |
|
964 | + } |
|
965 | + |
|
966 | + if (ini_get('safe_mode')) { |
|
967 | + $phpReport[] = [ |
|
968 | + 'severity' => 'warning', |
|
969 | + 'message' => elgg_echo("install:check:php:safe_mode") |
|
970 | + ]; |
|
971 | + } |
|
972 | + |
|
973 | + if (ini_get('arg_separator.output') !== '&') { |
|
974 | + $separator = htmlspecialchars(ini_get('arg_separator.output')); |
|
975 | + $msg = elgg_echo("install:check:php:arg_separator", [$separator]); |
|
976 | + $phpReport[] = [ |
|
977 | + 'severity' => 'failure', |
|
978 | + 'message' => $msg, |
|
979 | + ]; |
|
980 | + } |
|
981 | + |
|
982 | + if (ini_get('register_globals')) { |
|
983 | + $phpReport[] = [ |
|
984 | + 'severity' => 'failure', |
|
985 | + 'message' => elgg_echo("install:check:php:register_globals") |
|
986 | + ]; |
|
987 | + } |
|
988 | + |
|
989 | + if (ini_get('session.auto_start')) { |
|
990 | + $phpReport[] = [ |
|
991 | + 'severity' => 'failure', |
|
992 | + 'message' => elgg_echo("install:check:php:session.auto_start") |
|
993 | + ]; |
|
994 | + } |
|
995 | + } |
|
996 | + |
|
997 | + /** |
|
998 | + * Confirm that the rewrite rules are firing |
|
999 | + * |
|
1000 | + * @param array $report The requirements report array |
|
1001 | + * |
|
1002 | + * @return void |
|
1003 | + */ |
|
1004 | + protected function checkRewriteRules(&$report) { |
|
1005 | + $tester = new ElggRewriteTester(); |
|
1006 | + $url = $this->config->wwwroot; |
|
1007 | + $url .= Request::REWRITE_TEST_TOKEN . '?' . http_build_query([ |
|
1008 | + Request::REWRITE_TEST_TOKEN => '1', |
|
1009 | + ]); |
|
1010 | + $report['rewrite'] = [$tester->run($url, Paths::project())]; |
|
1011 | + } |
|
1012 | + |
|
1013 | + /** |
|
1014 | + * Count the number of failures in the requirements report |
|
1015 | + * |
|
1016 | + * @param array $report The requirements report array |
|
1017 | + * @param string $condition 'failure' or 'warning' |
|
1018 | + * |
|
1019 | + * @return int |
|
1020 | + */ |
|
1021 | + protected function countNumConditions($report, $condition) { |
|
1022 | + $count = 0; |
|
1023 | + foreach ($report as $category => $checks) { |
|
1024 | + foreach ($checks as $check) { |
|
1025 | + if ($check['severity'] === $condition) { |
|
1026 | + $count++; |
|
1027 | + } |
|
1028 | + } |
|
1029 | + } |
|
1030 | + |
|
1031 | + return $count; |
|
1032 | + } |
|
1033 | + |
|
1034 | + |
|
1035 | + /** |
|
1036 | + * Database support methods |
|
1037 | + */ |
|
1038 | + |
|
1039 | + /** |
|
1040 | + * Validate the variables for the database step |
|
1041 | + * |
|
1042 | + * @param array $submissionVars Submitted vars |
|
1043 | + * @param array $formVars Vars in the form |
|
1044 | + * |
|
1045 | + * @return bool |
|
1046 | + */ |
|
1047 | + protected function validateDatabaseVars($submissionVars, $formVars) { |
|
1048 | + |
|
1049 | + foreach ($formVars as $field => $info) { |
|
1050 | + if ($info['required'] == true && !$submissionVars[$field]) { |
|
1051 | + $name = elgg_echo("install:database:label:$field"); |
|
1052 | + register_error(elgg_echo('install:error:requiredfield', [$name])); |
|
1053 | + return false; |
|
1054 | + } |
|
1055 | + } |
|
1056 | + |
|
1057 | + // check that data root is absolute path |
|
1058 | + if (stripos(PHP_OS, 'win') === 0) { |
|
1059 | + if (strpos($submissionVars['dataroot'], ':') !== 1) { |
|
1060 | + $msg = elgg_echo('install:error:relative_path', [$submissionVars['dataroot']]); |
|
1061 | + register_error($msg); |
|
1062 | + return false; |
|
1063 | + } |
|
1064 | + } else { |
|
1065 | + if (strpos($submissionVars['dataroot'], '/') !== 0) { |
|
1066 | + $msg = elgg_echo('install:error:relative_path', [$submissionVars['dataroot']]); |
|
1067 | + register_error($msg); |
|
1068 | + return false; |
|
1069 | + } |
|
1070 | + } |
|
1071 | + |
|
1072 | + // check that data root exists |
|
1073 | + if (!is_dir($submissionVars['dataroot'])) { |
|
1074 | + $msg = elgg_echo('install:error:datadirectoryexists', [$submissionVars['dataroot']]); |
|
1075 | + register_error($msg); |
|
1076 | + return false; |
|
1077 | + } |
|
1078 | + |
|
1079 | + // check that data root is writable |
|
1080 | + if (!is_writable($submissionVars['dataroot'])) { |
|
1081 | + $msg = elgg_echo('install:error:writedatadirectory', [$submissionVars['dataroot']]); |
|
1082 | + register_error($msg); |
|
1083 | + return false; |
|
1084 | + } |
|
1085 | + |
|
1086 | + if (!$this->config->data_dir_override) { |
|
1087 | + // check that data root is not subdirectory of Elgg root |
|
1088 | + if (stripos($submissionVars['dataroot'], $this->config->path) === 0) { |
|
1089 | + $msg = elgg_echo('install:error:locationdatadirectory', [$submissionVars['dataroot']]); |
|
1090 | + register_error($msg); |
|
1091 | + return false; |
|
1092 | + } |
|
1093 | + } |
|
1094 | + |
|
1095 | + // according to postgres documentation: SQL identifiers and key words must |
|
1096 | + // begin with a letter (a-z, but also letters with diacritical marks and |
|
1097 | + // non-Latin letters) or an underscore (_). Subsequent characters in an |
|
1098 | + // identifier or key word can be letters, underscores, digits (0-9), or dollar signs ($). |
|
1099 | + // Refs #4994 |
|
1100 | + if (!preg_match("/^[a-zA-Z_][\w]*$/", $submissionVars['dbprefix'])) { |
|
1101 | + register_error(elgg_echo('install:error:database_prefix')); |
|
1102 | + return false; |
|
1103 | + } |
|
1104 | + |
|
1105 | + return $this->checkDatabaseSettings( |
|
1106 | + $submissionVars['dbuser'], |
|
1107 | + $submissionVars['dbpassword'], |
|
1108 | + $submissionVars['dbname'], |
|
1109 | + $submissionVars['dbhost'] |
|
1110 | + ); |
|
1111 | + } |
|
1112 | + |
|
1113 | + /** |
|
1114 | + * Confirm the settings for the database |
|
1115 | + * |
|
1116 | + * @param string $user Username |
|
1117 | + * @param string $password Password |
|
1118 | + * @param string $dbname Database name |
|
1119 | + * @param string $host Host |
|
1120 | + * |
|
1121 | + * @return bool |
|
1122 | + */ |
|
1123 | + protected function checkDatabaseSettings($user, $password, $dbname, $host) { |
|
1124 | + $config = new DbConfig((object) [ |
|
1125 | + 'dbhost' => $host, |
|
1126 | + 'dbuser' => $user, |
|
1127 | + 'dbpass' => $password, |
|
1128 | + 'dbname' => $dbname, |
|
1129 | + 'dbencoding' => 'utf8mb4', |
|
1130 | + ]); |
|
1131 | + $db = new \Elgg\Database($config); |
|
1132 | + |
|
1133 | + try { |
|
1134 | + $db->getDataRow("SELECT 1"); |
|
1135 | + } catch (DatabaseException $e) { |
|
1136 | + if (0 === strpos($e->getMessage(), "Elgg couldn't connect")) { |
|
1137 | + register_error(elgg_echo('install:error:databasesettings')); |
|
1138 | + } else { |
|
1139 | + register_error(elgg_echo('install:error:nodatabase', [$dbname])); |
|
1140 | + } |
|
1141 | + return false; |
|
1142 | + } |
|
1143 | + |
|
1144 | + // check MySQL version |
|
1145 | + $version = $db->getServerVersion(DbConfig::READ_WRITE); |
|
1146 | + if (version_compare($version, '5.5.3', '<')) { |
|
1147 | + register_error(elgg_echo('install:error:oldmysql2', [$version])); |
|
1148 | + return false; |
|
1149 | + } |
|
1150 | + |
|
1151 | + return true; |
|
1152 | + } |
|
1153 | + |
|
1154 | + /** |
|
1155 | + * Writes the settings file to the engine directory |
|
1156 | + * |
|
1157 | + * @param array $params Array of inputted params from the user |
|
1158 | + * |
|
1159 | + * @return bool |
|
1160 | + */ |
|
1161 | + protected function createSettingsFile($params) { |
|
1162 | + $template = Application::elggDir()->getContents("elgg-config/settings.example.php"); |
|
1163 | + if (!$template) { |
|
1164 | + register_error(elgg_echo('install:error:readsettingsphp')); |
|
1165 | + return false; |
|
1166 | + } |
|
1167 | + |
|
1168 | + foreach ($params as $k => $v) { |
|
1169 | + $template = str_replace("{{" . $k . "}}", $v, $template); |
|
1170 | + } |
|
1171 | + |
|
1172 | + $result = file_put_contents(Paths::settingsFile(), $template); |
|
1173 | + if ($result === false) { |
|
1174 | + register_error(elgg_echo('install:error:writesettingphp')); |
|
1175 | + return false; |
|
1176 | + } |
|
1177 | + |
|
1178 | + return true; |
|
1179 | + } |
|
1180 | + |
|
1181 | + /** |
|
1182 | + * Bootstrap database connection before entire engine is available |
|
1183 | + * |
|
1184 | + * @return bool |
|
1185 | + */ |
|
1186 | + protected function connectToDatabase() { |
|
1187 | + try { |
|
1188 | + $this->services->db->setupConnections(); |
|
1189 | + } catch (DatabaseException $e) { |
|
1190 | + register_error($e->getMessage()); |
|
1191 | + return false; |
|
1192 | + } |
|
1193 | + |
|
1194 | + return true; |
|
1195 | + } |
|
1196 | + |
|
1197 | + /** |
|
1198 | + * Create the database tables |
|
1199 | + * |
|
1200 | + * @return bool |
|
1201 | + */ |
|
1202 | + protected function installDatabase() { |
|
1203 | + $ret = \Elgg\Application::migrate(); |
|
1204 | + if ($ret) { |
|
1205 | + init_site_secret(); |
|
1206 | + } |
|
1207 | + return $ret; |
|
1208 | + } |
|
1209 | + |
|
1210 | + /** |
|
1211 | + * Site settings support methods |
|
1212 | + */ |
|
1213 | + |
|
1214 | + /** |
|
1215 | + * Create the data directory if requested |
|
1216 | + * |
|
1217 | + * @param array $submissionVars Submitted vars |
|
1218 | + * @param array $formVars Variables in the form |
|
1219 | + * |
|
1220 | + * @return bool |
|
1221 | + */ |
|
1222 | + protected function createDataDirectory(&$submissionVars, $formVars) { |
|
1223 | + // did the user have option of Elgg creating the data directory |
|
1224 | + if ($formVars['dataroot']['type'] != 'combo') { |
|
1225 | + return true; |
|
1226 | + } |
|
1227 | + |
|
1228 | + // did the user select the option |
|
1229 | + if ($submissionVars['dataroot'] != 'dataroot-checkbox') { |
|
1230 | + return true; |
|
1231 | + } |
|
1232 | + |
|
1233 | + $dir = sanitise_filepath($submissionVars['path']) . 'data'; |
|
1234 | + if (file_exists($dir) || mkdir($dir, 0700)) { |
|
1235 | + $submissionVars['dataroot'] = $dir; |
|
1236 | + if (!file_exists("$dir/.htaccess")) { |
|
1237 | + $htaccess = "Order Deny,Allow\nDeny from All\n"; |
|
1238 | + if (!file_put_contents("$dir/.htaccess", $htaccess)) { |
|
1239 | + return false; |
|
1240 | + } |
|
1241 | + } |
|
1242 | + return true; |
|
1243 | + } |
|
1244 | + |
|
1245 | + return false; |
|
1246 | + } |
|
1247 | + |
|
1248 | + /** |
|
1249 | + * Validate the site settings form variables |
|
1250 | + * |
|
1251 | + * @param array $submissionVars Submitted vars |
|
1252 | + * @param array $formVars Vars in the form |
|
1253 | + * |
|
1254 | + * @return bool |
|
1255 | + */ |
|
1256 | + protected function validateSettingsVars($submissionVars, $formVars) { |
|
1257 | + foreach ($formVars as $field => $info) { |
|
1258 | + $submissionVars[$field] = trim($submissionVars[$field]); |
|
1259 | + if ($info['required'] == true && $submissionVars[$field] === '') { |
|
1260 | + $name = elgg_echo("install:settings:label:$field"); |
|
1261 | + register_error(elgg_echo('install:error:requiredfield', [$name])); |
|
1262 | + return false; |
|
1263 | + } |
|
1264 | + } |
|
1265 | + |
|
1266 | + // check that email address is email address |
|
1267 | + if ($submissionVars['siteemail'] && !is_email_address($submissionVars['siteemail'])) { |
|
1268 | + $msg = elgg_echo('install:error:emailaddress', [$submissionVars['siteemail']]); |
|
1269 | + register_error($msg); |
|
1270 | + return false; |
|
1271 | + } |
|
1272 | + |
|
1273 | + // @todo check that url is a url |
|
1274 | + // @note filter_var cannot be used because it doesn't work on international urls |
|
1275 | + |
|
1276 | + return true; |
|
1277 | + } |
|
1278 | + |
|
1279 | + /** |
|
1280 | + * Initialize the site including site entity, plugins, and configuration |
|
1281 | + * |
|
1282 | + * @param array $submissionVars Submitted vars |
|
1283 | + * |
|
1284 | + * @return bool |
|
1285 | + */ |
|
1286 | + protected function saveSiteSettings($submissionVars) { |
|
1287 | + $site = new ElggSite(); |
|
1288 | + $site->name = strip_tags($submissionVars['sitename']); |
|
1289 | + $site->access_id = ACCESS_PUBLIC; |
|
1290 | + $site->email = $submissionVars['siteemail']; |
|
1291 | + |
|
1292 | + $guid = $site->save(); |
|
1293 | + if ($guid !== 1) { |
|
1294 | + register_error(elgg_echo('install:error:createsite')); |
|
1295 | + return false; |
|
1296 | + } |
|
1297 | + |
|
1298 | + $this->config->site = $site; |
|
1299 | + |
|
1300 | + // new installations have run all the upgrades |
|
1301 | + $upgrades = elgg_get_upgrade_files(Paths::elgg() . "engine/lib/upgrades/"); |
|
1302 | + |
|
1303 | + $sets = [ |
|
1304 | + 'installed' => time(), |
|
1305 | + 'version' => elgg_get_version(), |
|
1306 | + 'simplecache_enabled' => 1, |
|
1307 | + 'system_cache_enabled' => 1, |
|
1308 | + 'simplecache_lastupdate' => time(), |
|
1309 | + 'processed_upgrades' => $upgrades, |
|
1310 | + 'language' => 'en', |
|
1311 | + 'default_access' => $submissionVars['siteaccess'], |
|
1312 | + 'allow_registration' => false, |
|
1313 | + 'walled_garden' => false, |
|
1314 | + 'allow_user_default_access' => '', |
|
1315 | + 'default_limit' => 10, |
|
1316 | + 'security_protect_upgrade' => true, |
|
1317 | + 'security_notify_admins' => true, |
|
1318 | + 'security_notify_user_password' => true, |
|
1319 | + 'security_email_require_password' => true, |
|
1320 | + ]; |
|
1321 | + foreach ($sets as $key => $value) { |
|
1322 | + elgg_save_config($key, $value); |
|
1323 | + } |
|
1324 | + |
|
1325 | + // Enable a set of default plugins |
|
1326 | + _elgg_generate_plugin_entities(); |
|
1327 | + |
|
1328 | + foreach (elgg_get_plugins('any') as $plugin) { |
|
1329 | + if ($plugin->getManifest()) { |
|
1330 | + if ($plugin->getManifest()->getActivateOnInstall()) { |
|
1331 | + $plugin->activate(); |
|
1332 | + } |
|
1333 | + if (in_array('theme', $plugin->getManifest()->getCategories())) { |
|
1334 | + $plugin->setPriority('last'); |
|
1335 | + } |
|
1336 | + } |
|
1337 | + } |
|
1338 | + |
|
1339 | + return true; |
|
1340 | + } |
|
1341 | + |
|
1342 | + /** |
|
1343 | + * Admin account support methods |
|
1344 | + */ |
|
1345 | + |
|
1346 | + /** |
|
1347 | + * Validate account form variables |
|
1348 | + * |
|
1349 | + * @param array $submissionVars Submitted vars |
|
1350 | + * @param array $formVars Form vars |
|
1351 | + * |
|
1352 | + * @return bool |
|
1353 | + */ |
|
1354 | + protected function validateAdminVars($submissionVars, $formVars) { |
|
1355 | + |
|
1356 | + foreach ($formVars as $field => $info) { |
|
1357 | + if ($info['required'] == true && !$submissionVars[$field]) { |
|
1358 | + $name = elgg_echo("install:admin:label:$field"); |
|
1359 | + register_error(elgg_echo('install:error:requiredfield', [$name])); |
|
1360 | + return false; |
|
1361 | + } |
|
1362 | + } |
|
1363 | + |
|
1364 | + if ($submissionVars['password1'] !== $submissionVars['password2']) { |
|
1365 | + register_error(elgg_echo('install:admin:password:mismatch')); |
|
1366 | + return false; |
|
1367 | + } |
|
1368 | + |
|
1369 | + if (trim($submissionVars['password1']) == "") { |
|
1370 | + register_error(elgg_echo('install:admin:password:empty')); |
|
1371 | + return false; |
|
1372 | + } |
|
1373 | + |
|
1374 | + $minLength = $this->services->configTable->get('min_password_length'); |
|
1375 | + if (strlen($submissionVars['password1']) < $minLength) { |
|
1376 | + register_error(elgg_echo('install:admin:password:tooshort')); |
|
1377 | + return false; |
|
1378 | + } |
|
1379 | + |
|
1380 | + // check that email address is email address |
|
1381 | + if ($submissionVars['email'] && !is_email_address($submissionVars['email'])) { |
|
1382 | + $msg = elgg_echo('install:error:emailaddress', [$submissionVars['email']]); |
|
1383 | + register_error($msg); |
|
1384 | + return false; |
|
1385 | + } |
|
1386 | + |
|
1387 | + return true; |
|
1388 | + } |
|
1389 | + |
|
1390 | + /** |
|
1391 | + * Create a user account for the admin |
|
1392 | + * |
|
1393 | + * @param array $submissionVars Submitted vars |
|
1394 | + * @param bool $login Login in the admin user? |
|
1395 | + * |
|
1396 | + * @return bool |
|
1397 | + */ |
|
1398 | + protected function createAdminAccount($submissionVars, $login = false) { |
|
1399 | + try { |
|
1400 | + $guid = register_user( |
|
1401 | + $submissionVars['username'], |
|
1402 | + $submissionVars['password1'], |
|
1403 | + $submissionVars['displayname'], |
|
1404 | + $submissionVars['email'] |
|
1405 | + ); |
|
1406 | + } catch (Exception $e) { |
|
1407 | + register_error($e->getMessage()); |
|
1408 | + return false; |
|
1409 | + } |
|
1410 | + |
|
1411 | + if (!$guid) { |
|
1412 | + register_error(elgg_echo('install:admin:cannot_create')); |
|
1413 | + return false; |
|
1414 | + } |
|
1415 | + |
|
1416 | + $user = get_entity($guid); |
|
1417 | + if (!$user instanceof ElggUser) { |
|
1418 | + register_error(elgg_echo('install:error:loadadmin')); |
|
1419 | + return false; |
|
1420 | + } |
|
1421 | + |
|
1422 | + $ia = elgg_set_ignore_access(true); |
|
1423 | + if ($user->makeAdmin() == false) { |
|
1424 | + register_error(elgg_echo('install:error:adminaccess')); |
|
1425 | + } else { |
|
1426 | + $this->services->configTable->set('admin_registered', 1); |
|
1427 | + } |
|
1428 | + elgg_set_ignore_access($ia); |
|
1429 | + |
|
1430 | + // add validation data to satisfy user validation plugins |
|
1431 | + $user->validated = 1; |
|
1432 | + $user->validated_method = 'admin_user'; |
|
1433 | + |
|
1434 | + if (!$login) { |
|
1435 | + return true; |
|
1436 | + } |
|
1437 | + |
|
1438 | + $session = ElggSession::fromDatabase($this->config, $this->services->db); |
|
1439 | + $session->start(); |
|
1440 | + $this->services->setValue('session', $session); |
|
1441 | + if (login($user) == false) { |
|
1442 | + register_error(elgg_echo('install:error:adminlogin')); |
|
1443 | + } |
|
1444 | + |
|
1445 | + return true; |
|
1446 | + } |
|
1447 | 1447 | } |
@@ -76,9 +76,9 @@ |
||
76 | 76 | $version = elgg_get_version(true); |
77 | 77 | |
78 | 78 | $this->write("Elgg $version install successful"); |
79 | - $this->write("wwwroot: " . elgg_get_config('wwwroot')); |
|
80 | - $this->write("dataroot: " . elgg_get_config('dataroot')); |
|
81 | - $this->write("cacheroot: " . elgg_get_config('cacheroot')); |
|
79 | + $this->write("wwwroot: ".elgg_get_config('wwwroot')); |
|
80 | + $this->write("dataroot: ".elgg_get_config('dataroot')); |
|
81 | + $this->write("cacheroot: ".elgg_get_config('cacheroot')); |
|
82 | 82 | |
83 | 83 | } |
84 | 84 |
@@ -12,75 +12,75 @@ |
||
12 | 12 | */ |
13 | 13 | class InstallCommand extends \Symfony\Component\Console\Command\Command { |
14 | 14 | |
15 | - use ConsoleInteractions; |
|
15 | + use ConsoleInteractions; |
|
16 | 16 | |
17 | - /** |
|
18 | - * {@inheritdoc} |
|
19 | - */ |
|
20 | - protected function configure() { |
|
21 | - $this->setName('install') |
|
22 | - ->setDescription('Install Elgg using a configuration file or interactive questions') |
|
23 | - ->addOption('config', 'c', InputOption::VALUE_OPTIONAL, 'Path to php file that returns an array with installation configuration'); |
|
24 | - } |
|
17 | + /** |
|
18 | + * {@inheritdoc} |
|
19 | + */ |
|
20 | + protected function configure() { |
|
21 | + $this->setName('install') |
|
22 | + ->setDescription('Install Elgg using a configuration file or interactive questions') |
|
23 | + ->addOption('config', 'c', InputOption::VALUE_OPTIONAL, 'Path to php file that returns an array with installation configuration'); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * {@inheritdoc} |
|
28 | - */ |
|
29 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
26 | + /** |
|
27 | + * {@inheritdoc} |
|
28 | + */ |
|
29 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
30 | 30 | |
31 | - $this->input = $input; |
|
32 | - $this->output = $output; |
|
31 | + $this->input = $input; |
|
32 | + $this->output = $output; |
|
33 | 33 | |
34 | - $config = $this->option('config'); |
|
35 | - if ($config && file_exists(realpath($config))) { |
|
36 | - $params = include $config; |
|
37 | - } else { |
|
38 | - $params = [ |
|
39 | - /** |
|
40 | - * Admin account |
|
41 | - */ |
|
42 | - 'displayname' => 'Administrator', |
|
43 | - 'username' => $this->ask('Enter admin username: ', 'admin'), |
|
44 | - 'password' => $this->ask('Enter admin password: ', null, true), |
|
45 | - 'email' => $email = $this->ask('Enter admin email: '), |
|
46 | - /** |
|
47 | - * Database parameters |
|
48 | - */ |
|
49 | - 'dbuser' => $this->ask('Enter database username: '), |
|
50 | - 'dbpassword' => $this->ask('Enter database password: ', null, true), |
|
51 | - 'dbname' => $this->ask('Enter database name: '), |
|
52 | - 'dbprefix' => $this->ask('Enter database prefix [elgg_]: ', 'elgg_'), |
|
53 | - /** |
|
54 | - * Site settings |
|
55 | - */ |
|
56 | - 'sitename' => $this->ask('Enter site name: '), |
|
57 | - 'siteemail' => $this->ask("Enter site email [$email]: ", $email), |
|
58 | - 'wwwroot' => $this->ask('Enter site URL: '), |
|
59 | - 'dataroot' => $this->ask('Enter data directory path: '), |
|
60 | - 'timezone' => 'UTC' |
|
61 | - ]; |
|
62 | - } |
|
34 | + $config = $this->option('config'); |
|
35 | + if ($config && file_exists(realpath($config))) { |
|
36 | + $params = include $config; |
|
37 | + } else { |
|
38 | + $params = [ |
|
39 | + /** |
|
40 | + * Admin account |
|
41 | + */ |
|
42 | + 'displayname' => 'Administrator', |
|
43 | + 'username' => $this->ask('Enter admin username: ', 'admin'), |
|
44 | + 'password' => $this->ask('Enter admin password: ', null, true), |
|
45 | + 'email' => $email = $this->ask('Enter admin email: '), |
|
46 | + /** |
|
47 | + * Database parameters |
|
48 | + */ |
|
49 | + 'dbuser' => $this->ask('Enter database username: '), |
|
50 | + 'dbpassword' => $this->ask('Enter database password: ', null, true), |
|
51 | + 'dbname' => $this->ask('Enter database name: '), |
|
52 | + 'dbprefix' => $this->ask('Enter database prefix [elgg_]: ', 'elgg_'), |
|
53 | + /** |
|
54 | + * Site settings |
|
55 | + */ |
|
56 | + 'sitename' => $this->ask('Enter site name: '), |
|
57 | + 'siteemail' => $this->ask("Enter site email [$email]: ", $email), |
|
58 | + 'wwwroot' => $this->ask('Enter site URL: '), |
|
59 | + 'dataroot' => $this->ask('Enter data directory path: '), |
|
60 | + 'timezone' => 'UTC' |
|
61 | + ]; |
|
62 | + } |
|
63 | 63 | |
64 | - try { |
|
65 | - $installer = new ElggInstaller(); |
|
66 | - $htaccess = !is_file(\Elgg\Application::projectDir()->getPath('.htaccess')); |
|
67 | - $installer->batchInstall($params, $htaccess); |
|
68 | - } catch (\InstallationException $ex) { |
|
69 | - $this->dumpRegisters(); |
|
70 | - $this->write(elgg_format_element('error', [], $ex->getMessage())); |
|
64 | + try { |
|
65 | + $installer = new ElggInstaller(); |
|
66 | + $htaccess = !is_file(\Elgg\Application::projectDir()->getPath('.htaccess')); |
|
67 | + $installer->batchInstall($params, $htaccess); |
|
68 | + } catch (\InstallationException $ex) { |
|
69 | + $this->dumpRegisters(); |
|
70 | + $this->write(elgg_format_element('error', [], $ex->getMessage())); |
|
71 | 71 | |
72 | - return 1; |
|
73 | - } |
|
72 | + return 1; |
|
73 | + } |
|
74 | 74 | |
75 | - \Elgg\Application::start(); |
|
75 | + \Elgg\Application::start(); |
|
76 | 76 | |
77 | - $version = elgg_get_version(true); |
|
77 | + $version = elgg_get_version(true); |
|
78 | 78 | |
79 | - $this->write("Elgg $version install successful"); |
|
80 | - $this->write("wwwroot: " . elgg_get_config('wwwroot')); |
|
81 | - $this->write("dataroot: " . elgg_get_config('dataroot')); |
|
82 | - $this->write("cacheroot: " . elgg_get_config('cacheroot')); |
|
79 | + $this->write("Elgg $version install successful"); |
|
80 | + $this->write("wwwroot: " . elgg_get_config('wwwroot')); |
|
81 | + $this->write("dataroot: " . elgg_get_config('dataroot')); |
|
82 | + $this->write("cacheroot: " . elgg_get_config('cacheroot')); |
|
83 | 83 | |
84 | - } |
|
84 | + } |
|
85 | 85 | |
86 | 86 | } |
@@ -10,47 +10,47 @@ |
||
10 | 10 | */ |
11 | 11 | class Cli { |
12 | 12 | |
13 | - /** |
|
14 | - * @var ConsoleApplication |
|
15 | - */ |
|
16 | - protected $console; |
|
17 | - |
|
18 | - /** |
|
19 | - * @var HooksRegistrationService |
|
20 | - */ |
|
21 | - protected $hooks; |
|
22 | - |
|
23 | - /** |
|
24 | - * Constructor |
|
25 | - * |
|
26 | - * @param ConsoleApplication $console Console application instance |
|
27 | - * @param HooksRegistrationService $hooks Hooks registration service |
|
28 | - */ |
|
29 | - public function __construct(ConsoleApplication $console, HooksRegistrationService $hooks) { |
|
30 | - $this->console = $console; |
|
31 | - $this->hooks = $hooks; |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * Add CLI tools to the console application |
|
36 | - * @return void |
|
37 | - */ |
|
38 | - protected function bootstrap() { |
|
39 | - $commands = $this->hooks->trigger('commands', 'cli', null, []); |
|
40 | - foreach ($commands as $command) { |
|
41 | - if (class_exists($command) && is_subclass_of($command, Command::class)) { |
|
42 | - $this->console->add(new $command()); |
|
43 | - } |
|
44 | - } |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Bootstrap and run console application |
|
49 | - * @return void |
|
50 | - */ |
|
51 | - public function run() { |
|
52 | - $this->bootstrap(); |
|
53 | - $this->console->run(); |
|
54 | - } |
|
13 | + /** |
|
14 | + * @var ConsoleApplication |
|
15 | + */ |
|
16 | + protected $console; |
|
17 | + |
|
18 | + /** |
|
19 | + * @var HooksRegistrationService |
|
20 | + */ |
|
21 | + protected $hooks; |
|
22 | + |
|
23 | + /** |
|
24 | + * Constructor |
|
25 | + * |
|
26 | + * @param ConsoleApplication $console Console application instance |
|
27 | + * @param HooksRegistrationService $hooks Hooks registration service |
|
28 | + */ |
|
29 | + public function __construct(ConsoleApplication $console, HooksRegistrationService $hooks) { |
|
30 | + $this->console = $console; |
|
31 | + $this->hooks = $hooks; |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * Add CLI tools to the console application |
|
36 | + * @return void |
|
37 | + */ |
|
38 | + protected function bootstrap() { |
|
39 | + $commands = $this->hooks->trigger('commands', 'cli', null, []); |
|
40 | + foreach ($commands as $command) { |
|
41 | + if (class_exists($command) && is_subclass_of($command, Command::class)) { |
|
42 | + $this->console->add(new $command()); |
|
43 | + } |
|
44 | + } |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Bootstrap and run console application |
|
49 | + * @return void |
|
50 | + */ |
|
51 | + public function run() { |
|
52 | + $this->bootstrap(); |
|
53 | + $this->console->run(); |
|
54 | + } |
|
55 | 55 | |
56 | 56 | } |
@@ -9,110 +9,110 @@ |
||
9 | 9 | |
10 | 10 | trait ConsoleInteractions { |
11 | 11 | |
12 | - /** |
|
13 | - * @var InputInterface |
|
14 | - */ |
|
15 | - protected $input; |
|
16 | - |
|
17 | - /** |
|
18 | - * @var OutputInterface |
|
19 | - */ |
|
20 | - protected $output; |
|
21 | - |
|
22 | - /** |
|
23 | - * Ask a question |
|
24 | - * |
|
25 | - * @param string $question Question to ask |
|
26 | - * @param mixed $default Default value |
|
27 | - * @param bool $hidden Hide response |
|
28 | - * @param bool $required User input is required |
|
29 | - * |
|
30 | - * @return mixed |
|
31 | - */ |
|
32 | - public function ask($question, $default = null, $hidden = false, $required = true) { |
|
33 | - |
|
34 | - $helper = $this->getHelper('question'); |
|
35 | - |
|
36 | - $q = new Question($question, $default); |
|
37 | - |
|
38 | - if ($hidden) { |
|
39 | - $q->setHidden(true); |
|
40 | - $q->setHiddenFallback(false); |
|
41 | - } |
|
42 | - |
|
43 | - if ($required) { |
|
44 | - $q->setValidator([ |
|
45 | - $this, |
|
46 | - 'assertNotEmpty' |
|
47 | - ]); |
|
48 | - $q->setMaxAttempts(2); |
|
49 | - } |
|
50 | - |
|
51 | - return $helper->ask($this->input, $this->output, $q); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Write messages to output buffer |
|
56 | - * |
|
57 | - * @param string|array $messages Messages |
|
58 | - * |
|
59 | - * @return void |
|
60 | - */ |
|
61 | - public function write($messages) { |
|
62 | - $this->output->writeln($messages); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Returns option value |
|
67 | - * |
|
68 | - * @param string $name Option name |
|
69 | - * |
|
70 | - * @return mixed |
|
71 | - */ |
|
72 | - public function option($name) { |
|
73 | - return $this->input->getOption($name); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Returns argument value |
|
78 | - * |
|
79 | - * @param string $name Argument name |
|
80 | - * |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public function argument($name) { |
|
84 | - return $this->input->getArgument($name); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Question validator for required user response |
|
89 | - * |
|
90 | - * @param mixed $answer User answer |
|
91 | - * |
|
92 | - * @return bool |
|
93 | - */ |
|
94 | - public function assertNotEmpty($answer) { |
|
95 | - if (empty($answer)) { |
|
96 | - throw new \RuntimeException('Please enter a required answer'); |
|
97 | - } |
|
98 | - |
|
99 | - return $answer; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Dump and output system and error messages |
|
104 | - * @return void |
|
105 | - */ |
|
106 | - protected function dumpRegisters() { |
|
107 | - $registers = _elgg_services()->systemMessages->loadRegisters(); |
|
108 | - |
|
109 | - foreach ($registers as $prop => $values) { |
|
110 | - if (!empty($values)) { |
|
111 | - foreach ($values as $msg) { |
|
112 | - $tag = $prop == 'error' ? 'error' : 'info'; |
|
113 | - $this->write(elgg_format_element($tag, [], $msg)); |
|
114 | - } |
|
115 | - } |
|
116 | - } |
|
117 | - } |
|
12 | + /** |
|
13 | + * @var InputInterface |
|
14 | + */ |
|
15 | + protected $input; |
|
16 | + |
|
17 | + /** |
|
18 | + * @var OutputInterface |
|
19 | + */ |
|
20 | + protected $output; |
|
21 | + |
|
22 | + /** |
|
23 | + * Ask a question |
|
24 | + * |
|
25 | + * @param string $question Question to ask |
|
26 | + * @param mixed $default Default value |
|
27 | + * @param bool $hidden Hide response |
|
28 | + * @param bool $required User input is required |
|
29 | + * |
|
30 | + * @return mixed |
|
31 | + */ |
|
32 | + public function ask($question, $default = null, $hidden = false, $required = true) { |
|
33 | + |
|
34 | + $helper = $this->getHelper('question'); |
|
35 | + |
|
36 | + $q = new Question($question, $default); |
|
37 | + |
|
38 | + if ($hidden) { |
|
39 | + $q->setHidden(true); |
|
40 | + $q->setHiddenFallback(false); |
|
41 | + } |
|
42 | + |
|
43 | + if ($required) { |
|
44 | + $q->setValidator([ |
|
45 | + $this, |
|
46 | + 'assertNotEmpty' |
|
47 | + ]); |
|
48 | + $q->setMaxAttempts(2); |
|
49 | + } |
|
50 | + |
|
51 | + return $helper->ask($this->input, $this->output, $q); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Write messages to output buffer |
|
56 | + * |
|
57 | + * @param string|array $messages Messages |
|
58 | + * |
|
59 | + * @return void |
|
60 | + */ |
|
61 | + public function write($messages) { |
|
62 | + $this->output->writeln($messages); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Returns option value |
|
67 | + * |
|
68 | + * @param string $name Option name |
|
69 | + * |
|
70 | + * @return mixed |
|
71 | + */ |
|
72 | + public function option($name) { |
|
73 | + return $this->input->getOption($name); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Returns argument value |
|
78 | + * |
|
79 | + * @param string $name Argument name |
|
80 | + * |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public function argument($name) { |
|
84 | + return $this->input->getArgument($name); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Question validator for required user response |
|
89 | + * |
|
90 | + * @param mixed $answer User answer |
|
91 | + * |
|
92 | + * @return bool |
|
93 | + */ |
|
94 | + public function assertNotEmpty($answer) { |
|
95 | + if (empty($answer)) { |
|
96 | + throw new \RuntimeException('Please enter a required answer'); |
|
97 | + } |
|
98 | + |
|
99 | + return $answer; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Dump and output system and error messages |
|
104 | + * @return void |
|
105 | + */ |
|
106 | + protected function dumpRegisters() { |
|
107 | + $registers = _elgg_services()->systemMessages->loadRegisters(); |
|
108 | + |
|
109 | + foreach ($registers as $prop => $values) { |
|
110 | + if (!empty($values)) { |
|
111 | + foreach ($values as $msg) { |
|
112 | + $tag = $prop == 'error' ? 'error' : 'info'; |
|
113 | + $this->write(elgg_format_element($tag, [], $msg)); |
|
114 | + } |
|
115 | + } |
|
116 | + } |
|
117 | + } |
|
118 | 118 | } |
119 | 119 | \ No newline at end of file |
@@ -3,7 +3,6 @@ |
||
3 | 3 | namespace Elgg\Cli; |
4 | 4 | |
5 | 5 | use Elgg\Application; |
6 | -use Elgg\Config; |
|
7 | 6 | use Exception; |
8 | 7 | use RuntimeException; |
9 | 8 | use Symfony\Component\Console\Input\InputOption; |
@@ -15,130 +15,130 @@ |
||
15 | 15 | */ |
16 | 16 | class SimpletestCommand extends Command { |
17 | 17 | |
18 | - /** |
|
19 | - * {@inheritdoc} |
|
20 | - */ |
|
21 | - protected function configure() { |
|
22 | - $this->setName('simpletest') |
|
23 | - ->setDescription('Run simpletest test suite') |
|
24 | - ->addOption('config', 'c', InputOption::VALUE_OPTIONAL, |
|
25 | - 'Path to settings file that the Elgg Application should be bootstrapped with' |
|
26 | - ) |
|
27 | - ->addOption('plugins', 'p', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, |
|
28 | - 'A list of plugins to enable for testing or "all" to enable all plugins' |
|
29 | - ); |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * {@inheritdoc} |
|
34 | - */ |
|
35 | - protected function command() { |
|
36 | - |
|
37 | - if (!class_exists('ElggCoreUnitTest')) { |
|
38 | - elgg_log('You must install your Elgg application using "composer install --dev"', 'ERROR'); |
|
39 | - |
|
40 | - return 1; |
|
41 | - } |
|
42 | - |
|
43 | - // Disable maximum execution time. |
|
44 | - // Tests take a while... |
|
45 | - set_time_limit(0); |
|
46 | - |
|
47 | - ob_start(); |
|
48 | - |
|
49 | - $error = 0; |
|
50 | - |
|
51 | - try { |
|
52 | - $settings_path = $this->option('config'); |
|
53 | - if ($settings_path) { |
|
54 | - $sp = _elgg_services(); |
|
55 | - $app = Application::factory([ |
|
56 | - 'settings_path' => $settings_path, |
|
57 | - 'service_provider' => $sp, |
|
58 | - ]); |
|
59 | - Application::setInstance($app); |
|
60 | - } |
|
61 | - |
|
62 | - // turn off system log |
|
63 | - _elgg_services()->hooks->unregisterHandler('all', 'all', 'system_log_listener'); |
|
64 | - _elgg_services()->hooks->unregisterHandler('log', 'systemlog', 'system_log_default_logger'); |
|
65 | - |
|
66 | - $admin = array_shift(elgg_get_admins(['limit' => 1])); |
|
67 | - if (!login($admin)) { |
|
68 | - throw new RuntimeException("Failed to login as administrator."); |
|
69 | - } |
|
70 | - |
|
71 | - // disable emails |
|
72 | - elgg_set_email_transport(new \Zend\Mail\Transport\InMemory()); |
|
73 | - |
|
74 | - $plugins = $this->option('plugins'); |
|
75 | - if (in_array('all', $plugins)) { |
|
76 | - $plugins = []; |
|
77 | - $plugin_entities = elgg_get_plugins('inactive'); |
|
78 | - foreach ($plugin_entities as $plugin_entity) { |
|
79 | - $plugins[] = $plugin_entity->getID(); |
|
80 | - } |
|
81 | - } else if (empty($plugins)) { |
|
82 | - // plugins that contain unit tests |
|
83 | - $plugins = [ |
|
84 | - 'groups', |
|
85 | - 'thewire', |
|
86 | - 'web_services' |
|
87 | - ]; |
|
88 | - } |
|
89 | - |
|
90 | - $activated_plugins = []; |
|
91 | - |
|
92 | - // activate plugins that are not activated on install |
|
93 | - foreach ($plugins as $key => $id) { |
|
94 | - $plugin = elgg_get_plugin_from_id($id); |
|
95 | - if (!$plugin || $plugin->isActive()) { |
|
96 | - unset($plugins[$key]); |
|
97 | - continue; |
|
98 | - } |
|
99 | - if ($plugin->activate()) { |
|
100 | - $activated_plugins[] = $id; |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - $suite = new TestSuite('Elgg Core Unit Tests'); |
|
105 | - |
|
106 | - $test_cases = _elgg_services()->hooks->trigger('unit_test', 'system', null, []); |
|
107 | - foreach ($test_cases as $file) { |
|
108 | - if (substr($file, -4, 4) === '.php') { |
|
109 | - $suite->addFile($file); |
|
110 | - } else if (class_exists($file)) { |
|
111 | - $suite->add($file); |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - $start_time = microtime(true); |
|
116 | - |
|
117 | - $reporter = new TextReporter(); |
|
118 | - $result = $suite->Run($reporter); |
|
119 | - |
|
120 | - // deactivate plugins that were activated for test suite |
|
121 | - foreach ($activated_plugins as $key => $id) { |
|
122 | - $plugin = elgg_get_plugin_from_id($id); |
|
123 | - $plugin->deactivate(); |
|
124 | - } |
|
125 | - |
|
126 | - echo PHP_EOL . sprintf("Time: %.2f seconds, Memory: %.2fMb\n", |
|
127 | - microtime(true) - $start_time, |
|
128 | - memory_get_peak_usage() / 1048576.0 // in megabytes |
|
129 | - ) . PHP_EOL; |
|
130 | - |
|
131 | - if (!$result) { |
|
132 | - throw new RuntimeException('One or more tests have failed'); |
|
133 | - } |
|
134 | - } catch (Exception $e) { |
|
135 | - $error = $e->getCode() ? : 1; |
|
136 | - elgg_log("Test suite has failed with " . get_class($e) . ': ' . $e->getMessage(), 'ERROR'); |
|
137 | - } |
|
138 | - |
|
139 | - $this->write(ob_get_clean()); |
|
140 | - |
|
141 | - return $error; |
|
142 | - } |
|
18 | + /** |
|
19 | + * {@inheritdoc} |
|
20 | + */ |
|
21 | + protected function configure() { |
|
22 | + $this->setName('simpletest') |
|
23 | + ->setDescription('Run simpletest test suite') |
|
24 | + ->addOption('config', 'c', InputOption::VALUE_OPTIONAL, |
|
25 | + 'Path to settings file that the Elgg Application should be bootstrapped with' |
|
26 | + ) |
|
27 | + ->addOption('plugins', 'p', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, |
|
28 | + 'A list of plugins to enable for testing or "all" to enable all plugins' |
|
29 | + ); |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * {@inheritdoc} |
|
34 | + */ |
|
35 | + protected function command() { |
|
36 | + |
|
37 | + if (!class_exists('ElggCoreUnitTest')) { |
|
38 | + elgg_log('You must install your Elgg application using "composer install --dev"', 'ERROR'); |
|
39 | + |
|
40 | + return 1; |
|
41 | + } |
|
42 | + |
|
43 | + // Disable maximum execution time. |
|
44 | + // Tests take a while... |
|
45 | + set_time_limit(0); |
|
46 | + |
|
47 | + ob_start(); |
|
48 | + |
|
49 | + $error = 0; |
|
50 | + |
|
51 | + try { |
|
52 | + $settings_path = $this->option('config'); |
|
53 | + if ($settings_path) { |
|
54 | + $sp = _elgg_services(); |
|
55 | + $app = Application::factory([ |
|
56 | + 'settings_path' => $settings_path, |
|
57 | + 'service_provider' => $sp, |
|
58 | + ]); |
|
59 | + Application::setInstance($app); |
|
60 | + } |
|
61 | + |
|
62 | + // turn off system log |
|
63 | + _elgg_services()->hooks->unregisterHandler('all', 'all', 'system_log_listener'); |
|
64 | + _elgg_services()->hooks->unregisterHandler('log', 'systemlog', 'system_log_default_logger'); |
|
65 | + |
|
66 | + $admin = array_shift(elgg_get_admins(['limit' => 1])); |
|
67 | + if (!login($admin)) { |
|
68 | + throw new RuntimeException("Failed to login as administrator."); |
|
69 | + } |
|
70 | + |
|
71 | + // disable emails |
|
72 | + elgg_set_email_transport(new \Zend\Mail\Transport\InMemory()); |
|
73 | + |
|
74 | + $plugins = $this->option('plugins'); |
|
75 | + if (in_array('all', $plugins)) { |
|
76 | + $plugins = []; |
|
77 | + $plugin_entities = elgg_get_plugins('inactive'); |
|
78 | + foreach ($plugin_entities as $plugin_entity) { |
|
79 | + $plugins[] = $plugin_entity->getID(); |
|
80 | + } |
|
81 | + } else if (empty($plugins)) { |
|
82 | + // plugins that contain unit tests |
|
83 | + $plugins = [ |
|
84 | + 'groups', |
|
85 | + 'thewire', |
|
86 | + 'web_services' |
|
87 | + ]; |
|
88 | + } |
|
89 | + |
|
90 | + $activated_plugins = []; |
|
91 | + |
|
92 | + // activate plugins that are not activated on install |
|
93 | + foreach ($plugins as $key => $id) { |
|
94 | + $plugin = elgg_get_plugin_from_id($id); |
|
95 | + if (!$plugin || $plugin->isActive()) { |
|
96 | + unset($plugins[$key]); |
|
97 | + continue; |
|
98 | + } |
|
99 | + if ($plugin->activate()) { |
|
100 | + $activated_plugins[] = $id; |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + $suite = new TestSuite('Elgg Core Unit Tests'); |
|
105 | + |
|
106 | + $test_cases = _elgg_services()->hooks->trigger('unit_test', 'system', null, []); |
|
107 | + foreach ($test_cases as $file) { |
|
108 | + if (substr($file, -4, 4) === '.php') { |
|
109 | + $suite->addFile($file); |
|
110 | + } else if (class_exists($file)) { |
|
111 | + $suite->add($file); |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + $start_time = microtime(true); |
|
116 | + |
|
117 | + $reporter = new TextReporter(); |
|
118 | + $result = $suite->Run($reporter); |
|
119 | + |
|
120 | + // deactivate plugins that were activated for test suite |
|
121 | + foreach ($activated_plugins as $key => $id) { |
|
122 | + $plugin = elgg_get_plugin_from_id($id); |
|
123 | + $plugin->deactivate(); |
|
124 | + } |
|
125 | + |
|
126 | + echo PHP_EOL . sprintf("Time: %.2f seconds, Memory: %.2fMb\n", |
|
127 | + microtime(true) - $start_time, |
|
128 | + memory_get_peak_usage() / 1048576.0 // in megabytes |
|
129 | + ) . PHP_EOL; |
|
130 | + |
|
131 | + if (!$result) { |
|
132 | + throw new RuntimeException('One or more tests have failed'); |
|
133 | + } |
|
134 | + } catch (Exception $e) { |
|
135 | + $error = $e->getCode() ? : 1; |
|
136 | + elgg_log("Test suite has failed with " . get_class($e) . ': ' . $e->getMessage(), 'ERROR'); |
|
137 | + } |
|
138 | + |
|
139 | + $this->write(ob_get_clean()); |
|
140 | + |
|
141 | + return $error; |
|
142 | + } |
|
143 | 143 | |
144 | 144 | } |
145 | 145 | \ No newline at end of file |
@@ -123,17 +123,17 @@ |
||
123 | 123 | $plugin->deactivate(); |
124 | 124 | } |
125 | 125 | |
126 | - echo PHP_EOL . sprintf("Time: %.2f seconds, Memory: %.2fMb\n", |
|
126 | + echo PHP_EOL.sprintf("Time: %.2f seconds, Memory: %.2fMb\n", |
|
127 | 127 | microtime(true) - $start_time, |
128 | 128 | memory_get_peak_usage() / 1048576.0 // in megabytes |
129 | - ) . PHP_EOL; |
|
129 | + ).PHP_EOL; |
|
130 | 130 | |
131 | 131 | if (!$result) { |
132 | 132 | throw new RuntimeException('One or more tests have failed'); |
133 | 133 | } |
134 | 134 | } catch (Exception $e) { |
135 | - $error = $e->getCode() ? : 1; |
|
136 | - elgg_log("Test suite has failed with " . get_class($e) . ': ' . $e->getMessage(), 'ERROR'); |
|
135 | + $error = $e->getCode() ?: 1; |
|
136 | + elgg_log("Test suite has failed with ".get_class($e).': '.$e->getMessage(), 'ERROR'); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | $this->write(ob_get_clean()); |
@@ -546,7 +546,7 @@ |
||
546 | 546 | * @param string[] $value Test files |
547 | 547 | * @param array $params Hook params |
548 | 548 | * |
549 | - * @return array |
|
549 | + * @return string[] |
|
550 | 550 | */ |
551 | 551 | function _elgg_htmlawed_test($hook, $type, $value, $params) { |
552 | 552 | $value[] = Paths::elgg() . 'engine/tests/simpletest/ElggHtmLawedTest.php'; |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * @return mixed |
28 | 28 | */ |
29 | 29 | function get_input($variable, $default = null, $filter_result = true) { |
30 | - return _elgg_services()->input->get($variable, $default, $filter_result); |
|
30 | + return _elgg_services()->input->get($variable, $default, $filter_result); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * @return void |
42 | 42 | */ |
43 | 43 | function set_input($variable, $value) { |
44 | - _elgg_services()->input->set($variable, $value); |
|
44 | + _elgg_services()->input->set($variable, $value); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | * @since 3.0 |
55 | 55 | */ |
56 | 56 | function elgg_get_title_input($variable = 'title', $default = '') { |
57 | - $raw_input = get_input($variable, $default, false); |
|
58 | - return htmlspecialchars($raw_input, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); |
|
57 | + $raw_input = get_input($variable, $default, false); |
|
58 | + return htmlspecialchars($raw_input, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * @return mixed The filtered result - everything will be strings |
68 | 68 | */ |
69 | 69 | function filter_tags($var) { |
70 | - return elgg_trigger_plugin_hook('validate', 'input', null, $var); |
|
70 | + return elgg_trigger_plugin_hook('validate', 'input', null, $var); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -79,19 +79,19 @@ discard block |
||
79 | 79 | * @return string The current page URL. |
80 | 80 | */ |
81 | 81 | function current_page_url() { |
82 | - $url = parse_url(elgg_get_site_url()); |
|
82 | + $url = parse_url(elgg_get_site_url()); |
|
83 | 83 | |
84 | - $page = $url['scheme'] . "://" . $url['host']; |
|
84 | + $page = $url['scheme'] . "://" . $url['host']; |
|
85 | 85 | |
86 | - if (isset($url['port']) && $url['port']) { |
|
87 | - $page .= ":" . $url['port']; |
|
88 | - } |
|
86 | + if (isset($url['port']) && $url['port']) { |
|
87 | + $page .= ":" . $url['port']; |
|
88 | + } |
|
89 | 89 | |
90 | - $page = trim($page, "/"); |
|
90 | + $page = trim($page, "/"); |
|
91 | 91 | |
92 | - $page .= _elgg_services()->request->getRequestUri(); |
|
92 | + $page .= _elgg_services()->request->getRequestUri(); |
|
93 | 93 | |
94 | - return $page; |
|
94 | + return $page; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * @return bool |
103 | 103 | */ |
104 | 104 | function is_email_address($address) { |
105 | - return filter_var($address, FILTER_VALIDATE_EMAIL) === $address; |
|
105 | + return filter_var($address, FILTER_VALIDATE_EMAIL) === $address; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * @since 1.8.0 |
118 | 118 | */ |
119 | 119 | function elgg_make_sticky_form($form_name) { |
120 | - _elgg_services()->stickyForms->makeStickyForm($form_name); |
|
120 | + _elgg_services()->stickyForms->makeStickyForm($form_name); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | * @since 1.8.0 |
134 | 134 | */ |
135 | 135 | function elgg_clear_sticky_form($form_name) { |
136 | - _elgg_services()->stickyForms->clearStickyForm($form_name); |
|
136 | + _elgg_services()->stickyForms->clearStickyForm($form_name); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * @since 1.8.0 |
146 | 146 | */ |
147 | 147 | function elgg_is_sticky_form($form_name) { |
148 | - return _elgg_services()->stickyForms->isStickyForm($form_name); |
|
148 | + return _elgg_services()->stickyForms->isStickyForm($form_name); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @since 1.8.0 |
163 | 163 | */ |
164 | 164 | function elgg_get_sticky_value($form_name, $variable = '', $default = null, $filter_result = true) { |
165 | - return _elgg_services()->stickyForms->getStickyValue($form_name, $variable, $default, $filter_result); |
|
165 | + return _elgg_services()->stickyForms->getStickyValue($form_name, $variable, $default, $filter_result); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | * @since 1.8.0 |
176 | 176 | */ |
177 | 177 | function elgg_get_sticky_values($form_name, $filter_result = true) { |
178 | - return _elgg_services()->stickyForms->getStickyValues($form_name, $filter_result); |
|
178 | + return _elgg_services()->stickyForms->getStickyValues($form_name, $filter_result); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @since 1.8.0 |
189 | 189 | */ |
190 | 190 | function elgg_clear_sticky_value($form_name, $variable) { |
191 | - _elgg_services()->stickyForms->clearStickyValue($form_name, $variable); |
|
191 | + _elgg_services()->stickyForms->clearStickyValue($form_name, $variable); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -209,201 +209,201 @@ discard block |
||
209 | 209 | * @access private |
210 | 210 | */ |
211 | 211 | function input_livesearch_page_handler($page) { |
212 | - $dbprefix = _elgg_config()->dbprefix; |
|
213 | - |
|
214 | - // only return results to logged in users. |
|
215 | - if (!$user = elgg_get_logged_in_user_entity()) { |
|
216 | - exit; |
|
217 | - } |
|
218 | - |
|
219 | - if (!$q = get_input('term', get_input('q'))) { |
|
220 | - exit; |
|
221 | - } |
|
222 | - |
|
223 | - $input_name = get_input('name', 'members'); |
|
224 | - |
|
225 | - $q = sanitise_string($q); |
|
226 | - |
|
227 | - // replace mysql vars with escaped strings |
|
228 | - $q = str_replace(['_', '%'], ['\_', '\%'], $q); |
|
229 | - |
|
230 | - $match_on = get_input('match_on', 'all'); |
|
231 | - |
|
232 | - if (!is_array($match_on)) { |
|
233 | - $match_on = [$match_on]; |
|
234 | - } |
|
235 | - |
|
236 | - // all = users and groups |
|
237 | - if (in_array('all', $match_on)) { |
|
238 | - $match_on = ['users', 'groups']; |
|
239 | - } |
|
240 | - |
|
241 | - $owner_guid = ELGG_ENTITIES_ANY_VALUE; |
|
242 | - if (get_input('match_owner', false)) { |
|
243 | - $owner_guid = $user->getGUID(); |
|
244 | - } |
|
245 | - |
|
246 | - $limit = sanitise_int(get_input('limit', _elgg_config()->default_limit)); |
|
247 | - |
|
248 | - // grab a list of entities and send them in json. |
|
249 | - $results = []; |
|
250 | - foreach ($match_on as $match_type) { |
|
251 | - switch ($match_type) { |
|
252 | - case 'users': |
|
253 | - $options = [ |
|
254 | - 'type' => 'user', |
|
255 | - 'limit' => $limit, |
|
256 | - 'joins' => ["JOIN {$dbprefix}users_entity ue ON e.guid = ue.guid"], |
|
257 | - 'wheres' => [ |
|
258 | - "ue.banned = 'no'", |
|
259 | - "(ue.name LIKE '$q%' OR ue.name LIKE '% $q%' OR ue.username LIKE '$q%')" |
|
260 | - ] |
|
261 | - ]; |
|
212 | + $dbprefix = _elgg_config()->dbprefix; |
|
213 | + |
|
214 | + // only return results to logged in users. |
|
215 | + if (!$user = elgg_get_logged_in_user_entity()) { |
|
216 | + exit; |
|
217 | + } |
|
218 | + |
|
219 | + if (!$q = get_input('term', get_input('q'))) { |
|
220 | + exit; |
|
221 | + } |
|
222 | + |
|
223 | + $input_name = get_input('name', 'members'); |
|
224 | + |
|
225 | + $q = sanitise_string($q); |
|
226 | + |
|
227 | + // replace mysql vars with escaped strings |
|
228 | + $q = str_replace(['_', '%'], ['\_', '\%'], $q); |
|
229 | + |
|
230 | + $match_on = get_input('match_on', 'all'); |
|
231 | + |
|
232 | + if (!is_array($match_on)) { |
|
233 | + $match_on = [$match_on]; |
|
234 | + } |
|
235 | + |
|
236 | + // all = users and groups |
|
237 | + if (in_array('all', $match_on)) { |
|
238 | + $match_on = ['users', 'groups']; |
|
239 | + } |
|
240 | + |
|
241 | + $owner_guid = ELGG_ENTITIES_ANY_VALUE; |
|
242 | + if (get_input('match_owner', false)) { |
|
243 | + $owner_guid = $user->getGUID(); |
|
244 | + } |
|
245 | + |
|
246 | + $limit = sanitise_int(get_input('limit', _elgg_config()->default_limit)); |
|
247 | + |
|
248 | + // grab a list of entities and send them in json. |
|
249 | + $results = []; |
|
250 | + foreach ($match_on as $match_type) { |
|
251 | + switch ($match_type) { |
|
252 | + case 'users': |
|
253 | + $options = [ |
|
254 | + 'type' => 'user', |
|
255 | + 'limit' => $limit, |
|
256 | + 'joins' => ["JOIN {$dbprefix}users_entity ue ON e.guid = ue.guid"], |
|
257 | + 'wheres' => [ |
|
258 | + "ue.banned = 'no'", |
|
259 | + "(ue.name LIKE '$q%' OR ue.name LIKE '% $q%' OR ue.username LIKE '$q%')" |
|
260 | + ] |
|
261 | + ]; |
|
262 | 262 | |
263 | - $entities = elgg_get_entities($options); |
|
264 | - if (!empty($entities)) { |
|
265 | - foreach ($entities as $entity) { |
|
266 | - if (in_array('groups', $match_on)) { |
|
267 | - $value = $entity->guid; |
|
268 | - } else { |
|
269 | - $value = $entity->username; |
|
270 | - } |
|
271 | - |
|
272 | - $output = elgg_view_list_item($entity, [ |
|
273 | - 'use_hover' => false, |
|
274 | - 'use_link' => false, |
|
275 | - 'class' => 'elgg-autocomplete-item', |
|
276 | - 'title' => $entity->name, // Default title would be a link |
|
277 | - ]); |
|
278 | - |
|
279 | - $icon = elgg_view_entity_icon($entity, 'tiny', [ |
|
280 | - 'use_hover' => false, |
|
281 | - ]); |
|
282 | - |
|
283 | - $result = [ |
|
284 | - 'type' => 'user', |
|
285 | - 'name' => $entity->name, |
|
286 | - 'desc' => $entity->username, |
|
287 | - 'guid' => $entity->guid, |
|
288 | - 'label' => $output, |
|
289 | - 'value' => $value, |
|
290 | - 'icon' => $icon, |
|
291 | - 'url' => $entity->getURL(), |
|
292 | - 'html' => elgg_view('input/userpicker/item', [ |
|
293 | - 'entity' => $entity, |
|
294 | - 'input_name' => $input_name, |
|
295 | - ]), |
|
296 | - ]; |
|
297 | - $results[$entity->name . rand(1, 100)] = $result; |
|
298 | - } |
|
299 | - } |
|
300 | - break; |
|
301 | - |
|
302 | - case 'groups': |
|
303 | - // don't return results if groups aren't enabled. |
|
304 | - if (!elgg_is_active_plugin('groups')) { |
|
305 | - continue; |
|
306 | - } |
|
263 | + $entities = elgg_get_entities($options); |
|
264 | + if (!empty($entities)) { |
|
265 | + foreach ($entities as $entity) { |
|
266 | + if (in_array('groups', $match_on)) { |
|
267 | + $value = $entity->guid; |
|
268 | + } else { |
|
269 | + $value = $entity->username; |
|
270 | + } |
|
271 | + |
|
272 | + $output = elgg_view_list_item($entity, [ |
|
273 | + 'use_hover' => false, |
|
274 | + 'use_link' => false, |
|
275 | + 'class' => 'elgg-autocomplete-item', |
|
276 | + 'title' => $entity->name, // Default title would be a link |
|
277 | + ]); |
|
278 | + |
|
279 | + $icon = elgg_view_entity_icon($entity, 'tiny', [ |
|
280 | + 'use_hover' => false, |
|
281 | + ]); |
|
282 | + |
|
283 | + $result = [ |
|
284 | + 'type' => 'user', |
|
285 | + 'name' => $entity->name, |
|
286 | + 'desc' => $entity->username, |
|
287 | + 'guid' => $entity->guid, |
|
288 | + 'label' => $output, |
|
289 | + 'value' => $value, |
|
290 | + 'icon' => $icon, |
|
291 | + 'url' => $entity->getURL(), |
|
292 | + 'html' => elgg_view('input/userpicker/item', [ |
|
293 | + 'entity' => $entity, |
|
294 | + 'input_name' => $input_name, |
|
295 | + ]), |
|
296 | + ]; |
|
297 | + $results[$entity->name . rand(1, 100)] = $result; |
|
298 | + } |
|
299 | + } |
|
300 | + break; |
|
301 | + |
|
302 | + case 'groups': |
|
303 | + // don't return results if groups aren't enabled. |
|
304 | + if (!elgg_is_active_plugin('groups')) { |
|
305 | + continue; |
|
306 | + } |
|
307 | 307 | |
308 | - $options = [ |
|
309 | - 'type' => 'group', |
|
310 | - 'limit' => $limit, |
|
311 | - 'owner_guid' => $owner_guid, |
|
312 | - 'joins' => ["JOIN {$dbprefix}groups_entity ge ON e.guid = ge.guid"], |
|
313 | - 'wheres' => [ |
|
314 | - "(ge.name LIKE '$q%' OR ge.name LIKE '% $q%' OR ge.description LIKE '% $q%')" |
|
315 | - ] |
|
316 | - ]; |
|
308 | + $options = [ |
|
309 | + 'type' => 'group', |
|
310 | + 'limit' => $limit, |
|
311 | + 'owner_guid' => $owner_guid, |
|
312 | + 'joins' => ["JOIN {$dbprefix}groups_entity ge ON e.guid = ge.guid"], |
|
313 | + 'wheres' => [ |
|
314 | + "(ge.name LIKE '$q%' OR ge.name LIKE '% $q%' OR ge.description LIKE '% $q%')" |
|
315 | + ] |
|
316 | + ]; |
|
317 | 317 | |
318 | - $entities = elgg_get_entities($options); |
|
319 | - if (!empty($entities)) { |
|
320 | - foreach ($entities as $entity) { |
|
321 | - $output = elgg_view_list_item($entity, [ |
|
322 | - 'use_hover' => false, |
|
323 | - 'class' => 'elgg-autocomplete-item', |
|
324 | - 'full_view' => false, |
|
325 | - 'href' => false, |
|
326 | - 'title' => $entity->name, // Default title would be a link |
|
327 | - ]); |
|
328 | - |
|
329 | - $icon = elgg_view_entity_icon($entity, 'tiny', [ |
|
330 | - 'use_hover' => false, |
|
331 | - ]); |
|
332 | - |
|
333 | - $result = [ |
|
334 | - 'type' => 'group', |
|
335 | - 'name' => $entity->name, |
|
336 | - 'desc' => strip_tags($entity->description), |
|
337 | - 'guid' => $entity->guid, |
|
338 | - 'label' => $output, |
|
339 | - 'value' => $entity->guid, |
|
340 | - 'icon' => $icon, |
|
341 | - 'url' => $entity->getURL(), |
|
342 | - ]; |
|
343 | - |
|
344 | - $results[$entity->name . rand(1, 100)] = $result; |
|
345 | - } |
|
346 | - } |
|
347 | - break; |
|
348 | - |
|
349 | - case 'friends': |
|
350 | - $options = [ |
|
351 | - 'type' => 'user', |
|
352 | - 'limit' => $limit, |
|
353 | - 'relationship' => 'friend', |
|
354 | - 'relationship_guid' => $user->getGUID(), |
|
355 | - 'joins' => ["JOIN {$dbprefix}users_entity ue ON e.guid = ue.guid"], |
|
356 | - 'wheres' => [ |
|
357 | - "ue.banned = 'no'", |
|
358 | - "(ue.name LIKE '$q%' OR ue.name LIKE '% $q%' OR ue.username LIKE '$q%')" |
|
359 | - ] |
|
360 | - ]; |
|
318 | + $entities = elgg_get_entities($options); |
|
319 | + if (!empty($entities)) { |
|
320 | + foreach ($entities as $entity) { |
|
321 | + $output = elgg_view_list_item($entity, [ |
|
322 | + 'use_hover' => false, |
|
323 | + 'class' => 'elgg-autocomplete-item', |
|
324 | + 'full_view' => false, |
|
325 | + 'href' => false, |
|
326 | + 'title' => $entity->name, // Default title would be a link |
|
327 | + ]); |
|
328 | + |
|
329 | + $icon = elgg_view_entity_icon($entity, 'tiny', [ |
|
330 | + 'use_hover' => false, |
|
331 | + ]); |
|
332 | + |
|
333 | + $result = [ |
|
334 | + 'type' => 'group', |
|
335 | + 'name' => $entity->name, |
|
336 | + 'desc' => strip_tags($entity->description), |
|
337 | + 'guid' => $entity->guid, |
|
338 | + 'label' => $output, |
|
339 | + 'value' => $entity->guid, |
|
340 | + 'icon' => $icon, |
|
341 | + 'url' => $entity->getURL(), |
|
342 | + ]; |
|
343 | + |
|
344 | + $results[$entity->name . rand(1, 100)] = $result; |
|
345 | + } |
|
346 | + } |
|
347 | + break; |
|
348 | + |
|
349 | + case 'friends': |
|
350 | + $options = [ |
|
351 | + 'type' => 'user', |
|
352 | + 'limit' => $limit, |
|
353 | + 'relationship' => 'friend', |
|
354 | + 'relationship_guid' => $user->getGUID(), |
|
355 | + 'joins' => ["JOIN {$dbprefix}users_entity ue ON e.guid = ue.guid"], |
|
356 | + 'wheres' => [ |
|
357 | + "ue.banned = 'no'", |
|
358 | + "(ue.name LIKE '$q%' OR ue.name LIKE '% $q%' OR ue.username LIKE '$q%')" |
|
359 | + ] |
|
360 | + ]; |
|
361 | 361 | |
362 | - $entities = elgg_get_entities_from_relationship($options); |
|
363 | - if (!empty($entities)) { |
|
364 | - foreach ($entities as $entity) { |
|
365 | - $output = elgg_view_list_item($entity, [ |
|
366 | - 'use_hover' => false, |
|
367 | - 'use_link' => false, |
|
368 | - 'class' => 'elgg-autocomplete-item', |
|
369 | - 'title' => $entity->name, // Default title would be a link |
|
370 | - ]); |
|
371 | - |
|
372 | - $icon = elgg_view_entity_icon($entity, 'tiny', [ |
|
373 | - 'use_hover' => false, |
|
374 | - ]); |
|
375 | - |
|
376 | - $result = [ |
|
377 | - 'type' => 'user', |
|
378 | - 'name' => $entity->name, |
|
379 | - 'desc' => $entity->username, |
|
380 | - 'guid' => $entity->guid, |
|
381 | - 'label' => $output, |
|
382 | - 'value' => $entity->username, |
|
383 | - 'icon' => $icon, |
|
384 | - 'url' => $entity->getURL(), |
|
385 | - 'html' => elgg_view('input/userpicker/item', [ |
|
386 | - 'entity' => $entity, |
|
387 | - 'input_name' => $input_name, |
|
388 | - ]), |
|
389 | - ]; |
|
390 | - $results[$entity->name . rand(1, 100)] = $result; |
|
391 | - } |
|
392 | - } |
|
393 | - break; |
|
394 | - |
|
395 | - default: |
|
396 | - header("HTTP/1.0 400 Bad Request", true); |
|
397 | - echo "livesearch: unknown match_on of $match_type"; |
|
398 | - exit; |
|
399 | - break; |
|
400 | - } |
|
401 | - } |
|
402 | - |
|
403 | - ksort($results); |
|
404 | - header("Content-Type: application/json;charset=utf-8"); |
|
405 | - echo json_encode(array_values($results)); |
|
406 | - exit; |
|
362 | + $entities = elgg_get_entities_from_relationship($options); |
|
363 | + if (!empty($entities)) { |
|
364 | + foreach ($entities as $entity) { |
|
365 | + $output = elgg_view_list_item($entity, [ |
|
366 | + 'use_hover' => false, |
|
367 | + 'use_link' => false, |
|
368 | + 'class' => 'elgg-autocomplete-item', |
|
369 | + 'title' => $entity->name, // Default title would be a link |
|
370 | + ]); |
|
371 | + |
|
372 | + $icon = elgg_view_entity_icon($entity, 'tiny', [ |
|
373 | + 'use_hover' => false, |
|
374 | + ]); |
|
375 | + |
|
376 | + $result = [ |
|
377 | + 'type' => 'user', |
|
378 | + 'name' => $entity->name, |
|
379 | + 'desc' => $entity->username, |
|
380 | + 'guid' => $entity->guid, |
|
381 | + 'label' => $output, |
|
382 | + 'value' => $entity->username, |
|
383 | + 'icon' => $icon, |
|
384 | + 'url' => $entity->getURL(), |
|
385 | + 'html' => elgg_view('input/userpicker/item', [ |
|
386 | + 'entity' => $entity, |
|
387 | + 'input_name' => $input_name, |
|
388 | + ]), |
|
389 | + ]; |
|
390 | + $results[$entity->name . rand(1, 100)] = $result; |
|
391 | + } |
|
392 | + } |
|
393 | + break; |
|
394 | + |
|
395 | + default: |
|
396 | + header("HTTP/1.0 400 Bad Request", true); |
|
397 | + echo "livesearch: unknown match_on of $match_type"; |
|
398 | + exit; |
|
399 | + break; |
|
400 | + } |
|
401 | + } |
|
402 | + |
|
403 | + ksort($results); |
|
404 | + header("Content-Type: application/json;charset=utf-8"); |
|
405 | + echo json_encode(array_values($results)); |
|
406 | + exit; |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -425,38 +425,38 @@ discard block |
||
425 | 425 | * @return mixed |
426 | 426 | */ |
427 | 427 | function _elgg_htmlawed_filter_tags($hook, $type, $result, $params = null) { |
428 | - $var = $result; |
|
429 | - |
|
430 | - $config = [ |
|
431 | - // seems to handle about everything we need. |
|
432 | - 'safe' => true, |
|
433 | - |
|
434 | - // remove comments/CDATA instead of converting to text |
|
435 | - 'comment' => 1, |
|
436 | - 'cdata' => 1, |
|
437 | - |
|
438 | - 'deny_attribute' => 'class, on*', |
|
439 | - 'hook_tag' => '_elgg_htmlawed_tag_post_processor', |
|
440 | - |
|
441 | - 'schemes' => '*:http,https,ftp,news,mailto,rtsp,teamspeak,gopher,mms,callto', |
|
442 | - // apparent this doesn't work. |
|
443 | - // 'style:color,cursor,text-align,font-size,font-weight,font-style,border,margin,padding,float' |
|
444 | - ]; |
|
445 | - |
|
446 | - // add nofollow to all links on output |
|
447 | - if (!elgg_in_context('input')) { |
|
448 | - $config['anti_link_spam'] = ['/./', '']; |
|
449 | - } |
|
450 | - |
|
451 | - $config = elgg_trigger_plugin_hook('config', 'htmlawed', null, $config); |
|
452 | - $spec = elgg_trigger_plugin_hook('spec', 'htmlawed', null, ''); |
|
453 | - |
|
454 | - if (!is_array($var)) { |
|
455 | - return Htmlawed::filter($var, $config, $spec); |
|
456 | - } else { |
|
457 | - array_walk_recursive($var, '_elgg_htmLawedArray', [$config, $spec]); |
|
458 | - return $var; |
|
459 | - } |
|
428 | + $var = $result; |
|
429 | + |
|
430 | + $config = [ |
|
431 | + // seems to handle about everything we need. |
|
432 | + 'safe' => true, |
|
433 | + |
|
434 | + // remove comments/CDATA instead of converting to text |
|
435 | + 'comment' => 1, |
|
436 | + 'cdata' => 1, |
|
437 | + |
|
438 | + 'deny_attribute' => 'class, on*', |
|
439 | + 'hook_tag' => '_elgg_htmlawed_tag_post_processor', |
|
440 | + |
|
441 | + 'schemes' => '*:http,https,ftp,news,mailto,rtsp,teamspeak,gopher,mms,callto', |
|
442 | + // apparent this doesn't work. |
|
443 | + // 'style:color,cursor,text-align,font-size,font-weight,font-style,border,margin,padding,float' |
|
444 | + ]; |
|
445 | + |
|
446 | + // add nofollow to all links on output |
|
447 | + if (!elgg_in_context('input')) { |
|
448 | + $config['anti_link_spam'] = ['/./', '']; |
|
449 | + } |
|
450 | + |
|
451 | + $config = elgg_trigger_plugin_hook('config', 'htmlawed', null, $config); |
|
452 | + $spec = elgg_trigger_plugin_hook('spec', 'htmlawed', null, ''); |
|
453 | + |
|
454 | + if (!is_array($var)) { |
|
455 | + return Htmlawed::filter($var, $config, $spec); |
|
456 | + } else { |
|
457 | + array_walk_recursive($var, '_elgg_htmLawedArray', [$config, $spec]); |
|
458 | + return $var; |
|
459 | + } |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | // @codingStandardsIgnoreStart |
@@ -464,8 +464,8 @@ discard block |
||
464 | 464 | * wrapper function for htmlawed for handling arrays |
465 | 465 | */ |
466 | 466 | function _elgg_htmLawedArray(&$v, $k, $config_spec) { |
467 | - list ($config, $spec) = $config_spec; |
|
468 | - $v = Htmlawed::filter($v, $config, $spec); |
|
467 | + list ($config, $spec) = $config_spec; |
|
468 | + $v = Htmlawed::filter($v, $config, $spec); |
|
469 | 469 | } |
470 | 470 | // @codingStandardsIgnoreEnd |
471 | 471 | |
@@ -482,60 +482,60 @@ discard block |
||
482 | 482 | * @return string |
483 | 483 | */ |
484 | 484 | function _elgg_htmlawed_tag_post_processor($element, $attributes = false) { |
485 | - if ($attributes === false) { |
|
486 | - // This is a closing tag. Prevent further processing to avoid inserting a duplicate tag |
|
487 | - return "</${element}>"; |
|
488 | - } |
|
489 | - |
|
490 | - // this list should be coordinated with the WYSIWYG editor used (tinymce, ckeditor, etc.) |
|
491 | - $allowed_styles = [ |
|
492 | - 'color', 'cursor', 'text-align', 'vertical-align', 'font-size', |
|
493 | - 'font-weight', 'font-style', 'border', 'border-top', 'background-color', |
|
494 | - 'border-bottom', 'border-left', 'border-right', |
|
495 | - 'margin', 'margin-top', 'margin-bottom', 'margin-left', |
|
496 | - 'margin-right', 'padding', 'float', 'text-decoration' |
|
497 | - ]; |
|
498 | - |
|
499 | - $params = ['tag' => $element]; |
|
500 | - $allowed_styles = elgg_trigger_plugin_hook('allowed_styles', 'htmlawed', $params, $allowed_styles); |
|
501 | - |
|
502 | - // must return something. |
|
503 | - $string = ''; |
|
504 | - |
|
505 | - foreach ($attributes as $attr => $value) { |
|
506 | - if ($attr == 'style') { |
|
507 | - $styles = explode(';', $value); |
|
508 | - |
|
509 | - $style_str = ''; |
|
510 | - foreach ($styles as $style) { |
|
511 | - if (!trim($style)) { |
|
512 | - continue; |
|
513 | - } |
|
514 | - list($style_attr, $style_value) = explode(':', trim($style)); |
|
515 | - $style_attr = trim($style_attr); |
|
516 | - $style_value = trim($style_value); |
|
517 | - |
|
518 | - if (in_array($style_attr, $allowed_styles)) { |
|
519 | - $style_str .= "$style_attr: $style_value; "; |
|
520 | - } |
|
521 | - } |
|
522 | - |
|
523 | - if ($style_str) { |
|
524 | - $style_str = trim($style_str); |
|
525 | - $string .= " style=\"$style_str\""; |
|
526 | - } |
|
527 | - } else { |
|
528 | - $string .= " $attr=\"$value\""; |
|
529 | - } |
|
530 | - } |
|
531 | - |
|
532 | - // Some WYSIWYG editors do not like tags like <p > so only add a space if needed. |
|
533 | - if ($string = trim($string)) { |
|
534 | - $string = " $string"; |
|
535 | - } |
|
536 | - |
|
537 | - $r = "<$element$string>"; |
|
538 | - return $r; |
|
485 | + if ($attributes === false) { |
|
486 | + // This is a closing tag. Prevent further processing to avoid inserting a duplicate tag |
|
487 | + return "</${element}>"; |
|
488 | + } |
|
489 | + |
|
490 | + // this list should be coordinated with the WYSIWYG editor used (tinymce, ckeditor, etc.) |
|
491 | + $allowed_styles = [ |
|
492 | + 'color', 'cursor', 'text-align', 'vertical-align', 'font-size', |
|
493 | + 'font-weight', 'font-style', 'border', 'border-top', 'background-color', |
|
494 | + 'border-bottom', 'border-left', 'border-right', |
|
495 | + 'margin', 'margin-top', 'margin-bottom', 'margin-left', |
|
496 | + 'margin-right', 'padding', 'float', 'text-decoration' |
|
497 | + ]; |
|
498 | + |
|
499 | + $params = ['tag' => $element]; |
|
500 | + $allowed_styles = elgg_trigger_plugin_hook('allowed_styles', 'htmlawed', $params, $allowed_styles); |
|
501 | + |
|
502 | + // must return something. |
|
503 | + $string = ''; |
|
504 | + |
|
505 | + foreach ($attributes as $attr => $value) { |
|
506 | + if ($attr == 'style') { |
|
507 | + $styles = explode(';', $value); |
|
508 | + |
|
509 | + $style_str = ''; |
|
510 | + foreach ($styles as $style) { |
|
511 | + if (!trim($style)) { |
|
512 | + continue; |
|
513 | + } |
|
514 | + list($style_attr, $style_value) = explode(':', trim($style)); |
|
515 | + $style_attr = trim($style_attr); |
|
516 | + $style_value = trim($style_value); |
|
517 | + |
|
518 | + if (in_array($style_attr, $allowed_styles)) { |
|
519 | + $style_str .= "$style_attr: $style_value; "; |
|
520 | + } |
|
521 | + } |
|
522 | + |
|
523 | + if ($style_str) { |
|
524 | + $style_str = trim($style_str); |
|
525 | + $string .= " style=\"$style_str\""; |
|
526 | + } |
|
527 | + } else { |
|
528 | + $string .= " $attr=\"$value\""; |
|
529 | + } |
|
530 | + } |
|
531 | + |
|
532 | + // Some WYSIWYG editors do not like tags like <p > so only add a space if needed. |
|
533 | + if ($string = trim($string)) { |
|
534 | + $string = " $string"; |
|
535 | + } |
|
536 | + |
|
537 | + $r = "<$element$string>"; |
|
538 | + return $r; |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | /** |
@@ -549,8 +549,8 @@ discard block |
||
549 | 549 | * @return array |
550 | 550 | */ |
551 | 551 | function _elgg_htmlawed_test($hook, $type, $value, $params) { |
552 | - $value[] = Paths::elgg() . 'engine/tests/simpletest/ElggHtmLawedTest.php'; |
|
553 | - return $value; |
|
552 | + $value[] = Paths::elgg() . 'engine/tests/simpletest/ElggHtmLawedTest.php'; |
|
553 | + return $value; |
|
554 | 554 | } |
555 | 555 | |
556 | 556 | /** |
@@ -565,13 +565,13 @@ discard block |
||
565 | 565 | */ |
566 | 566 | function _elgg_disable_password_autocomplete($hook, $type, $return_value, $params) { |
567 | 567 | |
568 | - if (!_elgg_config()->security_disable_password_autocomplete) { |
|
569 | - return; |
|
570 | - } |
|
568 | + if (!_elgg_config()->security_disable_password_autocomplete) { |
|
569 | + return; |
|
570 | + } |
|
571 | 571 | |
572 | - $return_value['autocomplete'] = 'off'; |
|
572 | + $return_value['autocomplete'] = 'off'; |
|
573 | 573 | |
574 | - return $return_value; |
|
574 | + return $return_value; |
|
575 | 575 | } |
576 | 576 | |
577 | 577 | /** |
@@ -581,19 +581,19 @@ discard block |
||
581 | 581 | * @access private |
582 | 582 | */ |
583 | 583 | function _elgg_input_init() { |
584 | - // register an endpoint for live search / autocomplete. |
|
585 | - elgg_register_page_handler('livesearch', 'input_livesearch_page_handler'); |
|
584 | + // register an endpoint for live search / autocomplete. |
|
585 | + elgg_register_page_handler('livesearch', 'input_livesearch_page_handler'); |
|
586 | 586 | |
587 | - elgg_register_plugin_hook_handler('validate', 'input', '_elgg_htmlawed_filter_tags', 1); |
|
587 | + elgg_register_plugin_hook_handler('validate', 'input', '_elgg_htmlawed_filter_tags', 1); |
|
588 | 588 | |
589 | - elgg_register_plugin_hook_handler('unit_test', 'system', '_elgg_htmlawed_test'); |
|
589 | + elgg_register_plugin_hook_handler('unit_test', 'system', '_elgg_htmlawed_test'); |
|
590 | 590 | |
591 | - elgg_register_plugin_hook_handler('view_vars', 'input/password', '_elgg_disable_password_autocomplete'); |
|
591 | + elgg_register_plugin_hook_handler('view_vars', 'input/password', '_elgg_disable_password_autocomplete'); |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | /** |
595 | 595 | * @see \Elgg\Application::loadCore Do not do work here. Just register for events. |
596 | 596 | */ |
597 | 597 | return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
598 | - $events->registerHandler('init', 'system', '_elgg_input_init'); |
|
598 | + $events->registerHandler('init', 'system', '_elgg_input_init'); |
|
599 | 599 | }; |
@@ -81,10 +81,10 @@ discard block |
||
81 | 81 | function current_page_url() { |
82 | 82 | $url = parse_url(elgg_get_site_url()); |
83 | 83 | |
84 | - $page = $url['scheme'] . "://" . $url['host']; |
|
84 | + $page = $url['scheme']."://".$url['host']; |
|
85 | 85 | |
86 | 86 | if (isset($url['port']) && $url['port']) { |
87 | - $page .= ":" . $url['port']; |
|
87 | + $page .= ":".$url['port']; |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | $page = trim($page, "/"); |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | 'input_name' => $input_name, |
295 | 295 | ]), |
296 | 296 | ]; |
297 | - $results[$entity->name . rand(1, 100)] = $result; |
|
297 | + $results[$entity->name.rand(1, 100)] = $result; |
|
298 | 298 | } |
299 | 299 | } |
300 | 300 | break; |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | 'url' => $entity->getURL(), |
342 | 342 | ]; |
343 | 343 | |
344 | - $results[$entity->name . rand(1, 100)] = $result; |
|
344 | + $results[$entity->name.rand(1, 100)] = $result; |
|
345 | 345 | } |
346 | 346 | } |
347 | 347 | break; |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | 'input_name' => $input_name, |
388 | 388 | ]), |
389 | 389 | ]; |
390 | - $results[$entity->name . rand(1, 100)] = $result; |
|
390 | + $results[$entity->name.rand(1, 100)] = $result; |
|
391 | 391 | } |
392 | 392 | } |
393 | 393 | break; |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | 'font-weight', 'font-style', 'border', 'border-top', 'background-color', |
494 | 494 | 'border-bottom', 'border-left', 'border-right', |
495 | 495 | 'margin', 'margin-top', 'margin-bottom', 'margin-left', |
496 | - 'margin-right', 'padding', 'float', 'text-decoration' |
|
496 | + 'margin-right', 'padding', 'float', 'text-decoration' |
|
497 | 497 | ]; |
498 | 498 | |
499 | 499 | $params = ['tag' => $element]; |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | * @return array |
550 | 550 | */ |
551 | 551 | function _elgg_htmlawed_test($hook, $type, $value, $params) { |
552 | - $value[] = Paths::elgg() . 'engine/tests/simpletest/ElggHtmLawedTest.php'; |
|
552 | + $value[] = Paths::elgg().'engine/tests/simpletest/ElggHtmLawedTest.php'; |
|
553 | 553 | return $value; |
554 | 554 | } |
555 | 555 |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @see elgg_get_ignore_access() |
45 | 45 | */ |
46 | 46 | function elgg_set_ignore_access($ignore = true) { |
47 | - return _elgg_services()->session->setIgnoreAccess($ignore); |
|
47 | + return _elgg_services()->session->setIgnoreAccess($ignore); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @see elgg_set_ignore_access() |
56 | 56 | */ |
57 | 57 | function elgg_get_ignore_access() { |
58 | - return _elgg_services()->session->getIgnoreAccess(); |
|
58 | + return _elgg_services()->session->getIgnoreAccess(); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * @access private |
75 | 75 | */ |
76 | 76 | function get_access_list($user_guid = 0, $ignored = 0, $flush = false) { |
77 | - return _elgg_services()->accessCollections->getAccessList($user_guid, $flush); |
|
77 | + return _elgg_services()->accessCollections->getAccessList($user_guid, $flush); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * @return array An array of access collections ids |
104 | 104 | */ |
105 | 105 | function get_access_array($user_guid = 0, $ignored = 0, $flush = false) { |
106 | - return _elgg_services()->accessCollections->getAccessArray($user_guid, $flush); |
|
106 | + return _elgg_services()->accessCollections->getAccessArray($user_guid, $flush); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -119,26 +119,26 @@ discard block |
||
119 | 119 | * @return int default access id (see ACCESS defines in elgglib.php) |
120 | 120 | */ |
121 | 121 | function get_default_access(ElggUser $user = null, array $input_params = []) { |
122 | - // site default access |
|
123 | - $default_access = _elgg_config()->default_access; |
|
124 | - |
|
125 | - // user default access if enabled |
|
126 | - if (_elgg_config()->allow_user_default_access) { |
|
127 | - $user = $user ? $user : _elgg_services()->session->getLoggedInUser(); |
|
128 | - if ($user) { |
|
129 | - $user_access = $user->getPrivateSetting('elgg_default_access'); |
|
130 | - if ($user_access !== null) { |
|
131 | - $default_access = $user_access; |
|
132 | - } |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - $params = [ |
|
137 | - 'user' => $user, |
|
138 | - 'default_access' => $default_access, |
|
139 | - 'input_params' => $input_params, |
|
140 | - ]; |
|
141 | - return _elgg_services()->hooks->trigger('default', 'access', $params, $default_access); |
|
122 | + // site default access |
|
123 | + $default_access = _elgg_config()->default_access; |
|
124 | + |
|
125 | + // user default access if enabled |
|
126 | + if (_elgg_config()->allow_user_default_access) { |
|
127 | + $user = $user ? $user : _elgg_services()->session->getLoggedInUser(); |
|
128 | + if ($user) { |
|
129 | + $user_access = $user->getPrivateSetting('elgg_default_access'); |
|
130 | + if ($user_access !== null) { |
|
131 | + $default_access = $user_access; |
|
132 | + } |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + $params = [ |
|
137 | + 'user' => $user, |
|
138 | + 'default_access' => $default_access, |
|
139 | + 'input_params' => $input_params, |
|
140 | + ]; |
|
141 | + return _elgg_services()->hooks->trigger('default', 'access', $params, $default_access); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
@@ -157,10 +157,10 @@ discard block |
||
157 | 157 | * @return bool |
158 | 158 | */ |
159 | 159 | function access_show_hidden_entities($show_hidden) { |
160 | - global $ENTITY_SHOW_HIDDEN_OVERRIDE; |
|
161 | - $current_value = $ENTITY_SHOW_HIDDEN_OVERRIDE; |
|
162 | - $ENTITY_SHOW_HIDDEN_OVERRIDE = $show_hidden; |
|
163 | - return $current_value; |
|
160 | + global $ENTITY_SHOW_HIDDEN_OVERRIDE; |
|
161 | + $current_value = $ENTITY_SHOW_HIDDEN_OVERRIDE; |
|
162 | + $ENTITY_SHOW_HIDDEN_OVERRIDE = $show_hidden; |
|
163 | + return $current_value; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | * @return bool |
170 | 170 | */ |
171 | 171 | function access_get_show_hidden_status() { |
172 | - global $ENTITY_SHOW_HIDDEN_OVERRIDE; |
|
173 | - return $ENTITY_SHOW_HIDDEN_OVERRIDE; |
|
172 | + global $ENTITY_SHOW_HIDDEN_OVERRIDE; |
|
173 | + return $ENTITY_SHOW_HIDDEN_OVERRIDE; |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | * @access private |
214 | 214 | */ |
215 | 215 | function _elgg_get_access_where_sql(array $options = []) { |
216 | - return _elgg_services()->accessCollections->getWhereSql($options); |
|
216 | + return _elgg_services()->accessCollections->getWhereSql($options); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | * @return bool |
237 | 237 | */ |
238 | 238 | function has_access_to_entity($entity, $user = null) { |
239 | - return _elgg_services()->accessCollections->hasAccessToEntity($entity, $user); |
|
239 | + return _elgg_services()->accessCollections->hasAccessToEntity($entity, $user); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | * @return array List of access permissions |
267 | 267 | */ |
268 | 268 | function get_write_access_array($user_guid = 0, $ignored = 0, $flush = false, array $input_params = []) { |
269 | - return _elgg_services()->accessCollections->getWriteAccessArray($user_guid, $flush, $input_params); |
|
269 | + return _elgg_services()->accessCollections->getWriteAccessArray($user_guid, $flush, $input_params); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | /** |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | * @return bool |
285 | 285 | */ |
286 | 286 | function can_edit_access_collection($collection_id, $user_guid = null) { |
287 | - return _elgg_services()->accessCollections->canEdit($collection_id, $user_guid); |
|
287 | + return _elgg_services()->accessCollections->canEdit($collection_id, $user_guid); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /** |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | * @see delete_access_collection() |
307 | 307 | */ |
308 | 308 | function create_access_collection($name, $owner_guid = 0) { |
309 | - return _elgg_services()->accessCollections->create($name, $owner_guid); |
|
309 | + return _elgg_services()->accessCollections->create($name, $owner_guid); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | /** |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | * @see remove_user_from_access_collection() |
327 | 327 | */ |
328 | 328 | function update_access_collection($collection_id, $members) { |
329 | - return _elgg_services()->accessCollections->update($collection_id, $members); |
|
329 | + return _elgg_services()->accessCollections->update($collection_id, $members); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | /** |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | * @see update_access_collection() |
340 | 340 | */ |
341 | 341 | function delete_access_collection($collection_id) { |
342 | - return _elgg_services()->accessCollections->delete($collection_id); |
|
342 | + return _elgg_services()->accessCollections->delete($collection_id); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | /** |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | * @return ElggAccessCollection|false |
356 | 356 | */ |
357 | 357 | function get_access_collection($collection_id) { |
358 | - return _elgg_services()->accessCollections->get($collection_id); |
|
358 | + return _elgg_services()->accessCollections->get($collection_id); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | /** |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | * @see remove_user_from_access_collection() |
372 | 372 | */ |
373 | 373 | function add_user_to_access_collection($user_guid, $collection_id) { |
374 | - return _elgg_services()->accessCollections->addUser($user_guid, $collection_id); |
|
374 | + return _elgg_services()->accessCollections->addUser($user_guid, $collection_id); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | /** |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | * @see remove_user_from_access_collection() |
388 | 388 | */ |
389 | 389 | function remove_user_from_access_collection($user_guid, $collection_id) { |
390 | - return _elgg_services()->accessCollections->removeUser($user_guid, $collection_id); |
|
390 | + return _elgg_services()->accessCollections->removeUser($user_guid, $collection_id); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | /** |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | * @return \ElggAccessCollection[]|false |
401 | 401 | */ |
402 | 402 | function get_user_access_collections($owner_guid) { |
403 | - return _elgg_services()->accessCollections->getEntityCollections($owner_guid); |
|
403 | + return _elgg_services()->accessCollections->getEntityCollections($owner_guid); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | /** |
@@ -414,21 +414,21 @@ discard block |
||
414 | 414 | * @see add_user_to_access_collection() |
415 | 415 | */ |
416 | 416 | function get_members_of_access_collection($collection_id, $guids_only = false, array $options = []) { |
417 | - if (!isset($options['limit'])) { |
|
418 | - $options['limit'] = 0; |
|
419 | - } |
|
420 | - |
|
421 | - if (!$guids_only) { |
|
422 | - return _elgg_services()->accessCollections->getMembers($collection_id, $options); |
|
423 | - } |
|
424 | - |
|
425 | - $guids = []; |
|
426 | - $options['callback'] = false; |
|
427 | - $rows = _elgg_services()->accessCollections->getMembers($collection_id, $options); |
|
428 | - foreach ($rows as $row) { |
|
429 | - $guids[] = $row->guid; |
|
430 | - } |
|
431 | - return $guids; |
|
417 | + if (!isset($options['limit'])) { |
|
418 | + $options['limit'] = 0; |
|
419 | + } |
|
420 | + |
|
421 | + if (!$guids_only) { |
|
422 | + return _elgg_services()->accessCollections->getMembers($collection_id, $options); |
|
423 | + } |
|
424 | + |
|
425 | + $guids = []; |
|
426 | + $options['callback'] = false; |
|
427 | + $rows = _elgg_services()->accessCollections->getMembers($collection_id, $options); |
|
428 | + foreach ($rows as $row) { |
|
429 | + $guids[] = $row->guid; |
|
430 | + } |
|
431 | + return $guids; |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | /** |
@@ -444,25 +444,25 @@ discard block |
||
444 | 444 | * @since 1.7.0 |
445 | 445 | */ |
446 | 446 | function elgg_get_entities_from_access_id(array $options = []) { |
447 | - // restrict the resultset to access collection provided |
|
448 | - if (!isset($options['access_id'])) { |
|
449 | - return false; |
|
450 | - } |
|
451 | - |
|
452 | - // @todo add support for an array of collection_ids |
|
453 | - $where = "e.access_id = '{$options['access_id']}'"; |
|
454 | - if (isset($options['wheres'])) { |
|
455 | - if (is_array($options['wheres'])) { |
|
456 | - $options['wheres'][] = $where; |
|
457 | - } else { |
|
458 | - $options['wheres'] = [$options['wheres'], $where]; |
|
459 | - } |
|
460 | - } else { |
|
461 | - $options['wheres'] = [$where]; |
|
462 | - } |
|
463 | - |
|
464 | - // return entities with the desired options |
|
465 | - return _elgg_services()->entityTable->getEntities($options); |
|
447 | + // restrict the resultset to access collection provided |
|
448 | + if (!isset($options['access_id'])) { |
|
449 | + return false; |
|
450 | + } |
|
451 | + |
|
452 | + // @todo add support for an array of collection_ids |
|
453 | + $where = "e.access_id = '{$options['access_id']}'"; |
|
454 | + if (isset($options['wheres'])) { |
|
455 | + if (is_array($options['wheres'])) { |
|
456 | + $options['wheres'][] = $where; |
|
457 | + } else { |
|
458 | + $options['wheres'] = [$options['wheres'], $where]; |
|
459 | + } |
|
460 | + } else { |
|
461 | + $options['wheres'] = [$where]; |
|
462 | + } |
|
463 | + |
|
464 | + // return entities with the desired options |
|
465 | + return _elgg_services()->entityTable->getEntities($options); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | /** |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | * @return string |
477 | 477 | */ |
478 | 478 | function elgg_list_entities_from_access_id(array $options = []) { |
479 | - return elgg_list_entities($options, 'elgg_get_entities_from_access_id'); |
|
479 | + return elgg_list_entities($options, 'elgg_get_entities_from_access_id'); |
|
480 | 480 | } |
481 | 481 | |
482 | 482 | /** |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | * @since 1.7.0 |
497 | 497 | */ |
498 | 498 | function get_readable_access_level($entity_access_id) { |
499 | - return _elgg_services()->accessCollections->getReadableAccessLevel($entity_access_id); |
|
499 | + return _elgg_services()->accessCollections->getReadableAccessLevel($entity_access_id); |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | /** |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | * @return void |
508 | 508 | */ |
509 | 509 | function access_init() { |
510 | - _elgg_services()->accessCollections->markInitComplete(); |
|
510 | + _elgg_services()->accessCollections->markInitComplete(); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | /** |
@@ -522,18 +522,18 @@ discard block |
||
522 | 522 | * @access private |
523 | 523 | */ |
524 | 524 | function access_test($hook, $type, $value, $params) { |
525 | - $value[] = Paths::elgg() . 'engine/tests/simpletest/ElggCoreAccessCollectionsTest.php'; |
|
526 | - $value[] = Paths::elgg() . 'engine/tests/simpletest/ElggCoreAccessSQLTest.php'; |
|
527 | - return $value; |
|
525 | + $value[] = Paths::elgg() . 'engine/tests/simpletest/ElggCoreAccessCollectionsTest.php'; |
|
526 | + $value[] = Paths::elgg() . 'engine/tests/simpletest/ElggCoreAccessSQLTest.php'; |
|
527 | + return $value; |
|
528 | 528 | } |
529 | 529 | |
530 | 530 | /** |
531 | 531 | * @see \Elgg\Application::loadCore Do not do work here. Just register for events. |
532 | 532 | */ |
533 | 533 | return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
534 | - // Tell the access functions the system has booted, plugins are loaded, |
|
535 | - // and the user is logged in so it can start caching |
|
536 | - $events->registerHandler('ready', 'system', 'access_init'); |
|
534 | + // Tell the access functions the system has booted, plugins are loaded, |
|
535 | + // and the user is logged in so it can start caching |
|
536 | + $events->registerHandler('ready', 'system', 'access_init'); |
|
537 | 537 | |
538 | - $hooks->registerHandler('unit_test', 'system', 'access_test'); |
|
538 | + $hooks->registerHandler('unit_test', 'system', 'access_test'); |
|
539 | 539 | }; |
@@ -522,8 +522,8 @@ |
||
522 | 522 | * @access private |
523 | 523 | */ |
524 | 524 | function access_test($hook, $type, $value, $params) { |
525 | - $value[] = Paths::elgg() . 'engine/tests/simpletest/ElggCoreAccessCollectionsTest.php'; |
|
526 | - $value[] = Paths::elgg() . 'engine/tests/simpletest/ElggCoreAccessSQLTest.php'; |
|
525 | + $value[] = Paths::elgg().'engine/tests/simpletest/ElggCoreAccessCollectionsTest.php'; |
|
526 | + $value[] = Paths::elgg().'engine/tests/simpletest/ElggCoreAccessSQLTest.php'; |
|
527 | 527 | return $value; |
528 | 528 | } |
529 | 529 |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | * @return \ElggRelationship|false False if not found |
17 | 17 | */ |
18 | 18 | function get_relationship($id) { |
19 | - return _elgg_services()->relationshipsTable->get($id); |
|
19 | + return _elgg_services()->relationshipsTable->get($id); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * @return bool |
28 | 28 | */ |
29 | 29 | function delete_relationship($id) { |
30 | - return _elgg_services()->relationshipsTable->delete($id); |
|
30 | + return _elgg_services()->relationshipsTable->delete($id); |
|
31 | 31 | |
32 | 32 | } |
33 | 33 | |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * @throws InvalidArgumentException |
46 | 46 | */ |
47 | 47 | function add_entity_relationship($guid_one, $relationship, $guid_two) { |
48 | - return _elgg_services()->relationshipsTable->add($guid_one, $relationship, $guid_two); |
|
48 | + return _elgg_services()->relationshipsTable->add($guid_one, $relationship, $guid_two); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @return \ElggRelationship|false Depending on success |
61 | 61 | */ |
62 | 62 | function check_entity_relationship($guid_one, $relationship, $guid_two) { |
63 | - return _elgg_services()->relationshipsTable->check($guid_one, $relationship, $guid_two); |
|
63 | + return _elgg_services()->relationshipsTable->check($guid_one, $relationship, $guid_two); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * @return bool |
76 | 76 | */ |
77 | 77 | function remove_entity_relationship($guid_one, $relationship, $guid_two) { |
78 | - return _elgg_services()->relationshipsTable->remove($guid_one, $relationship, $guid_two); |
|
78 | + return _elgg_services()->relationshipsTable->remove($guid_one, $relationship, $guid_two); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @return true |
91 | 91 | */ |
92 | 92 | function remove_entity_relationships($guid, $relationship = "", $inverse_relationship = false, $type = '') { |
93 | - return _elgg_services()->relationshipsTable->removeAll($guid, $relationship, $inverse_relationship, $type); |
|
93 | + return _elgg_services()->relationshipsTable->removeAll($guid, $relationship, $inverse_relationship, $type); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * @return \ElggRelationship[] |
104 | 104 | */ |
105 | 105 | function get_entity_relationships($guid, $inverse_relationship = false) { |
106 | - return _elgg_services()->relationshipsTable->getAll($guid, $inverse_relationship); |
|
106 | + return _elgg_services()->relationshipsTable->getAll($guid, $inverse_relationship); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @since 1.7.0 |
189 | 189 | */ |
190 | 190 | function elgg_get_entities_from_relationship($options) { |
191 | - return _elgg_services()->relationshipsTable->getEntities($options); |
|
191 | + return _elgg_services()->relationshipsTable->getEntities($options); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -207,9 +207,9 @@ discard block |
||
207 | 207 | * @access private |
208 | 208 | */ |
209 | 209 | function elgg_get_entity_relationship_where_sql($column, $relationship = null, |
210 | - $relationship_guid = null, $inverse_relationship = false) { |
|
211 | - return _elgg_services()->relationshipsTable->getEntityRelationshipWhereSql( |
|
212 | - $column, $relationship, $relationship_guid, $inverse_relationship); |
|
210 | + $relationship_guid = null, $inverse_relationship = false) { |
|
211 | + return _elgg_services()->relationshipsTable->getEntityRelationshipWhereSql( |
|
212 | + $column, $relationship, $relationship_guid, $inverse_relationship); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | * @return string The viewable list of entities |
224 | 224 | */ |
225 | 225 | function elgg_list_entities_from_relationship(array $options = []) { |
226 | - return elgg_list_entities($options, 'elgg_get_entities_from_relationship'); |
|
226 | + return elgg_list_entities($options, 'elgg_get_entities_from_relationship'); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | * @since 1.8.0 |
238 | 238 | */ |
239 | 239 | function elgg_get_entities_from_relationship_count(array $options = []) { |
240 | - return _elgg_services()->relationshipsTable->getEntitiesFromCount($options); |
|
240 | + return _elgg_services()->relationshipsTable->getEntitiesFromCount($options); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * @since 1.8.0 |
252 | 252 | */ |
253 | 253 | function elgg_list_entities_from_relationship_count($options) { |
254 | - return elgg_list_entities($options, 'elgg_get_entities_from_relationship_count'); |
|
254 | + return elgg_list_entities($options, 'elgg_get_entities_from_relationship_count'); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
@@ -264,8 +264,8 @@ discard block |
||
264 | 264 | * @access private |
265 | 265 | */ |
266 | 266 | function _elgg_relationships_test($hook, $type, $tests) { |
267 | - $tests[] = Paths::elgg() . 'engine/tests/simpletest/ElggRelationshipTest.php'; |
|
268 | - return $tests; |
|
267 | + $tests[] = Paths::elgg() . 'engine/tests/simpletest/ElggRelationshipTest.php'; |
|
268 | + return $tests; |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | |
@@ -274,12 +274,12 @@ discard block |
||
274 | 274 | * @access private |
275 | 275 | */ |
276 | 276 | function _elgg_relationship_init() { |
277 | - elgg_register_plugin_hook_handler('unit_test', 'system', '_elgg_relationships_test'); |
|
277 | + elgg_register_plugin_hook_handler('unit_test', 'system', '_elgg_relationships_test'); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
281 | 281 | * @see \Elgg\Application::loadCore Do not do work here. Just register for events. |
282 | 282 | */ |
283 | 283 | return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
284 | - $events->registerHandler('init', 'system', '_elgg_relationship_init'); |
|
284 | + $events->registerHandler('init', 'system', '_elgg_relationship_init'); |
|
285 | 285 | }; |
@@ -264,7 +264,7 @@ |
||
264 | 264 | * @access private |
265 | 265 | */ |
266 | 266 | function _elgg_relationships_test($hook, $type, $tests) { |
267 | - $tests[] = Paths::elgg() . 'engine/tests/simpletest/ElggRelationshipTest.php'; |
|
267 | + $tests[] = Paths::elgg().'engine/tests/simpletest/ElggRelationshipTest.php'; |
|
268 | 268 | return $tests; |
269 | 269 | } |
270 | 270 |