public function DirectoryDestination::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 ListableDestinationInterface::queryFiles
1 method overrides DirectoryDestination::queryFiles()
- DrupalDirectoryDestination::queryFiles in src/
Destination/ DrupalDirectoryDestination.php - Run a basic query with sort on the list of files.
File
- lib/
backup_migrate_core/ src/ Destination/ DirectoryDestination.php, line 149
Class
- DirectoryDestination
- Class ServerDirectoryDestination.
Namespace
BackupMigrate\Core\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) {
return $b
->getMeta($sort) < $b
->getMeta($sort);
}
else {
return $b
->getMeta($sort) > $b
->getMeta($sort);
}
});
}
// Slice the return array.
if ($count || $start) {
$out = array_slice($out, $start, $count);
}
return $out;
}