| @@ 100-135 (lines=36) @@ | ||
| 97 | ||
| 98 | // Run for unscanned files |
|
| 99 | $cnt = 0; |
|
| 100 | while (($row = $result->fetch()) && $cnt < $batchSize) { |
|
| 101 | try { |
|
| 102 | $fileId = $row['fileid']; |
|
| 103 | $users = $this->getUserWithAccessToStorage((int)$row['storage']); |
|
| 104 | ||
| 105 | foreach ($users as $user) { |
|
| 106 | /** @var IUser $owner */ |
|
| 107 | $owner = $this->userManager->get($user['user_id']); |
|
| 108 | if (!$owner instanceof IUser) { |
|
| 109 | continue; |
|
| 110 | } |
|
| 111 | ||
| 112 | $userFolder = $this->rootFolder->getUserFolder($owner->getUID()); |
|
| 113 | $files = $userFolder->getById($fileId); |
|
| 114 | ||
| 115 | if ($files === []) { |
|
| 116 | continue; |
|
| 117 | } |
|
| 118 | ||
| 119 | $file = array_pop($files); |
|
| 120 | if ($file instanceof File) { |
|
| 121 | if ($userFolder->nodeExists($userFolder->getRelativePath($file->getPath()))) { |
|
| 122 | $this->scanOneFile($file); |
|
| 123 | } |
|
| 124 | } else { |
|
| 125 | $this->logger->error('Tried to scan non file'); |
|
| 126 | } |
|
| 127 | ||
| 128 | // increased only for successfully scanned files |
|
| 129 | $cnt++; |
|
| 130 | break; |
|
| 131 | } |
|
| 132 | } catch (\Exception $e) { |
|
| 133 | $this->logger->logException($e, ['app' => 'files_antivirus']); |
|
| 134 | } |
|
| 135 | } |
|
| 136 | ||
| 137 | if ($cnt === $batchSize) { |
|
| 138 | // we are done |
|
| @@ 150-186 (lines=37) @@ | ||
| 147 | return; |
|
| 148 | } |
|
| 149 | ||
| 150 | while (($row = $result->fetch()) && $cnt < $batchSize) { |
|
| 151 | try { |
|
| 152 | $fileId = $row['fileid']; |
|
| 153 | $users = $this->getUserWithAccessToStorage((int)$row['storage']); |
|
| 154 | ||
| 155 | foreach ($users as $user) { |
|
| 156 | /** @var IUser $owner */ |
|
| 157 | $owner = $this->userManager->get($user['user_id']); |
|
| 158 | if (!$owner instanceof IUser) { |
|
| 159 | continue; |
|
| 160 | } |
|
| 161 | ||
| 162 | $userFolder = $this->rootFolder->getUserFolder($owner->getUID()); |
|
| 163 | $files = $userFolder->getById($fileId); |
|
| 164 | ||
| 165 | if ($files === []) { |
|
| 166 | continue; |
|
| 167 | } |
|
| 168 | ||
| 169 | $file = array_pop($files); |
|
| 170 | ||
| 171 | if ($file instanceof File) { |
|
| 172 | if ($userFolder->nodeExists($userFolder->getRelativePath($file->getPath()))) { |
|
| 173 | $this->scanOneFile($file); |
|
| 174 | } |
|
| 175 | } else { |
|
| 176 | $this->logger->error('Tried to scan non file'); |
|
| 177 | } |
|
| 178 | ||
| 179 | // increased only for successfully scanned files |
|
| 180 | $cnt++; |
|
| 181 | break; |
|
| 182 | } |
|
| 183 | } catch (\Exception $e) { |
|
| 184 | $this->logger->error(__METHOD__ . ', exception: ' . $e->getMessage(), ['app' => 'files_antivirus']); |
|
| 185 | } |
|
| 186 | } |
|
| 187 | ||
| 188 | ||
| 189 | // Run for files that have been scanned in the past. Just start to rescan them as the virus definitaions might have been updated |
|
| @@ 197-232 (lines=36) @@ | ||
| 194 | return; |
|
| 195 | } |
|
| 196 | ||
| 197 | while (($row = $result->fetch()) && $cnt < $batchSize) { |
|
| 198 | try { |
|
| 199 | $fileId = $row['fileid']; |
|
| 200 | $users = $this->getUserWithAccessToStorage((int)$row['storage']); |
|
| 201 | ||
| 202 | foreach ($users as $user) { |
|
| 203 | /** @var IUser $owner */ |
|
| 204 | $owner = $this->userManager->get($user['user_id']); |
|
| 205 | if (!$owner instanceof IUser) { |
|
| 206 | continue; |
|
| 207 | } |
|
| 208 | ||
| 209 | $userFolder = $this->rootFolder->getUserFolder($owner->getUID()); |
|
| 210 | $files = $userFolder->getById($fileId); |
|
| 211 | ||
| 212 | if ($files === []) { |
|
| 213 | continue; |
|
| 214 | } |
|
| 215 | ||
| 216 | $file = array_pop($files); |
|
| 217 | if ($file instanceof File) { |
|
| 218 | if ($userFolder->nodeExists($userFolder->getRelativePath($file->getPath()))) { |
|
| 219 | $this->scanOneFile($file); |
|
| 220 | } |
|
| 221 | } else { |
|
| 222 | $this->logger->error('Tried to scan non file'); |
|
| 223 | } |
|
| 224 | ||
| 225 | // increased only for successfully scanned files |
|
| 226 | $cnt++; |
|
| 227 | break; |
|
| 228 | } |
|
| 229 | } catch (\Exception $e) { |
|
| 230 | $this->logger->error(__METHOD__ . ', exception: ' . $e->getMessage(), ['app' => 'files_antivirus']); |
|
| 231 | } |
|
| 232 | } |
|
| 233 | } |
|
| 234 | ||
| 235 | protected function getBatchSize(): int { |
|