Merge pull request #8921 from owncloud/fix-remove-storage-master

No need to create a storage within remove
This commit is contained in:
Thomas Müller 2014-06-06 16:16:44 +02:00
commit c053f27381
1 changed files with 22 additions and 10 deletions

View File

@ -43,12 +43,15 @@ class Storage {
} }
} }
/**
* @return string
*/
public function getNumericId() { public function getNumericId() {
return $this->numericId; return $this->numericId;
} }
/** /**
* @return string * @return string|null
*/ */
public static function getStorageId($numericId) { public static function getStorageId($numericId) {
@ -62,37 +65,46 @@ class Storage {
} }
/** /**
* @param string $storageId * @return string|null
*/ */
public static function exists($storageId) { public static function getNumericStorageId($storageId) {
if (strlen($storageId) > 64) { if (strlen($storageId) > 64) {
$storageId = md5($storageId); $storageId = md5($storageId);
} }
$sql = 'SELECT `numeric_id` FROM `*PREFIX*storages` WHERE `id` = ?'; $sql = 'SELECT `numeric_id` FROM `*PREFIX*storages` WHERE `id` = ?';
$result = \OC_DB::executeAudited($sql, array($storageId)); $result = \OC_DB::executeAudited($sql, array($storageId));
if ($row = $result->fetchRow()) { if ($row = $result->fetchRow()) {
return true; return $row['numeric_id'];
} else { } else {
return false; return null;
} }
} }
/**
* @param string $storageId
* @return bool
*/
public static function exists($storageId) {
return !is_null(self::getNumericStorageId($storageId));
}
/** /**
* remove the entry for the storage * remove the entry for the storage
* *
* @param string $storageId * @param string $storageId
*/ */
public static function remove($storageId) { public static function remove($storageId) {
$storageCache = new Storage($storageId);
$numericId = $storageCache->getNumericId();
if (strlen($storageId) > 64) { if (strlen($storageId) > 64) {
$storageId = md5($storageId); $storageId = md5($storageId);
} }
$sql = 'DELETE FROM `*PREFIX*storages` WHERE `id` = ?'; $sql = 'DELETE FROM `*PREFIX*storages` WHERE `id` = ?';
\OC_DB::executeAudited($sql, array($storageId)); \OC_DB::executeAudited($sql, array($storageId));
$numericId = self::exists($storageId);
if (!is_null($numericId)) {
$sql = 'DELETE FROM `*PREFIX*filecache` WHERE `storage` = ?'; $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `storage` = ?';
\OC_DB::executeAudited($sql, array($numericId)); \OC_DB::executeAudited($sql, array($numericId));
} }
}
} }