@@ 93-126 (lines=34) @@ | ||
90 | ||
91 | // Run for unscanned files |
|
92 | $cnt = 0; |
|
93 | while (($row = $result->fetch()) && $cnt < $batchSize) { |
|
94 | try { |
|
95 | $fileId = $row['fileid']; |
|
96 | $users = $this->getUserWithAccessToStorage((int)$row['storage']); |
|
97 | ||
98 | foreach ($users as $user) { |
|
99 | /** @var IUser $owner */ |
|
100 | $owner = $this->userManager->get($user['user_id']); |
|
101 | if (!$owner instanceof IUser){ |
|
102 | continue; |
|
103 | } |
|
104 | ||
105 | $userFolder = $this->rootFolder->getUserFolder($owner->getUID()); |
|
106 | $files = $userFolder->getById($fileId); |
|
107 | ||
108 | if ($files === []) { |
|
109 | continue; |
|
110 | } |
|
111 | ||
112 | $file = array_pop($files); |
|
113 | if ($file instanceof File) { |
|
114 | $this->scanOneFile($file); |
|
115 | } else { |
|
116 | $this->logger->error('Tried to scan non file'); |
|
117 | } |
|
118 | ||
119 | // increased only for successfully scanned files |
|
120 | $cnt++; |
|
121 | break; |
|
122 | } |
|
123 | } catch (\Exception $e) { |
|
124 | $this->logger->error( __METHOD__ . ', exception: ' . $e->getMessage(), ['app' => 'files_antivirus']); |
|
125 | } |
|
126 | } |
|
127 | ||
128 | if ($cnt === $batchSize) { |
|
129 | // we are done |
|
@@ 141-174 (lines=34) @@ | ||
138 | return; |
|
139 | } |
|
140 | ||
141 | while (($row = $result->fetch()) && $cnt < $batchSize) { |
|
142 | try { |
|
143 | $fileId = $row['fileid']; |
|
144 | $users = $this->getUserWithAccessToStorage((int)$row['storage']); |
|
145 | ||
146 | foreach ($users as $user) { |
|
147 | /** @var IUser $owner */ |
|
148 | $owner = $this->userManager->get($user['user_id']); |
|
149 | if (!$owner instanceof IUser){ |
|
150 | continue; |
|
151 | } |
|
152 | ||
153 | $userFolder = $this->rootFolder->getUserFolder($owner->getUID()); |
|
154 | $files = $userFolder->getById($fileId); |
|
155 | ||
156 | if ($files === []) { |
|
157 | continue; |
|
158 | } |
|
159 | ||
160 | $file = array_pop($files); |
|
161 | if ($file instanceof File) { |
|
162 | $this->scanOneFile($file); |
|
163 | } else { |
|
164 | $this->logger->error('Tried to scan non file'); |
|
165 | } |
|
166 | ||
167 | // increased only for successfully scanned files |
|
168 | $cnt++; |
|
169 | break; |
|
170 | } |
|
171 | } catch (\Exception $e) { |
|
172 | $this->logger->error( __METHOD__ . ', exception: ' . $e->getMessage(), ['app' => 'files_antivirus']); |
|
173 | } |
|
174 | } |
|
175 | ||
176 | ||
177 | // Run for files that have been scanned in the past. Just start to rescan them as the virus definitaions might have been updated |
|
@@ 185-218 (lines=34) @@ | ||
182 | return; |
|
183 | } |
|
184 | ||
185 | while (($row = $result->fetch()) && $cnt < $batchSize) { |
|
186 | try { |
|
187 | $fileId = $row['fileid']; |
|
188 | $users = $this->getUserWithAccessToStorage((int)$row['storage']); |
|
189 | ||
190 | foreach ($users as $user) { |
|
191 | /** @var IUser $owner */ |
|
192 | $owner = $this->userManager->get($user['user_id']); |
|
193 | if (!$owner instanceof IUser){ |
|
194 | continue; |
|
195 | } |
|
196 | ||
197 | $userFolder = $this->rootFolder->getUserFolder($owner->getUID()); |
|
198 | $files = $userFolder->getById($fileId); |
|
199 | ||
200 | if ($files === []) { |
|
201 | continue; |
|
202 | } |
|
203 | ||
204 | $file = array_pop($files); |
|
205 | if ($file instanceof File) { |
|
206 | $this->scanOneFile($file); |
|
207 | } else { |
|
208 | $this->logger->error('Tried to scan non file'); |
|
209 | } |
|
210 | ||
211 | // increased only for successfully scanned files |
|
212 | $cnt++; |
|
213 | break; |
|
214 | } |
|
215 | } catch (\Exception $e) { |
|
216 | $this->logger->error( __METHOD__ . ', exception: ' . $e->getMessage(), ['app' => 'files_antivirus']); |
|
217 | } |
|
218 | } |
|
219 | } |
|
220 | ||
221 | protected function getBatchSize(): int { |