add upgrade path from old cache to preserve file id's

This commit is contained in:
Robin Appelman 2012-11-30 01:41:30 +01:00
parent d33f697a5f
commit dbbb357f62
3 changed files with 63 additions and 3 deletions

View File

@ -1,8 +1,18 @@
<?php
$l=OC_L10N::get('files');
$l = OC_L10N::get('files');
OCP\App::registerAdmin('files', 'admin');
OCP\App::addNavigationEntry( array( "id" => "files_index", "order" => 0, "href" => OCP\Util::linkTo( "files", "index.php" ), "icon" => OCP\Util::imagePath( "core", "places/home.svg" ), "name" => $l->t("Files") ));
OCP\App::addNavigationEntry(array("id" => "files_index", "order" => 0, "href" => OCP\Util::linkTo("files", "index.php"), "icon" => OCP\Util::imagePath("core", "places/home.svg"), "name" => $l->t("Files")));
OC_Search::registerProvider('OC_Search_Provider_File');
if (OC_User::isLoggedIn()) {
// update OC4.5 filecache to OC5 filecache, can't do this in update.php since it needs to happen for each user individually
$cacheVersion = (int)OCP\Config::getUserValue(OC_User::getUser(), 'files', 'cache_version', 4);
if ($cacheVersion < 5) {
\OC_Log::write('files', 'updating filecache to 5.0 for user ' . OC_User::getUser(), \OC_Log::INFO);
\OC\Files\Cache\Upgrade::upgrade();
OCP\Config::setUserValue(OC_User::getUser(), 'files', 'cache_version', 5);
}
}

View File

@ -1 +1 @@
1.1.6
1.1.7

50
lib/files/cache/upgrade.php vendored Normal file
View File

@ -0,0 +1,50 @@
<?php
/**
* Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OC\Files\Cache;
class Upgrade {
static $permissionsCaches = array();
static function upgrade() {
$insertQuery = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache`( `fileid`, `storage`, `path`, `path_hash`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted` )
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
$oldEntriesQuery = \OC_DB::prepare('SELECT * FROM `*PREFIX*fscache` ORDER BY `id` ASC'); //sort ascending to ensure the parent gets inserted before a child
$oldEntriesResult = $oldEntriesQuery->execute();
while ($row = $oldEntriesResult->fetchRow()) {
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($row['path']);
/**
* @var \OC\Files\Storage\Storage $storage
* @var string $internalPath;
*/
$pathHash = md5($internalPath);
$storageId = $storage->getId();
$parentId = ($internalPath === '') ? -1 : $row['parent'];
$insertQuery->execute(array($row['id'], $storageId, $internalPath, $pathHash, $parentId, $row['name'], $row['mimetype'], $row['mimepart'], $row['size'], $row['mtime'], $row['encrypted']));
$permissions = ($row['writable']) ? \OCP\PERMISSION_ALL : \OCP\PERMISSION_READ;
$permissionsCache = self::getPermissionsCache($storage);
$permissionsCache->set($row['id'], $row['user'], $permissions);
}
}
/**
* @param \OC\Files\Storage\Storage $storage
* @return Permissions
*/
static function getPermissionsCache($storage) {
$storageId = $storage->getId();
if (!isset(self::$permissionsCaches[$storageId])) {
self::$permissionsCaches[$storageId] = $storage->getPermissionsCache();
}
return self::$permissionsCaches[$storageId];
}
}