|
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( |
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 | | - } |
| 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 | + } |
46 | 46 |
|
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 | | - } |
| 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 | + } |
70 | 70 |
|
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 | | - } |
| 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 | + } |
100 | 100 |
|
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 | | - } |
| 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 | + } |
119 | 119 | } |
0 commit comments