Skip to content

Commit

Permalink
allow scanning files for multiple users
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Jun 18, 2013
1 parent 0b74e71 commit 85585ed
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
42 changes: 29 additions & 13 deletions apps/files/ajax/scan.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

$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 = explode(',', $_GET['users']);
}
} else {
$users = array(OC_User::getUser());
}

$eventSource = new OC_EventSource();
ScanListener::$eventSource = $eventSource;
Expand All @@ -12,21 +22,27 @@
OC_Hook::connect('\OC\Files\Cache\Scanner', 'scan_folder', 'ScanListener', 'folder');
OC_Hook::connect('\OC\Files\Cache\Scanner', 'scan_file', 'ScanListener', 'file');

$absolutePath = \OC\Files\Filesystem::getView()->getAbsolutePath($dir);
foreach ($users as $user) {
$eventSource->send('user', $user);
OC_Util::tearDownFS();
OC_Util::setupFS($user);

$absolutePath = \OC\Files\Filesystem::getView()->getAbsolutePath($dir);

$mountPoints = \OC\Files\Filesystem::getMountPoints($absolutePath);
$mountPoints[] = \OC\Files\Filesystem::getMountPoint($absolutePath);
$mountPoints = array_reverse($mountPoints); //start with the mount point of $dir
$mountPoints = \OC\Files\Filesystem::getMountPoints($absolutePath);
$mountPoints[] = \OC\Files\Filesystem::getMountPoint($absolutePath);
$mountPoints = array_reverse($mountPoints); //start with the mount point of $dir

foreach ($mountPoints as $mountPoint) {
$storage = \OC\Files\Filesystem::getStorage($mountPoint);
if ($storage) {
ScanListener::$mountPoints[$storage->getId()] = $mountPoint;
$scanner = $storage->getScanner();
if ($force) {
$scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG);
} else {
$scanner->backgroundScan();
foreach ($mountPoints as $mountPoint) {
$storage = \OC\Files\Filesystem::getStorage($mountPoint);
if ($storage) {
ScanListener::$mountPoints[$storage->getId()] = $mountPoint;
$scanner = $storage->getScanner();
if ($force) {
$scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG);
} else {
$scanner->backgroundScan();
}
}
}
}
Expand Down
18 changes: 16 additions & 2 deletions apps/files/js/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ $(document).ready(function() {
}
});

function scanFiles(force, dir){
function scanFiles(force, dir, users){
if (!OC.currentUser) {
return;
}
Expand All @@ -705,7 +705,18 @@ function scanFiles(force, dir){
}
force = !!force; //cast to bool
scanFiles.scanning = true;
var scannerEventSource = new OC.EventSource(OC.filePath('files','ajax','scan.php'),{force:force,dir:dir});
var scannerEventSource;
if (users) {
var usersString;
if (users === 'all') {
usersString = users;
} else {
usersString = users.join(',');
}
scannerEventSource = new OC.EventSource(OC.filePath('files','ajax','scan.php'),{force: force,dir: dir, users: usersString});
} else {
scannerEventSource = new OC.EventSource(OC.filePath('files','ajax','scan.php'),{force: force,dir: dir});
}
scanFiles.cancel = scannerEventSource.close.bind(scannerEventSource);
scannerEventSource.listen('count',function(count){
console.log(count + ' files scanned')
Expand All @@ -717,6 +728,9 @@ function scanFiles(force, dir){
scanFiles.scanning=false;
console.log('done after ' + count + ' files');
});
scannerEventSource.listen('user',function(user){
console.log('scanning files for ' + user);
});
}
scanFiles.scanning=false;

Expand Down

0 comments on commit 85585ed

Please sign in to comment.