View source
<?php
backup_migrate_include('crud');
function backup_migrate_get_destination_types() {
$out = array();
foreach (module_implements('backup_migrate_destination_types') as $module) {
$fn = $module . '_backup_migrate_destination_types';
$out += $fn();
}
return $out;
}
function backup_migrate_backup_migrate_destination_types() {
$out = array();
if (!module_exists('nodesquirrel')) {
$out += array(
'nodesquirrel' => array(
'description' => t('!link is the cloud backup service for Drupal built by the maintainer of Backup and Migrate.', array(
'!link' => l(t('NodeSquirrel'), 'http://nodesquirrel.com'),
)),
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/destinations.nodesquirrel.inc',
'class' => 'backup_migrate_destination_nodesquirrel',
'type_name' => t('NodeSquirrel.com'),
'can_create' => TRUE,
),
);
}
if (variable_get('backup_migrate_allow_backup_to_file', TRUE)) {
$out += array(
'file' => array(
'description' => t('Save the backup files to any directory on the server which the web-server can write to.'),
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/destinations.file.inc',
'class' => 'backup_migrate_destination_files',
'type_name' => t('Server Directory'),
'can_create' => TRUE,
),
'file_manual' => array(
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/destinations.file.inc',
'type_name' => t('Server Directory'),
'class' => 'backup_migrate_destination_files_manual',
),
'file_scheduled' => array(
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/destinations.file.inc',
'type_name' => t('Server Directory'),
'class' => 'backup_migrate_destination_files_scheduled',
),
);
}
$out += array(
'browser_download' => array(
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/destinations.browser.inc',
'class' => 'backup_migrate_destination_browser_download',
),
'browser_upload' => array(
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/destinations.browser.inc',
'class' => 'backup_migrate_destination_browser_upload',
),
'db' => array(
'type_name' => t('Database'),
'description' => t('Import the backup directly into another database. Database destinations can also be used as a source to backup from.'),
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/destinations.db.inc',
'class' => 'backup_migrate_destination_db',
'can_create' => FALSE,
),
'mysql' => array(
'type_name' => t('MySQL Database'),
'description' => t('Import the backup directly into another MySQL database. Database destinations can also be used as a source to backup from.'),
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/destinations.db.mysql.inc',
'class' => 'backup_migrate_destination_db_mysql',
'can_create' => TRUE,
),
'ftp' => array(
'description' => t('Save the backup files to any a directory on an FTP server.'),
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/destinations.ftp.inc',
'class' => 'backup_migrate_destination_ftp',
'type_name' => t('FTP Directory'),
'can_create' => TRUE,
),
's3' => array(
'description' => t('Save the backup files to a bucket on your <a href="@link">Amazon S3 account</a>.', array(
'@link' => url('http://aws.amazon.com/s3/'),
)),
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/destinations.s3.inc',
'class' => 'backup_migrate_destination_s3',
'type_name' => t('Amazon S3 Bucket'),
'can_create' => TRUE,
),
'email' => array(
'type_name' => t('Email'),
'description' => t('Send the backup as an email attachment to the specified email address.'),
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/destinations.email.inc',
'class' => 'backup_migrate_destination_email',
'can_create' => TRUE,
),
);
return $out;
}
function backup_migrate_backup_migrate_destinations() {
$out = array();
if (variable_get('backup_migrate_allow_backup_to_file', TRUE)) {
$out['manual'] = backup_migrate_create_destination('file_manual', array(
'destination_id' => 'manual',
));
$out['scheduled'] = backup_migrate_create_destination('file_scheduled', array(
'destination_id' => 'scheduled',
));
}
if (variable_get('backup_migrate_allow_backup_to_download', TRUE)) {
$out['download'] = backup_migrate_create_destination('browser_download');
}
$out['upload'] = backup_migrate_create_destination('browser_upload');
if ($secret_key = variable_get('nodesquirrel_secret_key', '')) {
$out['nodesquirrel'] = backup_migrate_create_destination('nodesquirrel', array(
'destination_id' => 'nodesquirrel',
));
$out['nodesquirrel']->settings['secret_key'] = $secret_key;
}
backup_migrate_include('filters');
$out += backup_migrate_filters_invoke_all('destinations');
return $out;
}
function backup_migrate_get_destinations($op = 'all') {
static $destinations = NULL;
if ($destinations === NULL) {
$destinations = backup_migrate_crud_get_items('destination');
}
if ($op == 'all') {
return $destinations;
}
$out = array();
foreach ($destinations as $key => $destination) {
if ($destination
->op($op)) {
$out[$key] = $destination;
}
}
return $out;
}
function backup_migrate_get_destination($id) {
$destinations = backup_migrate_get_destinations('all');
return empty($destinations[$id]) ? NULL : $destinations[$id];
}
function backup_migrate_create_destination($destination_type, $params = array()) {
$params['type'] = $destination_type;
$destination = new backup_migrate_destination();
return $destination
->create($params);
}
function backup_migrate_destination_get_file($destination_id, $file_id) {
if ($destination = backup_migrate_get_destination($destination_id)) {
return $destination
->load_file($file_id);
}
return NULL;
}
function backup_migrate_destination_file_exists($destination_id, $file_id) {
if ($destination = backup_migrate_get_destination($destination_id)) {
return $destination
->file_exists($file_id);
}
return NULL;
}
function backup_migrate_destination_save_file($file, &$settings) {
if ($destination = $settings
->get_destination()) {
$file = $destination
->save_file($file, $settings);
return $file;
}
return NULL;
}
function backup_migrate_destination_delete_file($destination_id, $file_id) {
if ($destination = backup_migrate_get_destination($destination_id)) {
return $destination
->delete_file($file_id);
}
}
function _backup_migrate_destination_get_file_links($destination_id, $file_id) {
$out = array();
if ($destination = backup_migrate_get_destination($destination_id)) {
$out = $destination
->get_file_links($file_id);
}
return $out;
}
function backup_migrate_ui_destination_display_files($destination_id = NULL) {
$rows = $sort = array();
if ($destination = backup_migrate_get_destination($destination_id)) {
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' => 'Filename',
'field' => 'filename',
),
array(
'data' => 'Date',
'field' => 'filetime',
),
array(
'data' => 'Age',
'field' => 'filetime',
'sort' => 'desc',
),
array(
'data' => 'Size',
'field' => 'filesize',
),
t('Operations'),
);
$sort_order = tablesort_get_order($headers);
$sort_key = $sort_order['sql'] ? $sort_order['sql'] : 'filetime';
$sort_dir = tablesort_get_sort($headers) == 'desc' ? SORT_DESC : SORT_ASC;
$files = $destination
->list_files();
$i = 0;
foreach ((array) $files as $file) {
$info = $file
->info();
if ($file
->is_recognized_type()) {
$sort[] = $info[$sort_key];
$rows[] = array(
check_plain($info['filename']),
format_date($info['filetime'], 'small'),
format_interval(time() - $info['filetime'], 1),
format_size($info['filesize']),
implode(" | ", $destination
->get_file_links($file
->file_id())),
);
}
}
array_multisort($sort, $sort_dir, $rows);
if ($files) {
$out = theme("table", $headers, $rows);
}
else {
$out = t('There are no backup files to display.');
}
if ($destination->cache_files && $destination->fetch_time) {
$out .= '<div class="description">' . 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' => 'refresh=true',
)),
)) . '</div>';
}
return $out;
}
drupal_goto(BACKUP_MIGRATE_MENU_PATH . "/destination");
}
function backup_migrate_ui_destination_download_file($destination_id = NULL, $file_id = NULL) {
if ($file = backup_migrate_destination_get_file($destination_id, $file_id)) {
backup_migrate_include('files');
$file
->transfer();
}
drupal_goto(BACKUP_MIGRATE_MENU_PATH);
}
function backup_migrate_ui_destination_restore_file($destination_id = NULL, $file_id = NULL) {
if (backup_migrate_destination_file_exists($destination_id, $file_id)) {
return drupal_get_form('backup_migrate_ui_destination_restore_file_confirm', $destination_id, $file_id);
}
_backup_migrate_message('Cannot restore from the the file: %file_id because it does not exist.', array(
'%file_id' => $file_id,
), 'error');
if ($destination_id && user_access('access backup files')) {
drupal_goto(BACKUP_MIGRATE_MENU_PATH . '/destination/list/files/' . $destination_id);
}
drupal_goto(BACKUP_MIGRATE_MENU_PATH);
}
function backup_migrate_ui_destination_restore_file_confirm(&$form_state, $destination_id, $file_id) {
$sources = _backup_migrate_get_destination_form_item_options('source');
if (count($sources) > 1) {
$form['source_id'] = array(
"#type" => "select",
"#title" => t("Database"),
"#options" => _backup_migrate_get_destination_form_item_options('source'),
"#description" => t("Choose the database to restore to. Any database destinations you have created and any databases specified in your settings.php can be restored to."),
"#default_value" => 'db',
);
}
else {
$form['source_id'] = array(
"#type" => "value",
"#value" => 'db',
);
}
$form['destination_id'] = array(
'#type' => 'value',
'#value' => $destination_id,
);
$form['file_id'] = array(
'#type' => 'value',
'#value' => $file_id,
);
$form = confirm_form($form, t('Are you sure you want to restore the database?'), BACKUP_MIGRATE_MENU_PATH . "/destination/list/files/" . $destination_id, t('Are you sure you want to restore the database from the backup file %file_id? This will delete some or all of your data and cannot be undone. <strong>Always test your backups on a non-production server!</strong>', array(
'%file_id' => $file_id,
)), t('Restore'), t('Cancel'));
drupal_set_message(t('Restoring will delete some or all of your data and cannot be undone. <strong>Always test your backups on a non-production server!</strong>'), 'warning', FALSE);
$form = array_merge_recursive($form, backup_migrate_filters_settings_form(backup_migrate_filters_settings_default('restore'), 'restore'));
$form['actions']['#weight'] = 100;
if (@$form['advanced']) {
$form['advanced']['#type'] = 'fieldset';
$form['advanced']['#title'] = t('Advanced Options');
$form['advanced']['#collapsed'] = true;
$form['advanced']['#collapsible'] = true;
}
return $form;
}
function backup_migrate_ui_destination_restore_file_confirm_submit($form, &$form_state) {
$destination_id = $form_state['values']['destination_id'];
$file_id = $form_state['values']['file_id'];
if ($destination_id && $file_id) {
backup_migrate_perform_restore($destination_id, $file_id, $form_state['values']);
}
$redir = user_access('access backup files') ? BACKUP_MIGRATE_MENU_PATH . "/destination/list/files/" . $destination_id : BACKUP_MIGRATE_MENU_PATH;
$form_state['redirect'] = $redir;
}
function backup_migrate_ui_destination_delete_file($destination_id = NULL, $file_id = NULL) {
if (backup_migrate_destination_file_exists($destination_id, $file_id)) {
return drupal_get_form('backup_migrate_ui_destination_delete_file_confirm', $destination_id, $file_id);
}
_backup_migrate_message('Cannot delete the file: %file_id because it does not exist.', array(
'%file_id' => $file_id,
), 'error');
if ($destination_id && user_access('access backup files')) {
drupal_goto(BACKUP_MIGRATE_MENU_PATH . '/destination/list/files/' . $destination_id);
}
drupal_goto(BACKUP_MIGRATE_MENU_PATH);
}
function backup_migrate_ui_destination_delete_file_confirm(&$form_state, $destination_id, $file_id) {
$form['destination_id'] = array(
'#type' => 'value',
'#value' => $destination_id,
);
$form['file_id'] = array(
'#type' => 'value',
'#value' => $file_id,
);
return confirm_form($form, t('Are you sure you want to delete the backup file?'), BACKUP_MIGRATE_MENU_PATH . '/destination/list/files/' . $destination_id, t('Are you sure you want to delete the backup file %file_id? <strong>This action cannot be undone.</strong>', array(
'%file_id' => $file_id,
)), t('Delete'), t('Cancel'));
}
function backup_migrate_ui_destination_delete_file_confirm_submit($form, &$form_state) {
if (user_access('delete backup files')) {
$destination_id = $form_state['values']['destination_id'];
$file_id = $form_state['values']['file_id'];
backup_migrate_destination_delete_file($destination_id, $file_id);
_backup_migrate_message('Database backup file deleted: %file_id', array(
'%file_id' => $file_id,
));
}
$form_state['redirect'] = user_access('access backup files') ? BACKUP_MIGRATE_MENU_PATH . "/destination/list/files/" . $destination_id : BACKUP_MIGRATE_MENU_PATH;
}
function _backup_migrate_get_source_form($source_id = 'db') {
backup_migrate_include('destinations');
$form = array();
$sources = _backup_migrate_get_source_pulldown($source_id);
if (count($sources['#options']) > 1) {
$form['source'] = array(
"#type" => "fieldset",
"#title" => t("Backup Source"),
"#collapsible" => TRUE,
"#collapsed" => FALSE,
"#tree" => FALSE,
);
$sources['#description'] = t("Choose the database to backup. Any database destinations you have created and any databases specified in your settings.php can be backed up.");
$form['source']['source_id'] = $sources;
}
else {
$form = array();
$form['source']['source_id'] = array(
"#type" => "value",
"#value" => $source_id,
);
}
return $form;
}
function _backup_migrate_get_source_pulldown($source_id = NULL) {
backup_migrate_include('destinations');
$sources = _backup_migrate_get_destination_form_item_options('source');
$form = array(
"#type" => "select",
"#title" => t("Backup Source"),
"#options" => _backup_migrate_get_destination_form_item_options('source'),
"#default_value" => $source_id,
);
return $form;
}
function _backup_migrate_get_destination_form_item_options($op) {
$out = array();
foreach (backup_migrate_get_destinations($op) as $key => $destination) {
$out[$key] = $destination
->get_name();
}
return $out;
}
class backup_migrate_destination extends backup_migrate_item {
var $db_table = "backup_migrate_destinations";
var $type_name = "destination";
var $default_values = array(
'settings' => array(),
);
var $singular = 'destination';
var $plural = 'destinations';
var $cache_files = FALSE;
var $fetch_time = NULL;
var $cache_expire = 86400;
var $destination_type = "";
var $supported_ops = array();
function strings() {
t('Destination');
t('Destinations');
t('destinations');
t('destination');
}
function ops() {
return $this->supported_ops;
}
function op($op) {
$ops = (array) $this
->ops();
return in_array($op, $ops);
}
function remove_op($op) {
$key = array_search($op, $this->supported_ops);
if ($key !== FALSE) {
unset($this->supported_ops[$key]);
}
}
function get_name() {
return @$this->name;
}
function set_name($name) {
return $this->name = $name;
}
function set_type($type) {
$this->type = $type;
}
function set_location($location) {
$this->location = $location;
}
function get_location() {
return @$this->location;
}
function get_display_location() {
return $this
->get_location();
}
function file_types() {
return array();
}
function settings($key = NULL) {
$out = $this->settings;
if ($key) {
$out = isset($out[$key]) ? $out[$key] : NULL;
}
return $out;
}
function get_destination_type_name() {
if ($type = $this->destination_type) {
$types = backup_migrate_get_destination_types();
return isset($types[$type]['type_name']) ? $types[$type]['type_name'] : $type;
}
}
function save_file($file, $settings) {
$this
->file_cache_clear();
return $this
->_save_file($file, $settings);
}
function _save_file($file, $settings) {
return $file;
}
function load_file($file_id) {
return NULL;
}
function file_exists($file_id) {
$files = $this
->list_files();
return isset($files[$file_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;
}
function _list_files() {
return array();
}
function file_cache_set($files) {
cache_set('backup_migrate_file_list:' . $this
->get_id(), $files, 'cache', time() + $this->cache_expire);
}
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;
}
function file_cache_clear() {
if ($this->cache_files) {
$this
->file_cache_set(NULL);
}
}
function delete_file($file_id) {
$this
->file_cache_clear();
$this
->_delete_file($file_id);
}
function _delete_file($file_id) {
}
function edit_form() {
if (get_class($this) !== 'backup_migrate_destination') {
$form = parent::edit_form();
$form['name'] = array(
"#type" => "textfield",
"#title" => t("Destination name"),
"#default_value" => $this
->get_name(),
"#required" => TRUE,
);
$form['type'] = array(
"#type" => "value",
"#default_value" => $this->destination_type,
);
}
else {
$types = backup_migrate_get_destination_types();
$items = array();
foreach ($types as $key => $type) {
if (@$type['can_create']) {
$type_url_str = str_replace('_', '-', $key);
$out = '<dt>' . l($type['type_name'], BACKUP_MIGRATE_MENU_PATH . "/destination/list/add/{$type_url_str}", array(
'attributes' => array(
'title' => t('Add a new @s destination.', array(
'@s' => $type['type_name'],
)),
),
)) . '</dt>';
$out .= '<dd>' . filter_xss_admin($type['description']) . '</dd>';
$items[] = $out;
}
}
if (count($items)) {
$output = t('Choose the type of destination you would like to create:') . '<dl>' . implode('', $items) . '</dl>';
}
else {
$output = t('No destination types available.');
}
$form['select_type'] = array(
'#type' => 'markup',
'#value' => $output,
);
}
return $form;
}
function delete_confirm_message() {
return t('Are you sure you want to delete the destination %name? Backup files already saved to this destination will not be deleted.', array(
'%name' => $this
->get_name(),
));
}
function get_list_column_info() {
$out = parent::get_list_column_info();
$out = array(
'name' => array(
'title' => t('Name'),
),
'destination_type_name' => array(
'title' => t('Type'),
),
'display_location' => array(
'title' => t('Location'),
),
) + $out;
return $out;
}
function get_list_row() {
$out = parent::get_list_row();
if (empty($out['actions'])) {
return NULL;
}
return $out;
}
function get_action_links() {
$out = parent::get_action_links();
$item_id = $this
->get_id();
if ($this
->op('list files') && user_access("access backup files")) {
$out = array(
'list files' => l(t("list files"), BACKUP_MIGRATE_MENU_PATH . "/{$this->type_name}/list/files/" . $item_id),
) + $out;
}
if (!$this
->op('configure') || !user_access('administer backup and migrate')) {
unset($out['edit']);
}
return $out;
}
function get_file_links($file_id) {
$out = array();
$can_read = $this
->can_read_file($file_id);
$can_delete = $this
->can_delete_file($file_id);
$destination_id = $this
->get_id();
if ($can_read && user_access("access backup files")) {
$out[] = l(t("download"), BACKUP_MIGRATE_MENU_PATH . "/destination/downloadfile/" . $destination_id . '/' . $file_id);
}
if ($can_read && user_access("restore from backup")) {
$out[] = l(t("restore"), BACKUP_MIGRATE_MENU_PATH . "/destination/list/restorefile/" . $destination_id . '/' . $file_id);
}
if ($can_delete && user_access("delete backup files")) {
$out[] = l(t("delete"), BACKUP_MIGRATE_MENU_PATH . "/destination/list/deletefile/" . $destination_id . '/' . $file_id);
}
return $out;
}
function can_read_file($file_id) {
return $this
->op('restore');
}
function can_delete_file($file_id) {
return $this
->op('delete');
}
function settings_default() {
return array();
}
function settings_form($form) {
return $form;
}
function settings_form_validate($form_values) {
}
function settings_form_submit($form_values) {
return $form_values;
}
function create($params = array()) {
$out = NULL;
$types = backup_migrate_get_destination_types();
$destination_type = !empty($params['type']) ? $params['type'] : arg(BACKUP_MIGRATE_MENU_DEPTH + 3);
if ($destination_type && ($type = @$types[$destination_type])) {
if (!empty($type['file'])) {
require_once './' . $type['file'];
}
$out = new $type['class']($params + array(
'destination_type' => $destination_type,
));
}
if (empty($out)) {
$out = new backup_migrate_destination();
}
return $out;
}
function get_menu_items() {
$items = parent::get_menu_items();
$items[BACKUP_MIGRATE_MENU_PATH . '/destination/list/files'] = array(
'title' => 'Destination Files',
'page callback' => 'backup_migrate_menu_callback',
'page arguments' => array(
'destinations',
'backup_migrate_ui_destination_display_files',
TRUE,
),
'access arguments' => array(
'access backup files',
),
'type' => MENU_LOCAL_TASK,
);
$items[BACKUP_MIGRATE_MENU_PATH . '/destination/list/deletefile'] = array(
'title' => 'Delete File',
'description' => 'Delete a backup file',
'page callback' => 'backup_migrate_menu_callback',
'page arguments' => array(
'destinations',
'backup_migrate_ui_destination_delete_file',
TRUE,
),
'access arguments' => array(
'delete backup files',
),
'type' => MENU_LOCAL_TASK,
);
$items['admin/content/backup_migrate/destination/list/restorefile'] = array(
'title' => 'Restore from backup',
'description' => 'Restore database from a backup file on the server',
'page callback' => 'backup_migrate_menu_callback',
'page arguments' => array(
'destinations',
'backup_migrate_ui_destination_restore_file',
TRUE,
),
'access arguments' => array(
'restore from backup',
),
'type' => MENU_LOCAL_TASK,
);
$items[BACKUP_MIGRATE_MENU_PATH . '/destination/downloadfile'] = array(
'title' => 'Download File',
'description' => 'Download a backup file',
'page callback' => 'backup_migrate_menu_callback',
'page arguments' => array(
'destinations',
'backup_migrate_ui_destination_download_file',
TRUE,
),
'access arguments' => array(
'access backup files',
),
'type' => MENU_CALLBACK,
);
return $items;
}
function backup_settings_default() {
return array();
}
function backup_settings_form($settings) {
return array();
}
function backup_settings_form_validate($form, &$form_state) {
}
function backup_settings_form_submit($form, &$form_state) {
}
function restore_settings_default() {
return array();
}
function restore_settings_form($settings) {
return array();
}
function restore_settings_form_validate($form_values) {
}
function restore_settings_form_submit($form_values) {
return $form_values;
}
}
class backup_migrate_destination_remote extends backup_migrate_destination {
function get_location() {
return $this
->url(FALSE);
}
function get_display_location() {
return $this
->url(TRUE);
}
function set_location($location) {
$this->location = $location;
$this
->set_url($location);
}
function url($hide_password = TRUE) {
return $this
->glue_url($this->dest_url, $hide_password);
}
function glue_url($parts, $hide_password = TRUE) {
$parts['pass'] = $hide_password ? "" : $parts['pass'];
$out = "";
$out .= $parts['scheme'] . '://';
$out .= $parts['user'] ? urlencode($parts['user']) : '';
$out .= $parts['user'] && $parts['pass'] ? ":" . urlencode($parts['pass']) : '';
$out .= $parts['user'] || $parts['pass'] ? "@" : "";
$out .= $parts['host'];
$out .= !empty($parts['port']) ? ':' . $parts['port'] : '';
$out .= "/" . $parts['path'];
return $out;
}
function set_url($url) {
$parts = (array) parse_url($url);
$parts['user'] = urldecode(@$parts['user']);
$parts['pass'] = urldecode(@$parts['pass']);
$parts['path'] = urldecode(@$parts['path']);
$parts['path'] = ltrim(@$parts['path'], "/");
$this->dest_url = $parts;
}
function edit_form() {
$form = parent::edit_form();
$form['scheme'] = array(
"#type" => "select",
"#title" => t("Scheme"),
"#default_value" => @$this->dest_url['scheme'] ? $this->dest_url['scheme'] : 'mysql',
"#required" => TRUE,
"#options" => array(
$GLOBALS['db_type'] => $GLOBALS['db_type'],
),
"#weight" => 0,
);
$form['host'] = array(
"#type" => "textfield",
"#title" => t("Host"),
"#default_value" => @$this->dest_url['host'] ? $this->dest_url['host'] : 'localhost',
"#required" => TRUE,
"#weight" => 10,
);
$form['path'] = array(
"#type" => "textfield",
"#title" => t("Path"),
"#default_value" => @$this->dest_url['path'],
"#required" => TRUE,
"#weight" => 20,
);
$form['user'] = array(
"#type" => "textfield",
"#title" => t("Username"),
"#default_value" => @$this->dest_url['user'],
"#required" => TRUE,
"#weight" => 30,
);
$form['pass'] = array(
"#type" => "password",
"#title" => t("Password"),
"#default_value" => @$this->dest_url['pass'],
'#description' => '',
"#weight" => 40,
);
if (@$this->dest_url['pass']) {
$form['old_password'] = array(
"#type" => "value",
"#value" => @$this->dest_url['pass'],
);
$form['pass']["#description"] .= t(' You do not need to enter a password unless you wish to change the currently saved password.');
}
return $form;
}
function edit_form_submit($form, &$form_state) {
$form_state['values']['pass'] = $form_state['values']['pass'] ? $form_state['values']['pass'] : $form_state['values']['old_password'];
$form_state['values']['location'] = $this
->glue_url($form_state['values'], FALSE);
parent::edit_form_submit($form, $form_state);
}
}