public function ImceScanner::customScanFull in FileField Sources 8
Scan and return files, subdirectories.
File
- src/
ImceScanner.php, line 29
Class
- ImceScanner
- Imce scanner service.
Namespace
Drupal\filefield_sourcesCode
public function customScanFull($dirname, $options) {
// Get a list of files in the database for this directory.
$connection = \Drupal::service('database');
$scheme = $this->context['scheme'];
$sql_uri_name = $dirname == '.' ? $scheme . '://' : $dirname . '/';
$result = $connection
->select('file_managed', 'f')
->fields('f', [
'uri',
])
->condition('f.uri', $sql_uri_name . '%', 'LIKE')
->condition('f.uri', $sql_uri_name . '_%/%', 'NOT LIKE')
->execute();
$db_files = [];
foreach ($result as $row) {
$db_files[basename($row->uri)] = 1;
}
// Get the default IMCE directory scan, then filter down to database files.
$content = Imce::scanDir($dirname, $options);
foreach ($content['files'] as $filename => $file) {
if (!isset($db_files[$filename])) {
unset($content['files'][$filename]);
}
}
return $content;
}