示例#1
0
/**
 * The FileCache Upgrade routine
 *
 * @param UpdateWatcher $watcher
 */
function __doFileCacheUpgrade($watcher)
{
    try {
        $query = \OC_DB::prepare('
			SELECT DISTINCT `user`
			FROM `*PREFIX*fscache`
		');
        $result = $query->execute();
    } catch (\Exception $e) {
        return;
    }
    $users = $result->fetchAll();
    if (count($users) == 0) {
        return;
    }
    $step = 100 / count($users);
    $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');
}
示例#2
0
preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
if (count($matches) > 0 && $matches[1] <= 8) {
    $isIE8 = true;
}
// if IE8 and "?dir=path" was specified, reformat the URL to use a hash like "#?dir=path"
if ($isIE8 && isset($_GET['dir'])) {
    if ($dir === '') {
        $dir = '/';
    }
    header('Location: ' . OCP\Util::linkTo('files', 'index.php') . '#?dir=' . \OCP\Util::encodePath($dir));
    exit;
}
$ajaxLoad = false;
$files = array();
$user = OC_User::getUser();
if (\OC\Files\Cache\Upgrade::needUpgrade($user)) {
    //dont load anything if we need to upgrade the cache
    $needUpgrade = true;
    $freeSpace = 0;
} else {
    if ($isIE8) {
        // after the redirect above, the URL will have a format
        // like "files#?dir=path" which means that no path was given
        // (dir is not set). In that specific case, we don't return any
        // files because the client will take care of switching the dir
        // to the one from the hash, then ajax-load the initial file list
        $files = array();
        $ajaxLoad = true;
    } else {
        $files = \OCA\Files\Helper::getFiles($dir);
    }
示例#3
0
 /**
  * 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);
 }
示例#4
0
    private function upgradeFileCache()
    {
        try {
            $query = \OC_DB::prepare('
				SELECT DISTINCT `user`
				FROM `*PREFIX*fscache`
			');
            $result = $query->execute();
        } catch (\Exception $e) {
            return;
        }
        $users = $result->fetchAll();
        if (count($users) == 0) {
            return;
        }
        $step = 100 / count($users);
        $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
                $this->emit('\\OC\\Updater', 'filecacheStart');
                $startInfoShown = true;
            }
            $percentCompleted += $step;
            $out = floor($percentCompleted);
            if ($out != $lastPercentCompletedOutput) {
                $this->emit('\\OC\\Updater', 'filecacheProgress', array($out));
                $lastPercentCompletedOutput = $out;
            }
        }
        $this->emit('\\OC\\Updater', 'filecacheDone');
    }
示例#5
0
//scanning can take ages
session_write_close();
$user = OC_User::getUser();
$eventSource = new OC_EventSource();
$listener = new UpgradeListener($eventSource);
$legacy = new \OC\Files\Cache\Legacy($user);
if ($legacy->hasItems()) {
    OC_Hook::connect('\\OC\\Files\\Cache\\Upgrade', 'migrate_path', $listener, 'upgradePath');
    OC_DB::beginTransaction();
    $upgrade = new \OC\Files\Cache\Upgrade($legacy);
    $count = $legacy->getCount();
    $eventSource->send('total', $count);
    $upgrade->upgradePath('/' . $user . '/files');
    OC_DB::commit();
}
\OC\Files\Cache\Upgrade::upgradeDone($user);
$eventSource->send('done', true);
$eventSource->close();
class UpgradeListener
{
    /**
     * @var OC_EventSource $eventSource
     */
    private $eventSource;
    private $count = 0;
    private $lastSend = 0;
    public function __construct($eventSource)
    {
        $this->eventSource = $eventSource;
    }
    public function upgradePath($path)