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'] : '';
|
|
|
|
|
|
|
|
$eventSource = new OC_EventSource();
|
|
|
|
ScanListener::$eventSource = $eventSource;
|
|
|
|
ScanListener::$view = \OC\Files\Filesystem::getView();
|
2011-11-10 15:40:09 +00:00
|
|
|
|
2012-11-22 23:20:46 +00:00
|
|
|
OC_Hook::connect('\OC\Files\Cache\Scanner', 'scan_folder', 'ScanListener', 'folder');
|
|
|
|
OC_Hook::connect('\OC\Files\Cache\Scanner', 'scan_file', 'ScanListener', 'file');
|
2012-10-27 10:18:01 +00:00
|
|
|
|
2012-11-22 23:20:46 +00:00
|
|
|
$absolutePath = \OC\Files\Filesystem::getView()->getAbsolutePath($dir);
|
2012-01-30 22:32:55 +00:00
|
|
|
|
2012-11-22 23:20:46 +00:00
|
|
|
$mountPoints = \OC\Files\Filesystem::getMountPoints($absolutePath);
|
|
|
|
$mountPoints[] = \OC\Files\Filesystem::getMountPoint($absolutePath);
|
|
|
|
$mountPoints = array_reverse($mountPoints); //start with the mount point of $dir
|
2011-11-10 15:40:09 +00:00
|
|
|
|
2012-11-22 23:20:46 +00:00
|
|
|
foreach ($mountPoints as $mountPoint) {
|
|
|
|
$storage = \OC\Files\Filesystem::getStorage($mountPoint);
|
2012-11-24 21:42:54 +00:00
|
|
|
if ($storage) {
|
|
|
|
ScanListener::$mountPoints[$storage->getId()] = $mountPoint;
|
|
|
|
$scanner = $storage->getScanner();
|
|
|
|
if ($force) {
|
|
|
|
$scanner->scan('');
|
|
|
|
} else {
|
|
|
|
$scanner->backgroundScan();
|
|
|
|
}
|
2012-11-22 23:20:46 +00:00
|
|
|
}
|
2012-01-31 15:12:38 +00:00
|
|
|
}
|
|
|
|
|
2012-11-22 23:20:46 +00:00
|
|
|
$eventSource->send('done', ScanListener::$fileCount);
|
|
|
|
$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
|
|
|
|
2012-11-22 23:20:46 +00:00
|
|
|
static public $fileCount = 0;
|
|
|
|
static public $lastCount = 0;
|
2012-08-29 06:42:49 +00:00
|
|
|
|
2012-11-22 23:20:46 +00:00
|
|
|
/**
|
|
|
|
* @var \OC\Files\View $view
|
|
|
|
*/
|
|
|
|
static public $view;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array $mountPoints map storage ids to mountpoints
|
|
|
|
*/
|
|
|
|
static public $mountPoints = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \OC_EventSource event source to pass events to
|
|
|
|
*/
|
|
|
|
static public $eventSource;
|
|
|
|
|
|
|
|
static function folder($params) {
|
|
|
|
$internalPath = $params['path'];
|
|
|
|
$mountPoint = self::$mountPoints[$params['storage']];
|
|
|
|
$path = self::$view->getRelativePath($mountPoint . $internalPath);
|
|
|
|
self::$eventSource->send('folder', $path);
|
2012-02-05 00:23:04 +00:00
|
|
|
}
|
2012-11-22 23:20:46 +00:00
|
|
|
|
|
|
|
static function file() {
|
|
|
|
self::$fileCount++;
|
|
|
|
if (self::$fileCount > self::$lastCount + 20) { //send a count update every 20 files
|
|
|
|
self::$lastCount = self::$fileCount;
|
|
|
|
self::$eventSource->send('count', self::$fileCount);
|
|
|
|
}
|
2012-01-31 15:33:16 +00:00
|
|
|
}
|
2012-01-30 22:32:55 +00:00
|
|
|
}
|