summaryrefslogtreecommitdiffstats
path: root/lib/files/cache
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-11-30 01:41:30 +0100
committerRobin Appelman <icewind@owncloud.com>2012-11-30 01:41:30 +0100
commitdbbb357f62c1ba86bdff0fbe63e4cea9bc2977fc (patch)
tree81ceee024d224f530d82b50d043e43da570381f8 /lib/files/cache
parentd33f697a5f3438f286ba3abe63255b6797a6fc03 (diff)
downloadnextcloud-server-dbbb357f62c1ba86bdff0fbe63e4cea9bc2977fc.tar.gz
nextcloud-server-dbbb357f62c1ba86bdff0fbe63e4cea9bc2977fc.zip
add upgrade path from old cache to preserve file id's
Diffstat (limited to 'lib/files/cache')
-rw-r--r--lib/files/cache/upgrade.php50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/files/cache/upgrade.php b/lib/files/cache/upgrade.php
new file mode 100644
index 00000000000..5be04b42070
--- /dev/null
+++ b/lib/files/cache/upgrade.php
@@ -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];
+ }
+}