Skip to content

Commit

Permalink
Almost forgot to keep the original function.
Browse files Browse the repository at this point in the history
  • Loading branch information
tetebueno committed Mar 27, 2024
1 parent 43b9860 commit 4277560
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
28 changes: 26 additions & 2 deletions lib/Command/RescanPhotos.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,41 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
if ($userId === null) {
$this->userManager->callForSeenUsers(function (IUser $user) use ($inBackground) {
$this->scanUserPhotos($user->getUID(), $pathToScan, $inBackground);
if ($pathToScan === null) {
$this->rescanUserPhotos($user->getUID(), $inBackground);
} else {
$this->scanUserPhotos($user->getUID(), $pathToScan, $inBackground);
}
});
} else {
$user = $this->userManager->get($userId);
if ($user !== null) {
$this->scanUserPhotos($userId, $pathToScan, $inBackground);
if ($pathToScan === null) {
$this->rescanUserPhotos($userId, $inBackground);
} else {
$this->scanUserPhotos($userId, $pathToScan, $inBackground);
}
}
}
return 0;
}

/**
* @param string $userId
* @param bool $inBackground
* @return void
* @throws \OCP\PreConditionNotMetException
*/
private function rescanUserPhotos(string $userId, bool $inBackground=true) {
echo '======== User '.$userId.' ========'."\n";
$c = 1;
foreach ($this->photofilesService->rescan($userId, $inBackground) as $path) {
echo '['.$c.'] Photo "'.$path.'" added'."\n";
$c++;
}
$this->config->setUserValue($userId, 'maps', 'installScanDone', 'yes');
}

/**
* @param string $userId
* @param string $pathToScan
Expand Down
18 changes: 15 additions & 3 deletions lib/Service/PhotofilesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,23 @@ public function __construct (ILogger $logger,
$this->backgroundJobCache = $this->cacheFactory->createDistributed('maps:background-jobs');
}

public function rescanPath($userId, $pathToScan, $inBackground=true) {
public function rescan($userId, $inBackground=true) {
$this->photosCache->clear($userId);
$userFolder = $this->root->getUserFolder($userId);
if ($pathToScan !== null) {
$userFolder = $userFolder->get($pathToScan);
$photos = $this->gatherPhotoFiles($userFolder, true);
$this->photoMapper->deleteAll($userId);
foreach ($photos as $photo) {
if ($inBackground) {
$this->addPhoto($photo, $userId);
} else {
$this->addPhotoNow($photo, $userId);
}
yield $photo->getPath();
}
}

public function rescanPath($userId, $pathToScan, $inBackground=true) {
$userFolder = $this->root->getUserFolder($userId)->get($pathToScan);
$photos = $this->gatherPhotoFiles($userFolder, true);
foreach ($photos as $photo) {
if ($inBackground) {
Expand Down

0 comments on commit 4277560

Please sign in to comment.