Skip to content

Commit 4277560

Browse files
committed
Almost forgot to keep the original function.
1 parent 43b9860 commit 4277560

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

lib/Command/RescanPhotos.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,41 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8989
}
9090
if ($userId === null) {
9191
$this->userManager->callForSeenUsers(function (IUser $user) use ($inBackground) {
92-
$this->scanUserPhotos($user->getUID(), $pathToScan, $inBackground);
92+
if ($pathToScan === null) {
93+
$this->rescanUserPhotos($user->getUID(), $inBackground);
94+
} else {
95+
$this->scanUserPhotos($user->getUID(), $pathToScan, $inBackground);
96+
}
9397
});
9498
} else {
9599
$user = $this->userManager->get($userId);
96100
if ($user !== null) {
97-
$this->scanUserPhotos($userId, $pathToScan, $inBackground);
101+
if ($pathToScan === null) {
102+
$this->rescanUserPhotos($userId, $inBackground);
103+
} else {
104+
$this->scanUserPhotos($userId, $pathToScan, $inBackground);
105+
}
98106
}
99107
}
100108
return 0;
101109
}
102110

111+
/**
112+
* @param string $userId
113+
* @param bool $inBackground
114+
* @return void
115+
* @throws \OCP\PreConditionNotMetException
116+
*/
117+
private function rescanUserPhotos(string $userId, bool $inBackground=true) {
118+
echo '======== User '.$userId.' ========'."\n";
119+
$c = 1;
120+
foreach ($this->photofilesService->rescan($userId, $inBackground) as $path) {
121+
echo '['.$c.'] Photo "'.$path.'" added'."\n";
122+
$c++;
123+
}
124+
$this->config->setUserValue($userId, 'maps', 'installScanDone', 'yes');
125+
}
126+
103127
/**
104128
* @param string $userId
105129
* @param string $pathToScan

lib/Service/PhotofilesService.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,23 @@ public function __construct (ILogger $logger,
7878
$this->backgroundJobCache = $this->cacheFactory->createDistributed('maps:background-jobs');
7979
}
8080

81-
public function rescanPath($userId, $pathToScan, $inBackground=true) {
81+
public function rescan($userId, $inBackground=true) {
82+
$this->photosCache->clear($userId);
8283
$userFolder = $this->root->getUserFolder($userId);
83-
if ($pathToScan !== null) {
84-
$userFolder = $userFolder->get($pathToScan);
84+
$photos = $this->gatherPhotoFiles($userFolder, true);
85+
$this->photoMapper->deleteAll($userId);
86+
foreach ($photos as $photo) {
87+
if ($inBackground) {
88+
$this->addPhoto($photo, $userId);
89+
} else {
90+
$this->addPhotoNow($photo, $userId);
91+
}
92+
yield $photo->getPath();
8593
}
94+
}
95+
96+
public function rescanPath($userId, $pathToScan, $inBackground=true) {
97+
$userFolder = $this->root->getUserFolder($userId)->get($pathToScan);
8698
$photos = $this->gatherPhotoFiles($userFolder, true);
8799
foreach ($photos as $photo) {
88100
if ($inBackground) {

0 commit comments

Comments
 (0)