@@ -13,13 +13,13 @@ |
||
13 | 13 | class CustomHtmlEditorFieldToolbar extends Extension |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @param Form $form |
|
18 | - * @return void |
|
19 | - */ |
|
20 | - public function updateMediaForm(Form $form) |
|
21 | - { |
|
22 | - Requirements::add_i18n_javascript('cwp/cwp-core:javascript/lang'); |
|
23 | - Requirements::javascript('cwp/cwp-core:javascript/CustomHtmlEditorFieldToolbar.js'); |
|
24 | - } |
|
16 | + /** |
|
17 | + * @param Form $form |
|
18 | + * @return void |
|
19 | + */ |
|
20 | + public function updateMediaForm(Form $form) |
|
21 | + { |
|
22 | + Requirements::add_i18n_javascript('cwp/cwp-core:javascript/lang'); |
|
23 | + Requirements::javascript('cwp/cwp-core:javascript/CustomHtmlEditorFieldToolbar.js'); |
|
24 | + } |
|
25 | 25 | } |
@@ -18,194 +18,194 @@ |
||
18 | 18 | class CwpControllerExtension extends Extension implements PermissionProvider |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * Enables SSL redirections - disabling not recommended as it will prevent forcing SSL on admin panel. |
|
23 | - * |
|
24 | - * @config |
|
25 | - * @var bool |
|
26 | - */ |
|
27 | - private static $ssl_redirection_enabled = true; |
|
28 | - |
|
29 | - /** |
|
30 | - * Specify a domain to redirect the vulnerable areas to. |
|
31 | - * |
|
32 | - * If left as null, live instance will set this to <instance-id>.cwp.govt.nz via CWP_SECURE_DOMAIN in _config.php. |
|
33 | - * This allows us to automatically protect vulnerable areas on live even if the frontend cert is not installed. |
|
34 | - * |
|
35 | - * Set to false to redirect to https protocol on current domain (e.g. if you have frontend cert). |
|
36 | - * |
|
37 | - * Set to a domain string (e.g. 'example.com') to force that domain. |
|
38 | - * |
|
39 | - * @config |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - private static $ssl_redirection_force_domain = null; |
|
43 | - |
|
44 | - /** |
|
45 | - * Enables the BasicAuth protection on all test environments. Disable with caution - it will open up |
|
46 | - * all your UAT and test environments to the world. |
|
47 | - * |
|
48 | - * @config |
|
49 | - * @var bool |
|
50 | - */ |
|
51 | - private static $test_basicauth_enabled = true; |
|
52 | - |
|
53 | - /** |
|
54 | - * Enables the BasicAuth protection on all live environments. |
|
55 | - * Useful for securing sites prior to public launch. |
|
56 | - * |
|
57 | - * @config |
|
58 | - * @var bool |
|
59 | - */ |
|
60 | - private static $live_basicauth_enabled = false; |
|
61 | - |
|
62 | - /** |
|
63 | - * This executes the passed callback with subsite filter disabled, |
|
64 | - * then enabled the filter again before returning the callback result |
|
65 | - * (or throwing the exception the callback raised) |
|
66 | - * |
|
67 | - * @param callback $callback - The callback to execute |
|
68 | - * @return mixed The result of the callback |
|
69 | - * @throws Exception Any exception the callback raised |
|
70 | - */ |
|
71 | - protected function callWithSubsitesDisabled($callback) |
|
72 | - { |
|
73 | - $rv = null; |
|
74 | - |
|
75 | - try { |
|
76 | - if (class_exists(Subsite::class)) { |
|
77 | - Subsite::disable_subsite_filter(true); |
|
78 | - } |
|
79 | - |
|
80 | - $rv = call_user_func($callback); |
|
81 | - } catch (Exception $e) { |
|
82 | - if (class_exists(Subsite::class)) { |
|
83 | - Subsite::disable_subsite_filter(false); |
|
84 | - } |
|
85 | - |
|
86 | - throw $e; |
|
87 | - } |
|
88 | - |
|
89 | - if (class_exists(Subsite::class)) { |
|
90 | - Subsite::disable_subsite_filter(false); |
|
91 | - } |
|
92 | - |
|
93 | - return $rv; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Trigger Basic Auth protection, except when there's a reason to bypass it |
|
98 | - * - The source IP address is in the comma-seperated string in the constant CWP_IP_BYPASS_BASICAUTH |
|
99 | - * (so Pingdom, etc, can access the site) |
|
100 | - * - There is an identifiable member, that member has the ACCESS_UAT_SERVER permission, and they're trying |
|
101 | - * to access a white-list of URLs (so people following a reset password link can reset their password) |
|
102 | - */ |
|
103 | - protected function triggerBasicAuthProtection() |
|
104 | - { |
|
105 | - $allowWithoutAuth = false; |
|
106 | - |
|
107 | - // Allow whitelisting IPs for bypassing the basic auth. |
|
108 | - if (Environment::getEnv('CWP_IP_BYPASS_BASICAUTH')) { |
|
109 | - $remote = $_SERVER['REMOTE_ADDR']; |
|
110 | - $bypass = explode(',', Environment::getEnv('CWP_IP_BYPASS_BASICAUTH')); |
|
111 | - |
|
112 | - if (in_array($remote, $bypass)) { |
|
113 | - $allowWithoutAuth = true; |
|
114 | - } |
|
115 | - } |
|
116 | - |
|
117 | - // First, see if we can get a member to act on, either from a changepassword token or the session |
|
118 | - if (isset($_REQUEST['m']) && isset($_REQUEST['t'])) { |
|
119 | - $member = Member::get()->filter('ID', (int) $_REQUEST['m'])->first(); |
|
120 | - |
|
121 | - if (!$member->validateAutoLoginToken($_REQUEST['t'])) { |
|
122 | - $member = null; |
|
123 | - } |
|
124 | - } elseif ($this->owner->getRequest()->getSession()->get('AutoLoginHash')) { |
|
125 | - $member = Member::member_from_autologinhash( |
|
126 | - $this->owner->getRequest()->getSession()->get('AutoLoginHash') |
|
127 | - ); |
|
128 | - } else { |
|
129 | - $member = Security::getCurrentUser(); |
|
130 | - } |
|
131 | - |
|
132 | - // Then, if they have the right permissions, check the allowed URLs |
|
133 | - $existingMemberCanAccessUAT = $member && $this->callWithSubsitesDisabled(function () use ($member) { |
|
134 | - return Permission::checkMember($member, 'ACCESS_UAT_SERVER'); |
|
135 | - }); |
|
136 | - |
|
137 | - if ($existingMemberCanAccessUAT) { |
|
138 | - $allowed = array( |
|
139 | - '/^Security\/changepassword/', |
|
140 | - '/^Security\/ChangePasswordForm/' |
|
141 | - ); |
|
142 | - |
|
143 | - $relativeURL = Director::makeRelative(Director::absoluteURL($_SERVER['REQUEST_URI'])); |
|
144 | - |
|
145 | - foreach ($allowed as $pattern) { |
|
146 | - $allowWithoutAuth = $allowWithoutAuth || preg_match($pattern, $relativeURL); |
|
147 | - } |
|
148 | - } |
|
149 | - |
|
150 | - // Finally if they weren't allowed to bypass Basic Auth, trigger it |
|
151 | - if (!$allowWithoutAuth) { |
|
152 | - $this->callWithSubsitesDisabled(function () { |
|
153 | - BasicAuth::requireLogin( |
|
154 | - $this->owner->getRequest(), |
|
155 | - _t(__CLASS__ . '.LoginPrompt', "Please log in with your CMS credentials"), |
|
156 | - 'ACCESS_UAT_SERVER', |
|
157 | - true |
|
158 | - ); |
|
159 | - }); |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * @return void |
|
165 | - */ |
|
166 | - public function onBeforeInit() |
|
167 | - { |
|
168 | - // Grab global injectable service to allow testing. |
|
169 | - $director = Injector::inst()->get(Director::class); |
|
170 | - |
|
171 | - if (Config::inst()->get(__CLASS__, 'ssl_redirection_enabled')) { |
|
172 | - // redirect some vulnerable areas to the secure domain |
|
173 | - if (!$director::is_https()) { |
|
174 | - $forceDomain = Config::inst()->get(__CLASS__, 'ssl_redirection_force_domain'); |
|
175 | - |
|
176 | - if ($forceDomain) { |
|
177 | - $director::forceSSL(['/^Security/', '/^api/'], $forceDomain); |
|
178 | - } else { |
|
179 | - $director::forceSSL(['/^Security/', '/^api/']); |
|
180 | - } |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - if (Config::inst()->get(__CLASS__, 'test_basicauth_enabled')) { |
|
185 | - // Turn on Basic Auth in testing mode |
|
186 | - if ($director::isTest()) { |
|
187 | - $this->triggerBasicAuthProtection(); |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - if (Config::inst()->get(__CLASS__, 'live_basicauth_enabled')) { |
|
192 | - // Turn on Basic Auth in live mode |
|
193 | - if ($director::isLive()) { |
|
194 | - $this->triggerBasicAuthProtection(); |
|
195 | - } |
|
196 | - } |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * @return array |
|
201 | - */ |
|
202 | - public function providePermissions() |
|
203 | - { |
|
204 | - return [ |
|
205 | - 'ACCESS_UAT_SERVER' => _t( |
|
206 | - __CLASS__ . '.UatServerPermission', |
|
207 | - 'Allow users to use their accounts to access the UAT server' |
|
208 | - ) |
|
209 | - ]; |
|
210 | - } |
|
21 | + /** |
|
22 | + * Enables SSL redirections - disabling not recommended as it will prevent forcing SSL on admin panel. |
|
23 | + * |
|
24 | + * @config |
|
25 | + * @var bool |
|
26 | + */ |
|
27 | + private static $ssl_redirection_enabled = true; |
|
28 | + |
|
29 | + /** |
|
30 | + * Specify a domain to redirect the vulnerable areas to. |
|
31 | + * |
|
32 | + * If left as null, live instance will set this to <instance-id>.cwp.govt.nz via CWP_SECURE_DOMAIN in _config.php. |
|
33 | + * This allows us to automatically protect vulnerable areas on live even if the frontend cert is not installed. |
|
34 | + * |
|
35 | + * Set to false to redirect to https protocol on current domain (e.g. if you have frontend cert). |
|
36 | + * |
|
37 | + * Set to a domain string (e.g. 'example.com') to force that domain. |
|
38 | + * |
|
39 | + * @config |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + private static $ssl_redirection_force_domain = null; |
|
43 | + |
|
44 | + /** |
|
45 | + * Enables the BasicAuth protection on all test environments. Disable with caution - it will open up |
|
46 | + * all your UAT and test environments to the world. |
|
47 | + * |
|
48 | + * @config |
|
49 | + * @var bool |
|
50 | + */ |
|
51 | + private static $test_basicauth_enabled = true; |
|
52 | + |
|
53 | + /** |
|
54 | + * Enables the BasicAuth protection on all live environments. |
|
55 | + * Useful for securing sites prior to public launch. |
|
56 | + * |
|
57 | + * @config |
|
58 | + * @var bool |
|
59 | + */ |
|
60 | + private static $live_basicauth_enabled = false; |
|
61 | + |
|
62 | + /** |
|
63 | + * This executes the passed callback with subsite filter disabled, |
|
64 | + * then enabled the filter again before returning the callback result |
|
65 | + * (or throwing the exception the callback raised) |
|
66 | + * |
|
67 | + * @param callback $callback - The callback to execute |
|
68 | + * @return mixed The result of the callback |
|
69 | + * @throws Exception Any exception the callback raised |
|
70 | + */ |
|
71 | + protected function callWithSubsitesDisabled($callback) |
|
72 | + { |
|
73 | + $rv = null; |
|
74 | + |
|
75 | + try { |
|
76 | + if (class_exists(Subsite::class)) { |
|
77 | + Subsite::disable_subsite_filter(true); |
|
78 | + } |
|
79 | + |
|
80 | + $rv = call_user_func($callback); |
|
81 | + } catch (Exception $e) { |
|
82 | + if (class_exists(Subsite::class)) { |
|
83 | + Subsite::disable_subsite_filter(false); |
|
84 | + } |
|
85 | + |
|
86 | + throw $e; |
|
87 | + } |
|
88 | + |
|
89 | + if (class_exists(Subsite::class)) { |
|
90 | + Subsite::disable_subsite_filter(false); |
|
91 | + } |
|
92 | + |
|
93 | + return $rv; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Trigger Basic Auth protection, except when there's a reason to bypass it |
|
98 | + * - The source IP address is in the comma-seperated string in the constant CWP_IP_BYPASS_BASICAUTH |
|
99 | + * (so Pingdom, etc, can access the site) |
|
100 | + * - There is an identifiable member, that member has the ACCESS_UAT_SERVER permission, and they're trying |
|
101 | + * to access a white-list of URLs (so people following a reset password link can reset their password) |
|
102 | + */ |
|
103 | + protected function triggerBasicAuthProtection() |
|
104 | + { |
|
105 | + $allowWithoutAuth = false; |
|
106 | + |
|
107 | + // Allow whitelisting IPs for bypassing the basic auth. |
|
108 | + if (Environment::getEnv('CWP_IP_BYPASS_BASICAUTH')) { |
|
109 | + $remote = $_SERVER['REMOTE_ADDR']; |
|
110 | + $bypass = explode(',', Environment::getEnv('CWP_IP_BYPASS_BASICAUTH')); |
|
111 | + |
|
112 | + if (in_array($remote, $bypass)) { |
|
113 | + $allowWithoutAuth = true; |
|
114 | + } |
|
115 | + } |
|
116 | + |
|
117 | + // First, see if we can get a member to act on, either from a changepassword token or the session |
|
118 | + if (isset($_REQUEST['m']) && isset($_REQUEST['t'])) { |
|
119 | + $member = Member::get()->filter('ID', (int) $_REQUEST['m'])->first(); |
|
120 | + |
|
121 | + if (!$member->validateAutoLoginToken($_REQUEST['t'])) { |
|
122 | + $member = null; |
|
123 | + } |
|
124 | + } elseif ($this->owner->getRequest()->getSession()->get('AutoLoginHash')) { |
|
125 | + $member = Member::member_from_autologinhash( |
|
126 | + $this->owner->getRequest()->getSession()->get('AutoLoginHash') |
|
127 | + ); |
|
128 | + } else { |
|
129 | + $member = Security::getCurrentUser(); |
|
130 | + } |
|
131 | + |
|
132 | + // Then, if they have the right permissions, check the allowed URLs |
|
133 | + $existingMemberCanAccessUAT = $member && $this->callWithSubsitesDisabled(function () use ($member) { |
|
134 | + return Permission::checkMember($member, 'ACCESS_UAT_SERVER'); |
|
135 | + }); |
|
136 | + |
|
137 | + if ($existingMemberCanAccessUAT) { |
|
138 | + $allowed = array( |
|
139 | + '/^Security\/changepassword/', |
|
140 | + '/^Security\/ChangePasswordForm/' |
|
141 | + ); |
|
142 | + |
|
143 | + $relativeURL = Director::makeRelative(Director::absoluteURL($_SERVER['REQUEST_URI'])); |
|
144 | + |
|
145 | + foreach ($allowed as $pattern) { |
|
146 | + $allowWithoutAuth = $allowWithoutAuth || preg_match($pattern, $relativeURL); |
|
147 | + } |
|
148 | + } |
|
149 | + |
|
150 | + // Finally if they weren't allowed to bypass Basic Auth, trigger it |
|
151 | + if (!$allowWithoutAuth) { |
|
152 | + $this->callWithSubsitesDisabled(function () { |
|
153 | + BasicAuth::requireLogin( |
|
154 | + $this->owner->getRequest(), |
|
155 | + _t(__CLASS__ . '.LoginPrompt', "Please log in with your CMS credentials"), |
|
156 | + 'ACCESS_UAT_SERVER', |
|
157 | + true |
|
158 | + ); |
|
159 | + }); |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * @return void |
|
165 | + */ |
|
166 | + public function onBeforeInit() |
|
167 | + { |
|
168 | + // Grab global injectable service to allow testing. |
|
169 | + $director = Injector::inst()->get(Director::class); |
|
170 | + |
|
171 | + if (Config::inst()->get(__CLASS__, 'ssl_redirection_enabled')) { |
|
172 | + // redirect some vulnerable areas to the secure domain |
|
173 | + if (!$director::is_https()) { |
|
174 | + $forceDomain = Config::inst()->get(__CLASS__, 'ssl_redirection_force_domain'); |
|
175 | + |
|
176 | + if ($forceDomain) { |
|
177 | + $director::forceSSL(['/^Security/', '/^api/'], $forceDomain); |
|
178 | + } else { |
|
179 | + $director::forceSSL(['/^Security/', '/^api/']); |
|
180 | + } |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + if (Config::inst()->get(__CLASS__, 'test_basicauth_enabled')) { |
|
185 | + // Turn on Basic Auth in testing mode |
|
186 | + if ($director::isTest()) { |
|
187 | + $this->triggerBasicAuthProtection(); |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + if (Config::inst()->get(__CLASS__, 'live_basicauth_enabled')) { |
|
192 | + // Turn on Basic Auth in live mode |
|
193 | + if ($director::isLive()) { |
|
194 | + $this->triggerBasicAuthProtection(); |
|
195 | + } |
|
196 | + } |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * @return array |
|
201 | + */ |
|
202 | + public function providePermissions() |
|
203 | + { |
|
204 | + return [ |
|
205 | + 'ACCESS_UAT_SERVER' => _t( |
|
206 | + __CLASS__ . '.UatServerPermission', |
|
207 | + 'Allow users to use their accounts to access the UAT server' |
|
208 | + ) |
|
209 | + ]; |
|
210 | + } |
|
211 | 211 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | |
117 | 117 | // First, see if we can get a member to act on, either from a changepassword token or the session |
118 | 118 | if (isset($_REQUEST['m']) && isset($_REQUEST['t'])) { |
119 | - $member = Member::get()->filter('ID', (int) $_REQUEST['m'])->first(); |
|
119 | + $member = Member::get()->filter('ID', (int)$_REQUEST['m'])->first(); |
|
120 | 120 | |
121 | 121 | if (!$member->validateAutoLoginToken($_REQUEST['t'])) { |
122 | 122 | $member = null; |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | } |
131 | 131 | |
132 | 132 | // Then, if they have the right permissions, check the allowed URLs |
133 | - $existingMemberCanAccessUAT = $member && $this->callWithSubsitesDisabled(function () use ($member) { |
|
133 | + $existingMemberCanAccessUAT = $member && $this->callWithSubsitesDisabled(function() use ($member) { |
|
134 | 134 | return Permission::checkMember($member, 'ACCESS_UAT_SERVER'); |
135 | 135 | }); |
136 | 136 | |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | |
150 | 150 | // Finally if they weren't allowed to bypass Basic Auth, trigger it |
151 | 151 | if (!$allowWithoutAuth) { |
152 | - $this->callWithSubsitesDisabled(function () { |
|
152 | + $this->callWithSubsitesDisabled(function() { |
|
153 | 153 | BasicAuth::requireLogin( |
154 | 154 | $this->owner->getRequest(), |
155 | 155 | _t(__CLASS__ . '.LoginPrompt', "Please log in with your CMS credentials"), |
@@ -7,20 +7,20 @@ |
||
7 | 7 | class CwpHtmlEditorConfig extends DataExtension |
8 | 8 | { |
9 | 9 | |
10 | - /** |
|
11 | - * @return string |
|
12 | - * |
|
13 | - * Override the default HtmlEditorConfig from 'cms' to 'cwp' defined in cwp-core/_config.php |
|
14 | - * However if the group has a custom editor configuration set, use that instead. |
|
15 | - */ |
|
16 | - public function getHtmlEditorConfig() |
|
17 | - { |
|
18 | - $originalConfig = $this->owner->getField("HtmlEditorConfig"); |
|
10 | + /** |
|
11 | + * @return string |
|
12 | + * |
|
13 | + * Override the default HtmlEditorConfig from 'cms' to 'cwp' defined in cwp-core/_config.php |
|
14 | + * However if the group has a custom editor configuration set, use that instead. |
|
15 | + */ |
|
16 | + public function getHtmlEditorConfig() |
|
17 | + { |
|
18 | + $originalConfig = $this->owner->getField("HtmlEditorConfig"); |
|
19 | 19 | |
20 | - if ($originalConfig) { |
|
21 | - return $originalConfig; |
|
22 | - } |
|
20 | + if ($originalConfig) { |
|
21 | + return $originalConfig; |
|
22 | + } |
|
23 | 23 | |
24 | - return 'cwp'; |
|
25 | - } |
|
24 | + return 'cwp'; |
|
25 | + } |
|
26 | 26 | } |
@@ -19,78 +19,78 @@ |
||
19 | 19 | class LoginAttemptNotifications extends Extension |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * |
|
24 | - * @return mixed null |
|
25 | - */ |
|
26 | - public function init() |
|
27 | - { |
|
22 | + /** |
|
23 | + * |
|
24 | + * @return mixed null |
|
25 | + */ |
|
26 | + public function init() |
|
27 | + { |
|
28 | 28 | |
29 | - // Exclude default admin. |
|
30 | - $member = Security::getCurrentUser(); |
|
31 | - if (!$member || !$member->ID) { |
|
32 | - return; |
|
33 | - } |
|
29 | + // Exclude default admin. |
|
30 | + $member = Security::getCurrentUser(); |
|
31 | + if (!$member || !$member->ID) { |
|
32 | + return; |
|
33 | + } |
|
34 | 34 | |
35 | - $message = null; |
|
36 | - $session = $this->owner->getRequest()->getSession(); |
|
35 | + $message = null; |
|
36 | + $session = $this->owner->getRequest()->getSession(); |
|
37 | 37 | |
38 | - Requirements::javascript('cwp/cwp-core:javascript/LoginAttemptNotifications.js'); |
|
39 | - $sessionLastVisited = $session->get('LoginAttemptNotifications.SessionLastVisited'); |
|
40 | - if ($sessionLastVisited) { |
|
41 | - // Session already in progress. Show all attempts since the session was last visited. |
|
38 | + Requirements::javascript('cwp/cwp-core:javascript/LoginAttemptNotifications.js'); |
|
39 | + $sessionLastVisited = $session->get('LoginAttemptNotifications.SessionLastVisited'); |
|
40 | + if ($sessionLastVisited) { |
|
41 | + // Session already in progress. Show all attempts since the session was last visited. |
|
42 | 42 | |
43 | - $meantimeLoginAttempts = LoginAttempt::get()->filter([ |
|
44 | - 'MemberID' => $member->ID, |
|
45 | - 'Created:GreaterThan' => $sessionLastVisited |
|
46 | - ]); |
|
43 | + $meantimeLoginAttempts = LoginAttempt::get()->filter([ |
|
44 | + 'MemberID' => $member->ID, |
|
45 | + 'Created:GreaterThan' => $sessionLastVisited |
|
46 | + ]); |
|
47 | 47 | |
48 | - $attempts = $meantimeLoginAttempts->count(); |
|
49 | - if ($attempts) { |
|
50 | - $lastVisitedObj = DBDatetime::create(); |
|
51 | - $lastVisitedObj->setValue($sessionLastVisited); |
|
52 | - $elapsed = $lastVisitedObj->TimeDiff(); |
|
53 | - $failures = $meantimeLoginAttempts->filter(['Status' => 'Failure'])->count(); |
|
54 | - $IPs = array_unique($meantimeLoginAttempts->column('IP')); |
|
48 | + $attempts = $meantimeLoginAttempts->count(); |
|
49 | + if ($attempts) { |
|
50 | + $lastVisitedObj = DBDatetime::create(); |
|
51 | + $lastVisitedObj->setValue($sessionLastVisited); |
|
52 | + $elapsed = $lastVisitedObj->TimeDiff(); |
|
53 | + $failures = $meantimeLoginAttempts->filter(['Status' => 'Failure'])->count(); |
|
54 | + $IPs = array_unique($meantimeLoginAttempts->column('IP')); |
|
55 | 55 | |
56 | - if ($attempts == 1) { |
|
57 | - $statusString = $failures ? "a failed" : "a successful"; |
|
58 | - $message = "In the last $elapsed $statusString login attempt to your account was " |
|
59 | - . "registered. The attempt was made from ${IPs[0]}. "; |
|
60 | - } else { |
|
61 | - if ($failures == $attempts) { |
|
62 | - $statusString = $failures ? "failed" : "successful"; |
|
63 | - $message = "In the last $elapsed $attempts $statusString login " |
|
64 | - . "attempts to your account were registered. "; |
|
65 | - } else { |
|
66 | - $message = "In the last $elapsed $attempts login attempts to your " |
|
67 | - . "account were registered, of which $failures failed. "; |
|
68 | - } |
|
56 | + if ($attempts == 1) { |
|
57 | + $statusString = $failures ? "a failed" : "a successful"; |
|
58 | + $message = "In the last $elapsed $statusString login attempt to your account was " |
|
59 | + . "registered. The attempt was made from ${IPs[0]}. "; |
|
60 | + } else { |
|
61 | + if ($failures == $attempts) { |
|
62 | + $statusString = $failures ? "failed" : "successful"; |
|
63 | + $message = "In the last $elapsed $attempts $statusString login " |
|
64 | + . "attempts to your account were registered. "; |
|
65 | + } else { |
|
66 | + $message = "In the last $elapsed $attempts login attempts to your " |
|
67 | + . "account were registered, of which $failures failed. "; |
|
68 | + } |
|
69 | 69 | |
70 | - $message .= "The attempts were from " . implode(', ', $IPs) . '. '; |
|
70 | + $message .= "The attempts were from " . implode(', ', $IPs) . '. '; |
|
71 | 71 | |
72 | - // TODO: add this call to action in a way that doesn't break out of the availabel space. Fix CSS? |
|
73 | - // $message .= "If you suspect somebody else might be trying to access |
|
74 | - // . "your account, please contact support."; |
|
75 | - } |
|
76 | - } |
|
77 | - } else { |
|
78 | - // New session - show last login attempt. |
|
79 | - // TODO: this currently does NOT surface to the frontend in any way. |
|
80 | - $lastLoginAttempt = LoginAttempt::get()->filter([ |
|
81 | - 'MemberID' => $member->ID |
|
82 | - ])->sort('Created DESC')->First(); |
|
72 | + // TODO: add this call to action in a way that doesn't break out of the availabel space. Fix CSS? |
|
73 | + // $message .= "If you suspect somebody else might be trying to access |
|
74 | + // . "your account, please contact support."; |
|
75 | + } |
|
76 | + } |
|
77 | + } else { |
|
78 | + // New session - show last login attempt. |
|
79 | + // TODO: this currently does NOT surface to the frontend in any way. |
|
80 | + $lastLoginAttempt = LoginAttempt::get()->filter([ |
|
81 | + 'MemberID' => $member->ID |
|
82 | + ])->sort('Created DESC')->First(); |
|
83 | 83 | |
84 | - if ($lastLoginAttempt) { |
|
85 | - $date = $lastLoginAttempt->Created; |
|
86 | - $message = "Last login attempt to your account was on $lastLoginAttempt->Created " |
|
87 | - . "from $lastLoginAttempt->IP"; |
|
88 | - $message .= $lastLoginAttempt->Status == 'Failure' ? " and was successful." : "and has failed."; |
|
89 | - } |
|
90 | - } |
|
84 | + if ($lastLoginAttempt) { |
|
85 | + $date = $lastLoginAttempt->Created; |
|
86 | + $message = "Last login attempt to your account was on $lastLoginAttempt->Created " |
|
87 | + . "from $lastLoginAttempt->IP"; |
|
88 | + $message .= $lastLoginAttempt->Status == 'Failure' ? " and was successful." : "and has failed."; |
|
89 | + } |
|
90 | + } |
|
91 | 91 | |
92 | - $session->set('LoginAttemptNotifications.SessionLastVisited', DBDatetime::now()->Format('Y-m-d H:i:s')); |
|
92 | + $session->set('LoginAttemptNotifications.SessionLastVisited', DBDatetime::now()->Format('Y-m-d H:i:s')); |
|
93 | 93 | |
94 | - $this->owner->getResponse()->addHeader('X-LoginAttemptNotifications', $message); |
|
95 | - } |
|
94 | + $this->owner->getResponse()->addHeader('X-LoginAttemptNotifications', $message); |
|
95 | + } |
|
96 | 96 | } |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | $failures = $meantimeLoginAttempts->filter(['Status' => 'Failure'])->count(); |
54 | 54 | $IPs = array_unique($meantimeLoginAttempts->column('IP')); |
55 | 55 | |
56 | - if ($attempts == 1) { |
|
56 | + if ($attempts==1) { |
|
57 | 57 | $statusString = $failures ? "a failed" : "a successful"; |
58 | 58 | $message = "In the last $elapsed $statusString login attempt to your account was " |
59 | 59 | . "registered. The attempt was made from ${IPs[0]}. "; |
60 | 60 | } else { |
61 | - if ($failures == $attempts) { |
|
61 | + if ($failures==$attempts) { |
|
62 | 62 | $statusString = $failures ? "failed" : "successful"; |
63 | 63 | $message = "In the last $elapsed $attempts $statusString login " |
64 | 64 | . "attempts to your account were registered. "; |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $date = $lastLoginAttempt->Created; |
86 | 86 | $message = "Last login attempt to your account was on $lastLoginAttempt->Created " |
87 | 87 | . "from $lastLoginAttempt->IP"; |
88 | - $message .= $lastLoginAttempt->Status == 'Failure' ? " and was successful." : "and has failed."; |
|
88 | + $message .= $lastLoginAttempt->Status=='Failure' ? " and was successful." : "and has failed."; |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 |
@@ -9,22 +9,22 @@ |
||
9 | 9 | */ |
10 | 10 | class CwpSolrIndex extends CwpSearchIndex |
11 | 11 | { |
12 | - public function init() |
|
13 | - { |
|
14 | - $this->addClass(SiteTree::class); |
|
12 | + public function init() |
|
13 | + { |
|
14 | + $this->addClass(SiteTree::class); |
|
15 | 15 | |
16 | - // By default, we only add text fields that are 'visible' to users (where the content is directly visible on |
|
17 | - // the website), along with the 'meta' fields that are commonly used to boost / refine search results |
|
18 | - $this->addFulltextField('Title'); |
|
19 | - $this->addFulltextField('MenuTitle'); |
|
20 | - $this->addFulltextField('Content'); |
|
21 | - $this->addFulltextField('MetaDescription'); |
|
22 | - $this->addFulltextField('ExtraMeta'); |
|
16 | + // By default, we only add text fields that are 'visible' to users (where the content is directly visible on |
|
17 | + // the website), along with the 'meta' fields that are commonly used to boost / refine search results |
|
18 | + $this->addFulltextField('Title'); |
|
19 | + $this->addFulltextField('MenuTitle'); |
|
20 | + $this->addFulltextField('Content'); |
|
21 | + $this->addFulltextField('MetaDescription'); |
|
22 | + $this->addFulltextField('ExtraMeta'); |
|
23 | 23 | |
24 | - // Adds 'ShowInSearch' boolean field to Solr document so we can later ensure that only documents included in |
|
25 | - // search are returned by Solr. |
|
26 | - $this->addFilterField('ShowInSearch'); |
|
24 | + // Adds 'ShowInSearch' boolean field to Solr document so we can later ensure that only documents included in |
|
25 | + // search are returned by Solr. |
|
26 | + $this->addFilterField('ShowInSearch'); |
|
27 | 27 | |
28 | - parent::init(); |
|
29 | - } |
|
28 | + parent::init(); |
|
29 | + } |
|
30 | 30 | } |
@@ -18,86 +18,86 @@ |
||
18 | 18 | abstract class CwpSearchIndex extends SolrIndex |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * Copy all fields into both search and spellcheck data source |
|
23 | - * |
|
24 | - * @var array |
|
25 | - * @config |
|
26 | - */ |
|
27 | - private static $copy_fields = array( |
|
28 | - '_text', |
|
29 | - '_spellcheckText' |
|
30 | - ); |
|
21 | + /** |
|
22 | + * Copy all fields into both search and spellcheck data source |
|
23 | + * |
|
24 | + * @var array |
|
25 | + * @config |
|
26 | + */ |
|
27 | + private static $copy_fields = array( |
|
28 | + '_text', |
|
29 | + '_spellcheckText' |
|
30 | + ); |
|
31 | 31 | |
32 | - /** |
|
33 | - * Default dictionary to use. This will overwrite the 'spellcheck.dictionary' option for searches given, |
|
34 | - * unless set to empty. |
|
35 | - * |
|
36 | - * '_spellcheck' is a predefined by the cwp infrastructure, which is configured |
|
37 | - * to be built from the '_spellcheckText' field. You can't rename this within CWP. |
|
38 | - * |
|
39 | - * @var string |
|
40 | - * @config |
|
41 | - */ |
|
42 | - private static $dictionary = '_spellcheck'; |
|
32 | + /** |
|
33 | + * Default dictionary to use. This will overwrite the 'spellcheck.dictionary' option for searches given, |
|
34 | + * unless set to empty. |
|
35 | + * |
|
36 | + * '_spellcheck' is a predefined by the cwp infrastructure, which is configured |
|
37 | + * to be built from the '_spellcheckText' field. You can't rename this within CWP. |
|
38 | + * |
|
39 | + * @var string |
|
40 | + * @config |
|
41 | + */ |
|
42 | + private static $dictionary = '_spellcheck'; |
|
43 | 43 | |
44 | - public function init() |
|
45 | - { |
|
46 | - // Add optional boost |
|
47 | - if (SiteTree::has_extension(CwpSearchBoostExtension::class)) { |
|
48 | - $this->setFieldBoosting(SiteTree::class . '_SearchBoost', SiteTree::config()->get('search_boost')); |
|
49 | - } |
|
50 | - } |
|
44 | + public function init() |
|
45 | + { |
|
46 | + // Add optional boost |
|
47 | + if (SiteTree::has_extension(CwpSearchBoostExtension::class)) { |
|
48 | + $this->setFieldBoosting(SiteTree::class . '_SearchBoost', SiteTree::config()->get('search_boost')); |
|
49 | + } |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Upload config for this index to the given store |
|
54 | - * |
|
55 | - * @param SolrConfigStore $store |
|
56 | - */ |
|
57 | - public function uploadConfig($store) |
|
58 | - { |
|
59 | - parent::uploadConfig($store); |
|
52 | + /** |
|
53 | + * Upload config for this index to the given store |
|
54 | + * |
|
55 | + * @param SolrConfigStore $store |
|
56 | + */ |
|
57 | + public function uploadConfig($store) |
|
58 | + { |
|
59 | + parent::uploadConfig($store); |
|
60 | 60 | |
61 | - // Upload configured synonyms {@see SynonymsSiteConfig} |
|
62 | - $siteConfig = SiteConfig::current_site_config(); |
|
63 | - if ($siteConfig->SearchSynonyms) { |
|
64 | - $store->uploadString( |
|
65 | - $this->getIndexName(), |
|
66 | - 'synonyms.txt', |
|
67 | - $siteConfig->SearchSynonyms |
|
68 | - ); |
|
69 | - } |
|
70 | - } |
|
61 | + // Upload configured synonyms {@see SynonymsSiteConfig} |
|
62 | + $siteConfig = SiteConfig::current_site_config(); |
|
63 | + if ($siteConfig->SearchSynonyms) { |
|
64 | + $store->uploadString( |
|
65 | + $this->getIndexName(), |
|
66 | + 'synonyms.txt', |
|
67 | + $siteConfig->SearchSynonyms |
|
68 | + ); |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - public function getFieldDefinitions() |
|
77 | - { |
|
78 | - $xml = parent::getFieldDefinitions(); |
|
79 | - $xml .= "\n\n\t\t<!-- Additional custom fields for spell checking -->"; |
|
80 | - $xml .= "\n\t\t<field name='_spellcheckText' type='textSpellHtml' indexed='true' " |
|
81 | - . "stored='false' multiValued='true' />"; |
|
72 | + /** |
|
73 | + * |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + public function getFieldDefinitions() |
|
77 | + { |
|
78 | + $xml = parent::getFieldDefinitions(); |
|
79 | + $xml .= "\n\n\t\t<!-- Additional custom fields for spell checking -->"; |
|
80 | + $xml .= "\n\t\t<field name='_spellcheckText' type='textSpellHtml' indexed='true' " |
|
81 | + . "stored='false' multiValued='true' />"; |
|
82 | 82 | |
83 | - return $xml; |
|
84 | - } |
|
83 | + return $xml; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * |
|
88 | - * @param SearchQuery $query |
|
89 | - * @param int $offset |
|
90 | - * @param int $limit |
|
91 | - * @param array $params |
|
92 | - * @return ArrayData |
|
93 | - */ |
|
94 | - public function search(SearchQuery $query, $offset = -1, $limit = -1, $params = []) |
|
95 | - { |
|
96 | - // Override dictionary if given |
|
97 | - if ($dictionary = $this->config()->dictionary) { |
|
98 | - $params["spellcheck.dictionary"] = $dictionary; |
|
99 | - } |
|
86 | + /** |
|
87 | + * |
|
88 | + * @param SearchQuery $query |
|
89 | + * @param int $offset |
|
90 | + * @param int $limit |
|
91 | + * @param array $params |
|
92 | + * @return ArrayData |
|
93 | + */ |
|
94 | + public function search(SearchQuery $query, $offset = -1, $limit = -1, $params = []) |
|
95 | + { |
|
96 | + // Override dictionary if given |
|
97 | + if ($dictionary = $this->config()->dictionary) { |
|
98 | + $params["spellcheck.dictionary"] = $dictionary; |
|
99 | + } |
|
100 | 100 | |
101 | - return parent::search($query, $offset, $limit, $params); |
|
102 | - } |
|
101 | + return parent::search($query, $offset, $limit, $params); |
|
102 | + } |
|
103 | 103 | } |
@@ -14,119 +14,119 @@ |
||
14 | 14 | */ |
15 | 15 | class CwpSolr |
16 | 16 | { |
17 | - use Configurable; |
|
17 | + use Configurable; |
|
18 | 18 | |
19 | - /** |
|
20 | - * |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - private static $options; |
|
19 | + /** |
|
20 | + * |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + private static $options; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Configure Solr. |
|
27 | - * |
|
28 | - * $options - An array consisting of: |
|
29 | - * |
|
30 | - * 'extraspath' - (String) Where to find Solr core configuartion files. |
|
31 | - * Defaults to '<BASE_PATH>/mysite/conf/extras'. |
|
32 | - * 'version' - select the Solr configuration to use when in CWP. One of: |
|
33 | - * * 'cwp-4': preferred version, uses secured 4.x service available on CWP |
|
34 | - * * 'local-4': this can be use for development using silverstripe-localsolr package, 4.x branch |
|
35 | - */ |
|
36 | - public static function configure() |
|
37 | - { |
|
38 | - if (!class_exists(Solr::class)) { |
|
39 | - return; |
|
40 | - } |
|
25 | + /** |
|
26 | + * Configure Solr. |
|
27 | + * |
|
28 | + * $options - An array consisting of: |
|
29 | + * |
|
30 | + * 'extraspath' - (String) Where to find Solr core configuartion files. |
|
31 | + * Defaults to '<BASE_PATH>/mysite/conf/extras'. |
|
32 | + * 'version' - select the Solr configuration to use when in CWP. One of: |
|
33 | + * * 'cwp-4': preferred version, uses secured 4.x service available on CWP |
|
34 | + * * 'local-4': this can be use for development using silverstripe-localsolr package, 4.x branch |
|
35 | + */ |
|
36 | + public static function configure() |
|
37 | + { |
|
38 | + if (!class_exists(Solr::class)) { |
|
39 | + return; |
|
40 | + } |
|
41 | 41 | |
42 | - // get options from configuration |
|
43 | - $options = static::config()->get('options'); |
|
42 | + // get options from configuration |
|
43 | + $options = static::config()->get('options'); |
|
44 | 44 | |
45 | - // get version specific options |
|
46 | - switch ($options['version']) { |
|
47 | - case 'cwp-4': |
|
48 | - $solrOptions = self::options_for_cwp($options); |
|
49 | - break; |
|
50 | - case 'local-4': |
|
51 | - $solrOptions = self::options_for_local($options); |
|
52 | - break; |
|
53 | - default: |
|
54 | - throw new InvalidArgumentException(sprintf( |
|
55 | - 'Solr version "%s" is not supported on CWP. Please use "local-4" on local ' . |
|
56 | - 'and "cwp-4" on production. For preferred configuration see ' . |
|
57 | - 'https://www.cwp.govt.nz/developer-docs/.', |
|
58 | - $options['version'] |
|
59 | - )); |
|
60 | - break; |
|
61 | - } |
|
45 | + // get version specific options |
|
46 | + switch ($options['version']) { |
|
47 | + case 'cwp-4': |
|
48 | + $solrOptions = self::options_for_cwp($options); |
|
49 | + break; |
|
50 | + case 'local-4': |
|
51 | + $solrOptions = self::options_for_local($options); |
|
52 | + break; |
|
53 | + default: |
|
54 | + throw new InvalidArgumentException(sprintf( |
|
55 | + 'Solr version "%s" is not supported on CWP. Please use "local-4" on local ' . |
|
56 | + 'and "cwp-4" on production. For preferred configuration see ' . |
|
57 | + 'https://www.cwp.govt.nz/developer-docs/.', |
|
58 | + $options['version'] |
|
59 | + )); |
|
60 | + break; |
|
61 | + } |
|
62 | 62 | |
63 | - // Allow users to override extras path. |
|
64 | - // CAUTION: CWP does not permit usage of customised solrconfig.xml. |
|
65 | - if (isset($options['extraspath']) && file_exists($options['extraspath'])) { |
|
66 | - $solrOptions['extraspath'] = $options['extraspath']; |
|
67 | - } elseif (file_exists(BASE_PATH . '/mysite/conf/extras')) { |
|
68 | - $solrOptions['extraspath'] = BASE_PATH . '/mysite/conf/extras'; |
|
69 | - } |
|
63 | + // Allow users to override extras path. |
|
64 | + // CAUTION: CWP does not permit usage of customised solrconfig.xml. |
|
65 | + if (isset($options['extraspath']) && file_exists($options['extraspath'])) { |
|
66 | + $solrOptions['extraspath'] = $options['extraspath']; |
|
67 | + } elseif (file_exists(BASE_PATH . '/mysite/conf/extras')) { |
|
68 | + $solrOptions['extraspath'] = BASE_PATH . '/mysite/conf/extras'; |
|
69 | + } |
|
70 | 70 | |
71 | - Solr::configure_server($solrOptions); |
|
72 | - } |
|
71 | + Solr::configure_server($solrOptions); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @throws Exception |
|
76 | - */ |
|
77 | - public static function options_from_environment() |
|
78 | - { |
|
79 | - throw new Exception( |
|
80 | - 'CwpSolr::options_from_environment has been deprecated, in favour of implicit Solr ' . |
|
81 | - 'configuration provided by the CwpSolr class in the cwp-core module. For preferred configuration see ' . |
|
82 | - 'https://www.cwp.govt.nz/developer-docs/.' |
|
83 | - ); |
|
84 | - } |
|
74 | + /** |
|
75 | + * @throws Exception |
|
76 | + */ |
|
77 | + public static function options_from_environment() |
|
78 | + { |
|
79 | + throw new Exception( |
|
80 | + 'CwpSolr::options_from_environment has been deprecated, in favour of implicit Solr ' . |
|
81 | + 'configuration provided by the CwpSolr class in the cwp-core module. For preferred configuration see ' . |
|
82 | + 'https://www.cwp.govt.nz/developer-docs/.' |
|
83 | + ); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * @param array $options |
|
88 | - * @return array |
|
89 | - */ |
|
90 | - public static function options_for_cwp($options) |
|
91 | - { |
|
92 | - $version = $options['version']; |
|
86 | + /** |
|
87 | + * @param array $options |
|
88 | + * @return array |
|
89 | + */ |
|
90 | + public static function options_for_cwp($options) |
|
91 | + { |
|
92 | + $version = $options['version']; |
|
93 | 93 | |
94 | - return [ |
|
95 | - 'host' => Environment::getEnv('SOLR_SERVER'), |
|
96 | - 'port' => Environment::getEnv('SOLR_PORT'), |
|
97 | - 'path' => '/v4/', |
|
98 | - 'version' => 4, |
|
99 | - 'indexstore' => [ |
|
100 | - 'mode' => CwpSolrConfigStore::class, |
|
101 | - 'path' => '/v4', |
|
102 | - ], |
|
103 | - ]; |
|
104 | - } |
|
94 | + return [ |
|
95 | + 'host' => Environment::getEnv('SOLR_SERVER'), |
|
96 | + 'port' => Environment::getEnv('SOLR_PORT'), |
|
97 | + 'path' => '/v4/', |
|
98 | + 'version' => 4, |
|
99 | + 'indexstore' => [ |
|
100 | + 'mode' => CwpSolrConfigStore::class, |
|
101 | + 'path' => '/v4', |
|
102 | + ], |
|
103 | + ]; |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * |
|
108 | - * @param array $options |
|
109 | - * @return array |
|
110 | - */ |
|
111 | - public static function options_for_local($options) |
|
112 | - { |
|
113 | - return [ |
|
114 | - 'host' => Environment::getEnv('SOLR_SERVER') ? Environment::getEnv('SOLR_SERVER') : 'localhost', |
|
115 | - 'port' => Environment::getEnv('SOLR_PORT') ? Environment::getEnv('SOLR_PORT') : 8983, |
|
116 | - 'path' => Environment::getEnv('SOLR_PATH') ? Environment::getEnv('SOLR_PATH') : '/solr/', |
|
117 | - 'version' => 4, |
|
118 | - 'indexstore' => [ |
|
119 | - 'mode' => Environment::getEnv('SOLR_MODE') ? Environment::getEnv('SOLR_MODE') : 'file', |
|
120 | - 'auth' => Environment::getEnv('SOLR_AUTH') ? Environment::getEnv('SOLR_AUTH') : null, |
|
121 | - // Allow storing the solr index and config data in an arbitrary location, |
|
122 | - // e.g. outside of the webroot |
|
123 | - 'path' => Environment::getEnv('SOLR_INDEXSTORE_PATH') |
|
124 | - ? Environment::getEnv('SOLR_INDEXSTORE_PATH') |
|
125 | - : BASE_PATH . '/.solr', |
|
126 | - 'remotepath' => Environment::getEnv('SOLR_REMOTE_PATH') |
|
127 | - ? Environment::getEnv('SOLR_REMOTE_PATH') |
|
128 | - : null |
|
129 | - ] |
|
130 | - ]; |
|
131 | - } |
|
106 | + /** |
|
107 | + * |
|
108 | + * @param array $options |
|
109 | + * @return array |
|
110 | + */ |
|
111 | + public static function options_for_local($options) |
|
112 | + { |
|
113 | + return [ |
|
114 | + 'host' => Environment::getEnv('SOLR_SERVER') ? Environment::getEnv('SOLR_SERVER') : 'localhost', |
|
115 | + 'port' => Environment::getEnv('SOLR_PORT') ? Environment::getEnv('SOLR_PORT') : 8983, |
|
116 | + 'path' => Environment::getEnv('SOLR_PATH') ? Environment::getEnv('SOLR_PATH') : '/solr/', |
|
117 | + 'version' => 4, |
|
118 | + 'indexstore' => [ |
|
119 | + 'mode' => Environment::getEnv('SOLR_MODE') ? Environment::getEnv('SOLR_MODE') : 'file', |
|
120 | + 'auth' => Environment::getEnv('SOLR_AUTH') ? Environment::getEnv('SOLR_AUTH') : null, |
|
121 | + // Allow storing the solr index and config data in an arbitrary location, |
|
122 | + // e.g. outside of the webroot |
|
123 | + 'path' => Environment::getEnv('SOLR_INDEXSTORE_PATH') |
|
124 | + ? Environment::getEnv('SOLR_INDEXSTORE_PATH') |
|
125 | + : BASE_PATH . '/.solr', |
|
126 | + 'remotepath' => Environment::getEnv('SOLR_REMOTE_PATH') |
|
127 | + ? Environment::getEnv('SOLR_REMOTE_PATH') |
|
128 | + : null |
|
129 | + ] |
|
130 | + ]; |
|
131 | + } |
|
132 | 132 | } |
@@ -12,68 +12,68 @@ |
||
12 | 12 | */ |
13 | 13 | class CwpSolrConfigStore implements SolrConfigStore |
14 | 14 | { |
15 | - /** |
|
16 | - * @var string |
|
17 | - */ |
|
18 | - protected $remote = ''; |
|
15 | + /** |
|
16 | + * @var string |
|
17 | + */ |
|
18 | + protected $remote = ''; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $url = ''; |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $url = ''; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @param array $config |
|
27 | - */ |
|
28 | - public function __construct($config) |
|
29 | - { |
|
30 | - $options = Solr::solr_options(); |
|
25 | + /** |
|
26 | + * @param array $config |
|
27 | + */ |
|
28 | + public function __construct($config) |
|
29 | + { |
|
30 | + $options = Solr::solr_options(); |
|
31 | 31 | |
32 | - $this->url = implode('', [ |
|
33 | - 'http://', |
|
34 | - isset($config['auth']) ? $config['auth'] . '@' : '', |
|
35 | - $options['host'] . ':' . $options['port'], |
|
36 | - $config['path'] |
|
37 | - ]); |
|
38 | - $this->remote = $config['remotepath']; |
|
39 | - } |
|
32 | + $this->url = implode('', [ |
|
33 | + 'http://', |
|
34 | + isset($config['auth']) ? $config['auth'] . '@' : '', |
|
35 | + $options['host'] . ':' . $options['port'], |
|
36 | + $config['path'] |
|
37 | + ]); |
|
38 | + $this->remote = $config['remotepath']; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param string $index |
|
43 | - * @param string $file |
|
44 | - * @return void |
|
45 | - */ |
|
46 | - public function uploadFile($index, $file) |
|
47 | - { |
|
48 | - $this->uploadString($index, basename($file), file_get_contents($file)); |
|
49 | - } |
|
41 | + /** |
|
42 | + * @param string $index |
|
43 | + * @param string $file |
|
44 | + * @return void |
|
45 | + */ |
|
46 | + public function uploadFile($index, $file) |
|
47 | + { |
|
48 | + $this->uploadString($index, basename($file), file_get_contents($file)); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * |
|
53 | - * @param string $index |
|
54 | - * @param string $filename |
|
55 | - * @param string $string |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function uploadString($index, $filename, $string) |
|
59 | - { |
|
60 | - $targetDir = "{$this->url}/config/$index"; |
|
51 | + /** |
|
52 | + * |
|
53 | + * @param string $index |
|
54 | + * @param string $filename |
|
55 | + * @param string $string |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function uploadString($index, $filename, $string) |
|
59 | + { |
|
60 | + $targetDir = "{$this->url}/config/$index"; |
|
61 | 61 | |
62 | - file_get_contents($targetDir . '/' . $filename, false, stream_context_create([ |
|
63 | - 'http' => [ |
|
64 | - 'method' => 'POST', |
|
65 | - 'header' => 'Content-type: application/octet-stream', |
|
66 | - 'content' => (string) $string |
|
67 | - ] |
|
68 | - ])); |
|
69 | - } |
|
62 | + file_get_contents($targetDir . '/' . $filename, false, stream_context_create([ |
|
63 | + 'http' => [ |
|
64 | + 'method' => 'POST', |
|
65 | + 'header' => 'Content-type: application/octet-stream', |
|
66 | + 'content' => (string) $string |
|
67 | + ] |
|
68 | + ])); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * @param string $index |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - public function instanceDir($index) |
|
76 | - { |
|
77 | - return $this->remote ? "{$this->remote}/$index" : $index; |
|
78 | - } |
|
71 | + /** |
|
72 | + * @param string $index |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + public function instanceDir($index) |
|
76 | + { |
|
77 | + return $this->remote ? "{$this->remote}/$index" : $index; |
|
78 | + } |
|
79 | 79 | } |
@@ -63,7 +63,7 @@ |
||
63 | 63 | 'http' => [ |
64 | 64 | 'method' => 'POST', |
65 | 65 | 'header' => 'Content-type: application/octet-stream', |
66 | - 'content' => (string) $string |
|
66 | + 'content' => (string)$string |
|
67 | 67 | ] |
68 | 68 | ])); |
69 | 69 | } |
@@ -52,7 +52,7 @@ |
||
52 | 52 | $records = []; |
53 | 53 | |
54 | 54 | // Get the query to apply across all variants: looks at all subsites, translations, live stage only. |
55 | - $crossVariant = (function ($dataQuery) { |
|
55 | + $crossVariant = (function($dataQuery) { |
|
56 | 56 | $params = [ |
57 | 57 | 'Subsite.filter' => false, |
58 | 58 | 'Versioned.mode' => 'stage', |
@@ -20,108 +20,108 @@ |
||
20 | 20 | */ |
21 | 21 | class CwpStatsReport extends Report |
22 | 22 | { |
23 | - public function title() |
|
24 | - { |
|
25 | - return _t(__CLASS__ . '.Title', 'Summary statistics'); |
|
26 | - } |
|
27 | - |
|
28 | - public function description() |
|
29 | - { |
|
30 | - return _t( |
|
31 | - __CLASS__ . '.Description', |
|
32 | - 'This report provides various statistics for this site. The "total live page count" is the number that ' . |
|
33 | - 'can be compared against the instance size specifications.' |
|
34 | - ); |
|
35 | - } |
|
36 | - |
|
37 | - public function columns() |
|
38 | - { |
|
39 | - return [ |
|
40 | - 'Name' => _t(__CLASS__ . '.Name', 'Name'), |
|
41 | - 'Count' => _t(__CLASS__ . '.Count', 'Count'), |
|
42 | - ]; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * Manually create source records for the report. Agreggates cannot be provided as a column of a DataQuery result. |
|
47 | - * |
|
48 | - * {@inheritDoc} |
|
49 | - */ |
|
50 | - public function sourceRecords($params = [], $sort = null, $limit = null) |
|
51 | - { |
|
52 | - $records = []; |
|
53 | - |
|
54 | - // Get the query to apply across all variants: looks at all subsites, translations, live stage only. |
|
55 | - $crossVariant = (function ($dataQuery) { |
|
56 | - $params = [ |
|
57 | - 'Subsite.filter' => false, |
|
58 | - 'Versioned.mode' => 'stage', |
|
59 | - 'Versioned.stage' => Versioned::LIVE, |
|
60 | - ]; |
|
61 | - |
|
62 | - return $dataQuery->setDataQueryParam($params); |
|
63 | - }); |
|
64 | - |
|
65 | - // Total. |
|
66 | - $records[] = [ |
|
67 | - 'Name' => _t( |
|
68 | - __CLASS__ . '.TotalPageCount', |
|
69 | - 'Total live page count, across all translations and subsites' |
|
70 | - ), |
|
71 | - 'Count' => $crossVariant(SiteTree::get())->count(), |
|
72 | - ]; |
|
73 | - |
|
74 | - if (class_exists(Subsite::class)) { |
|
75 | - // Main site. |
|
76 | - $records[] = [ |
|
77 | - 'Name' => _t(__CLASS__ . '.PagesForMainSite', '- in the main site'), |
|
78 | - 'Count' => $crossVariant(SiteTree::get()) |
|
79 | - ->filter(['SubsiteID' => 0]) |
|
80 | - ->count(), |
|
81 | - ]; |
|
82 | - |
|
83 | - // Per subsite. |
|
84 | - $subsites = Subsite::get(); |
|
85 | - foreach ($subsites as $subsite) { |
|
86 | - $records[] = [ |
|
87 | - 'Name' => _t( |
|
88 | - __CLASS__ . '.PagesForSubsite', |
|
89 | - "- in the subsite '{SubsiteTitle}'", |
|
90 | - ['SubsiteTitle' => $subsite->Title] |
|
91 | - ), |
|
92 | - 'Count' => $crossVariant(SiteTree::get()) |
|
93 | - ->filter(['SubsiteID' => $subsite->ID]) |
|
94 | - ->count(), |
|
95 | - ]; |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - // Files. |
|
100 | - $records[] = [ |
|
101 | - 'Name' => _t(__CLASS__ . '.FileCount', 'File count'), |
|
102 | - 'Count' => File::get() |
|
103 | - ->setDataQueryParam('Subsite.filter', false) |
|
104 | - ->filter(['ClassName:not' => Folder::class]) |
|
105 | - ->count(), |
|
106 | - ]; |
|
107 | - |
|
108 | - return ArrayList::create($records); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * @return GridField |
|
113 | - */ |
|
114 | - public function getReportField() |
|
115 | - { |
|
116 | - /** @var GridField $gridField */ |
|
117 | - $gridField = parent::getReportField(); |
|
118 | - |
|
119 | - /** @var GridFieldConfig $gridConfig */ |
|
120 | - $gridConfig = $gridField->getConfig(); |
|
121 | - $gridConfig->removeComponentsByType(GridFieldPrintButton::class); |
|
122 | - $gridConfig->removeComponentsByType(GridFieldExportButton::class); |
|
123 | - $gridConfig->removeComponentsByType(GridFieldSortableHeader::class); |
|
124 | - |
|
125 | - return $gridField; |
|
126 | - } |
|
23 | + public function title() |
|
24 | + { |
|
25 | + return _t(__CLASS__ . '.Title', 'Summary statistics'); |
|
26 | + } |
|
27 | + |
|
28 | + public function description() |
|
29 | + { |
|
30 | + return _t( |
|
31 | + __CLASS__ . '.Description', |
|
32 | + 'This report provides various statistics for this site. The "total live page count" is the number that ' . |
|
33 | + 'can be compared against the instance size specifications.' |
|
34 | + ); |
|
35 | + } |
|
36 | + |
|
37 | + public function columns() |
|
38 | + { |
|
39 | + return [ |
|
40 | + 'Name' => _t(__CLASS__ . '.Name', 'Name'), |
|
41 | + 'Count' => _t(__CLASS__ . '.Count', 'Count'), |
|
42 | + ]; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * Manually create source records for the report. Agreggates cannot be provided as a column of a DataQuery result. |
|
47 | + * |
|
48 | + * {@inheritDoc} |
|
49 | + */ |
|
50 | + public function sourceRecords($params = [], $sort = null, $limit = null) |
|
51 | + { |
|
52 | + $records = []; |
|
53 | + |
|
54 | + // Get the query to apply across all variants: looks at all subsites, translations, live stage only. |
|
55 | + $crossVariant = (function ($dataQuery) { |
|
56 | + $params = [ |
|
57 | + 'Subsite.filter' => false, |
|
58 | + 'Versioned.mode' => 'stage', |
|
59 | + 'Versioned.stage' => Versioned::LIVE, |
|
60 | + ]; |
|
61 | + |
|
62 | + return $dataQuery->setDataQueryParam($params); |
|
63 | + }); |
|
64 | + |
|
65 | + // Total. |
|
66 | + $records[] = [ |
|
67 | + 'Name' => _t( |
|
68 | + __CLASS__ . '.TotalPageCount', |
|
69 | + 'Total live page count, across all translations and subsites' |
|
70 | + ), |
|
71 | + 'Count' => $crossVariant(SiteTree::get())->count(), |
|
72 | + ]; |
|
73 | + |
|
74 | + if (class_exists(Subsite::class)) { |
|
75 | + // Main site. |
|
76 | + $records[] = [ |
|
77 | + 'Name' => _t(__CLASS__ . '.PagesForMainSite', '- in the main site'), |
|
78 | + 'Count' => $crossVariant(SiteTree::get()) |
|
79 | + ->filter(['SubsiteID' => 0]) |
|
80 | + ->count(), |
|
81 | + ]; |
|
82 | + |
|
83 | + // Per subsite. |
|
84 | + $subsites = Subsite::get(); |
|
85 | + foreach ($subsites as $subsite) { |
|
86 | + $records[] = [ |
|
87 | + 'Name' => _t( |
|
88 | + __CLASS__ . '.PagesForSubsite', |
|
89 | + "- in the subsite '{SubsiteTitle}'", |
|
90 | + ['SubsiteTitle' => $subsite->Title] |
|
91 | + ), |
|
92 | + 'Count' => $crossVariant(SiteTree::get()) |
|
93 | + ->filter(['SubsiteID' => $subsite->ID]) |
|
94 | + ->count(), |
|
95 | + ]; |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + // Files. |
|
100 | + $records[] = [ |
|
101 | + 'Name' => _t(__CLASS__ . '.FileCount', 'File count'), |
|
102 | + 'Count' => File::get() |
|
103 | + ->setDataQueryParam('Subsite.filter', false) |
|
104 | + ->filter(['ClassName:not' => Folder::class]) |
|
105 | + ->count(), |
|
106 | + ]; |
|
107 | + |
|
108 | + return ArrayList::create($records); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * @return GridField |
|
113 | + */ |
|
114 | + public function getReportField() |
|
115 | + { |
|
116 | + /** @var GridField $gridField */ |
|
117 | + $gridField = parent::getReportField(); |
|
118 | + |
|
119 | + /** @var GridFieldConfig $gridConfig */ |
|
120 | + $gridConfig = $gridField->getConfig(); |
|
121 | + $gridConfig->removeComponentsByType(GridFieldPrintButton::class); |
|
122 | + $gridConfig->removeComponentsByType(GridFieldExportButton::class); |
|
123 | + $gridConfig->removeComponentsByType(GridFieldSortableHeader::class); |
|
124 | + |
|
125 | + return $gridField; |
|
126 | + } |
|
127 | 127 | } |