2011-11-10 15:40:09 +00:00
|
|
|
<?php
|
2012-11-22 23:20:46 +00:00
|
|
|
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'] : '';
|
2013-06-18 23:26:08 +00:00
|
|
|
if (isset($_GET['users'])) {
|
|
|
|
OC_JSON::checkAdminUser();
|
|
|
|
if ($_GET['users'] === 'all') {
|
|
|
|
$users = OC_User::getUsers();
|
|
|
|
} else {
|
2013-06-19 13:02:18 +00:00
|
|
|
$users = json_decode($_GET['users']);
|
2013-06-18 23:26:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$users = array(OC_User::getUser());
|
|
|
|
}
|
2012-11-22 23:20:46 +00:00
|
|
|
|
|
|
|
$eventSource = new OC_EventSource();
|
2013-07-19 14:44:47 +00:00
|
|
|
$listener = new ScanListener($eventSource);
|
2012-10-27 10:18:01 +00:00
|
|
|
|
2013-06-18 23:26:08 +00:00
|
|
|
foreach ($users as $user) {
|
|
|
|
$eventSource->send('user', $user);
|
2013-07-19 14:44:47 +00:00
|
|
|
$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);
|
2012-11-22 23:20:46 +00:00
|
|
|
}
|
2012-01-31 15:12:38 +00:00
|
|
|
}
|
|
|
|
|
2013-07-19 14:44:47 +00:00
|
|
|
$eventSource->send('done', $listener->getCount());
|
2012-11-22 23:20:46 +00:00
|
|
|
$eventSource->close();
|
2012-01-31 15:12:38 +00:00
|
|
|
|
2012-11-22 23:20:46 +00:00
|
|
|
class ScanListener {
|
2012-08-29 06:42:49 +00:00
|
|
|
|
2013-07-19 14:44:47 +00:00
|
|
|
private $fileCount = 0;
|
|
|
|
private $lastCount = 0;
|
2012-08-29 06:42:49 +00:00
|
|
|
|
2012-11-22 23:20:46 +00:00
|
|
|
/**
|
2013-07-19 14:44:47 +00:00
|
|
|
* @var \OC_EventSource event source to pass events to
|
2012-11-22 23:20:46 +00:00
|
|
|
*/
|
2013-07-19 14:44:47 +00:00
|
|
|
private $eventSource;
|
2012-11-22 23:20:46 +00:00
|
|
|
|
|
|
|
/**
|
2013-07-19 14:44:47 +00:00
|
|
|
* @param \OC_EventSource $eventSource
|
2012-11-22 23:20:46 +00:00
|
|
|
*/
|
2013-07-19 14:44:47 +00:00
|
|
|
public function __construct($eventSource) {
|
|
|
|
$this->eventSource = $eventSource;
|
|
|
|
}
|
2012-11-22 23:20:46 +00:00
|
|
|
|
|
|
|
/**
|
2013-07-19 14:44:47 +00:00
|
|
|
* @param string $path
|
2012-11-22 23:20:46 +00:00
|
|
|
*/
|
2013-07-19 14:44:47 +00:00
|
|
|
public function folder($path) {
|
|
|
|
$this->eventSource->send('folder', $path);
|
2012-02-05 00:23:04 +00:00
|
|
|
}
|
2012-11-22 23:20:46 +00:00
|
|
|
|
2013-07-19 14:44:47 +00:00
|
|
|
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);
|
2012-11-22 23:20:46 +00:00
|
|
|
}
|
2012-01-31 15:33:16 +00:00
|
|
|
}
|
2013-07-19 14:44:47 +00:00
|
|
|
|
|
|
|
public function getCount() {
|
|
|
|
return $this->fileCount;
|
|
|
|
}
|
2012-01-30 22:32:55 +00:00
|
|
|
}
|