summaryrefslogtreecommitdiffstats
path: root/apps/files/ajax/upgrade.php
blob: 7237b02c0b06af48a65d074c0d07145dd3d4f318 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
set_time_limit(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) {
		$this->count++;
		if ($this->count > ($this->lastSend + 5)) {
			$this->lastSend = $this->count;
			$this->eventSource->send('count', $this->count);
		}
	}
}