Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix lastinsertid for postgres wehn reusing fileid
  • Loading branch information
tomneedham committed Nov 1, 2017
commit 2c62c8a647416166d6b77d6993fedac0ac529c65
14 changes: 11 additions & 3 deletions lib/private/Repair/RepairMismatchFileCachePath.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@

namespace OC\Repair;

use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use OCP\DB\QueryBuilder\IQueryBuilder;
use Doctrine\DBAL\Platforms\OraclePlatform;
use OCP\Files\IMimeTypeLoader;
use OCP\IDBConnection;
Expand Down Expand Up @@ -121,7 +122,7 @@ private function fixEntryPath(IOutput $out, $fileId, $wrongPath, $correctStorage
$out->advance(1, $text);
}

private function addQueryConditionsParentIdWrongPath($qb, $storageNumericId) {
private function addQueryConditionsParentIdWrongPath($qb) {
// thanks, VicDeo!
if ($this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
$concatFunction = $qb->createFunction("CONCAT(fcp.path, '/', fc.name)");
Expand Down Expand Up @@ -399,7 +400,14 @@ private function getOrCreateEntry($storageId, $path, $reuseFileId = null) {
}
$qb->insert('filecache')->values($values);
$qb->execute();
return $this->connection->lastInsertId('*PREFIX*filecache');

// If we reused the fileid then this is the id to return
if($reuseFileId !== null) {
return $reuseFileId;
} else {
// Else we inserted a new row with auto generated id, use that
return $this->connection->lastInsertId('*PREFIX*filecache');
}
}

/**
Expand Down
3 changes: 3 additions & 0 deletions lib/public/IDBConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public function executeUpdate($query, array $params = array(), array $types = ar

/**
* Used to get the id of the just inserted element
* Note: On postgres platform, this will return the last sequence id which
* may not be the id last inserted if you were reinserting a previously
* used auto_increment id.
* @param string $table the name of the table where we inserted the item
* @return int the id of the inserted element
* @since 6.0.0
Expand Down
8 changes: 0 additions & 8 deletions tests/lib/Repair/RepairMismatchFileCachePathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ public function testRepairDetachedSubtree() {
// end corrupt storage

// Parallel test storage
/*
$storageId_parallel = 2;
$rootId1_parallel = $this->createFileCacheEntry($storageId_parallel, '');
$baseId1_parallel = $this->createFileCacheEntry($storageId_parallel, 'files', $rootId1_parallel);
Expand All @@ -593,7 +592,6 @@ public function testRepairDetachedSubtree() {
$notOrphanedFolderChild2_parallel = $this->createFileCacheEntry($storageId_parallel, 'missingdir/missingdir1', $notOrphanedFolder2_parallel);
$notOrphanedId2_parallel = $this->createFileCacheEntry($storageId_parallel, 'missingdir/missingdir1/orphaned2', $notOrphanedFolder2_parallel);
// end parallel test storage
*/

$outputMock = $this->createMock(IOutput::class);
$this->repair->setStorageNumericId($storageId);
Expand Down Expand Up @@ -642,7 +640,6 @@ public function testRepairDetachedSubtree() {
$this->assertEquals(md5(''), $entry['path_hash']);

// now check the parallel storage is intact
/*
// orphaned entry reattached
$entry = $this->getFileCacheEntry($notOrphanedId1_parallel);
$this->assertEquals($notOrphanedFolder_parallel, $entry['parent']);
Expand Down Expand Up @@ -684,7 +681,6 @@ public function testRepairDetachedSubtree() {
$this->assertEquals((string)$storageId_parallel, $entry['storage']);
$this->assertEquals('', $entry['path']);
$this->assertEquals(md5(''), $entry['path_hash']);
*/
}

/**
Expand All @@ -699,11 +695,9 @@ public function testRepairMissingRoot() {
$orphanedId = $this->createFileCacheEntry($storageId, 'noroot', $nonExistingParentId);

// Test parallel storage which should be untouched by the repair operation
/*
$testStorageId = 2;
$baseId = $this->createFileCacheEntry($testStorageId, '');
$noRootid = $this->createFileCacheEntry($testStorageId, 'noroot', $baseId);
*/


$outputMock = $this->createMock(IOutput::class);
Expand All @@ -724,7 +718,6 @@ public function testRepairMissingRoot() {
$this->assertEquals('', $entry['path']);
$this->assertEquals(md5(''), $entry['path_hash']);

/*
// Check that the parallel test storage is still intact
$entry = $this->getFileCacheEntry($noRootid);
$this->assertEquals($baseId, $entry['parent']);
Expand All @@ -736,7 +729,6 @@ public function testRepairMissingRoot() {
$this->assertEquals((string)$testStorageId, $entry['storage']);
$this->assertEquals('', $entry['path']);
$this->assertEquals(md5(''), $entry['path_hash']);
*/
}
}