diff options
Diffstat (limited to 'apps/files/ajax/scan.php')
-rw-r--r-- | apps/files/ajax/scan.php | 74 |
1 files changed, 29 insertions, 45 deletions
diff --git a/apps/files/ajax/scan.php b/apps/files/ajax/scan.php index 0706d4e7829..5b32b6db9b7 100644 --- a/apps/files/ajax/scan.php +++ b/apps/files/ajax/scan.php @@ -16,72 +16,56 @@ if (isset($_GET['users'])) { } $eventSource = new OC_EventSource(); -ScanListener::$eventSource = $eventSource; -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'); +$listener = new ScanListener($eventSource); 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 - - 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(); - } - } + $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); } } -$eventSource->send('done', ScanListener::$fileCount); +$eventSource->send('done', $listener->getCount()); $eventSource->close(); class ScanListener { - static public $fileCount = 0; - static public $lastCount = 0; + private $fileCount = 0; + private $lastCount = 0; /** - * @var \OC\Files\View $view + * @var \OC_EventSource event source to pass events to */ - static public $view; + private $eventSource; /** - * @var array $mountPoints map storage ids to mountpoints + * @param \OC_EventSource $eventSource */ - static public $mountPoints = array(); + public function __construct($eventSource) { + $this->eventSource = $eventSource; + } /** - * @var \OC_EventSource event source to pass events to + * @param string $path */ - 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); + public function folder($path) { + $this->eventSource->send('folder', $path); } - 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); + 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); } } + + public function getCount() { + return $this->fileCount; + } } |