You are here

public function ServiceAuditFilesNotInDatabase::auditfilesGetExclusions in Audit Files 8.2

Same name and namespace in other branches
  1. 8.3 src/ServiceAuditFilesNotInDatabase.php \Drupal\auditfiles\ServiceAuditFilesNotInDatabase::auditfilesGetExclusions()
  2. 4.x src/ServiceAuditFilesNotInDatabase.php \Drupal\auditfiles\ServiceAuditFilesNotInDatabase::auditfilesGetExclusions()

Creates an exclusion string.

This function creates a list of file and/or directory exclusions to be used with a preg_* function.

Return value

string The excluions.

File

src/ServiceAuditFilesNotInDatabase.php, line 301

Class

ServiceAuditFilesNotInDatabase
Define all methods that are used on Files not in database functionality.

Namespace

Drupal\auditfiles

Code

public function auditfilesGetExclusions() {
  $config = $this->configFactory
    ->get('auditfiles.settings');
  $exclusions_array = [];
  $files = $config
    ->get('auditfiles_exclude_files');
  if ($files) {
    $exclude_files = explode(';', $files);
    array_walk($exclude_files, '\\Drupal\\auditfiles\\AuditFilesBatchProcess::auditfilesMakePreg', FALSE);
    $exclusions_array = array_merge($exclusions_array, $exclude_files);
  }
  $paths = $config
    ->get('auditfiles_exclude_paths');
  if ($paths) {
    $exclude_paths = explode(';', $paths);
    array_walk($exclude_paths, '\\Drupal\\auditfiles\\AuditFilesBatchProcess::auditfilesMakePreg', TRUE);
    $exclusions_array = array_merge($exclusions_array, $exclude_paths);
  }

  // Exclude other file streams that may be defined and in use.
  $exclude_streams = [];
  $auditfiles_file_system_path = $config
    ->get('auditfiles_file_system_path');
  $file_system_paths = $this->streamWrapperManager
    ->getWrappers(StreamWrapperInterface::LOCAL);
  foreach ($file_system_paths as $file_system_path_id => $file_system_path) {
    if ($file_system_path_id != $auditfiles_file_system_path) {
      $wrapper = $this->streamWrapperManager
        ->getViaUri($file_system_path_id . '://');
      if ($wrapper && $wrapper
        ->realpath()) {
        $exclude_streams[] = $wrapper
          ->realpath();
      }
    }
  }
  array_walk($exclude_streams, '\\Drupal\\auditfiles\\AuditFilesBatchProcess::auditfilesMakePreg', FALSE);
  $exclusions_array = array_merge($exclusions_array, $exclude_streams);

  // Create the list of requested extension exclusions. (This is a little more
  // complicated.)
  $extensions = $config
    ->get('auditfiles_exclude_extensions');
  if ($extensions) {
    $exclude_extensions = explode(';', $extensions);
    array_walk($exclude_extensions, '\\Drupal\\auditfiles\\AuditFilesBatchProcess::auditfilesMakePreg', FALSE);
    $extensions = implode('|', $exclude_extensions);
    $extensions = '(' . $extensions . ')$';
    $exclusions_array[] = $extensions;
  }

  // Implode exclusions array to a string.
  $exclusions = implode('|', $exclusions_array);

  // Return prepared exclusion string.
  return $exclusions;
}