|
|
@ -11,6 +11,21 @@ namespace OC\DB; |
|
|
|
use Doctrine\DBAL\DBALException; |
|
|
|
use Doctrine\DBAL\DBALException; |
|
|
|
|
|
|
|
|
|
|
|
class SQLiteMigrator extends Migrator { |
|
|
|
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 |
|
|
|
* @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
|
|
* @throws \OC\DB\MigrationException |
|
|
|
* @throws \OC\DB\MigrationException |
|
|
@ -19,7 +34,7 @@ class SQLiteMigrator extends Migrator { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function checkMigrate(\Doctrine\DBAL\Schema\Schema $targetSchema) { |
|
|
|
public function checkMigrate(\Doctrine\DBAL\Schema\Schema $targetSchema) { |
|
|
|
$dbFile = $this->connection->getDatabase(); |
|
|
|
$dbFile = $this->connection->getDatabase(); |
|
|
|
$tmpFile = \OC_Helper::tmpFile('.db'); |
|
|
|
$tmpFile = $this->buildTempDatabase(); |
|
|
|
copy($dbFile, $tmpFile); |
|
|
|
copy($dbFile, $tmpFile); |
|
|
|
|
|
|
|
|
|
|
|
$connectionParams = array( |
|
|
|
$connectionParams = array( |
|
|
@ -37,4 +52,13 @@ class SQLiteMigrator extends Migrator { |
|
|
|
throw new MigrationException('', $e->getMessage()); |
|
|
|
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"; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|