summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-06-20 01:41:49 -0700
committerThomas Müller <thomas.mueller@tmit.eu>2013-06-20 01:41:49 -0700
commit5aaf807366ab92bcd7126a5217cc586bef005818 (patch)
tree2e38d3a1106bded49be30f08b91e188bac359182 /apps
parent91c0b81130da4fc781ea700ca015e387947d3542 (diff)
parent6778a45d45e7fe0274bc920b2a47800069da49b6 (diff)
downloadnextcloud-server-5aaf807366ab92bcd7126a5217cc586bef005818.tar.gz
nextcloud-server-5aaf807366ab92bcd7126a5217cc586bef005818.zip
Merge pull request #3784 from owncloud/rescan-all
Give admins the ability to rescan the filesystem for multiple users at once
Diffstat (limited to 'apps')
-rw-r--r--apps/files/ajax/scan.php42
-rw-r--r--apps/files/js/files.js18
2 files changed, 45 insertions, 15 deletions
diff --git a/apps/files/ajax/scan.php b/apps/files/ajax/scan.php
index 6659cd459c8..0706d4e7829 100644
--- a/apps/files/ajax/scan.php
+++ b/apps/files/ajax/scan.php
@@ -4,6 +4,16 @@ 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();
ScanListener::$eventSource = $eventSource;
@@ -12,21 +22,27 @@ ScanListener::$view = \OC\Files\Filesystem::getView();
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();
+ }
}
}
}
diff --git a/apps/files/js/files.js b/apps/files/js/files.js
index a79d34c9b23..3438c1c30a1 100644
--- a/apps/files/js/files.js
+++ b/apps/files/js/files.js
@@ -695,7 +695,7 @@ $(document).ready(function() {
}
});
-function scanFiles(force, dir){
+function scanFiles(force, dir, users){
if (!OC.currentUser) {
return;
}
@@ -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 = JSON.stringify(users);
+ }
+ 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')
@@ -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;