/** * Create a storage entry * * @param string $storageId * @return int */ private function createStorage($storageId) { $sql = 'INSERT INTO `*PREFIX*storages` (`id`)' . ' VALUES (?)'; $storageId = Storage::adjustStorageId($storageId); $numRows = $this->connection->executeUpdate($sql, array($storageId)); $this->assertEquals(1, $numRows); return \OC_DB::insertid('*PREFIX*storages'); }
/** * Create a storage entry * * @param string $storageId * @return int */ private function createStorage($storageId) { $sql = 'INSERT INTO `*PREFIX*storages` (`id`)' . ' VALUES (?)'; $storageId = Storage::adjustStorageId($storageId); $numRows = $this->connection->executeUpdate($sql, array($storageId)); $this->assertEquals(1, $numRows); return \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*storages'); }
/** * Fix the given legacy storage by renaming the old id * to the new id. If the new id already exists, whichever * storage that has data in the file cache will be used. * If both have data, nothing will be done and false is * returned. * * @param string $oldId old storage id * @param int $oldNumericId old storage numeric id * @param string $userId * @return bool true if fixed, false otherwise * @throws RepairException */ private function fixLegacyStorage($oldId, $oldNumericId, $userId = null) { // check whether the new storage already exists if (is_null($userId)) { $userId = $this->extractUserId($oldId); } $newId = 'home::' . $userId; // check if target id already exists $newNumericId = Storage::getNumericStorageId($newId); if (!is_null($newNumericId)) { $newNumericId = (int) $newNumericId; // try and resolve the conflict // check which one of "local::" or "home::" needs to be kept $this->findStorageInCacheStatement->execute(array($oldNumericId, $newNumericId)); $row1 = $this->findStorageInCacheStatement->fetch(); $row2 = $this->findStorageInCacheStatement->fetch(); $this->findStorageInCacheStatement->closeCursor(); if ($row2 !== false) { // two results means both storages have data, not auto-fixable throw new RepairException('Could not automatically fix legacy storage ' . '"' . $oldId . '" => "' . $newId . '"' . ' because they both have data.'); } if ($row1 === false || (int) $row1['storage'] === $oldNumericId) { // old storage has data, then delete the empty new id $toDelete = $newId; } else { if ((int) $row1['storage'] === $newNumericId) { // new storage has data, then delete the empty old id $toDelete = $oldId; } else { // unknown case, do not continue return false; } } // delete storage including file cache Storage::remove($toDelete); // if we deleted the old id, the new id will be used // automatically if ($toDelete === $oldId) { // nothing more to do return true; } } // rename old id to new id $newId = Storage::adjustStorageId($newId); $oldId = Storage::adjustStorageId($oldId); $rowCount = $this->renameStorageStatement->execute(array($newId, $oldId)); $this->renameStorageStatement->closeCursor(); return $rowCount === 1; }