Skip to content

Commit fa440d3

Browse files
committed
Let's see if this passes Lint once and for all.
Signed-off-by: tetebueno <[email protected]>
1 parent 0f607a1 commit fa440d3

File tree

2 files changed

+71
-64
lines changed

2 files changed

+71
-64
lines changed

lib/Command/RescanPhotos.php

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,27 @@
2626

2727
class RescanPhotos extends Command {
2828

29-
protected IUserManager $userManager;
30-
protected OutputInterface $output;
31-
protected IManager $encryptionManager;
32-
protected PhotofilesService $photofilesService;
33-
protected IConfig $config;
29+
protected IUserManager $userManager;
30+
protected OutputInterface $output;
31+
protected IManager $encryptionManager;
32+
protected PhotofilesService $photofilesService;
33+
protected IConfig $config;
3434

35-
public function __construct(IUserManager $userManager,
36-
IManager $encryptionManager,
37-
PhotofilesService $photofilesService,
38-
IConfig $config) {
39-
parent::__construct();
40-
$this->userManager = $userManager;
41-
$this->encryptionManager = $encryptionManager;
42-
$this->photofilesService = $photofilesService;
43-
$this->config = $config;
44-
}
35+
public function __construct(
36+
IUserManager $userManager,
37+
IManager $encryptionManager,
38+
PhotofilesService $photofilesService,
39+
IConfig $config) {
40+
parent::__construct();
41+
$this->userManager = $userManager;
42+
$this->encryptionManager = $encryptionManager;
43+
$this->photofilesService = $photofilesService;
44+
$this->config = $config;
45+
}
4546

46-
/**
47-
* @return void
48-
*/
47+
/**
48+
* @return void
49+
*/
4950
protected function configure() {
5051
$this->setName('maps:scan-photos')
5152
->setDescription('Rescan photos GPS exif data')
@@ -57,21 +58,21 @@ protected function configure() {
5758
->addArgument(
5859
'path',
5960
InputArgument::OPTIONAL,
60-
'Scan photos GPS exif data for the given path under user\'s files without wiping the database'
61+
'Scan photos GPS exif data for the given path under user\'s files without wiping the database.'
6162
)
62-
->addOption(
63-
'now',
64-
null,
65-
InputOption::VALUE_NONE,
66-
'Dot the rescan now and not as background jobs. Doing it now might run out of memory.'
67-
);
68-
}
63+
->addOption(
64+
'now',
65+
null,
66+
InputOption::VALUE_NONE,
67+
'Dot the rescan now and not as background jobs. Doing it now might run out of memory.'
68+
);
69+
}
6970

70-
/**
71-
* @param InputInterface $input
72-
* @param OutputInterface $output
73-
* @return int
74-
*/
71+
/**
72+
* @param InputInterface $input
73+
* @param OutputInterface $output
74+
* @return int
75+
*/
7576
protected function execute(InputInterface $input, OutputInterface $output): int {
7677
if ($this->encryptionManager->isEnabled()) {
7778
$output->writeln('Encryption is enabled. Aborted.');
@@ -80,10 +81,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8081
$this->output = $output;
8182
$userId = $input->getArgument('user_id');
8283
$pathToScan = $input->getArgument('path');
83-
$inBackground = !($input->getOption('now') ?? true);
84-
if ($inBackground) {
85-
echo "Extracting coordinates from photo is performed in a BackgroundJob \n";
86-
}
84+
$inBackground = !($input->getOption('now') ?? true);
85+
if ($inBackground) {
86+
echo "Extracting coordinates from photo is performed in a BackgroundJob \n";
87+
}
8788
if ($userId === null) {
8889
$this->userManager->callForSeenUsers(function (IUser $user, string $pathToScan) use ($inBackground) {
8990
$this->rescanUserPhotos($user->getUID(), $inBackground, $pathToScan);
@@ -97,18 +98,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9798
return 0;
9899
}
99100

100-
/**
101-
* @param string $userId
102-
* @param bool $inBackground
103-
* @param string $pathToScan
104-
* @return void
105-
* @throws \OCP\PreConditionNotMetException
106-
*/
107-
private function rescanUserPhotos(string $userId, bool $inBackground=true, string $pathToScan=null) {
108-
echo '======== User '.$userId.' ========'."\n";
101+
/**
102+
* @param string $userId
103+
* @param bool $inBackground
104+
* @param string $pathToScan
105+
* @return void
106+
* @throws \OCP\PreConditionNotMetException
107+
*/
108+
private function rescanUserPhotos(string $userId, bool $inBackground = true, string $pathToScan = null) {
109+
echo '======== User ' . $userId . ' ========' . "\n";
109110
$c = 1;
110111
foreach ($this->photofilesService->rescan($userId, $inBackground, $pathToScan) as $path) {
111-
echo '['.$c.'] Photo "'.$path.'" added'."\n";
112+
echo '[' . $c . '] Photo "' . $path . '" added' . "\n";
112113
$c++;
113114
}
114115
if ($pathToScan === null) {

lib/Service/PhotofilesService.php

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use Psr\Log\LoggerInterface;
3232

3333
require_once __DIR__ . '/../../vendor/autoload.php';
34+
3435
use lsolesen\pel\PelDataWindow;
3536
use lsolesen\pel\PelEntryAscii;
3637
use lsolesen\pel\PelEntryRational;
@@ -71,17 +72,17 @@ public function __construct(
7172
$this->backgroundJobCache = $this->cacheFactory->createDistributed('maps:background-jobs');
7273
}
7374

74-
public function rescan($userId, $inBackground=true, $pathToScan=null) {
75+
public function rescan($userId, $inBackground = true, $pathToScan = null) {
7576
$this->photosCache->clear($userId);
76-
$userFolder = $this->root->getUserFolder($userId);
77-
if ($pathToScan === null) {
78-
$folder = $userFolder;
79-
$this->photoMapper->deleteAll($userId);
80-
} else {
81-
$folder = $userFolder->get($pathToScan);
82-
}
83-
$photos = $this->gatherPhotoFiles($folder, true);
84-
foreach ($photos as $photo) {
77+
$userFolder = $this->root->getUserFolder($userId);
78+
if ($pathToScan === null) {
79+
$folder = $userFolder;
80+
$this->photoMapper->deleteAll($userId);
81+
} else {
82+
$folder = $userFolder->get($pathToScan);
83+
}
84+
$photos = $this->gatherPhotoFiles($folder, true);
85+
foreach ($photos as $photo) {
8586
if ($inBackground) {
8687
$this->addPhoto($photo, $userId);
8788
} else {
@@ -409,7 +410,7 @@ private function gatherPhotoFiles($folder, $recursive) {
409410
}
410411
try {
411412
$notes = array_merge($notes, $this->gatherPhotoFiles($node, $recursive));
412-
} catch (\OCP\Files\StorageNotAvailableException|\Exception $e) {
413+
} catch (\OCP\Files\StorageNotAvailableException | \Exception $e) {
413414
$msg = 'WARNING: Could not access ' . $node->getName();
414415
echo($msg . "\n");
415416
$this->logger->error($msg);
@@ -447,12 +448,12 @@ private function getExif($file) : ?ExifGeoData {
447448
$exif_geo_data->validate(true);
448449
} catch (ExifDataInvalidException $e) {
449450
$exif_geo_data = null;
450-
$this->logger->notice($e->getMessage(), ['code' => $e->getCode(),'path' => $path]);
451+
$this->logger->notice($e->getMessage(), ['code' => $e->getCode(), 'path' => $path]);
451452
} catch (ExifDataNoLocationException $e) {
452-
$this->logger->notice($e->getMessage(), ['code' => $e->getCode(),'path' => $path]);
453+
$this->logger->notice($e->getMessage(), ['code' => $e->getCode(), 'path' => $path]);
453454
} catch (\Throwable $f) {
454455
$exif_geo_data = null;
455-
$this->logger->error($f->getMessage(), ['code' => $f->getCode(),'path' => $path]);
456+
$this->logger->error($f->getMessage(), ['code' => $f->getCode(), 'path' => $path]);
456457
}
457458
return $exif_geo_data;
458459
}
@@ -524,19 +525,25 @@ private function setGeolocation($pelSubIfdGps, $latitudeDegreeDecimal, $longitud
524525
= $this->degreeDecimalToDegreeMinuteSecond(abs($longitudeDegreeDecimal));
525526

526527
$pelSubIfdGps->addEntry(new PelEntryAscii(
527-
PelTag::GPS_LATITUDE_REF, $latitudeRef));
528+
PelTag::GPS_LATITUDE_REF,
529+
$latitudeRef
530+
));
528531
$pelSubIfdGps->addEntry(new PelEntryRational(
529532
PelTag::GPS_LATITUDE,
530533
[$latitudeDegreeMinuteSecond['degree'], 1],
531534
[$latitudeDegreeMinuteSecond['minute'], 1],
532-
[round($latitudeDegreeMinuteSecond['second'] * 1000), 1000]));
535+
[round($latitudeDegreeMinuteSecond['second'] * 1000), 1000]
536+
));
533537
$pelSubIfdGps->addEntry(new PelEntryAscii(
534-
PelTag::GPS_LONGITUDE_REF, $longitudeRef));
538+
PelTag::GPS_LONGITUDE_REF,
539+
$longitudeRef
540+
));
535541
$pelSubIfdGps->addEntry(new PelEntryRational(
536542
PelTag::GPS_LONGITUDE,
537543
[$longitudeDegreeMinuteSecond['degree'], 1],
538544
[$longitudeDegreeMinuteSecond['minute'], 1],
539-
[round($longitudeDegreeMinuteSecond['second'] * 1000), 1000]));
545+
[round($longitudeDegreeMinuteSecond['second'] * 1000), 1000]
546+
));
540547
}
541548

542549
private function degreeDecimalToDegreeMinuteSecond($degreeDecimal) {
@@ -547,5 +554,4 @@ private function degreeDecimalToDegreeMinuteSecond($degreeDecimal) {
547554
$second = $remainder * 60;
548555
return ['degree' => $degree, 'minute' => $minute, 'second' => $second];
549556
}
550-
551557
}

0 commit comments

Comments
 (0)