aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/console/scan.php
blob: b9eccfb9934bd39a9e0ae1bde6896f28aca52052 (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
<?php

if (!OC::$CLI) {
	echo "This script can be run from the command line only\n";
	return;
}
if (count($argv) !== 2) {
	echo "Usage:" . PHP_EOL;
	echo " files:scan <user_id>" . PHP_EOL;
	echo "  will rescan all files of the given user" . PHP_EOL;
	echo " files:scan --all" . PHP_EOL;
	echo "  will rescan all files of all known users" . PHP_EOL;
	return;
}

function scanFiles($user) {
	$scanner = new \OC\Files\Utils\Scanner($user);
	$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function($path) {
		echo "Scanning $path" . PHP_EOL;
	});
	$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function($path) {
		echo "Scanning $path" . PHP_EOL;
	});
	$scanner->scan('');
}

if ($argv[1] === '--all') {
	$users = OC_User::getUsers();
} else {
	$users = array($argv[1]);
}

foreach ($users as $user) {
	scanFiles($user);
}