Blame view
sources/apps/files/ajax/scan.php
1.62 KB
|
03e52840d
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php
set_time_limit(0); //scanning can take ages
session_write_close();
$force = (isset($_GET['force']) and ($_GET['force'] === 'true'));
$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
if (isset($_GET['users'])) {
OC_JSON::checkAdminUser();
if ($_GET['users'] === 'all') {
$users = OC_User::getUsers();
} else {
$users = json_decode($_GET['users']);
}
} else {
$users = array(OC_User::getUser());
}
$eventSource = new OC_EventSource();
|
|
31b7f2792
|
19 |
$listener = new ScanListener($eventSource); |
|
03e52840d
|
20 21 22 |
foreach ($users as $user) {
$eventSource->send('user', $user);
|
|
31b7f2792
|
23 24 25 26 27 28 29 |
$scanner = new \OC\Files\Utils\Scanner($user);
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', array($listener, 'file'));
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', array($listener, 'folder'));
if ($force) {
$scanner->scan($dir);
} else {
$scanner->backgroundScan($dir);
|
|
03e52840d
|
30 31 |
} } |
|
31b7f2792
|
32 |
$eventSource->send('done', $listener->getCount());
|
|
03e52840d
|
33 34 35 |
$eventSource->close();
class ScanListener {
|
|
31b7f2792
|
36 37 |
private $fileCount = 0; private $lastCount = 0; |
|
03e52840d
|
38 39 |
/** |
|
31b7f2792
|
40 |
* @var \OC_EventSource event source to pass events to |
|
03e52840d
|
41 |
*/ |
|
31b7f2792
|
42 |
private $eventSource; |
|
03e52840d
|
43 44 |
/** |
|
31b7f2792
|
45 |
* @param \OC_EventSource $eventSource |
|
03e52840d
|
46 |
*/ |
|
31b7f2792
|
47 48 49 |
public function __construct($eventSource) {
$this->eventSource = $eventSource;
}
|
|
03e52840d
|
50 51 |
/** |
|
31b7f2792
|
52 |
* @param string $path |
|
03e52840d
|
53 |
*/ |
|
31b7f2792
|
54 55 |
public function folder($path) {
$this->eventSource->send('folder', $path);
|
|
03e52840d
|
56 |
} |
|
31b7f2792
|
57 58 59 60 61 |
public function file() {
$this->fileCount++;
if ($this->fileCount > $this->lastCount + 20) { //send a count update every 20 files
$this->lastCount = $this->fileCount;
$this->eventSource->send('count', $this->fileCount);
|
|
03e52840d
|
62 63 |
} } |
|
31b7f2792
|
64 65 66 67 |
public function getCount() {
return $this->fileCount;
}
|
|
03e52840d
|
68 |
} |