You are here

protected function FileDirectorySource::getFilesToBackup in Backup and Migrate 8.4

Get a list if files to be backed up from the given directory.

@internal param $directory

Parameters

string $dir The name of the directory to list.:

Return value

array

Throws

\BackupMigrate\Core\Exception\BackupMigrateException

\BackupMigrate\Core\Exception\IgnorableException

2 calls to FileDirectorySource::getFilesToBackup()
DrupalSiteArchiveSource::getFilesToBackup in src/Source/DrupalSiteArchiveSource.php
Get a list if files to be backed up from the given directory. Do not include files that match the 'exclude_filepaths' setting.
FileDirectorySource::exportToFile in lib/backup_migrate_core/src/Source/FileDirectorySource.php
Export this source to the given temp file. This should be the main back up function for this source.
1 method overrides FileDirectorySource::getFilesToBackup()
DrupalSiteArchiveSource::getFilesToBackup in src/Source/DrupalSiteArchiveSource.php
Get a list if files to be backed up from the given directory. Do not include files that match the 'exclude_filepaths' setting.

File

lib/backup_migrate_core/src/Source/FileDirectorySource.php, line 123

Class

FileDirectorySource
Class FileDirectorySource.

Namespace

BackupMigrate\Core\Source

Code

protected function getFilesToBackup($dir) {

  // Add a trailing slash if there is none.
  if (substr($dir, -1) !== '/') {
    $dir .= '/';
  }
  if (!file_exists($dir)) {
    throw new BackupMigrateException('Directory %dir does not exist.', [
      '%dir' => $dir,
    ]);
  }
  if (!is_dir($dir)) {
    throw new BackupMigrateException('The file %dir is not a directory.', [
      '%dir' => $dir,
    ]);
  }
  if (!is_readable($dir)) {
    throw new BackupMigrateException('Directory %dir could not be read from.', [
      '%dir' => $dir,
    ]);
  }

  // Get a filtered list if files from the directory.
  list($out, $errors) = $this
    ->_getFilesFromDirectory($dir);

  // Alert the user to any errors there might have been.
  if ($errors) {
    $count = count($errors);
    $file_list = implode(', ', array_slice($errors, 0, 5));
    if ($count > 5) {
      $file_list .= ', ...';
    }
    if (!$this
      ->confGet('ignore_errors')) {
      throw new IgnorableException('The backup could not be completed because !count files could not be read: (!files).', [
        '!count' => $count,
        '!files' => $file_list,
      ]);
    }
    else {

      // throw new IgnorableException('!count files could not be read: (!files).', ['!files' => $filesmsg]);
      // @TODO: Log the ignored files.
    }
  }
  return $out;
}