summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRonan Dowling2011-02-01 03:48:49 (GMT)
committer Ronan Dowling2011-02-01 03:48:49 (GMT)
commit20bc85936db985aa9ce15132af5abe51cd0e9ad0 (patch)
treef27f7a3e932cf59b2e43e2bbd829413cdf8d21c7
parent871a7916efddac4ff1555f940f26a1d81115695d (diff)
Added multi-source settings (ported from D6 branch)
-rw-r--r--includes/crud.inc16
-rw-r--r--includes/destinations.db.inc28
-rw-r--r--includes/destinations.db.mysql.inc2
-rw-r--r--includes/destinations.inc12
-rw-r--r--includes/filters.backup_restore.inc35
-rw-r--r--includes/filters.inc2
6 files changed, 64 insertions, 31 deletions
diff --git a/includes/crud.inc b/includes/crud.inc
index 8a75439..adb1b6c 100644
--- a/includes/crud.inc
+++ b/includes/crud.inc
@@ -317,6 +317,20 @@ class backup_migrate_item {
$this->from_array($params);
}
+
+ /**
+ * Decode a loaded db row (unserialize necessary fields).
+ */
+ function decode_db_row($data) {
+ $params = array();
+ $schema = $this->get_schema();
+ // Load fields as specified in the schema.
+ foreach ($schema['fields'] as $field => $info) {
+ $params[$field] = empty($info['serialize']) ? $data[$field] : unserialize($data[$field]);
+ }
+ return $params;
+ }
+
/**
* Return the fields which must be serialized before saving to the db.
*/
@@ -618,8 +632,8 @@ class backup_migrate_item {
// Get the items from the db.
$result = db_query("SELECT * FROM {{$this->db_table}}", array(), array('fetch' => PDO::FETCH_ASSOC));
foreach ($result as $info) {
+ $info = $this->decode_db_row($info);
if ($item = $this->create($info)) {
- $item->load_row($info);
$item->storage = empty($items[$item->get_id()]) ? BACKUP_MIGRATE_STORAGE_DB : BACKUP_MIGRATE_STORAGE_OVERRIDEN;
$items[$item->get_id()] = $item;
}
diff --git a/includes/destinations.db.inc b/includes/destinations.db.inc
index 2447e6e..582eae3 100644
--- a/includes/destinations.db.inc
+++ b/includes/destinations.db.inc
@@ -108,18 +108,10 @@ class backup_migrate_destination_db extends backup_migrate_destination_remote {
/**
* Get the form for the backup settings for this destination.
*/
- function backup_settings_form(&$form, $settings) {
+ function backup_settings_form($settings) {
$tables = $this->get_table_names();
- $form['database'] = array(
- "#type" => "fieldset",
- "#title" => t("Database Options"),
- "#collapsible" => TRUE,
- "#collapsed" => TRUE,
- "#tree" => FALSE,
- "#description" => t("You may omit specific tables, or specific table data from the backup file. Only omit data that you know you will not need such as cache data, or tables from other applications. Excluding tables can break your Drupal install, so <strong>do not change these settings unless you know what you're doing</strong>."),
- '#weight' => 5,
- );
- $form['database']['exclude_tables'] = array(
+ $form['#description'] = t("You may omit specific tables, or specific table data from the backup file. Only omit data that you know you will not need such as cache data, or tables from other applications. Excluding tables can break your Drupal install, so <strong>do not change these settings unless you know what you're doing</strong>.");
+ $form['exclude_tables'] = array(
"#type" => "select",
"#multiple" => TRUE,
"#title" => t("Exclude the following tables altogether"),
@@ -127,7 +119,7 @@ class backup_migrate_destination_db extends backup_migrate_destination_remote {
"#default_value" => $settings['exclude_tables'],
"#description" => t("The selected tables will not be added to the backup file."),
);
- $form['database']['nodata_tables'] = array(
+ $form['nodata_tables'] = array(
"#type" => "select",
"#multiple" => TRUE,
"#title" => t("Exclude the data from the following tables"),
@@ -135,13 +127,12 @@ class backup_migrate_destination_db extends backup_migrate_destination_remote {
"#default_value" => $settings['nodata_tables'],
"#description" => t("The selected tables will have their structure backed up but not their contents. This is useful for excluding cache data to reduce file size."),
);
- $form['database']['utils_lock_tables'] = array(
+ $form['utils_lock_tables'] = array(
'#type' => 'checkbox',
'#title' => t('Lock tables during backup'),
'#default_value' => !empty($settings['utils_lock_tables']) ? $settings['utils_lock_tables'] : NULL,
'#description' => t('This can help reduce data corruption, but will make your site unresponsive.'),
);
-
return $form;
}
@@ -244,6 +235,15 @@ class backup_migrate_destination_db extends backup_migrate_destination_remote {
*/
function get_table_names() {
// Must be overridden.
+ $out = $this->_get_table_names();
+ return $out;
+ }
+
+ /**
+ * Get a list of tables in the database.
+ */
+ function _get_table_names() {
+ // Must be overridden.
return array();
}
diff --git a/includes/destinations.db.mysql.inc b/includes/destinations.db.mysql.inc
index 56897f7..292aab3 100644
--- a/includes/destinations.db.mysql.inc
+++ b/includes/destinations.db.mysql.inc
@@ -148,7 +148,7 @@ class backup_migrate_destination_db_mysql extends backup_migrate_destination_db
/**
* Get a list of tables in the database.
*/
- function get_table_names() {
+ function _get_table_names() {
$out = array();
foreach ($this->_get_tables() as $table) {
$out[$table['name']] = $table['name'];
diff --git a/includes/destinations.inc b/includes/destinations.inc
index c2242fd..d67cc57 100644
--- a/includes/destinations.inc
+++ b/includes/destinations.inc
@@ -260,7 +260,7 @@ function _backup_migrate_destination_get_file_links($destination_id, $file_id) {
function backup_migrate_ui_destination_display_files($destination_id = NULL) {
$rows = $sort = array();
if ($destination = backup_migrate_get_destination($destination_id)) {
- // Refresh the file listing cache if requested.
+ // Refresh the file listing cache if requested.
if (isset($_GET['refresh'])) {
$destination->file_cache_clear();
drupal_goto($_GET['q']);
@@ -318,7 +318,7 @@ function backup_migrate_ui_destination_display_files($destination_id = NULL) {
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;
+ return $out;
}
drupal_goto(BACKUP_MIGRATE_MENU_PATH . "/destination");
}
@@ -916,20 +916,20 @@ class backup_migrate_destination extends backup_migrate_item {
/**
* Get the form for the settings for this filter.
*/
- function backup_settings_form(&$form, $settings) {
+ function backup_settings_form($settings) {
+ return array();
}
/**
* Get the form for the settings for this filter.
*/
- function backup_settings_form_validate($form_values) {
+ function backup_settings_form_validate($form, &$form_state) {
}
/**
* Submit the settings form. Any values returned will be saved.
*/
- function backup_settings_form_submit($form_values) {
- return $form_values;
+ function backup_settings_form_submit($form, &$form_state) {
}
/**
diff --git a/includes/filters.backup_restore.inc b/includes/filters.backup_restore.inc
index 35be989..6a145f0 100644
--- a/includes/filters.backup_restore.inc
+++ b/includes/filters.backup_restore.inc
@@ -33,9 +33,10 @@ class backup_migrate_filter_backup_restore extends backup_migrate_filter {
* Get the default backup settings for this filter.
*/
function backup_settings_default() {
+ backup_migrate_include('destinations');
$out = array();
- foreach ($this->_get_destination_types() as $destination) {
- $out += $destination->backup_settings_default();
+ foreach (backup_migrate_get_destinations('source') as $destination) {
+ $out['destinations'][$destination->get_id()] = $destination->backup_settings_default();
}
return $out;
}
@@ -73,11 +74,25 @@ class backup_migrate_filter_backup_restore extends backup_migrate_filter {
* Get the form for the backup settings for this filter.
*/
function backup_settings_form($settings) {
- $form = array();
- foreach ($this->_get_destination_types() as $destination) {
- $destination->backup_settings_form($form, $settings);
+ backup_migrate_include('destinations');
+ $out = array('destinations' => array(
+ '#tree' => TRUE,
+
+ ));
+ foreach (backup_migrate_get_destinations('source') as $destination) {
+ $destination_settings = (array)(@$settings['destinations'][$destination->get_id()]) + $settings;
+ if ($form = $destination->backup_settings_form($destination_settings)) {
+ $out['destinations'][$destination->get_id()] = array(
+ '#type' => 'fieldset',
+ '#title' => t('!name Backup Options', array('!name' => $destination->get('name'))),
+ "#collapsible" => TRUE,
+ "#collapsed" => TRUE,
+ '#tree' => TRUE,
+ '#parents' => array('filters', 'destinations', $destination->get_id()),
+ ) + $form;
+ }
}
- return $form;
+ return $out;
}
/**
@@ -107,6 +122,9 @@ class backup_migrate_filter_backup_restore extends backup_migrate_filter {
*/
function backup($file, &$settings) {
if ($source = $settings->get_source()) {
+ if (!empty($settings->filters['destinations'][$source->get_id()])) {
+ $settings->filters = (array)($settings->filters['destinations'][$source->get_id()]) + $settings->filters;
+ }
$file = $source->backup_to_file($file, $settings);
return $file;
}
@@ -119,7 +137,8 @@ class backup_migrate_filter_backup_restore extends backup_migrate_filter {
*/
function restore($file, &$settings) {
if ($source = $settings->get_source()) {
- $num = $source->restore_from_file($file, $settings);
+ $source_settings = (array)(@$settings['destinations'][$source->get_id()]) + $settings;
+ $num = $source->restore_from_file($file, $source_settings);
return $num ? $file : FALSE;
}
backup_migrate_restore_fail("Could not run restore because the source '%source' is missing.", array('%source' => $settings->source_id), $settings);
@@ -146,4 +165,4 @@ class backup_migrate_filter_backup_restore extends backup_migrate_filter {
}
return $destinations;
}
-} \ No newline at end of file
+}
diff --git a/includes/filters.inc b/includes/filters.inc
index c00e7db..ede6e9a 100644
--- a/includes/filters.inc
+++ b/includes/filters.inc
@@ -136,9 +136,9 @@ function backup_migrate_filters_settings_form($settings, $op) {
*/
function backup_migrate_filters_settings_form_set_parents($form) {
foreach (element_children($form) as $key) {
- $form[$key] = backup_migrate_filters_settings_form_set_parents($form[$key]);
if (!isset($form[$key]['#parents'])) {
$form[$key]['#parents'] = array('filters', $key);
+ $form[$key] = backup_migrate_filters_settings_form_set_parents($form[$key]);
}
}
return $form;