1 | <?php |
||
18 | class BackgroundScanner { |
||
19 | |||
20 | const BATCH_SIZE = 10; |
||
21 | |||
22 | /** @var IRootFolder */ |
||
23 | protected $rootFolder; |
||
24 | |||
25 | /** @var \OCP\Files\Folder[] */ |
||
26 | protected $userFolders; |
||
27 | |||
28 | /** @var ScannerFactory */ |
||
29 | private $scannerFactory; |
||
30 | |||
31 | /** @var IL10N */ |
||
32 | private $l10n; |
||
33 | |||
34 | /** @var AppConfig */ |
||
35 | private $appConfig; |
||
36 | |||
37 | /** @var string */ |
||
38 | protected $currentFilesystemUser; |
||
39 | |||
40 | /** @var \OCP\IUserSession */ |
||
41 | protected $userSession; |
||
42 | |||
43 | /** |
||
44 | * A constructor |
||
45 | * |
||
46 | * @param \OCA\Files_Antivirus\ScannerFactory $scannerFactory |
||
47 | * @param IL10N $l10n |
||
48 | * @param AppConfig $appConfig |
||
49 | * @param IRootFolder $rootFolder |
||
50 | * @param IUserSession $userSession |
||
51 | */ |
||
52 | 2 | public function __construct(ScannerFactory $scannerFactory, |
|
64 | |||
65 | /** |
||
66 | * Background scanner main job |
||
67 | * @return null |
||
68 | */ |
||
69 | 1 | public function run(){ |
|
97 | |||
98 | 2 | protected function getFilesForScan(){ |
|
99 | 2 | $dirMimeTypeId = \OC::$server->getMimeTypeLoader()->getId('httpd/unix-directory'); |
|
100 | |||
101 | 2 | $dbConnection = \OC::$server->getDatabaseConnection(); |
|
102 | 2 | $qb = $dbConnection->getQueryBuilder(); |
|
103 | 2 | if ($dbConnection->getDatabasePlatform() instanceof MySqlPlatform) { |
|
104 | $concatFunction = $qb->createFunction( |
||
105 | "CONCAT('/', mnt.user_id, '/')" |
||
106 | ); |
||
107 | } else { |
||
108 | 2 | $concatFunction = $qb->createFunction( |
|
109 | 2 | "'/' || " . $qb->getColumnName('mnt.user_id') . " || '/'" |
|
110 | ); |
||
111 | } |
||
112 | |||
113 | 2 | $sizeLimit = intval($this->appConfig->getAvMaxFileSize()); |
|
114 | 2 | if ( $sizeLimit === -1 ){ |
|
115 | 2 | $sizeLimitExpr = $qb->expr()->neq('fc.size', $qb->expr()->literal('0')); |
|
116 | } else { |
||
117 | $sizeLimitExpr = $qb->expr()->andX( |
||
118 | $qb->expr()->neq('fc.size', $qb->expr()->literal('0')), |
||
119 | $qb->expr()->lt('fc.size', $qb->expr()->literal((string) $sizeLimit)) |
||
120 | ); |
||
121 | } |
||
122 | |||
123 | 2 | $qb->select(['fc.fileid', 'mnt.user_id']) |
|
124 | 2 | ->from('filecache', 'fc') |
|
125 | 2 | ->leftJoin('fc', 'files_antivirus', 'fa', $qb->expr()->eq('fa.fileid', 'fc.fileid')) |
|
126 | 2 | ->innerJoin( |
|
127 | 2 | 'fc', |
|
128 | 2 | 'mounts', |
|
129 | 2 | 'mnt', |
|
130 | 2 | $qb->expr()->andX( |
|
131 | 2 | $qb->expr()->eq('fc.storage', 'mnt.storage_id'), |
|
132 | 2 | $qb->expr()->eq('mnt.mount_point', $concatFunction) |
|
133 | ) |
||
134 | ) |
||
135 | 2 | ->where( |
|
136 | 2 | $qb->expr()->neq('fc.mimetype', $qb->expr()->literal($dirMimeTypeId)) |
|
137 | ) |
||
138 | 2 | ->andWhere( |
|
139 | 2 | $qb->expr()->orX( |
|
140 | 2 | $qb->expr()->isNull('fa.fileid'), |
|
141 | 2 | $qb->expr()->gt('fc.mtime', 'fa.check_time') |
|
142 | ) |
||
143 | ) |
||
144 | 2 | ->andWhere( |
|
145 | 2 | $qb->expr()->like('fc.path', $qb->expr()->literal('files/%')) |
|
146 | ) |
||
147 | 2 | ->andWhere( $sizeLimitExpr ) |
|
148 | ; |
||
149 | 2 | return $qb->execute(); |
|
150 | } |
||
151 | |||
152 | /** |
||
153 | * @param IUser $owner |
||
154 | * @param int $fileId |
||
155 | */ |
||
156 | protected function scanOneFile($owner, $fileId){ |
||
167 | |||
168 | /** |
||
169 | * @param \OCP\IUser $user |
||
170 | * @return \OCP\Files\Folder |
||
171 | */ |
||
172 | protected function getUserFolder(IUser $user) { |
||
179 | |||
180 | /** |
||
181 | * @param IUser $user |
||
182 | */ |
||
183 | protected function initFilesystemForUser(IUser $user) { |
||
194 | |||
195 | /** |
||
196 | * |
||
197 | */ |
||
198 | 1 | protected function tearDownFilesystem(){ |
|
202 | |||
203 | /** |
||
204 | * @deprecated since v8.0.0 |
||
205 | */ |
||
206 | public static function check(){ |
||
208 | } |
||
209 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.