Merge pull request #9949 from owncloud/fixing-sqlite-migration-shared-hoster

generate copy of sqlite database file in data directory
remotes/origin/fix-10825
Morris Jobke 10 years ago
commit 1fbbaed261
  1. 3
      lib/private/db/mdb2schemamanager.php
  2. 26
      lib/private/db/sqlitemigrator.php

@ -59,7 +59,8 @@ class MDB2SchemaManager {
public function getMigrator() {
$platform = $this->conn->getDatabasePlatform();
if ($platform instanceof SqlitePlatform) {
return new SQLiteMigrator($this->conn);
$config = \OC::$server->getConfig();
return new SQLiteMigrator($this->conn, $config);
} else if ($platform instanceof OraclePlatform) {
return new OracleMigrator($this->conn);
} else if ($platform instanceof MySqlPlatform) {

@ -11,6 +11,21 @@ namespace OC\DB;
use Doctrine\DBAL\DBALException;
class SQLiteMigrator extends Migrator {
/**
* @var \OCP\IConfig
*/
private $config;
/**
* @param \Doctrine\DBAL\Connection $connection
* @param \OCP\IConfig $config
*/
public function __construct(\Doctrine\DBAL\Connection $connection, \OCP\IConfig $config) {
parent::__construct($connection);
$this->config = $config;
}
/**
* @param \Doctrine\DBAL\Schema\Schema $targetSchema
* @throws \OC\DB\MigrationException
@ -19,7 +34,7 @@ class SQLiteMigrator extends Migrator {
*/
public function checkMigrate(\Doctrine\DBAL\Schema\Schema $targetSchema) {
$dbFile = $this->connection->getDatabase();
$tmpFile = \OC_Helper::tmpFile('.db');
$tmpFile = $this->buildTempDatabase();
copy($dbFile, $tmpFile);
$connectionParams = array(
@ -37,4 +52,13 @@ class SQLiteMigrator extends Migrator {
throw new MigrationException('', $e->getMessage());
}
}
/**
* @return string
*/
private function buildTempDatabase() {
$dataDir = $this->config->getSystemValue("datadirectory", \OC::$SERVERROOT . '/data');
$tmpFile = uniqid("oc_");
return "$dataDir/$tmpFile.db";
}
}

Loading…
Cancel
Save