|
26 | 26 |
|
27 | 27 | class RescanPhotos extends Command {
|
28 | 28 |
|
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; |
34 | 34 |
|
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 | + } |
45 | 46 |
|
46 |
| - /** |
47 |
| - * @return void |
48 |
| - */ |
49 |
| - protected function configure() { |
50 |
| - $this->setName('maps:scan-photos') |
51 |
| - ->setDescription('Rescan photos GPS exif data') |
52 |
| - ->addArgument( |
53 |
| - 'user_id', |
54 |
| - InputArgument::OPTIONAL, |
55 |
| - 'Rescan photos GPS exif data for the given user' |
56 |
| - ) |
57 |
| - ->addOption( |
58 |
| - 'now', |
59 |
| - null, |
60 |
| - InputOption::VALUE_NONE, |
61 |
| - 'Dot the rescan now and not as background jobs. Doing it now might run out of memory.' |
62 |
| - ); |
63 |
| - } |
| 47 | + /** |
| 48 | + * @return void |
| 49 | + */ |
| 50 | + protected function configure() { |
| 51 | + $this->setName('maps:scan-photos') |
| 52 | + ->setDescription('Rescan photos GPS exif data') |
| 53 | + ->addArgument( |
| 54 | + 'user_id', |
| 55 | + InputArgument::OPTIONAL, |
| 56 | + 'Rescan photos GPS exif data for the given user' |
| 57 | + ) |
| 58 | + ->addArgument( |
| 59 | + 'path', |
| 60 | + InputArgument::OPTIONAL, |
| 61 | + 'Scan photos GPS exif data for the given path under user\'s files without wiping the database.' |
| 62 | + ) |
| 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 | + } |
64 | 70 |
|
65 |
| - /** |
66 |
| - * @param InputInterface $input |
67 |
| - * @param OutputInterface $output |
68 |
| - * @return int |
69 |
| - */ |
70 |
| - protected function execute(InputInterface $input, OutputInterface $output): int { |
71 |
| - if ($this->encryptionManager->isEnabled()) { |
72 |
| - $output->writeln('Encryption is enabled. Aborted.'); |
73 |
| - return 1; |
74 |
| - } |
75 |
| - $this->output = $output; |
76 |
| - $userId = $input->getArgument('user_id'); |
77 |
| - $inBackground = !($input->getOption('now') ?? true); |
78 |
| - if ($inBackground) { |
79 |
| - echo "Extracting coordinates from photo is performed in a BackgroundJob \n"; |
80 |
| - } |
81 |
| - if ($userId === null) { |
82 |
| - $this->userManager->callForSeenUsers(function (IUser $user) use ($inBackground) { |
83 |
| - $this->rescanUserPhotos($user->getUID(), $inBackground); |
84 |
| - }); |
85 |
| - } else { |
86 |
| - $user = $this->userManager->get($userId); |
87 |
| - if ($user !== null) { |
88 |
| - $this->rescanUserPhotos($userId, $inBackground); |
89 |
| - } |
90 |
| - } |
91 |
| - return 0; |
92 |
| - } |
| 71 | + /** |
| 72 | + * @param InputInterface $input |
| 73 | + * @param OutputInterface $output |
| 74 | + * @return int |
| 75 | + */ |
| 76 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
| 77 | + if ($this->encryptionManager->isEnabled()) { |
| 78 | + $output->writeln('Encryption is enabled. Aborted.'); |
| 79 | + return 1; |
| 80 | + } |
| 81 | + $this->output = $output; |
| 82 | + $userId = $input->getArgument('user_id'); |
| 83 | + $pathToScan = $input->getArgument('path'); |
| 84 | + $inBackground = !($input->getOption('now') ?? true); |
| 85 | + if ($inBackground) { |
| 86 | + echo "Extracting coordinates from photo is performed in a BackgroundJob \n"; |
| 87 | + } |
| 88 | + if ($userId === null) { |
| 89 | + $this->userManager->callForSeenUsers(function (IUser $user, string $pathToScan) use ($inBackground) { |
| 90 | + $this->rescanUserPhotos($user->getUID(), $inBackground, $pathToScan); |
| 91 | + }); |
| 92 | + } else { |
| 93 | + $user = $this->userManager->get($userId); |
| 94 | + if ($user !== null) { |
| 95 | + $this->rescanUserPhotos($userId, $inBackground, $pathToScan); |
| 96 | + } |
| 97 | + } |
| 98 | + return 0; |
| 99 | + } |
93 | 100 |
|
94 |
| - /** |
95 |
| - * @param string $userId |
96 |
| - * @param bool $inBackground |
97 |
| - * @return void |
98 |
| - * @throws \OCP\PreConditionNotMetException |
99 |
| - */ |
100 |
| - private function rescanUserPhotos(string $userId, bool $inBackground = true) { |
101 |
| - echo '======== User '.$userId.' ========'."\n"; |
102 |
| - $c = 1; |
103 |
| - foreach ($this->photofilesService->rescan($userId, $inBackground) as $path) { |
104 |
| - echo '['.$c.'] Photo "'.$path.'" added'."\n"; |
105 |
| - $c++; |
106 |
| - } |
107 |
| - $this->config->setUserValue($userId, 'maps', 'installScanDone', 'yes'); |
108 |
| - } |
| 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"; |
| 110 | + $c = 1; |
| 111 | + foreach ($this->photofilesService->rescan($userId, $inBackground, $pathToScan) as $path) { |
| 112 | + echo '[' . $c . '] Photo "' . $path . '" added' . "\n"; |
| 113 | + $c++; |
| 114 | + } |
| 115 | + if ($pathToScan === null) { |
| 116 | + $this->config->setUserValue($userId, 'maps', 'installScanDone', 'yes'); |
| 117 | + } |
| 118 | + } |
109 | 119 | }
|
0 commit comments