Conditions | 20 |
Paths | > 20000 |
Total Lines | 212 |
Code Lines | 130 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 2 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
101 | public function doGET($request) |
||
102 | { |
||
103 | self::$logger->debug('>>doGET($request=['.var_export($request, true).'])'); |
||
104 | |||
105 | $config = ConfigProvider::getInstance(); |
||
106 | |||
107 | $sessionProvider = $config->get('session.provider.name'); |
||
108 | $session = SessionProviderFactory::getInstance($sessionProvider); |
||
109 | |||
110 | // if there is nobody logged in, we will send them off to the Login controller to do so before coming back here |
||
111 | if ($session->get('currentUser') === false) { |
||
112 | self::$logger->info('Nobody logged in, invoking Login controller...'); |
||
113 | |||
114 | $controller = new LoginController(); |
||
115 | $controller->setName('LoginController'); |
||
116 | $controller->setRequest($request); |
||
117 | $controller->setUnitOfWork(array('Alpha\Controller\LoginController', 'Alpha\Controller\InstallController')); |
||
118 | |||
119 | self::$logger->debug('<<__construct'); |
||
120 | |||
121 | return $controller->doGET($request); |
||
122 | } |
||
123 | |||
124 | $params = $request->getParams(); |
||
125 | |||
126 | $sessionProvider = $config->get('session.provider.name'); |
||
127 | $session = SessionProviderFactory::getInstance($sessionProvider); |
||
128 | |||
129 | $body = View::displayPageHead($this); |
||
130 | |||
131 | $body .= '<h1>Installing the '.$config->get('app.title').' application</h1>'; |
||
132 | |||
133 | try { |
||
134 | $body .= $this->createApplicationDirs(); |
||
135 | } catch (\Exception $e) { |
||
136 | $body .= View::displayErrorMessage($e->getMessage()); |
||
137 | $body .= View::displayErrorMessage('Aborting.'); |
||
138 | |||
139 | return new Response(500, $body, array('Content-Type' => 'text/html')); |
||
140 | } |
||
141 | |||
142 | // start a new database transaction |
||
143 | ActiveRecord::begin(); |
||
144 | |||
145 | /* |
||
146 | * Create DEnum tables |
||
147 | */ |
||
148 | $DEnum = new DEnum(); |
||
149 | $DEnumItem = new DEnumItem(); |
||
150 | |||
151 | try { |
||
152 | $body .= '<p>Attempting to create the DEnum tables...'; |
||
153 | if (!$DEnum->checkTableExists()) { |
||
154 | $DEnum->makeTable(); |
||
155 | } |
||
156 | self::$logger->info('Created the ['.$DEnum->getTableName().'] table successfully'); |
||
157 | |||
158 | if (!$DEnumItem->checkTableExists()) { |
||
159 | $DEnumItem->makeTable(); |
||
160 | } |
||
161 | self::$logger->info('Created the ['.$DEnumItem->getTableName().'] table successfully'); |
||
162 | |||
163 | // create a default article DEnum category |
||
164 | $DEnum = new DEnum('Alpha\Model\Article::section'); |
||
165 | $DEnumItem = new DEnumItem(); |
||
166 | $DEnumItem->set('value', 'Main'); |
||
167 | $DEnumItem->set('DEnumID', $DEnum->getID()); |
||
168 | $DEnumItem->save(); |
||
169 | |||
170 | $body .= View::displayUpdateMessage('DEnums set up successfully.'); |
||
171 | } catch (\Exception $e) { |
||
172 | $body .= View::displayErrorMessage($e->getMessage()); |
||
173 | $body .= View::displayErrorMessage('Aborting.'); |
||
174 | self::$logger->error($e->getMessage()); |
||
175 | ActiveRecord::rollback(); |
||
176 | |||
177 | return new Response(500, $body, array('Content-Type' => 'text/html')); |
||
178 | } |
||
179 | |||
180 | /* |
||
181 | * Loop over each business object in the system, and create a table for it |
||
182 | */ |
||
183 | $classNames = ActiveRecord::getBOClassNames(); |
||
184 | $loadedClasses = array(); |
||
185 | |||
186 | foreach ($classNames as $classname) { |
||
187 | array_push($loadedClasses, $classname); |
||
188 | } |
||
189 | |||
190 | foreach ($loadedClasses as $classname) { |
||
191 | try { |
||
192 | $body .= '<p>Attempting to create the table for the class ['.$classname.']...'; |
||
193 | |||
194 | try { |
||
195 | $BO = new $classname(); |
||
196 | |||
197 | if (!$BO->checkTableExists()) { |
||
198 | $BO->makeTable(); |
||
199 | } else { |
||
200 | if ($BO->checkTableNeedsUpdate()) { |
||
201 | $missingFields = $BO->findMissingFields(); |
||
202 | |||
203 | $count = count($missingFields); |
||
204 | |||
205 | for ($i = 0; $i < $count; ++$i) { |
||
206 | $BO->addProperty($missingFields[$i]); |
||
207 | } |
||
208 | } |
||
209 | } |
||
210 | } catch (FailedIndexCreateException $eice) { |
||
211 | // this are safe to ignore for now as they will be auto-created later once all of the tables are in place |
||
212 | self::$logger->warn($eice->getMessage()); |
||
213 | } catch (FailedLookupCreateException $elce) { |
||
214 | // this are safe to ignore for now as they will be auto-created later once all of the tables are in place |
||
215 | self::$logger->warn($elce->getMessage()); |
||
216 | } |
||
217 | |||
218 | self::$logger->info('Created the ['.$BO->getTableName().'] table successfully'); |
||
219 | $body .= View::displayUpdateMessage('Created the ['.$BO->getTableName().'] table successfully'); |
||
220 | } catch (\Exception $e) { |
||
221 | $body .= View::displayErrorMessage($e->getMessage()); |
||
222 | $body .= View::displayErrorMessage('Aborting.'); |
||
223 | self::$logger->error($e->getMessage()); |
||
224 | ActiveRecord::rollback(); |
||
225 | |||
226 | return new Response(500, $body, array('Content-Type' => 'text/html')); |
||
227 | } |
||
228 | } |
||
229 | |||
230 | $body .= View::displayUpdateMessage('All business object tables created successfully!'); |
||
231 | |||
232 | /* |
||
233 | * Create the Admin and Standard groups |
||
234 | */ |
||
235 | $adminGroup = new Rights(); |
||
236 | $adminGroup->set('name', 'Admin'); |
||
237 | $standardGroup = new Rights(); |
||
238 | $standardGroup->set('name', 'Standard'); |
||
239 | |||
240 | try { |
||
241 | try { |
||
242 | $body .= '<p>Attempting to create the Admin and Standard groups...'; |
||
243 | $adminGroup->save(); |
||
244 | $standardGroup->save(); |
||
245 | |||
246 | self::$logger->info('Created the Admin and Standard rights groups successfully'); |
||
247 | $body .= View::displayUpdateMessage('Created the Admin and Standard rights groups successfully'); |
||
248 | } catch (FailedIndexCreateException $eice) { |
||
249 | // this are safe to ignore for now as they will be auto-created later once all of the tables are in place |
||
250 | self::$logger->warn($eice->getMessage()); |
||
251 | } catch (FailedLookupCreateException $elce) { |
||
252 | // this are safe to ignore for now as they will be auto-created later once all of the tables are in place |
||
253 | self::$logger->warn($elce->getMessage()); |
||
254 | } |
||
255 | } catch (\Exception $e) { |
||
256 | $body .= View::displayErrorMessage($e->getMessage()); |
||
257 | $body .= View::displayErrorMessage('Aborting.'); |
||
258 | self::$logger->error($e->getMessage()); |
||
259 | ActiveRecord::rollback(); |
||
260 | |||
261 | return new Response(500, $body, array('Content-Type' => 'text/html')); |
||
262 | } |
||
263 | |||
264 | /* |
||
265 | * Save the admin user to the database in the right group |
||
266 | */ |
||
267 | try { |
||
268 | try { |
||
269 | $body .= '<p>Attempting to save the Admin account...'; |
||
270 | $admin = new Person(); |
||
271 | $admin->set('displayName', 'Admin'); |
||
272 | $admin->set('email', $session->get('currentUser')->get('email')); |
||
273 | $admin->set('password', $session->get('currentUser')->get('password')); |
||
274 | $admin->save(); |
||
275 | self::$logger->info('Created the admin user account ['.$session->get('currentUser')->get('email').'] successfully'); |
||
276 | |||
277 | $adminGroup->loadByAttribute('name', 'Admin'); |
||
278 | |||
279 | $lookup = $adminGroup->getMembers()->getLookup(); |
||
280 | $lookup->setValue(array($admin->getID(), $adminGroup->getID())); |
||
281 | $lookup->save(); |
||
282 | |||
283 | self::$logger->info('Added the admin account to the Admin group successfully'); |
||
284 | $body .= View::displayUpdateMessage('Added the admin account to the Admin group successfully'); |
||
285 | } catch (FailedIndexCreateException $eice) { |
||
286 | // this are safe to ignore for now as they will be auto-created later once all of the tables are in place |
||
287 | self::$logger->warn($eice->getMessage()); |
||
288 | } catch (FailedLookupCreateException $elce) { |
||
289 | // this are safe to ignore for now as they will be auto-created later once all of the tables are in place |
||
290 | self::$logger->warn($elce->getMessage()); |
||
291 | } |
||
292 | } catch (\Exception $e) { |
||
293 | $body .= View::displayErrorMessage($e->getMessage()); |
||
294 | $body .= View::displayErrorMessage('Aborting.'); |
||
295 | self::$logger->error($e->getMessage()); |
||
296 | ActiveRecord::rollback(); |
||
297 | |||
298 | return new Response(500, $body, array('Content-Type' => 'text/html')); |
||
299 | } |
||
300 | |||
301 | $body .= '<br><p align="center"><a href="'.FrontController::generateSecureURL('act=Alpha\Controller\ListActiveRecordsController').'">Administration Home Page</a></p><br>'; |
||
302 | $body .= View::displayPageFoot($this); |
||
303 | |||
304 | // commit |
||
305 | ActiveRecord::commit(); |
||
306 | |||
307 | self::$logger->info('Finished installation!'); |
||
308 | self::$logger->action('Installed the application'); |
||
309 | self::$logger->debug('<<doGET'); |
||
310 | |||
311 | return new Response(200, $body, array('Content-Type' => 'text/html')); |
||
312 | } |
||
313 | |||
491 |