コード例 #1
0
ファイル: Step6.php プロジェクト: Clansuite/Clansuite
 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());
     }
 }
コード例 #2
0
ファイル: Step4.php プロジェクト: Clansuite/Clansuite
 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);
     }
 }