Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 2 additions & 22 deletions lib/private/DB/MDB2SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,6 @@ public function __construct($conn) {
$this->conn = $conn;
}

/**
* saves database scheme to xml file
* @param string $file name of file
* @return bool
*
* TODO: write more documentation
*/
public function getDbStructure($file) {
return \OC\DB\MDB2SchemaWriter::saveSchemaToFile($file, $this->conn);
}

/**
* Creates tables from XML file
* @param string $file file to read structure from
Expand Down Expand Up @@ -117,19 +106,10 @@ public function updateDbFromStructure($file, $generateSql = false) {

if ($generateSql) {
return $migrator->generateChangeScript($toSchema);
} else {
$migrator->migrate($toSchema);
return true;
}
}

/**
* @param \Doctrine\DBAL\Schema\Schema $schema
* @return string
*/
public function generateChangeScript($schema) {
$migrator = $this->getMigrator();
return $migrator->generateChangeScript($schema);
$migrator->migrate($toSchema);
return true;
}

/**
Expand Down
177 changes: 0 additions & 177 deletions lib/private/DB/MDB2SchemaWriter.php

This file was deleted.

45 changes: 0 additions & 45 deletions lib/private/DB/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,32 +107,6 @@ protected function generateTemporaryTableName($name) {
return $this->config->getSystemValue('dbtableprefix', 'oc_') . $name . '_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
}

/**
* @param \Doctrine\DBAL\Schema\Table $table
* @param string $newName
* @return \Doctrine\DBAL\Schema\Table
*/
protected function renameTableSchema(Table $table, $newName) {
/**
* @var \Doctrine\DBAL\Schema\Index[] $indexes
*/
$indexes = $table->getIndexes();
$newIndexes = [];
foreach ($indexes as $index) {
if ($index->isPrimary()) {
// do not rename primary key
$indexName = $index->getName();
} else {
// avoid conflicts in index names
$indexName = $this->config->getSystemValue('dbtableprefix', 'oc_') . $this->random->generate(13, ISecureRandom::CHAR_LOWER);
}
$newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary());
}

// foreign keys are not supported so we just set it to an empty array
return new Table($newName, $table->getColumns(), $newIndexes, [], 0, $table->getOptions());
}

public function createSchema() {
$filterExpression = $this->getFilterExpression();
$this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression);
Expand Down Expand Up @@ -201,18 +175,6 @@ protected function applySchema(Schema $targetSchema, \Doctrine\DBAL\Connection $
$connection->commit();
}

/**
* @param string $sourceName
* @param string $targetName
*/
protected function copyTable($sourceName, $targetName) {
$quotedSource = $this->connection->quoteIdentifier($sourceName);
$quotedTarget = $this->connection->quoteIdentifier($targetName);

$this->connection->exec('CREATE TABLE ' . $quotedTarget . ' (LIKE ' . $quotedSource . ')');
$this->connection->exec('INSERT INTO ' . $quotedTarget . ' SELECT * FROM ' . $quotedSource);
}

/**
* @param string $name
*/
Expand Down Expand Up @@ -244,11 +206,4 @@ protected function emit($sql, $step, $max) {
}
$this->dispatcher->dispatch(new GenericEvent($sql, [$step+1, $max]), '\OC\DB\Migrator::executeSql');
}

private function emitCheckStep($tableName, $step, $max) {
if ($this->dispatcher === null) {
return;
}
$this->dispatcher->dispatch(new GenericEvent($tableName, [$step+1, $max]), '\OC\DB\Migrator::checkTable');
}
}
10 changes: 0 additions & 10 deletions tests/lib/DB/DBSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ protected function tearDown(): void {
public function testSchema() {
$this->doTestSchemaCreating();
$this->doTestSchemaChanging();
$this->doTestSchemaDumping();
$this->doTestSchemaRemoving();
}

Expand All @@ -73,15 +72,6 @@ public function doTestSchemaChanging() {
$this->assertTableExist($this->table2);
}

public function doTestSchemaDumping() {
$outfile = 'static://db_out.xml';
$connection = \OC::$server->getDatabaseConnection();
(new \OC\DB\MDB2SchemaManager($connection))->getDbStructure($outfile);
$content = \file_get_contents($outfile);
$this->assertStringContainsString($this->table1, $content);
$this->assertStringContainsString($this->table2, $content);
}

public function doTestSchemaRemoving() {
$connection = \OC::$server->getDatabaseConnection();
(new \OC\DB\MDB2SchemaManager($connection))->removeDBStructure($this->schema_file);
Expand Down