summaryrefslogtreecommitdiffstats
path: root/lib/files/cache/upgrade.php
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2013-03-22 13:23:43 +0100
committerArthur Schiwon <blizzz@owncloud.com>2013-03-27 19:11:35 +0100
commit7839ec5093272fb516ad701b79387af158c8994d (patch)
treeb8590b0c2eabbe3da376b09c0f1e16a14d730567 /lib/files/cache/upgrade.php
parent599778b153f17fe1e749d2f10b47e32ba1eedb06 (diff)
downloadnextcloud-server-7839ec5093272fb516ad701b79387af158c8994d.tar.gz
nextcloud-server-7839ec5093272fb516ad701b79387af158c8994d.zip
Fix lost ETag on Cache Upgrade
Diffstat (limited to 'lib/files/cache/upgrade.php')
-rw-r--r--lib/files/cache/upgrade.php77
1 files changed, 74 insertions, 3 deletions
diff --git a/lib/files/cache/upgrade.php b/lib/files/cache/upgrade.php
index 4d6c28de851..cf2eb7f9ef8 100644
--- a/lib/files/cache/upgrade.php
+++ b/lib/files/cache/upgrade.php
@@ -74,12 +74,12 @@ class Upgrade {
function insert($data) {
if (!$this->inCache($data['storage'], $data['path_hash'], $data['id'])) {
$insertQuery = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache`
- ( `fileid`, `storage`, `path`, `path_hash`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted` )
- VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
+ ( `fileid`, `storage`, `path`, `path_hash`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `etag` )
+ VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
$insertQuery->execute(array($data['id'], $data['storage'],
$data['path'], $data['path_hash'], $data['parent'], $data['name'],
- $data['mimetype'], $data['mimepart'], $data['size'], $data['mtime'], $data['encrypted']));
+ $data['mimetype'], $data['mimepart'], $data['size'], $data['mtime'], $data['encrypted'], $data['etag']));
}
}
@@ -101,6 +101,25 @@ class Upgrade {
* get the new data array from the old one
*
* @param array $data the data from the old cache
+ * Example data array
+ * Array
+ * (
+ * [id] => 418
+ * [path] => /tina/files/picture.jpg //relative to datadir
+ * [path_hash] => 66d4547e372888deed80b24fec9b192b
+ * [parent] => 234
+ * [name] => picture.jpg
+ * [user] => tina
+ * [size] => 1265283
+ * [ctime] => 1363909709
+ * [mtime] => 1363909709
+ * [mimetype] => image/jpeg
+ * [mimepart] => image
+ * [encrypted] => 0
+ * [versioned] => 0
+ * [writable] => 1
+ * )
+ *
* @return array
*/
function getNewData($data) {
@@ -119,6 +138,7 @@ class Upgrade {
$newData['storage_object'] = $storage;
$newData['mimetype'] = $this->getMimetypeId($newData['mimetype'], $storage);
$newData['mimepart'] = $this->getMimetypeId($newData['mimepart'], $storage);
+ $newData['etag'] = $this->getETag($data['path'], $data['user'], $internalPath, $storage);
return $newData;
} else {
\OC_Log::write('core', 'Unable to migrate data from old cache for '.$data['path'].' because the storage was not found', \OC_Log::ERROR);
@@ -127,6 +147,57 @@ class Upgrade {
}
/**
+ * get a file`s E-Tag
+ *
+ * @param string $legacyPath in the form of a legacy path
+ * @param string $user the user ID the file referred to in path belongs to
+ * @param string $internalPath
+ * @param \OC\Files\Storage\Storage $storage
+ * @return string Etag
+ */
+ function getETag($legacyPath, $user, $internalPath, $storage) {
+ static $queryGetETag = null;
+ static $queryCleanUp = null;
+
+ //the path in the database is stored wo /$user/files
+ //we need to strip it off, care is taken if user == files
+ $offset = strpos($legacyPath, '/files/', 2) + 6;
+ $legacyPath = substr($legacyPath, $offset);
+
+ //Look for the E-Tag in the old database
+ if(is_null($queryGetETag)) {
+ $queryGetETag = \OC_DB::prepare('
+ SELECT `propertyvalue`
+ FROM `*PREFIX*properties`
+ WHERE `propertyname` = \'{DAV:}getetag\'
+ AND `propertypath` = ?
+ AND `userid` = ?
+ LIMIT 1');
+ }
+ $result = $queryGetETag->execute(array($legacyPath, $user));
+ $etag = $result->fetchOne();
+
+ if($etag) {
+ if(is_null($queryCleanUp)) {
+ $queryCleanUp = \OC_DB::prepare('
+ DELETE FROM `*PREFIX*properties`
+ WHERE `propertyname` = \'{DAV:}getetag\'
+ AND `propertypath` = ?
+ AND `userid` = ?
+ LIMIT 1
+ ');
+ }
+
+ //On success: remove the old DB entry and return the value
+ $queryCleanUp->execute(array($legacyPath, $user));
+ return $etag;
+ }
+
+ //No etag detected, determine it with new methods
+ return $storage->getETag($internalPath);
+ }
+
+ /**
* get the numeric storage id
*
* @param \OC\Files\Storage\Storage $storage