Fix lost ETag on Cache Upgrade
This commit is contained in:
parent
599778b153
commit
7839ec5093
|
@ -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);
|
||||
|
@ -126,6 +146,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
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue