public function DrupalDirectoryDestination::queryFiles in Backup and Migrate 5.0.x
Run a basic query with sort on the list of files.
Parameters
array $filters: An array of metadata fields to filter by.
string $sort: A metadata field to sort by, defaults to 'datestamp'.
int $sort_direction: The direction to sort by, either SORT_ASC or SORT_DESC.
int $count: The number of records to obtain.
int $start: The first item to start the result set from.
Return value
mixed
Overrides DirectoryDestination::queryFiles
File
- src/
Drupal/ Destination/ DrupalDirectoryDestination.php, line 95
Class
- DrupalDirectoryDestination
- @package Drupal\backup_migrate\Drupal\Destination
Namespace
Drupal\backup_migrate\Drupal\DestinationCode
public function queryFiles(array $filters = [], $sort = 'datestamp', $sort_direction = SORT_DESC, $count = 100, $start = 0) {
// Get the full list of files.
$out = $this
->listFiles($count + $start);
foreach ($out as $key => $file) {
$out[$key] = $this
->loadFileMetadata($file);
}
// Filter the output.
if ($filters) {
$out = array_filter($out, function ($file) use ($filters) {
foreach ($filters as $key => $value) {
if ($file
->getMeta($key) !== $value) {
return FALSE;
}
}
return TRUE;
});
}
// Sort the files.
if ($sort && $sort_direction) {
uasort($out, function ($a, $b) use ($sort, $sort_direction) {
if ($sort_direction == SORT_DESC) {
if ($sort == 'name') {
return $a
->getFullName() <=> $b
->getFullName();
}
// @todo fix this in core
return $a
->getMeta($sort) <=> $b
->getMeta($sort);
}
else {
if ($sort == 'name') {
return $b
->getFullName() <=> $a
->getFullName();
}
// @todo fix this in core
return $b
->getMeta($sort) <=> $a
->getMeta($sort);
}
});
}
// Slice the return array.
if ($count || $start) {
$out = array_slice($out, $start, $count);
}
return $out;
}