Beispiel #1
0
 public function processValues()
 {
     /**
      * security class is required
      * for building the user password and salt hashes.
      */
     require KOCH . 'Security/Security.php';
     // generate salted hash
     $hashArray = \Koch\Security\Security::build_salted_hash($_POST['admin_password'], $_SESSION['encryption']);
     /**
      * Insert admin user into the database.
      *
      * We are using a raw sql statement with bound variables passing it to Doctrine2.
      */
     try {
         $db = Helper::getDoctrineEntityManager()->getConnection();
         $raw_sql_query = 'INSERT INTO ' . $_SESSION['config']['database']['prefix'] . 'users
                         SET  email = :email,
                             nick = :nick,
                             passwordhash = :hash,
                             salt = :salt,
                             joined = :joined,
                             language = :language,
                             activated = :activated';
         $stmt = $db->prepare($raw_sql_query);
         $params = array('email' => $_POST['admin_email'], 'nick' => $_POST['admin_name'], 'hash' => $hashArray['hash'], 'salt' => $hashArray['salt'], 'joined' => time(), 'language' => $_SESSION['admin_language'], 'activated' => '1');
         $stmt->execute($params);
     } catch (\Exception $e) {
         $this->setStep(6);
         $this->setErrormessage($e->getMessage());
     }
 }
Beispiel #2
0
 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 />');
     }
 }
Beispiel #3
0
 public function calculateInstallationProgress()
 {
     /**
      * Calculate Progress Percentage
      */
     $_SESSION['progress'] = Helper::calculateProgress($this->step, $this->total_steps);
 }
Beispiel #4
0
 public static function getDoctrineEntityManager($connectionParams = null)
 {
     try {
         if (is_array($connectionParams) === false) {
             include ROOT . 'core/config/adapter/ini.php';
             // get clansuite config
             $clansuite_config = \Koch\Config\Adapter\Ini::readConfig(ROOT_APP . 'configuration/clansuite.php');
             // reduce config array to the dsn/connection settings
             $connectionParams = $clansuite_config['database'];
         }
         // connect
         $config = new \Doctrine\DBAL\Configuration();
         $connection = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
         $connection->setCharset('UTF8');
         // get Event and Config
         $event = $connection->getEventManager();
         $config = new \Doctrine\ORM\Configuration();
         // add Table Prefix
         $prefix = $connectionParams['prefix'];
         $tablePrefix = new \DoctrineExtensions\TablePrefix\TablePrefix($prefix);
         $event->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $tablePrefix);
         // setup Cache
         $cache = new \Doctrine\Common\Cache\ArrayCache();
         $config->setMetadataCacheImpl($cache);
         // setup Proxy Dir
         $config->setProxyDir(realpath(ROOT . 'application\\doctrine'));
         $config->setProxyNamespace('proxies');
         // setup Annotation Driver
         $driverImpl = $config->newDefaultAnnotationDriver(Helper::getModelPathsForAllModules());
         $config->setMetadataDriverImpl($driverImpl);
         // finally: instantiate EntityManager
         $entityManager = \Doctrine\ORM\EntityManager::create($connection, $config, $event);
         return $entityManager;
     } catch (\Exception $e) {
         $msg = 'The initialization of Doctrine2 failed!' . NL . NL . 'Reason: ' . $e->getMessage();
         throw new Exception($msg);
     }
 }
Beispiel #5
0
 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);
     }
 }