public function DrupalDirectoryDestination::queryFiles in Backup and Migrate 8.4
Run a basic query with sort on the list of files.
Parameters
array $filters An array of of metadata fields to filter by.:
string $sort A metadata field to sort bby:
int $sort_direction The direction to sort by. SORT_ASC or SORT_DESC:
int $count:
int $start:
Return value
mixed
Overrides DirectoryDestination::queryFiles
File
- src/
Destination/ DrupalDirectoryDestination.php, line 90
Class
- DrupalDirectoryDestination
- Class DrupalDirectoryDestination.
Namespace
BackupMigrate\Drupal\DestinationCode
public function queryFiles($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 $a
->getFullName() <=> $b
->getFullName();
}
// @TODO: fix this in core
return $a
->getMeta($sort) <=> $b
->getMeta($sort);
}
});
}
// Slice the return array.
if ($count || $start) {
$out = array_slice($out, $start, $count);
}
return $out;
}