* @return \OC\DB\Migrator
*/
public function getMigrator() {
+ $random = \OC::$server->getSecureRandom()->getMediumStrengthGenerator();
$platform = $this->conn->getDatabasePlatform();
if ($platform instanceof SqlitePlatform) {
$config = \OC::$server->getConfig();
- return new SQLiteMigrator($this->conn, $config);
+ return new SQLiteMigrator($this->conn, $random, $config);
} else if ($platform instanceof OraclePlatform) {
- return new OracleMigrator($this->conn);
+ return new OracleMigrator($this->conn, $random);
} else if ($platform instanceof MySqlPlatform) {
- return new MySQLMigrator($this->conn);
+ return new MySQLMigrator($this->conn, $random);
} else if ($platform instanceof SQLServerPlatform) {
- return new MsSqlMigrator($this->conn);
+ return new MsSqlMigrator($this->conn, $random);
} else if ($platform instanceof PostgreSqlPlatform) {
- return new Migrator($this->conn);
+ return new Migrator($this->conn, $random);
} else {
- return new NoCheckMigrator($this->conn);
+ return new NoCheckMigrator($this->conn, $random);
}
}
use \Doctrine\DBAL\Schema\Schema;
use \Doctrine\DBAL\Schema\SchemaConfig;
use \Doctrine\DBAL\Schema\Comparator;
+use OCP\Security\ISecureRandom;
class Migrator {
+
/**
* @var \Doctrine\DBAL\Connection $connection
*/
protected $connection;
+ /**
+ * @var ISecureRandom
+ */
+ private $random;
+
/**
* @param \Doctrine\DBAL\Connection $connection
+ * @param ISecureRandom $random
*/
- public function __construct(\Doctrine\DBAL\Connection $connection) {
+ public function __construct(\Doctrine\DBAL\Connection $connection, ISecureRandom $random) {
$this->connection = $connection;
+ $this->random = $random;
}
/**
$script = '';
$sqls = $schemaDiff->toSql($this->connection->getDatabasePlatform());
foreach ($sqls as $sql) {
- $script .= $sql . ';';
- $script .= PHP_EOL;
+ $script .= $this->convertStatementToScript($sql);
}
return $script;
* @return string
*/
protected function generateTemporaryTableName($name) {
- return 'oc_' . $name . '_' . \OCP\Util::generateRandomBytes(13);
+ return 'oc_' . $name . '_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
}
/**
$indexName = $index->getName();
} else {
// avoid conflicts in index names
- $indexName = 'oc_' . \OCP\Util::generateRandomBytes(13);
+ $indexName = 'oc_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
}
$newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary());
}
protected function dropTable($name) {
$this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($name));
}
+
+ /**
+ * @param $statement
+ * @return string
+ */
+ protected function convertStatementToScript($statement) {
+ $script = $statement . ';';
+ $script .= PHP_EOL;
+ $script .= PHP_EOL;
+ return $script;
+ }
}
protected function generateTemporaryTableName($name) {
return 'oc_' . uniqid();
}
+
+ /**
+ * @param $statement
+ * @return string
+ */
+ protected function convertStatementToScript($statement) {
+ if (substr($statement, -1) === ';') {
+ return $statement . PHP_EOL . '/' . PHP_EOL;
+ }
+ $script = $statement . ';';
+ $script .= PHP_EOL;
+ $script .= PHP_EOL;
+ return $script;
+ }
}
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Schema\Schema;
+use OCP\Security\ISecureRandom;
class SQLiteMigrator extends Migrator {
/**
* @param \Doctrine\DBAL\Connection $connection
+ * @param ISecureRandom $random
* @param \OCP\IConfig $config
*/
- public function __construct(\Doctrine\DBAL\Connection $connection, \OCP\IConfig $config) {
- parent::__construct($connection);
+ public function __construct(\Doctrine\DBAL\Connection $connection, ISecureRandom $random, \OCP\IConfig $config) {
+ parent::__construct($connection, $random);
$this->config = $config;
}