| @@ 92-125 (lines=34) @@ | ||
| 89 | ||
| 90 | // Run for unscanned files |
|
| 91 | $cnt = 0; |
|
| 92 | while (($row = $result->fetch()) && $cnt < $batchSize) { |
|
| 93 | try { |
|
| 94 | $fileId = $row['fileid']; |
|
| 95 | $users = $this->getUserWithAccessToStorage((int)$row['storage']); |
|
| 96 | ||
| 97 | foreach ($users as $user) { |
|
| 98 | /** @var IUser $owner */ |
|
| 99 | $owner = $this->userManager->get($user['user_id']); |
|
| 100 | if (!$owner instanceof IUser){ |
|
| 101 | continue; |
|
| 102 | } |
|
| 103 | ||
| 104 | $userFolder = $this->rootFolder->getUserFolder($owner->getUID()); |
|
| 105 | $files = $userFolder->getById($fileId); |
|
| 106 | ||
| 107 | if ($files === []) { |
|
| 108 | continue; |
|
| 109 | } |
|
| 110 | ||
| 111 | $file = array_pop($files); |
|
| 112 | if ($file instanceof File) { |
|
| 113 | $this->scanOneFile($file); |
|
| 114 | } else { |
|
| 115 | $this->logger->error('Tried to scan non file'); |
|
| 116 | } |
|
| 117 | ||
| 118 | // increased only for successfully scanned files |
|
| 119 | $cnt++; |
|
| 120 | break; |
|
| 121 | } |
|
| 122 | } catch (\Exception $e) { |
|
| 123 | $this->logger->error( __METHOD__ . ', exception: ' . $e->getMessage(), ['app' => 'files_antivirus']); |
|
| 124 | } |
|
| 125 | } |
|
| 126 | ||
| 127 | if ($cnt === $batchSize) { |
|
| 128 | // we are done |
|
| @@ 140-173 (lines=34) @@ | ||
| 137 | return; |
|
| 138 | } |
|
| 139 | ||
| 140 | while (($row = $result->fetch()) && $cnt < $batchSize) { |
|
| 141 | try { |
|
| 142 | $fileId = $row['fileid']; |
|
| 143 | $users = $this->getUserWithAccessToStorage((int)$row['storage']); |
|
| 144 | ||
| 145 | foreach ($users as $user) { |
|
| 146 | /** @var IUser $owner */ |
|
| 147 | $owner = $this->userManager->get($user); |
|
| 148 | if (!$owner instanceof IUser){ |
|
| 149 | continue; |
|
| 150 | } |
|
| 151 | ||
| 152 | $userFolder = $this->rootFolder->getUserFolder($owner->getUID()); |
|
| 153 | $files = $userFolder->getById($fileId); |
|
| 154 | ||
| 155 | if ($files === []) { |
|
| 156 | continue; |
|
| 157 | } |
|
| 158 | ||
| 159 | $file = array_pop($files); |
|
| 160 | if ($file instanceof File) { |
|
| 161 | $this->scanOneFile($file); |
|
| 162 | } else { |
|
| 163 | $this->logger->error('Tried to scan non file'); |
|
| 164 | } |
|
| 165 | ||
| 166 | // increased only for successfully scanned files |
|
| 167 | $cnt++; |
|
| 168 | break; |
|
| 169 | } |
|
| 170 | } catch (\Exception $e) { |
|
| 171 | $this->logger->error( __METHOD__ . ', exception: ' . $e->getMessage(), ['app' => 'files_antivirus']); |
|
| 172 | } |
|
| 173 | } |
|
| 174 | } |
|
| 175 | ||
| 176 | protected function getBatchSize(): int { |
|