示例#1
0
文件: scan.php 项目: kenwi/core
 protected function scanFiles($user, $path, $verbose, OutputInterface $output)
 {
     $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection(), \OC::$server->getLogger());
     # printout and count
     if ($verbose) {
         $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFile', function ($path) use($output) {
             $output->writeln("Scanning file   <info>{$path}</info>");
             $this->filesCounter += 1;
         });
         $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFolder', function ($path) use($output) {
             $output->writeln("Scanning folder <info>{$path}</info>");
             $this->foldersCounter += 1;
         });
         $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use($output) {
             $output->writeln("Error while scanning, storage not available (" . $e->getMessage() . ")");
         });
         # count only
     } else {
         $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFile', function ($path) use($output) {
             $this->filesCounter += 1;
         });
         $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFolder', function ($path) use($output) {
             $this->foldersCounter += 1;
         });
     }
     try {
         $scanner->scan($path);
     } catch (ForbiddenException $e) {
         $output->writeln("<error>Home storage for user {$user} not writable</error>");
         $output->writeln("Make sure you're running the scan command only as the user the web server runs as");
     }
 }
示例#2
0
 protected function scanFiles($user, $path, $verbose, OutputInterface $output, $backgroundScan = false)
 {
     $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection(), \OC::$server->getLogger());
     # check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception
     # printout and count
     if ($verbose) {
         $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFile', function ($path) use($output) {
             $output->writeln("\tFile   <info>{$path}</info>");
             $this->filesCounter += 1;
             if ($this->hasBeenInterrupted()) {
                 throw new \Exception('ctrl-c');
             }
         });
         $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFolder', function ($path) use($output) {
             $output->writeln("\tFolder <info>{$path}</info>");
             $this->foldersCounter += 1;
             if ($this->hasBeenInterrupted()) {
                 throw new \Exception('ctrl-c');
             }
         });
         $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use($output) {
             $output->writeln("Error while scanning, storage not available (" . $e->getMessage() . ")");
         });
         # count only
     } else {
         $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFile', function () use($output) {
             $this->filesCounter += 1;
             if ($this->hasBeenInterrupted()) {
                 throw new \Exception('ctrl-c');
             }
         });
         $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFolder', function () use($output) {
             $this->foldersCounter += 1;
             if ($this->hasBeenInterrupted()) {
                 throw new \Exception('ctrl-c');
             }
         });
     }
     $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFile', function ($path) use($output) {
         $this->checkScanWarning($path, $output);
     });
     $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFolder', function ($path) use($output) {
         $this->checkScanWarning($path, $output);
     });
     try {
         if ($backgroundScan) {
             $scanner->backgroundScan($path);
         } else {
             $scanner->scan($path);
         }
     } catch (ForbiddenException $e) {
         $output->writeln("<error>Home storage for user {$user} not writable</error>");
         $output->writeln("Make sure you're running the scan command only as the user the web server runs as");
     } catch (\Exception $e) {
         if ($e->getMessage() !== 'ctrl-c') {
             $output->writeln('<error>Exception while scanning: ' . $e->getMessage() . "\n" . $e->getTraceAsString() . '</error>');
         }
         return;
     }
 }
示例#3
0
文件: scan.php 项目: hjimmy/owncloud
 protected function scanFiles($user, OutputInterface $output)
 {
     $scanner = new \OC\Files\Utils\Scanner($user);
     $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFile', function ($path) use($output) {
         $output->writeln("Scanning <info>{$path}</info>");
     });
     $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFolder', function ($path) use($output) {
         $output->writeln("Scanning <info>{$path}</info>");
     });
     $scanner->scan('');
 }
示例#4
0
文件: scan.php 项目: Combustible/core
 protected function scanFiles($user, OutputInterface $output)
 {
     $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection());
     $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFile', function ($path) use($output) {
         $output->writeln("Scanning <info>{$path}</info>");
     });
     $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFolder', function ($path) use($output) {
         $output->writeln("Scanning <info>{$path}</info>");
     });
     try {
         $scanner->scan('');
     } catch (ForbiddenException $e) {
         $output->writeln("<error>Home storage for user {$user} not writable</error>");
         $output->writeln("Make sure you're running the scan command only as the user the web server runs as");
     }
 }
示例#5
0
if (isset($_GET['users'])) {
    \OCP\JSON::checkAdminUser();
    if ($_GET['users'] === 'all') {
        $users = OC_User::getUsers();
    } else {
        $users = json_decode($_GET['users']);
    }
} else {
    $users = array(OC_User::getUser());
}
$eventSource = \OC::$server->createEventSource();
$listener = new ScanListener($eventSource);
foreach ($users as $user) {
    $eventSource->send('user', $user);
    $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection());
    $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFile', array($listener, 'file'));
    $scanner->listen('\\OC\\Files\\Utils\\Scanner', 'scanFolder', array($listener, 'folder'));
    try {
        if ($force) {
            $scanner->scan($dir);
        } else {
            $scanner->backgroundScan($dir);
        }
    } catch (\Exception $e) {
        $eventSource->send('error', get_class($e) . ': ' . $e->getMessage());
    }
}
$eventSource->send('done', $listener->getCount());
$eventSource->close();
class ScanListener
{