| Conditions | 20 |
| Paths | > 20000 |
| Total Lines | 205 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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 = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); |
||
| 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 | $sessionProvider = $config->get('session.provider.name'); |
||
| 125 | $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); |
||
| 126 | |||
| 127 | $body = View::displayPageHead($this); |
||
| 128 | |||
| 129 | $body .= '<h1>Installing the '.$config->get('app.title').' application</h1>'; |
||
| 130 | |||
| 131 | try { |
||
| 132 | $body .= $this->createApplicationDirs(); |
||
| 133 | } catch (\Exception $e) { |
||
| 134 | $body .= View::displayErrorMessage($e->getMessage()); |
||
| 135 | $body .= View::displayErrorMessage('Aborting.'); |
||
| 136 | |||
| 137 | return new Response(500, $body, array('Content-Type' => 'text/html')); |
||
| 138 | } |
||
| 139 | |||
| 140 | ActiveRecord::createDatabase(); |
||
| 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 | $body .= View::displayUpdateMessage('DEnums set up successfully.'); |
||
| 164 | } catch (\Exception $e) { |
||
| 165 | $body .= View::displayErrorMessage($e->getMessage()); |
||
| 166 | $body .= View::displayErrorMessage('Aborting.'); |
||
| 167 | self::$logger->error($e->getMessage()); |
||
| 168 | ActiveRecord::rollback(); |
||
| 169 | |||
| 170 | return new Response(500, $body, array('Content-Type' => 'text/html')); |
||
| 171 | } |
||
| 172 | |||
| 173 | /* |
||
| 174 | * Loop over each business object in the system, and create a table for it |
||
| 175 | */ |
||
| 176 | $classNames = ActiveRecord::getRecordClassNames(); |
||
| 177 | $loadedClasses = array(); |
||
| 178 | |||
| 179 | foreach ($classNames as $classname) { |
||
| 180 | array_push($loadedClasses, $classname); |
||
| 181 | } |
||
| 182 | |||
| 183 | foreach ($loadedClasses as $classname) { |
||
| 184 | try { |
||
| 185 | $body .= '<p>Attempting to create the table for the class ['.$classname.']...'; |
||
| 186 | |||
| 187 | try { |
||
| 188 | $Record = new $classname(); |
||
| 189 | |||
| 190 | if (!$Record->checkTableExists()) { |
||
| 191 | $Record->makeTable(); |
||
| 192 | } else { |
||
| 193 | if ($Record->checkTableNeedsUpdate()) { |
||
| 194 | $missingFields = $Record->findMissingFields(); |
||
| 195 | |||
| 196 | $count = count($missingFields); |
||
| 197 | |||
| 198 | for ($i = 0; $i < $count; ++$i) { |
||
| 199 | $Record->addProperty($missingFields[$i]); |
||
| 200 | } |
||
| 201 | } |
||
| 202 | } |
||
| 203 | } catch (FailedIndexCreateException $eice) { |
||
| 204 | // this are safe to ignore for now as they will be auto-created later once all of the tables are in place |
||
| 205 | self::$logger->warn($eice->getMessage()); |
||
| 206 | } catch (FailedLookupCreateException $elce) { |
||
| 207 | // this are safe to ignore for now as they will be auto-created later once all of the tables are in place |
||
| 208 | self::$logger->warn($elce->getMessage()); |
||
| 209 | } |
||
| 210 | |||
| 211 | self::$logger->info('Created the ['.$Record->getTableName().'] table successfully'); |
||
| 212 | $body .= View::displayUpdateMessage('Created the ['.$Record->getTableName().'] table successfully'); |
||
| 213 | } catch (\Exception $e) { |
||
| 214 | $body .= View::displayErrorMessage($e->getMessage()); |
||
| 215 | $body .= View::displayErrorMessage('Aborting.'); |
||
| 216 | self::$logger->error($e->getMessage()); |
||
| 217 | ActiveRecord::rollback(); |
||
| 218 | |||
| 219 | return new Response(500, $body, array('Content-Type' => 'text/html')); |
||
| 220 | } |
||
| 221 | } |
||
| 222 | |||
| 223 | $body .= View::displayUpdateMessage('All business object tables created successfully!'); |
||
| 224 | |||
| 225 | /* |
||
| 226 | * Create the Admin and Standard groups |
||
| 227 | */ |
||
| 228 | $adminGroup = new Rights(); |
||
| 229 | $adminGroup->set('name', 'Admin'); |
||
| 230 | $standardGroup = new Rights(); |
||
| 231 | $standardGroup->set('name', 'Standard'); |
||
| 232 | |||
| 233 | try { |
||
| 234 | try { |
||
| 235 | $body .= '<p>Attempting to create the Admin and Standard groups...'; |
||
| 236 | $adminGroup->save(); |
||
| 237 | $standardGroup->save(); |
||
| 238 | |||
| 239 | self::$logger->info('Created the Admin and Standard rights groups successfully'); |
||
| 240 | $body .= View::displayUpdateMessage('Created the Admin and Standard rights groups successfully'); |
||
| 241 | } catch (FailedIndexCreateException $eice) { |
||
| 242 | // this are safe to ignore for now as they will be auto-created later once all of the tables are in place |
||
| 243 | self::$logger->warn($eice->getMessage()); |
||
| 244 | } catch (FailedLookupCreateException $elce) { |
||
| 245 | // this are safe to ignore for now as they will be auto-created later once all of the tables are in place |
||
| 246 | self::$logger->warn($elce->getMessage()); |
||
| 247 | } |
||
| 248 | } catch (\Exception $e) { |
||
| 249 | $body .= View::displayErrorMessage($e->getMessage()); |
||
| 250 | $body .= View::displayErrorMessage('Aborting.'); |
||
| 251 | self::$logger->error($e->getMessage()); |
||
| 252 | ActiveRecord::rollback(); |
||
| 253 | |||
| 254 | return new Response(500, $body, array('Content-Type' => 'text/html')); |
||
| 255 | } |
||
| 256 | |||
| 257 | /* |
||
| 258 | * Save the admin user to the database in the right group |
||
| 259 | */ |
||
| 260 | try { |
||
| 261 | try { |
||
| 262 | $body .= '<p>Attempting to save the Admin account...'; |
||
| 263 | $admin = new Person(); |
||
| 264 | $admin->set('username', 'Admin'); |
||
| 265 | $admin->set('email', $session->get('currentUser')->get('email')); |
||
| 266 | $admin->set('password', $session->get('currentUser')->get('password')); |
||
| 267 | $admin->save(); |
||
| 268 | self::$logger->info('Created the admin user account ['.$session->get('currentUser')->get('email').'] successfully'); |
||
| 269 | |||
| 270 | $adminGroup->loadByAttribute('name', 'Admin'); |
||
| 271 | |||
| 272 | $lookup = $adminGroup->getMembers()->getLookup(); |
||
| 273 | $lookup->setValue(array($admin->getID(), $adminGroup->getID())); |
||
| 274 | $lookup->save(); |
||
| 275 | |||
| 276 | self::$logger->info('Added the admin account to the Admin group successfully'); |
||
| 277 | $body .= View::displayUpdateMessage('Added the admin account to the Admin group successfully'); |
||
| 278 | } catch (FailedIndexCreateException $eice) { |
||
| 279 | // this are safe to ignore for now as they will be auto-created later once all of the tables are in place |
||
| 280 | self::$logger->warn($eice->getMessage()); |
||
| 281 | } catch (FailedLookupCreateException $elce) { |
||
| 282 | // this are safe to ignore for now as they will be auto-created later once all of the tables are in place |
||
| 283 | self::$logger->warn($elce->getMessage()); |
||
| 284 | } |
||
| 285 | } catch (\Exception $e) { |
||
| 286 | $body .= View::displayErrorMessage($e->getMessage()); |
||
| 287 | $body .= View::displayErrorMessage('Aborting.'); |
||
| 288 | self::$logger->error($e->getMessage()); |
||
| 289 | ActiveRecord::rollback(); |
||
| 290 | |||
| 291 | return new Response(500, $body, array('Content-Type' => 'text/html')); |
||
| 292 | } |
||
| 293 | |||
| 294 | $body .= '<br><p align="center"><a href="'.FrontController::generateSecureURL('act=Alpha\Controller\ListActiveRecordsController').'">Administration Home Page</a></p><br>'; |
||
| 295 | $body .= View::displayPageFoot($this); |
||
| 296 | |||
| 297 | // commit |
||
| 298 | ActiveRecord::commit(); |
||
| 299 | |||
| 300 | self::$logger->info('Finished installation!'); |
||
| 301 | self::$logger->info('Installed the application'); |
||
| 302 | self::$logger->debug('<<doGET'); |
||
| 303 | |||
| 304 | return new Response(200, $body, array('Content-Type' => 'text/html')); |
||
| 305 | } |
||
| 306 | |||
| 474 |