protected function DisplayFileList::dbSync in Filebrowser 8.2
Same name and namespace in other branches
- 3.x src/File/DisplayFileList.php \Drupal\filebrowser\File\DisplayFileList::dbSync()
Synchronizes what we seen on filesystem with what is stored in database We also build an access URL (link) for each file as it is why we stored this stuff in DB (have a unique ID for each file and path) to get rid of national character mess in URLS.
Parameters
array $db_content:
array $files: List of DisplayFiles objects
integer $subdir_fid:
1 call to DisplayFileList::dbSync()
File
- src/
File/ DisplayFileList.php, line 293
Class
- DisplayFileList
- Class FileDisplayList @package Drupal\filebrowser This class holds the list of files to be displayed on the filebrowser node. These files are retrieved from the filesystem and filtered for user and node access. The array produced by this class…
Namespace
Drupal\filebrowser\FileCode
protected function dbSync(&$db_content, &$files, $subdir_fid = null) {
/** @var DisplayFile $files[$key] */
$to_delete = [];
// Build the fragment to be used with folders.
$theme = \Drupal::theme()
->getActiveTheme()
->getName();
$fragment = 'block-' . str_replace('_', '-', $theme) . '-page-title';
foreach ($db_content as $path => &$record) {
if (!isset($record['nid'])) {
}
if (!isset($record['exists'])) {
$to_delete[] = $record['fid'];
}
else {
if (!isset($record['fid'])) {
$record['fid'] = $this->storage
->insertRecord($record);
}
$key = $record['display_name'];
$files[$key]->fid = $record['fid'];
$link = $this
->makeLink($files[$key], $record['fid'], $fragment);
$files[$key]->link = $link
->toRenderable();
$files[$key]->href = $link
->getUrl();
// fire an event so modules can create metadata for this file.
/** @var MetadataEvent $event */
$dispatcher = \Drupal::service('event_dispatcher');
$e = new MetadataEvent($this->node
->id(), $record['fid'], $files[$key], $subdir_fid, $this->filebrowser->visibleColumns);
$dispatcher
->dispatch('filebrowser.metadata_event', $e);
}
}
// A quick way to drip obsolete records
if (count($to_delete)) {
$this->storage
->deleteFileRecords($to_delete);
}
}