mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #38860 from nextcloud/scanner-change-summary
add summary of detected changes to files:scan output
This commit is contained in:
commit
c912a3f0f6
3 changed files with 38 additions and 4 deletions
|
|
@ -37,6 +37,9 @@ use OC\Core\Command\Base;
|
|||
use OC\Core\Command\InterruptedException;
|
||||
use OC\DB\Connection;
|
||||
use OC\DB\ConnectionAdapter;
|
||||
use OCP\Files\Events\FileCacheUpdated;
|
||||
use OCP\Files\Events\NodeAddedToCache;
|
||||
use OCP\Files\Events\NodeRemovedFromCache;
|
||||
use OCP\Files\File;
|
||||
use OC\ForbiddenException;
|
||||
use OC\Metadata\MetadataManager;
|
||||
|
|
@ -59,18 +62,27 @@ class Scan extends Base {
|
|||
protected int $foldersCounter = 0;
|
||||
protected int $filesCounter = 0;
|
||||
protected int $errorsCounter = 0;
|
||||
protected int $newCounter = 0;
|
||||
protected int $updatedCounter = 0;
|
||||
protected int $removedCounter = 0;
|
||||
private IRootFolder $root;
|
||||
private MetadataManager $metadataManager;
|
||||
private IEventDispatcher $eventDispatcher;
|
||||
private LoggerInterface $logger;
|
||||
|
||||
public function __construct(
|
||||
IUserManager $userManager,
|
||||
IRootFolder $rootFolder,
|
||||
MetadataManager $metadataManager
|
||||
MetadataManager $metadataManager,
|
||||
IEventDispatcher $eventDispatcher,
|
||||
LoggerInterface $logger
|
||||
) {
|
||||
$this->userManager = $userManager;
|
||||
parent::__construct();
|
||||
$this->root = $rootFolder;
|
||||
$this->metadataManager = $metadataManager;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
protected function configure() {
|
||||
|
|
@ -157,6 +169,16 @@ class Scan extends Base {
|
|||
++$this->errorsCounter;
|
||||
});
|
||||
|
||||
$this->eventDispatcher->addListener(NodeAddedToCache::class, function() {
|
||||
++$this->newCounter;
|
||||
});
|
||||
$this->eventDispatcher->addListener(FileCacheUpdated::class, function() {
|
||||
++$this->updatedCounter;
|
||||
});
|
||||
$this->eventDispatcher->addListener(NodeRemovedFromCache::class, function() {
|
||||
++$this->removedCounter;
|
||||
});
|
||||
|
||||
try {
|
||||
if ($backgroundScan) {
|
||||
$scanner->backgroundScan($path);
|
||||
|
|
@ -277,9 +299,14 @@ class Scan extends Base {
|
|||
// Stop the timer
|
||||
$this->execTime += microtime(true);
|
||||
|
||||
$this->logger->info("Completed scan of {$this->filesCounter} files in {$this->foldersCounter} folder. Found {$this->newCounter} new, {$this->updatedCounter} updated and {$this->removedCounter} removed items");
|
||||
|
||||
$headers = [
|
||||
'Folders',
|
||||
'Files',
|
||||
'New',
|
||||
'Updated',
|
||||
'Removed',
|
||||
'Errors',
|
||||
'Elapsed time',
|
||||
];
|
||||
|
|
@ -287,6 +314,9 @@ class Scan extends Base {
|
|||
$rows = [
|
||||
$this->foldersCounter,
|
||||
$this->filesCounter,
|
||||
$this->newCounter,
|
||||
$this->updatedCounter,
|
||||
$this->removedCounter,
|
||||
$this->errorsCounter,
|
||||
$niceDate,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -291,7 +291,7 @@ class Scanner extends BasicEmitter implements IScanner {
|
|||
$data['permissions'] = $data['scan_permissions'];
|
||||
}
|
||||
\OC_Hook::emit('Scanner', 'addToCache', ['file' => $path, 'data' => $data]);
|
||||
$this->emit('\OC\Files\Cache\Scanner', 'addToCache', [$path, $this->storageId, $data]);
|
||||
$this->emit('\OC\Files\Cache\Scanner', 'addToCache', [$path, $this->storageId, $data, $fileId]);
|
||||
if ($this->cacheActive) {
|
||||
if ($fileId !== -1) {
|
||||
$this->cache->update($fileId, $data);
|
||||
|
|
|
|||
|
|
@ -251,9 +251,13 @@ class Scanner extends PublicEmitter {
|
|||
$this->postProcessEntry($storage, $path);
|
||||
$this->dispatcher->dispatchTyped(new FileCacheUpdated($storage, $path));
|
||||
});
|
||||
$scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) {
|
||||
$scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path, $storageId, $data, $fileId) use ($storage) {
|
||||
$this->postProcessEntry($storage, $path);
|
||||
$this->dispatcher->dispatchTyped(new NodeAddedToCache($storage, $path));
|
||||
if ($fileId) {
|
||||
$this->dispatcher->dispatchTyped(new FileCacheUpdated($storage, $path));
|
||||
} else {
|
||||
$this->dispatcher->dispatchTyped(new NodeAddedToCache($storage, $path));
|
||||
}
|
||||
});
|
||||
|
||||
if (!$storage->file_exists($relativePath)) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue