diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2013-03-22 23:33:40 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@owncloud.com> | 2013-03-27 19:12:28 +0100 |
commit | e2afd0cb42af17a968d6fbefac7372d13b71399a (patch) | |
tree | ca5be3aa1140da9320d3e522e92494537e628a27 | |
parent | 9d25058905f8a50e729397052d39eb84dcb9fe01 (diff) | |
download | nextcloud-server-e2afd0cb42af17a968d6fbefac7372d13b71399a.tar.gz nextcloud-server-e2afd0cb42af17a968d6fbefac7372d13b71399a.zip |
Upgrade FileCache on ownCloud upgrade for all users with files
-rw-r--r-- | core/ajax/update.php | 45 | ||||
-rw-r--r-- | lib/files/cache/upgrade.php | 22 |
2 files changed, 66 insertions, 1 deletions
diff --git a/core/ajax/update.php b/core/ajax/update.php index 8b20150d432..a2fc72f511c 100644 --- a/core/ajax/update.php +++ b/core/ajax/update.php @@ -14,6 +14,10 @@ if (OC::checkUpgrade(false)) { try { $result = OC_DB::updateDbFromStructure(OC::$SERVERROOT.'/db_structure.xml'); $watcher->success('Updated database'); + + // do a file cache upgrade for users with files + // this can take loooooooooooooooooooooooong + __doFileCacheUpgrade($watcher); } catch (Exception $exception) { $watcher->failure($exception->getMessage()); } @@ -26,6 +30,47 @@ if (OC::checkUpgrade(false)) { $watcher->done(); } +/** + * The FileCache Upgrade routine + * + * @param UpdateWatcher $watcher + */ +function __doFileCacheUpgrade($watcher) { + file_put_contents('/tmp/debug', "START\n", FILE_APPEND); + $query = \OC_DB::prepare(' + SELECT DISTINCT user + FROM`*PREFIX*fscache` + '); + $result = $query->execute(); + $users = $result->fetchAll(); + if(count($users) == 0) { + return; + } + $step = 100 / count($users); + file_put_contents('/tmp/debug', 'Step '. print_r($step, true)."\n", FILE_APPEND); + $percentCompleted = 0; + $lastPercentCompletedOutput = 0; + $startInfoShown = false; + foreach($users as $userRow) { + $user = $userRow['user']; + \OC\Files\Filesystem::initMountPoints($user); + \OC\Files\Cache\Upgrade::doSilentUpgrade($user); + if(!$startInfoShown) { + //We show it only now, because otherwise Info about upgraded apps + //will appear between this and progress info + $watcher->success('Updating filecache, this may take really long...'); + $startInfoShown = true; + } + $percentCompleted += $step; + $out = floor($percentCompleted); + if($out != $lastPercentCompletedOutput) { + $watcher->success('... '. $out.'% done ...'); + $lastPercentCompletedOutput = $out; + } + } + $watcher->success('Updated filecache'); +} + class UpdateWatcher { /** * @var \OC_EventSource $eventSource; diff --git a/lib/files/cache/upgrade.php b/lib/files/cache/upgrade.php index efb06a2b943..47184615b46 100644 --- a/lib/files/cache/upgrade.php +++ b/lib/files/cache/upgrade.php @@ -36,7 +36,6 @@ class Upgrade { return; } \OC_Hook::emit('\OC\Files\Cache\Upgrade', 'migrate_path', $path); - if ($row = $this->legacy->get($path)) { $data = $this->getNewData($row); if ($data) { @@ -251,4 +250,25 @@ class Upgrade { static function upgradeDone($user) { \OCP\Config::setUserValue($user, 'files', 'cache_version', 5); } + + /** + * Does a "silent" upgrade, i.e. without an Event-Source as triggered + * on User-Login via Ajax. This method is called within the regular + * ownCloud upgrade. + * + * @param string $user a User ID + */ + public static function doSilentUpgrade($user) { + if(!self::needUpgrade($user)) { + return; + } + $legacy = new \OC\Files\Cache\Legacy($user); + if ($legacy->hasItems()) { + \OC_DB::beginTransaction(); + $upgrade = new \OC\Files\Cache\Upgrade($legacy); + $upgrade->upgradePath('/' . $user . '/files'); + \OC_DB::commit(); + } + \OC\Files\Cache\Upgrade::upgradeDone($user); + } } |