/** * Handles connector requests. * * @param string $action */ public function handle($action = '') { $this->beginTimer(); /* prepare the settings */ $settings = $_REQUEST; if (empty($settings['installmode'])) { $settings['installmode'] = modInstall::MODE_NEW; } $settings['installmode'] = $this->getInstallMode($settings['installmode']); $this->settings->fromArray($settings); /* load CLI args into settings */ /* load the config.xml file */ $config = $this->getConfig($settings['installmode']); if (empty($config)) { $this->end($this->install->lexicon('cli_no_config_file')); } $this->settings->fromArray($config); $this->settings->fromArray($settings); /* do again to allow CLI-based overrides of config.xml */ /* load the driver */ $this->install->loadDriver(); /* Run tests */ $mode = (int) $this->install->settings->get('installmode'); $results = $this->install->test($mode); if (!$this->install->test->success) { $msg = "\n"; foreach ($results['fail'] as $field => $result) { $msg .= $field . ': ' . $result['title'] . ' - ' . $result['message']; } $msg = $this->install->lexicon('cli_tests_failed', array('errors' => $msg)); $this->end($msg); } /** Attempt to create the database */ $this->checkDatabase(); /* Run installer */ $this->install->getService('runner', 'runner.modInstallRunnerWeb'); $failed = true; $errors = array(); if ($this->install->runner) { $success = $this->install->runner->run($mode); $results = $this->install->runner->getResults(); $failed = false; foreach ($results as $item) { if ($item['class'] === 'failed') { $failed = true; $this->install->xpdo->log(xPDO::LOG_LEVEL_ERROR, $item['msg']); $errors[] = $item; break; } } } if ($failed) { $msg = "\n"; foreach ($errors as $field => $result) { $msg .= $result['msg']; } $msg = $this->install->lexicon('cli_install_failed', array('errors' => $msg)); $this->end($msg); } /* cleanup */ $errors = $this->install->verify(); foreach ($errors as $error) { $this->install->xpdo->log(xPDO::LOG_LEVEL_ERROR, $error); } $cleanupErrors = $this->install->cleanup(); foreach ($cleanupErrors as $key => $error) { $this->install->xpdo->log(xPDO::LOG_LEVEL_ERROR, $error); } if ($this->settings->get('remove_setup_directory')) { $this->install->removeSetupDirectory(); } $this->endTimer(); $this->end('' . $this->install->lexicon('installation_finished', array('time' => $this->timeTotal))); }