1 backup.inc | backup_directory_list() |
Get a list of all available backups.
File
- core/
includes/ backup.inc, line 67 - Contains functionality related to creating and restoring site backups.
Code
function backup_directory_list() {
$backups = array();
$backup_directory = backup_get_backup_directory();
if (empty($backup_directory)) {
return $backups;
}
$current_directory = '';
$skip_this_directory = FALSE;
$backup_file_list = file_scan_directory($backup_directory, '/\.backup\.json$/', array(
'max_depth' => 2,
));
foreach ($backup_file_list as $backup_file) {
$backup_file_directory = dirname($backup_file->uri);
$backup_file_path = $backup_file->uri;
if ($backup_file_directory != $current_directory) {
$current_directory = $backup_file_directory;
$skip_this_directory = FALSE;
}
// If a single backup or JSON file in this directory is invalid, skip the
// entire backup.
if ($skip_this_directory) {
continue;
}
// Check if the JSON file is valid, if not, continue to the next file.
$backup_info = @backdrop_json_decode(file_get_contents($backup_file_path));
$backup_name = basename($backup_file_directory);
if (!$backup_info || !isset($backup_info['targets'])) {
$backups[$backup_name] = array(
'label' => $backup_name,
'valid' => FALSE,
);
$skip_this_directory = TRUE;
continue;
}
// If valid, add to list of backups.
if (!isset($backups[$backup_name])) {
$backups[$backup_name] = array(
'valid' => TRUE,
) + $backup_info;
// Overwrite the backup_directory value to be the current location.
$backups[$backup_name]['backup_directory'] = $backup_file_directory;
}
}
return $backups;
}