Get all files from all users for indexing

Hello!

Is it possible to get all files from all users and get the fileinfo for those files as well?
I want to iterate over the files and send them to an Elasticsearch Index.

So far i tried

$path = $this->view->getPath($file);
$this->logger->info("path: " . $path);
$fileInfo = $this->view->getFileInfo($path);

but with these functions i can only access my own files.

Is it even possible to do this?
Or is there a better way to index all the files?

Thanks a lot!

Fabian

Hi Fabian,
another way that I’m aware of is the following:

/** @var OCP\IDBConnection */
$connection;
/** @var OCP\EventDispatcher\IEventDispatcher */
$eventDispatcher;
/** @var OCP\ILogger */
$logger;
$users =  $this->userManager->callForAllUsers(function (IUser $user) use ($connection, $eventDispatcher, $logger): void {
  $scanner = new OC\Files\Utils\Scanner($user->getUID(), $connection, $eventDispatcher, $logger);
  $scanner->listen(
    '\OC\Files\Utils\Scanner',
    'postScanFile',
    function ($path) use ($logger) {
      $logger->info("path: " . $path);
    }
  );
});

But I’m not sure if this is the best way.
This way has also the downside that it does not show files that have been shared.

Regards

Christian

FYI there is an existing app for that https://github.com/nextcloud/fulltextsearch_elasticsearch

For completeness the link to the nextcloud app
app fulltextsearch_elasticsearch