summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--backup_migrate.css4
-rw-r--r--includes/destinations.ftp.inc6
-rw-r--r--includes/destinations.inc93
-rw-r--r--includes/destinations.s3.inc7
4 files changed, 97 insertions, 13 deletions
diff --git a/backup_migrate.css b/backup_migrate.css
index 776356b..2494393 100644
--- a/backup_migrate.css
+++ b/backup_migrate.css
@@ -5,6 +5,10 @@
opacity: .50;
}
+.backup-migrate-cache-time {
+ font-size: 0.85em;
+}
+
.backup-migrate-tables-checkboxes .form-item label {
width: 15em;
float: left;
diff --git a/includes/destinations.ftp.inc b/includes/destinations.ftp.inc
index 5fc9a35..37dcb27 100644
--- a/includes/destinations.ftp.inc
+++ b/includes/destinations.ftp.inc
@@ -19,7 +19,7 @@ class backup_migrate_destination_ftp extends backup_migrate_destination_remote {
/**
* Save to the ftp destination.
*/
- function save_file($file, $settings) {
+ function _save_file($file, $settings) {
$ftp = $this->ftp_object();
if (drupal_ftp_file_to_ftp($file->filepath(), $file->filename(), '.', $ftp)) {
return $file;
@@ -43,12 +43,12 @@ class backup_migrate_destination_ftp extends backup_migrate_destination_remote {
/**
* Delete from the ftp destination.
*/
- function delete_file($file_id) {
+ function _delete_file($file_id) {
$this->ftp_object();
drupal_ftp_delete_file($file_id, $this->ftp);
}
- function list_files() {
+ function _list_files() {
backup_migrate_include('files');
$files = array();
$this->ftp_object();
diff --git a/includes/destinations.inc b/includes/destinations.inc
index 77eafff..c2242fd 100644
--- a/includes/destinations.inc
+++ b/includes/destinations.inc
@@ -258,10 +258,15 @@ function _backup_migrate_destination_get_file_links($destination_id, $file_id) {
* List the backup files in the given destination.
*/
function backup_migrate_ui_destination_display_files($destination_id = NULL) {
- $out = $sort = array();
+ $rows = $sort = array();
if ($destination = backup_migrate_get_destination($destination_id)) {
- drupal_set_title(t('@title Files', array('@title' => $destination->get_name())));
+ // Refresh the file listing cache if requested.
+ if (isset($_GET['refresh'])) {
+ $destination->file_cache_clear();
+ drupal_goto($_GET['q']);
+ }
+ drupal_set_title(t('@title Files', array('@title' => $destination->get_name())));
$headers = array(
array('data' => t('Filename'), 'field' => 'filename'),
array('data' => t('Date'), 'field' => 'filetime'),
@@ -284,7 +289,7 @@ function backup_migrate_ui_destination_display_files($destination_id = NULL) {
// Show only files that can be restored from.
if ($file->is_recognized_type()) {
$sort[] = $info[$sort_key];
- $out[] = array_merge(array(
+ $rows[] = array_merge(array(
check_plain($info['filename']),
format_date($info['filetime'], 'small'),
format_interval(time() - $info['filetime'], 1),
@@ -299,14 +304,21 @@ function backup_migrate_ui_destination_display_files($destination_id = NULL) {
$headers[] = array('data' => t('Operations'), 'colspan' => $ops);
}
- array_multisort($sort, $sort_dir, $out);
+ array_multisort($sort, $sort_dir, $rows);
- if ($out) {
- return theme('table', array('header' => $headers, 'rows' => $out));
+ if ($rows) {
+ drupal_add_css(drupal_get_path('module', 'backup_migrate') .'/backup_migrate.css');
+ $out = '';
+ $out .= theme('table', array('header' => $headers, 'rows' => $rows));
}
else {
- return t('There are no backup files to display.');
+ $out = t('There are no backup files to display.');
}
+ if ($destination->cache_files && $destination->fetch_time) {
+ drupal_add_css(drupal_get_path('module', 'backup_migrate') .'/backup_migrate.css');
+ $out .= '<div class="backup-migrate-cache-time">'. t('This listing was fetched !time ago. !refresh', array('!time' => format_interval(time() - $destination->fetch_time, 1), '!refresh' => l(t('fetch now'), $_GET['q'], array('query' => array('refresh' => 'true'))))) .'</div>';
+ }
+ return $out;
}
drupal_goto(BACKUP_MIGRATE_MENU_PATH . "/destination");
}
@@ -483,6 +495,9 @@ class backup_migrate_destination extends backup_migrate_item {
var $default_values = array('settings' => array());
var $singular = 'destination';
var $plural = 'destinations';
+ var $cache_files = FALSE;
+ var $fetch_time = NULL;
+ var $cache_expire = 86400; // 24 hours
var $destination_type = "";
var $supported_ops = array();
@@ -567,6 +582,15 @@ class backup_migrate_destination extends backup_migrate_item {
*/
function save_file($file, $settings) {
// This must be overriden.
+ $this->file_cache_clear();
+ return $this->_save_file($file, $settings);
+ }
+
+ /**
+ * Save the given file to the destination.
+ */
+ function _save_file($file, $settings) {
+ // This must be overriden.
return $file;
}
@@ -591,13 +615,68 @@ class backup_migrate_destination extends backup_migrate_item {
* List all the available files in the given destination with their destination specific id.
*/
function list_files() {
+ $out = NULL;
+ if ($this->cache_files) {
+ $out = $this->file_cache_get();
+ }
+ if ($out === NULL) {
+ $out = $this->_list_files();
+ if ($this->cache_files) {
+ $this->file_cache_set($out);
+ }
+ }
+ return $out;
+ }
+
+ /**
+ * List all the available files in the given destination with their destination specific id.
+ */
+ function _list_files() {
return array();
}
/**
+ * Cache the file list.
+ */
+ function file_cache_set($files) {
+ cache_set('backup_migrate_file_list:'. $this->get_id(), $files, 'cache', time() + $this->cache_expire);
+ }
+
+ /**
+ * Retrieve the file list.
+ */
+ function file_cache_get() {
+ backup_migrate_include('files');
+ $cache = cache_get('backup_migrate_file_list:'. $this->get_id());
+ if (!empty($cache->data) && $cache->created > (time() - $this->cache_expire)) {
+ $this->fetch_time = $cache->created;
+ return $cache->data;
+ }
+ $this->fetch_time = 0;
+ return NULL;
+ }
+
+ /**
+ * Retrieve the file list.
+ */
+ function file_cache_clear() {
+ if ($this->cache_files) {
+ $this->file_cache_set(NULL);
+ }
+ }
+
+ /**
* Delete the file with the given destination specific id.
*/
function delete_file($file_id) {
+ $this->file_cache_clear();
+ $this->_delete_file($file_id);
+ }
+
+ /**
+ * Delete the file with the given destination specific id.
+ */
+ function _delete_file($file_id) {
// This must be overriden.
}
diff --git a/includes/destinations.s3.inc b/includes/destinations.s3.inc
index d8e135f..6889290 100644
--- a/includes/destinations.s3.inc
+++ b/includes/destinations.s3.inc
@@ -15,11 +15,12 @@
class backup_migrate_destination_s3 extends backup_migrate_destination_remote {
var $supported_ops = array('scheduled backup', 'manual backup', 'restore', 'list files', 'configure', 'delete');
var $s3 = NULL;
+ var $cache_files = TRUE;
/**
* Save to to the s3 destination.
*/
- function save_file($file, $settings) {
+ function _save_file($file, $settings) {
if ($s3 = $this->s3_object()) {
$path = $file->filename();
if ($s3->putObject($s3->inputFile($file->filepath(), FALSE), $this->get_bucket(), $this->remote_path($file->filename()), S3::ACL_PRIVATE)) {
@@ -47,7 +48,7 @@ class backup_migrate_destination_s3 extends backup_migrate_destination_remote {
/**
* Delete from the s3 destination.
*/
- function delete_file($file_id) {
+ function _delete_file($file_id) {
if ($s3 = $this->s3_object()) {
$s3->deleteObject($this->get_bucket(), $this->remote_path($file_id));
}
@@ -56,7 +57,7 @@ class backup_migrate_destination_s3 extends backup_migrate_destination_remote {
/**
* List all files from the s3 destination.
*/
- function list_files() {
+ function _list_files() {
backup_migrate_include('files');
$files = array();
if ($s3 = $this->s3_object()) {