protected function FileDirectorySource::getFilesFromDirectory in Backup and Migrate 5.0.x
@internal param string $dir
Parameters
$base_path: The name of the directory to list. This must always end in '/'.
string $subdir:
Return value
array
1 call to FileDirectorySource::getFilesFromDirectory()
- FileDirectorySource::getFilesToBackup in src/
Core/ Source/ FileDirectorySource.php - Get a list if files to be backed up from the given directory.
File
- src/
Core/ Source/ FileDirectorySource.php, line 178
Class
- FileDirectorySource
- @package Drupal\backup_migrate\Core\Source
Namespace
Drupal\backup_migrate\Core\SourceCode
protected function getFilesFromDirectory($base_path, $subdir = '') {
$out = $errors = [];
// Open the directory.
if (!($handle = opendir($base_path . $subdir))) {
$errors[] = $base_path . $subdir;
}
else {
while (($file = readdir($handle)) !== FALSE) {
// If not a dot file and the file name isn't excluded.
if ($file != '.' && $file != '..') {
// Get the full path of the file.
$path = $base_path . $subdir . $file;
// Allow filters to modify or exclude this path.
$path = $this
->plugins()
->call('beforeFileBackup', $path, [
'source' => $this,
'base_path' => $base_path,
]);
if ($path) {
if (is_dir($path)) {
list($sub_files, $sub_errors) = $this
->getFilesFromDirectory($base_path, $subdir . $file . '/');
// Add the directory if it is empty.
if (empty($sub_files)) {
$out[$subdir . $file] = $path;
}
// Add the sub-files to the output.
$out = array_merge($out, $sub_files);
$errors = array_merge($errors, $sub_errors);
}
else {
if (is_readable($path)) {
$out[$subdir . $file] = $path;
}
else {
$errors[] = $path;
}
}
}
}
}
closedir($handle);
}
return [
$out,
$errors,
];
}