public function processValues() { $config_array = array(); $config_array = $_POST['config']; // transform the GMTOFFSET (3600 = GMT+1) into a timezone name, like "Europe/Berlin". $config_array['language']['timezone'] = (string) timezone_name_from_abbr('', $_POST['config']['language']['gmtoffset'], 0); // write Settings to clansuite.config.php if (false === Helper::write_config_settings($config_array)) { $this->setStep(5); $this->setErrorMessage('Config not written <br />'); } }
public function processValues() { /** * 2) Create database. * * Has the user requested to create the database? */ if (isset($_POST['config']['database']['create_database']) and $_POST['config']['database']['create_database'] == 'on') { try { // connection without dbname (must be blank for create table) $connectionParams = array('user' => $_POST['config']['database']['user'], 'password' => $_POST['config']['database']['password'], 'host' => $_POST['config']['database']['host'], 'driver' => $_POST['config']['database']['driver']); $config = new \Doctrine\DBAL\Configuration(); $connection = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); $connection->setCharset('UTF8'); /** * fetch doctrine schema manager * and create database */ $schema_manager = $connection->getSchemaManager(); $schema_manager->createDatabase($_POST['config']['database']['dbname']); /** * Another way of doing this is via the specific database platform command. * Then for creating the database the platform is asked, which SQL CMD to use. * For "pdo_mysql" it would result in a string like 'CREATE DATABASE name'. */ #$db = $connection->getDatabasePlatform(); #$sql = $db->getCreateDatabaseSQL('databasename'); #$connection->exec($sql); // Drop Connection. unset($connection); } catch (\Exception $e) { // force return $this->setStep(4); $error = $this->language['ERROR_WHILE_CREATING_DATABASE'] . NL . NL; $error .= $e->getMessage() . '.'; $this->setErrorMessage($error); } } /** * 3) Connect to Database */ // Setup Connection Parameters. This time with "dbname". $connectionParams = array('dbname' => $_POST['config']['database']['dbname'], 'user' => $_POST['config']['database']['user'], 'password' => $_POST['config']['database']['password'], 'host' => $_POST['config']['database']['host'], 'driver' => $_POST['config']['database']['driver'], 'prefix' => $_POST['config']['database']['prefix']); $entityManager = Helper::getDoctrineEntityManager($connectionParams); /** * 4) Validate Database Schemas */ try { // instantiate validator $validator = new \Doctrine\ORM\Tools\SchemaValidator($entityManager); // validate $validation_error = $validator->validateMapping(); // handle validation errors if ($validation_error) { // @todo this is experimental... $this->setErrorMessage(var_export($validation_error, false)); } } catch (Exception $e) { // force return $this->setStep(4); $error = $this->language['ERROR_NO_DB_CONNECT'] . NL . $e->getMessage(); $this->setErrorMessage($error); } /** * 5) Insert/Update Schemas * * "recreate" will do a database drop, before schemas are updated. */ try { $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($entityManager); $metadata = $entityManager->getMetadataFactory()->getAllMetadata(); if (isset($_GET['recreate'])) { $schemaTool->dropSchema($metadata); } $schemaTool->updateSchema($metadata); $entityManager->flush(); } catch (Exception $e) { $html = ''; $html .= 'The update failed!' . NL; $html .= 'Do you want to force a database drop (' . $connectionParams['dbname'] . ')?' . NL; $html .= 'This will result in a total loss of all data and database tables.' . NL; $html .= 'It will allow for an clean installation of the database.' . NL; $html .= 'WARNING: Act carefully!' . NL; $html .= '<form action="index.php?step=4&recreate=true" method="post">'; $html .= '<input type="submit" value="Recreate Database" class="retry"></form>'; // force return $this->setStep(4); $error = $this->language['ERROR_NO_DB_CONNECT'] . NL . $e->getMessage(); $error .= NL . NL . $html; $this->setErrorMessage($error); } /** * 6. Write Settings to clansuite.config.php */ if (false === Helper::write_config_settings($_POST['config'])) { // force return $this->setStep(4); $error = 'Config not written.' . NL; $this->setErrorMessage($error); } }