/**
  * Creates the token DB table.
  * @param CDbConnection $db the database connection
  * @param string $tableName the name of the table to be created
  */
 protected function createTokenTable($db, $tableName)
 {
     $driver = $db->getDriverName();
     $file = dirname(__DIR__) . '/migrations/' . $this->tokenTableName . '.' . $db->getDriverName();
     $pdo = $this->getDbConnection()->pdoInstance;
     $sql = file_get_contents($file);
     $sql = rtrim($sql);
     $sqls = preg_replace_callback("/\\((.*)\\)/", create_function('$matches', 'return str_replace(";"," $$$ ",$matches[0]);'), $sql);
     $sqls = explode(";", $sqls);
     foreach ($sqls as $sql) {
         if (!empty($sql)) {
             $sql = str_replace(" \$\$\$ ", ";", $sql) . ";";
             $pdo->exec($sql);
         }
     }
 }
예제 #2
0
 /**
  * Creates the session DB table.
  * @param CDbConnection $db the database connection
  * @param string $tableName the name of the table to be created
  */
 protected function createSessionTable($db, $tableName)
 {
     $driver = $db->getDriverName();
     if ($driver === 'mysql') {
         $blob = 'LONGBLOB';
     } elseif ($driver === 'pgsql') {
         $blob = 'BYTEA';
     } else {
         $blob = 'BLOB';
     }
     $db->createCommand()->createTable($tableName, array('id' => 'CHAR(255) PRIMARY KEY', 'expire' => 'integer', 'user_id' => 'integer', 'data' => $blob));
 }
예제 #3
0
파일: CDbLogRoute.php 프로젝트: romeo14/pow
 /**
  * Creates the DB table for storing log messages.
  * @param CDbConnection $db the database connection
  * @param string $tableName the name of the table to be created
  */
 protected function createLogTable($db, $tableName)
 {
     $driver = $db->getDriverName();
     if ($driver === 'mysql') {
         $logID = 'id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY';
     } else {
         if ($driver === 'pgsql') {
             $logID = 'id SERIAL PRIMARY KEY';
         } else {
             $logID = 'id INTEGER NOT NULL PRIMARY KEY';
         }
     }
     $sql = "\r\nCREATE TABLE {$tableName}\r\n(\r\n\t{$logID},\r\n\tlevel VARCHAR(128),\r\n\tcategory VARCHAR(128),\r\n\tlogtime INTEGER,\r\n\tmessage TEXT\r\n)";
     $db->createCommand($sql)->execute();
 }
예제 #4
0
 /**
  * Creates the session DB table.
  * @param CDbConnection $db the database connection
  * @param string $tableName the name of the table to be created
  */
 public function createSessionTable($db, $tableName)
 {
     switch ($db->getDriverName()) {
         case 'mysql':
             $blob = 'LONGBLOB';
             break;
         case 'pgsql':
             $blob = 'BYTEA';
             break;
         case 'sqlsrv':
         case 'mssql':
         case 'dblib':
             $blob = 'VARBINARY(MAX)';
             break;
         default:
             $blob = 'BLOB';
             break;
     }
     $db->createCommand()->createTable($tableName, array('id' => 'CHAR(32) PRIMARY KEY', 'expire' => 'integer', 'data' => $blob, 'user_id' => 'integer', 'start_expire' => 'integer', 'user_agent' => 'text', 'user_type' => 'integer', 'user_avatar' => 'string', 'ip_address' => 'string', 'current_url' => 'text'));
 }
예제 #5
0
 /**
  * Sets up list of migrations.
  *
  * @return void
  * @since 0.1.0
  */
 public function setMigrations()
 {
     $path = Yii::getPathOfAlias('application.migrations');
     Yii::import('application.migrations.*');
     $files = scandir($path);
     // this was very weird, but late static binding didn't help all
     // migrations being put in the very same array
     $driverName = static::$db->getDriverName();
     static::$migrations[$driverName] = array();
     foreach ($files as $file) {
         if (preg_match('#^m\\d{6}_\\d{6}[\\w_]*\\.php$#', $file)) {
             $migrationName = substr($file, 0, strlen($file) - 4);
             /**
              * @var $migration CDbMigration
              */
             $migration = new $migrationName();
             $migration->setDbConnection(static::$db);
             $tthis = get_called_class();
             static::$migrations[$driverName][] = $migration;
         }
     }
 }
예제 #6
0
 /**
  * Creates the session DB table.
  * @param CDbConnection $db the database connection
  * @param string $tableName the name of the table to be created
  */
 protected function createSessionTable($db, $tableName)
 {
     switch ($db->getDriverName()) {
         case 'mysql':
             $blob = 'LONGBLOB';
             break;
         case 'pgsql':
             $blob = 'BYTEA';
             break;
         case 'sqlsrv':
         case 'mssql':
         case 'dblib':
             $blob = 'VARBINARY(MAX)';
             break;
         default:
             $blob = 'BLOB';
             break;
     }
     $db->createCommand()->createTable($tableName, array('id' => 'CHAR(32) PRIMARY KEY', 'expire' => 'integer', 'data' => $blob));
 }
예제 #7
0
    /**
     * Creates the cache DB table.
     * @param CDbConnection $db the database connection
     * @param string $tableName the name of the table to be created
     */
    protected function createCacheTable($db, $tableName)
    {
        $driver = $db->getDriverName();
        if ($driver === 'mysql') {
            $blob = 'LONGBLOB';
        } else {
            if ($driver === 'pgsql') {
                $blob = 'BYTEA';
            } else {
                $blob = 'BLOB';
            }
        }
        $sql = <<<EOD
CREATE TABLE {$tableName}
(
\tid CHAR(128) PRIMARY KEY,
\texpire INTEGER,
\tvalue {$blob}
)
EOD;
        $db->createCommand($sql)->execute();
    }
 /**
  * Optional settings screen
  */
 private function stepOptionalConfiguration()
 {
     $aData['clang'] = $clang = $this->lang;
     $aData['confirmation'] = Yii::app()->session['optconfig_message'];
     $aData['title'] = $clang->gT("Optional settings");
     $aData['descp'] = $clang->gT("Optional settings to give you a head start");
     $aData['classesForStep'] = array('off', 'off', 'off', 'off', 'off', 'on');
     $aData['progressValue'] = 80;
     $this->loadHelper('surveytranslator');
     $aData['model'] = $model = new InstallerConfigForm('optional');
     if (isset($_POST['InstallerConfigForm'])) {
         $model->attributes = $_POST['InstallerConfigForm'];
         //run validation, if it fails, load the view again else proceed to next step.
         if ($model->validate()) {
             $sDefaultAdminUserName = $model->adminLoginName;
             $sDefaultAdminPassword = $model->adminLoginPwd;
             $sDefaultAdminRealName = $model->adminName;
             $sDefaultSiteName = $model->siteName;
             $sDefaultSiteLanguage = $model->surveylang;
             $sDefaultAdminEmail = $model->adminEmail;
             $aData['title'] = $clang->gT("Database configuration");
             $aData['descp'] = $clang->gT("Please enter the database settings you want to use for LimeSurvey:");
             $aData['classesForStep'] = array('off', 'off', 'off', 'on', 'off', 'off');
             $aData['progressValue'] = 40;
             //config file is written, and we've a db in place
             $this->connection = Yii::app()->db;
             //checking DB Connection
             if ($this->connection->getActive() == true) {
                 $sPasswordHash = hash('sha256', $sDefaultAdminPassword);
                 try {
                     if (User::model()->count() > 0) {
                         die;
                     }
                     // Save user
                     $user = new User();
                     // Fix UserID to 1 for MySQL even if installed in master-master configuration scenario
                     if (in_array($this->connection->getDriverName(), array('mysql', 'mysqli'))) {
                         $user->uid = 1;
                     }
                     $user->users_name = $sDefaultAdminUserName;
                     $user->password = $sPasswordHash;
                     $user->full_name = $sDefaultAdminRealName;
                     $user->parent_id = 0;
                     $user->lang = $sDefaultSiteLanguage;
                     $user->email = $sDefaultAdminEmail;
                     $user->save();
                     // Save permissions
                     $permission = new Permission();
                     $permission->entity_id = 0;
                     $permission->entity = 'global';
                     $permission->uid = $user->uid;
                     $permission->permission = 'superadmin';
                     $permission->read_p = 1;
                     $permission->save();
                     // Save  global settings
                     $this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => 'SessionName', 'stg_value' => self::_getRandomString()));
                     $this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => 'sitename', 'stg_value' => $sDefaultSiteName));
                     $this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => 'siteadminname', 'stg_value' => $sDefaultAdminRealName));
                     $this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => 'siteadminemail', 'stg_value' => $sDefaultAdminEmail));
                     $this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => 'siteadminbounce', 'stg_value' => $sDefaultAdminEmail));
                     $this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => 'defaultlang', 'stg_value' => $sDefaultSiteLanguage));
                     // only continue if we're error free otherwise setup is broken.
                 } catch (Exception $e) {
                     throw new Exception(sprintf('Could not add optional settings: %s.', $e));
                 }
                 Yii::app()->session['deletedirectories'] = true;
                 $aData['title'] = $clang->gT("Success!");
                 $aData['descp'] = $clang->gT("LimeSurvey has been installed successfully.");
                 $aData['classesForStep'] = array('off', 'off', 'off', 'off', 'off', 'off');
                 $aData['progressValue'] = 100;
                 $aData['user'] = $sDefaultAdminUserName;
                 $aData['pwd'] = $sDefaultAdminPassword;
                 $this->render('/installer/success_view', $aData);
                 return;
             }
         } else {
             // if passwords don't match, redirect to proper link.
             Yii::app()->session['optconfig_message'] = sprintf('<b>%s</b>', $clang->gT("Passwords don't match."));
             $this->redirect(array('installer/optional'));
         }
     } elseif (empty(Yii::app()->session['configFileWritten'])) {
         $this->_writeConfigFile();
     }
     $this->render('/installer/optconfig_view', $aData);
 }
 public function testOdbc()
 {
     if (!extension_loaded('pdo_odbc')) {
         $this->markTestSkipped('pdo_odbc extension is required.');
     }
     $db = new CDbConnection();
     $db->connectionString = 'odbc:Driver=SQLite3;Database=:memory:';
     $db->driverName = 'sqlite';
     try {
         $this->assertEquals('odbc', $db->getAttribute(PDO::ATTR_DRIVER_NAME));
         $this->assertEquals('sqlite', $db->getDriverName());
     } catch (Exception $e) {
         $this->markTestSkipped('SQLite3 ODBC driver package must be installed in your operating system.');
     }
     $db->active = true;
     $db->pdoInstance->exec(file_get_contents(dirname(__FILE__) . '/data/sqlite.sql'));
     $command = $db->createCommand('SELECT * FROM posts');
     $this->assertTrue($command instanceof CDbCommand);
 }
예제 #10
0
 /**
  * Creates the session DB table.
  * @param CDbConnection $db the database connection
  * @param string $tableName the name of the table to be created
  */
 protected function createSessionTable($db, $tableName)
 {
     $driver = $db->getDriverName();
     if ($driver === 'mysql') {
         $blob = 'LONGBLOB';
     } else {
         if ($driver === 'pgsql') {
             $blob = 'BYTEA';
         } else {
             $blob = 'BLOB';
         }
     }
     $sql = "\nCREATE TABLE {$tableName}\n(\n\tid CHAR(32) PRIMARY KEY,\n\texpire INTEGER,\n\tdata {$blob}\n)";
     $db->createCommand($sql)->execute();
 }