You are here

protected function FileDirectorySource::getFilesToBackup in Backup and Migrate 5.0.x

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

\Drupal\backup_migrate\Core\Exception\BackupMigrateException

\Drupal\backup_migrate\Core\Exception\IgnorableException

2 calls to FileDirectorySource::getFilesToBackup()
DrupalSiteArchiveSource::getFilesToBackup in src/Drupal/Source/DrupalSiteArchiveSource.php
Get a list if files to be backed up from the given directory.
FileDirectorySource::exportToFile in src/Core/Source/FileDirectorySource.php
Export this source to the given temp file.
1 method overrides FileDirectorySource::getFilesToBackup()
DrupalSiteArchiveSource::getFilesToBackup in src/Drupal/Source/DrupalSiteArchiveSource.php
Get a list if files to be backed up from the given directory.

File

src/Core/Source/FileDirectorySource.php, line 128

Class

FileDirectorySource
@package Drupal\backup_migrate\Core\Source

Namespace

Drupal\backup_migrate\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;
}