From 96a9d171b3fc31a6ad1ed89dca987765ed1ce721 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 16 Jul 2015 12:55:28 +0200 Subject: Fix db schema --- db_structure.xml | 35 +++++++++++++++++++++++++++- lib/private/lock/abstractlockingprovider.php | 2 -- lib/private/lock/dblockingprovider.php | 16 ++++++------- lib/repair/dropoldtables.php | 1 + tests/lib/lock/dblockingprovider.php | 2 +- 5 files changed, 44 insertions(+), 12 deletions(-) diff --git a/db_structure.xml b/db_structure.xml index 95acefcfaee..5c2b26e5f15 100644 --- a/db_structure.xml +++ b/db_structure.xml @@ -1185,10 +1185,20 @@ - *dbprefix*locks + *dbprefix*file_locks + + id + integer + 0 + true + true + 4 + 1 + + lock integer @@ -1204,9 +1214,24 @@ 64 + + ttl + integer + true + 4 + true + true + lock_id_index + + id + ascending + + + + true lock_path_index @@ -1215,6 +1240,14 @@ + + lock_ttl_index + + ttl + ascending + + + diff --git a/lib/private/lock/abstractlockingprovider.php b/lib/private/lock/abstractlockingprovider.php index 290bb77e52f..03b4912ea13 100644 --- a/lib/private/lock/abstractlockingprovider.php +++ b/lib/private/lock/abstractlockingprovider.php @@ -1,8 +1,6 @@ * @author Robin Appelman - * @author Thomas Müller * * @copyright Copyright (c) 2015, ownCloud, Inc. * @license AGPL-3.0 diff --git a/lib/private/lock/dblockingprovider.php b/lib/private/lock/dblockingprovider.php index 70f4539eb28..aee66bca745 100644 --- a/lib/private/lock/dblockingprovider.php +++ b/lib/private/lock/dblockingprovider.php @@ -38,7 +38,7 @@ class DBLockingProvider extends AbstractLockingProvider { } protected function initLockField($path) { - $this->connection->insertIfNotExist('*PREFIX*locks', ['path' => $path, 'lock' => 0], ['path']); + $this->connection->insertIfNotExist('*PREFIX*file_locks', ['path' => $path, 'lock' => 0], ['path']); } /** @@ -47,7 +47,7 @@ class DBLockingProvider extends AbstractLockingProvider { * @return bool */ public function isLocked($path, $type) { - $query = $this->connection->prepare('SELECT `lock` from `*PREFIX*locks` WHERE `path` = ?'); + $query = $this->connection->prepare('SELECT `lock` from `*PREFIX*file_locks` WHERE `path` = ?'); $query->execute([$path]); $lockValue = (int)$query->fetchColumn(); if ($type === self::LOCK_SHARED) { @@ -68,12 +68,12 @@ class DBLockingProvider extends AbstractLockingProvider { $this->initLockField($path); if ($type === self::LOCK_SHARED) { $result = $this->connection->executeUpdate( - 'UPDATE `*PREFIX*locks` SET `lock` = `lock` + 1 WHERE `path` = ? AND `lock` >= 0', + 'UPDATE `*PREFIX*file_locks` SET `lock` = `lock` + 1 WHERE `path` = ? AND `lock` >= 0', [$path] ); } else { $result = $this->connection->executeUpdate( - 'UPDATE `*PREFIX*locks` SET `lock` = -1 WHERE `path` = ? AND `lock` = 0', + 'UPDATE `*PREFIX*file_locks` SET `lock` = -1 WHERE `path` = ? AND `lock` = 0', [$path] ); } @@ -91,12 +91,12 @@ class DBLockingProvider extends AbstractLockingProvider { $this->initLockField($path); if ($type === self::LOCK_SHARED) { $this->connection->executeUpdate( - 'UPDATE `*PREFIX*locks` SET `lock` = `lock` - 1 WHERE `path` = ? AND `lock` > 0', + 'UPDATE `*PREFIX*file_locks` SET `lock` = `lock` - 1 WHERE `path` = ? AND `lock` > 0', [$path] ); } else { $this->connection->executeUpdate( - 'UPDATE `*PREFIX*locks` SET `lock` = 0 WHERE `path` = ? AND `lock` = -1', + 'UPDATE `*PREFIX*file_locks` SET `lock` = 0 WHERE `path` = ? AND `lock` = -1', [$path] ); } @@ -114,12 +114,12 @@ class DBLockingProvider extends AbstractLockingProvider { $this->initLockField($path); if ($targetType === self::LOCK_SHARED) { $result = $this->connection->executeUpdate( - 'UPDATE `*PREFIX*locks` SET `lock` = 1 WHERE `path` = ? AND `lock` = -1', + 'UPDATE `*PREFIX*file_locks` SET `lock` = 1 WHERE `path` = ? AND `lock` = -1', [$path] ); } else { $result = $this->connection->executeUpdate( - 'UPDATE `*PREFIX*locks` SET `lock` = -1 WHERE `path` = ? AND `lock` = 1', + 'UPDATE `*PREFIX*file_locks` SET `lock` = -1 WHERE `path` = ? AND `lock` = 1', [$path] ); } diff --git a/lib/repair/dropoldtables.php b/lib/repair/dropoldtables.php index 89f872e16cc..cfe0df6cb5b 100644 --- a/lib/repair/dropoldtables.php +++ b/lib/repair/dropoldtables.php @@ -76,6 +76,7 @@ class DropOldTables extends BasicEmitter implements RepairStep { 'calendar_share_event', 'foldersize', 'fscache', + 'locks', 'log', 'media_albums', 'media_artists', diff --git a/tests/lib/lock/dblockingprovider.php b/tests/lib/lock/dblockingprovider.php index 4229ffb9c51..4818ef1ceca 100644 --- a/tests/lib/lock/dblockingprovider.php +++ b/tests/lib/lock/dblockingprovider.php @@ -37,7 +37,7 @@ class DBLockingProvider extends LockingProvider { } public function tearDown() { - $this->connection->executeQuery('DELETE FROM `*PREFIX*locks`'); + $this->connection->executeQuery('DELETE FROM `*PREFIX*file_locks`'); parent::tearDown(); } } -- cgit v1.2.3