Add error handling to the file cache upgrade

This commit is contained in:
Michael Gapczynski 2013-03-16 14:28:42 -04:00
parent dfbf57207d
commit c69dc3483a
1 changed files with 24 additions and 16 deletions

View File

@ -39,9 +39,10 @@ class Upgrade {
if ($row = $this->legacy->get($path)) { if ($row = $this->legacy->get($path)) {
$data = $this->getNewData($row); $data = $this->getNewData($row);
$this->insert($data); if ($data) {
$this->insert($data);
$this->upgradeChilds($data['id'], $mode); $this->upgradeChilds($data['id'], $mode);
}
} }
} }
@ -53,9 +54,11 @@ class Upgrade {
foreach ($children as $child) { foreach ($children as $child) {
$childData = $this->getNewData($child); $childData = $this->getNewData($child);
\OC_Hook::emit('\OC\Files\Cache\Upgrade', 'migrate_path', $child['path']); \OC_Hook::emit('\OC\Files\Cache\Upgrade', 'migrate_path', $child['path']);
$this->insert($childData); if ($childData) {
if ($mode == Scanner::SCAN_RECURSIVE) { $this->insert($childData);
$this->upgradeChilds($child['id']); if ($mode == Scanner::SCAN_RECURSIVE) {
$this->upgradeChilds($child['id']);
}
} }
} }
} }
@ -95,20 +98,25 @@ class Upgrade {
*/ */
function getNewData($data) { function getNewData($data) {
$newData = $data; $newData = $data;
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($data['path']);
/** /**
* @var \OC\Files\Storage\Storage $storage * @var \OC\Files\Storage\Storage $storage
* @var string $internalPath; * @var string $internalPath;
*/ */
$newData['path_hash'] = md5($internalPath); list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($data['path']);
$newData['path'] = $internalPath; if ($storage) {
$newData['storage'] = $this->getNumericId($storage); $newData['path_hash'] = md5($internalPath);
$newData['parent'] = ($internalPath === '') ? -1 : $data['parent']; $newData['path'] = $internalPath;
$newData['permissions'] = ($data['writable']) ? \OCP\PERMISSION_ALL : \OCP\PERMISSION_READ; $newData['storage'] = $this->getNumericId($storage);
$newData['storage_object'] = $storage; $newData['parent'] = ($internalPath === '') ? -1 : $data['parent'];
$newData['mimetype'] = $this->getMimetypeId($newData['mimetype'], $storage); $newData['permissions'] = ($data['writable']) ? \OCP\PERMISSION_ALL : \OCP\PERMISSION_READ;
$newData['mimepart'] = $this->getMimetypeId($newData['mimepart'], $storage); $newData['storage_object'] = $storage;
return $newData; $newData['mimetype'] = $this->getMimetypeId($newData['mimetype'], $storage);
$newData['mimepart'] = $this->getMimetypeId($newData['mimepart'], $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);
return false;
}
} }
/** /**