security update for contrib modules

This commit is contained in:
2019-04-23 16:27:46 +02:00
parent 3c1b4f164e
commit 868629cbb2
729 changed files with 41254 additions and 20866 deletions
@@ -1,11 +1,10 @@
<?php
/**
* @file
* Drush commands for backup and migrate.
*/
/**
* Implementation of hook_drush_command().
*/
@@ -15,9 +14,9 @@ function backup_migrate_drush_command() {
'description' => dt('Backup the site\'s database with Backup and Migrate.'),
'aliases' => array('bb'),
'examples' => array(
'drush bam-backup' => 'Backup the default databse to the manual backup directory using the default settings.',
'drush bam-backup db scheduled mysettings' => 'Backup the database to the scheduled directory using a settings profile called "mysettings"',
'drush bam-backup files' => 'Backup the files directory to the manual directory using the default settings. The Backup and Migrate Files module is required for files backups.',
'drush bam-backup' => 'Backup the default database to the manual backup directory using the default settings.',
'drush bam-backup db scheduled mysettings' => 'Backup the database to the scheduled directory using a settings profile called "mysettings"',
'drush bam-backup files' => 'Backup the files directory to the manual directory using the default settings.',
),
'arguments' => array(
'source' => "Optional. The id of the source (usually a database) to backup. Use 'drush bam-sources' to get a list of sources. Defaults to 'db'",
@@ -41,7 +40,6 @@ function backup_migrate_drush_command() {
'callback' => 'backup_migrate_drush_destinations',
'description' => dt('Get a list of available destinations.'),
);
$items['bam-sources'] = array(
'callback' => 'backup_migrate_drush_sources',
'description' => dt('Get a list of available sources.'),
@@ -57,6 +55,17 @@ function backup_migrate_drush_command() {
'destination' => "Optional. The id of destination to list backups from. Use 'drush bam-destinations' to get a list of destinations.",
),
);
$items['bam-schedule'] = array(
'callback' => 'backup_migrate_drush_schedule',
'description' => dt('Backup using a specific schedule.'),
'arguments' => array(
'schedule_id' => dt('The ID of the schedule to run.'),
),
);
$items['bam-schedules'] = array(
'callback' => 'backup_migrate_drush_schedules',
'description' => dt('Get a list of available schedules.'),
);
return $items;
}
@@ -67,12 +76,16 @@ function backup_migrate_drush_help($section) {
switch ($section) {
case 'drush:bam-backup':
return dt("Backup the site's database using default settings.");
case 'drush:bam-restore':
return dt('Restore the site\'s database with Backup and Migrate.');
case 'drush:bam-destinations':
return dt('Get a list of available destinations.');
case 'drush:bam-profiles':
return dt('Get a list of available settings profiles.');
case 'drush:bam-backups':
return dt('Get a list of previously created backup files.');
}
@@ -96,7 +109,7 @@ function backup_migrate_drush_backup($source_id = 'db', $destination_id = 'manua
return;
}
$settings = backup_migrate_get_profile($profile_id);
if(!$settings) {
if (!$settings) {
_backup_migrate_message("Could not find the profile '@profile'. Try using 'drush bam-profiles' to get a list of available profiles.", array('@profile' => $profile_id), 'error');
return;
}
@@ -107,11 +120,49 @@ function backup_migrate_drush_backup($source_id = 'db', $destination_id = 'manua
backup_migrate_perform_backup($settings);
}
/**
* Backup using schedule.
*/
function backup_migrate_drush_schedule($schedule_id = '') {
backup_migrate_include('schedules');
// Set the message mode to drush output.
_backup_migrate_message_callback('_backup_migrate_message_drush');
if (!($schedule = backup_migrate_get_schedule($schedule_id))) {
_backup_migrate_message("Could not find the schedule '@schedule'. Try using 'drush bam-schedules' to get a list of available schedules.", array('@schedule' => $schedule_id), 'error');
return;
}
if (!$schedule->enabled) {
_backup_migrate_message("Nothing to do, the schedule '@schedule' is disabled.", array('@schedule' => $schedule_id), 'warning');
return;
}
_backup_migrate_message("Starting schedule '$schedule_id'...");
backup_migrate_schedule_run($schedule_id);
}
/**
* Get a list of available destinations.
*/
function backup_migrate_drush_schedules() {
backup_migrate_include('schedules');
$rows = array(array(dt('ID'), dt('Name')));
foreach (backup_migrate_get_schedules() as $schedule) {
$rows[] = array(
$schedule->get_id(),
$schedule->get_name(),
);
}
drush_print_table($rows, TRUE, array(32, 32));
}
/**
* Restore to the default database.
*/
function backup_migrate_drush_restore($source_id = '', $destination_id = '', $file_id = '') {
backup_migrate_include('profiles', 'destinations', 'sources');
// Set the message mode to drush output.
@@ -125,7 +176,7 @@ function backup_migrate_drush_restore($source_id = '', $destination_id = '', $fi
_backup_migrate_message("Could not find the destination '@destination'. Try using 'drush bam-destinations' to get a list of available destinations.", array('@destination' => $destination_id), 'error');
return;
}
else if (!$file_id || !$file = backup_migrate_destination_get_file($destination_id, $file_id)) {
elseif (!$file_id || !$file = backup_migrate_destination_get_file($destination_id, $file_id)) {
_backup_migrate_message("Could not find the file '@file'. Try using 'drush bam-backups @destination' to get a list of available backup files in this destination destinations.", array('@destination' => $destination_id, '@file' => $file_id), 'error');
return;
}
@@ -136,7 +187,7 @@ function backup_migrate_drush_restore($source_id = '', $destination_id = '', $fi
}
_backup_migrate_message('Starting restore...');
$settings = array('source_id' => $source_id);
backup_migrate_perform_restore($destination_id, $file_id);
backup_migrate_perform_restore($destination_id, $file_id, $settings);
}
/**
@@ -164,7 +215,7 @@ function _backup_migrate_drush_destinations($op = NULL) {
$rows[] = array(
$destination->get_id(),
$destination->get_name(),
implode (', ', $destination->ops()),
implode(', ', $destination->ops()),
);
}
drush_print_table($rows, TRUE, array(32, 32));
@@ -181,7 +232,7 @@ function _backup_migrate_drush_sources($op = NULL) {
$rows[] = array(
$destination->get_id(),
$destination->get_name(),
implode (', ', $destination->ops()),
implode(', ', $destination->ops()),
);
}
drush_print_table($rows, TRUE, array(32, 32));
@@ -203,7 +254,7 @@ function backup_migrate_drush_profiles() {
}
/**
* Get a list of files in a given destination
* Get a list of files in a given destination.
*/
function backup_migrate_drush_destination_files($destination_id = NULL) {
backup_migrate_include('destinations');
@@ -220,7 +271,7 @@ function backup_migrate_drush_destination_files($destination_id = NULL) {
if ($destination) {
$destinations = array($destination);
}
// List all destinations
// List all destinations.
else {
$destinations = backup_migrate_get_destinations('list files');
}
@@ -243,13 +294,15 @@ function backup_migrate_drush_destination_files($destination_id = NULL) {
}
}
$headers = array(array(
dt('Filename'),
dt('Destination'),
dt('Date'),
dt('Age'),
dt('Size'),
));
$headers = array(
array(
dt('Filename'),
dt('Destination'),
dt('Date'),
dt('Age'),
dt('Size'),
),
);
if (count($rows)) {
array_multisort($sort, SORT_DESC, $rows);
@@ -264,8 +317,15 @@ function backup_migrate_drush_destination_files($destination_id = NULL) {
* Send a message to the drush log.
*/
function _backup_migrate_message_drush($message, $replace, $type) {
// Use drush_log to display to the user.
drush_log(strip_tags(dt($message, $replace)), str_replace('status', 'notice', $type));
// If this is an error use drush_set_error to notify the end user and set the
// exit status.
if ($type == 'error') {
drush_set_error(strip_tags(dt($message, $replace)));
}
else {
// Use drush_log to display to the user.
drush_log(strip_tags(dt($message, $replace)), str_replace('status', 'notice', $type));
}
// Watchdog log the message as well for admins.
_backup_migrate_message_log($message, $replace, $type);
}
@@ -56,14 +56,15 @@ function backup_migrate_crud_subtypes($type) {
backup_migrate_include($info['include']);
}
// Allow modules (including this one) to declare backup and migrate subtypes.
// We don't use module_invoke_all so we can avoid the side-effects of array_merge_recursive.
// Allow modules (including this one) to declare backup and migrate
// subtypes. We don't use module_invoke_all so we can avoid the
// side-effects of array_merge_recursive.
$out = array();
foreach (module_implements('backup_migrate_' . $type . '_subtypes') as $module) {
$function = $module . '_backup_migrate_' . $type . '_subtypes';
$function = $module . '_backup_migrate_' . $type . '_subtypes';
$result = $function();
if (isset($result) && is_array($result)) {
foreach ($result as $key => $val) {
foreach ($result as $key => $val) {
$out[$key] = $val;
}
}
@@ -87,7 +88,8 @@ function backup_migrate_crud_subtype_info($type, $subtype) {
/**
* Get a generic object of the given type to be used for static-like functions.
*
* I'm not using actual static method calls since they don't work on variables prior to PHP 5.3.0
* I'm not using actual static method calls since they don't work on variables
* prior to PHP 5.3.0.
*/
function backup_migrate_crud_type_load($type, $subtype = NULL) {
$out = $info = NULL;
@@ -104,7 +106,7 @@ function backup_migrate_crud_type_load($type, $subtype = NULL) {
backup_migrate_include($info['include']);
}
if (!empty($info['file'])) {
include_once './'. (isset($info['path']) ? $info['path'] : '') . $info['file'];
include_once './' . (isset($info['path']) ? $info['path'] : '') . $info['file'];
}
if (class_exists($info['class'])) {
@@ -132,10 +134,10 @@ function backup_migrate_crud_menu() {
$items = array();
foreach (backup_migrate_crud_types() as $type => $info) {
$item = backup_migrate_crud_type_load($type);
$items += (array)$item->get_menu_items();
$items += (array) $item->get_menu_items();
foreach (backup_migrate_crud_subtypes($type) as $subtype => $info) {
$subitem = backup_migrate_crud_type_load($type, $subtype);
$items += (array)$subitem->get_menu_items();
$items += (array) $subitem->get_menu_items();
}
}
return $items;
@@ -166,7 +168,7 @@ function backup_migrate_crud_ui_list($type) {
* Page callback to list all items.
*/
function backup_migrate_crud_ui_list_all() {
$out = '';
$out = array();
foreach (backup_migrate_crud_types() as $type => $info) {
$type = backup_migrate_crud_type_load($type);
$out[] = theme('backup_migrate_group', array('title' => t($type->title_plural), 'body' => $type->get_list()));
@@ -189,7 +191,7 @@ function backup_migrate_crud_ui_edit($type, $item_id = NULL) {
/**
* Does a crud item with the given name exist.
*
*
* Callback for the 'machine_name' form type.
*/
function backup_migrate_crud_item_exists($machine_name, $element, $form_state) {
@@ -232,7 +234,6 @@ function backup_migrate_crud_edit_form_submit($form, &$form_state) {
}
}
/**
* Page callback to delete an item.
*/
@@ -256,10 +257,11 @@ function backup_migrate_crud_delete_confirm_form($form, &$form_state, $item) {
if ($item->storage == BACKUP_MIGRATE_STORAGE_OVERRIDEN) {
$message = $item->revert_confirm_message();
return confirm_form($form, t('Are you sure?'), $item->get_settings_path(), $message, t('Revert'), t('Cancel'));
} else {
}
else {
$message = $item->delete_confirm_message();
return confirm_form($form, t('Are you sure?'), $item->get_settings_path(), $message, t('Delete'), t('Cancel'));
}
}
}
/**
@@ -322,7 +324,7 @@ function backup_migrate_crud_import_form($form, &$form_state) {
}
/**
* Validate handler to import a view
* Validate handler to import a view.
*/
function backup_migrate_crud_import_form_validate($form, &$form_state) {
$item = backup_migrate_crud_create_from_import($form_state['values']['code']);
@@ -330,12 +332,12 @@ function backup_migrate_crud_import_form_validate($form, &$form_state) {
$form_state['values']['item'] = $item;
}
else {
form_set_error('code', t('Unable to import item.'));
form_set_error('code', t('Unable to import item.'));
}
}
/**
* import a item after confirmation.
* Import a item after confirmation.
*/
function backup_migrate_crud_import_form_submit($form, &$form_state) {
$item = $form_state['values']['item'];
@@ -373,7 +375,6 @@ function backup_migrate_crud_get_items($type) {
}
}
/**
* Get an item of the specified type.
*/
@@ -393,24 +394,26 @@ function backup_migrate_crud_create_item($type, $params) {
}
/**
* A base class for items which can be stored in the database, listed, edited, deleted etc.
* A base class for items which can be stored in the database.
*/
class backup_migrate_item {
var $show_in_list = TRUE;
var $settings_path = '/settings/';
var $db_table = '';
var $type_name = '';
var $storage = FALSE;
var $default_values = array();
var $singular = 'item';
var $plural = 'items';
var $title_plural = 'Items';
var $title_singular = 'Item';
public $show_in_list = TRUE;
public $settings_path = '/settings/';
public $db_table = '';
public $type_name = '';
public $storage = FALSE;
public $default_values = array();
public $singular = 'item';
public $plural = 'items';
public $title_plural = 'Items';
public $title_singular = 'Item';
/**
* This function is not supposed to be called. It is just here to help the po extractor out.
* This function is not supposed to be called.
*
* It is just here to help the po extractor out.
*/
function strings() {
public function strings() {
// Help the pot extractor find these strings.
t('item');
t('items');
@@ -425,25 +428,25 @@ class backup_migrate_item {
t('Export !type');
}
/**
* Constructor, set the basic info pulled from the db or generated programatically.
* Set the basic info pulled from the db or generated programatically.
*/
function __construct($params = array()) {
$this->from_array($this->_merge_defaults((array)$params, (array)$this->get_default_values()));
public function __construct($params = array()) {
$this->from_array($this->_merge_defaults((array) $params, (array) $this->get_default_values()));
}
/**
* Merge parameters with the given defaults.
*
* Works like array_merge_recursive, but it doesn't turn scalar values into arrays.
* Works like array_merge_recursive, but it doesn't turn scalar values into
* arrays.
*/
function _merge_defaults($params, $defaults) {
public function _merge_defaults($params, $defaults) {
foreach ($defaults as $key => $val) {
if (!isset($params[$key])) {
$params[$key] = $val;
}
else if (is_array($params[$key])) {
elseif (is_array($params[$key])) {
$params[$key] = $this->_merge_defaults($params[$key], $val);
}
}
@@ -453,14 +456,14 @@ class backup_migrate_item {
/**
* Get the default values for standard parameters.
*/
function get_default_values() {
public function get_default_values() {
return $this->default_values;
}
/**
* Save the item to the database.
*/
function save() {
*/
public function save() {
if (!$this->get_id()) {
$this->unique_id();
}
@@ -470,20 +473,19 @@ class backup_migrate_item {
/**
* Delete the item from the database.
*/
function delete() {
$keys = (array)$this->get_machine_name_field();
*/
public function delete() {
$keys = (array) $this->get_machine_name_field();
db_query('DELETE FROM {' . $this->db_table . '} WHERE ' . $keys[0] . ' = :id', array(':id' => $this->get_id()));
}
/**
* Load an existing item from an array.
*/
function from_array($params) {
public function from_array($params) {
foreach ($params as $key => $value) {
if (method_exists($this, 'set_'. $key)) {
$this->{'set_'. $key}($value);
if (method_exists($this, 'set_' . $key)) {
$this->{'set_' . $key}($value);
}
else {
$this->{$key} = $value;
@@ -494,7 +496,7 @@ class backup_migrate_item {
/**
* Return as an array of values.
*/
function to_array() {
public function to_array() {
$out = array();
// Return fields as specified in the schema.
$schema = $this->get_schema();
@@ -509,7 +511,7 @@ class backup_migrate_item {
/**
* Return as an exported array of values.
*/
function export() {
public function export() {
$out = $this->to_array();
$out['type_name'] = $this->type_name;
@@ -523,7 +525,7 @@ class backup_migrate_item {
/**
* Load an existing item from an database (serialized) array.
*/
function load_row($data) {
public function load_row($data) {
$params = array();
$schema = $this->get_schema();
// Load fields as specified in the schema.
@@ -533,11 +535,10 @@ class backup_migrate_item {
$this->from_array($params);
}
/**
* Decode a loaded db row (unserialize necessary fields).
*/
function decode_db_row($data) {
public function decode_db_row($data) {
$params = array();
$schema = $this->get_schema();
// Load fields as specified in the schema.
@@ -550,7 +551,7 @@ class backup_migrate_item {
/**
* Return the fields which must be serialized before saving to the db.
*/
function get_serialized_fields() {
public function get_serialized_fields() {
$out = array();
$schema = $this->get_schema();
foreach ($schema['fields'] as $field => $info) {
@@ -564,7 +565,7 @@ class backup_migrate_item {
/**
* Get the primary key field title from the schema.
*/
function get_primary_key() {
public function get_primary_key() {
$schema = $this->get_schema();
return @$schema['primary key'];
}
@@ -572,7 +573,7 @@ class backup_migrate_item {
/**
* Get the machine name field name from the schema.
*/
function get_machine_name_field() {
public function get_machine_name_field() {
$schema = $this->get_schema();
if (isset($schema['export']['key'])) {
return $schema['export']['key'];
@@ -583,7 +584,7 @@ class backup_migrate_item {
/**
* Get the schema for the item type.
*/
function get_schema() {
public function get_schema() {
return drupal_get_schema($this->db_table);
}
@@ -592,16 +593,16 @@ class backup_migrate_item {
*
* We only handle single field keys since that's all we need.
*/
function get_id() {
$keys = (array)$this->get_machine_name_field();
return !empty($keys[0]) && !empty($this->{$keys[0]}) ? (string)$this->{$keys[0]} : '';
public function get_id() {
$keys = (array) $this->get_machine_name_field();
return !empty($keys[0]) && !empty($this->{$keys[0]}) ? (string) $this->{$keys[0]} : '';
}
/**
* Set the primary id for this item (if any is set).
*/
function set_id($id) {
$keys = (array)$this->get_machine_name_field();
public function set_id($id) {
$keys = (array) $this->get_machine_name_field();
if (!empty($keys[0])) {
return $this->{$keys[0]} = $id;
}
@@ -611,8 +612,8 @@ class backup_migrate_item {
/**
* Return a random (very very likely unique) string id for a new item.
*/
function generate_id() {
$id = md5(uniqid(mt_rand(), true));
public function generate_id() {
$id = md5(uniqid(mt_rand(), TRUE));
// Find the shortest possible unique id from (min 4 chars).
for ($i = 4; $i < 32; $i++) {
@@ -621,23 +622,27 @@ class backup_migrate_item {
return $new_id;
}
}
// If we get here, then all 28 increasingly complex ids were already taken so we'll try again.
// this could theoretially lead to an infinite loop, but the odds are incredibly low.
// If we get here, then all 28 increasingly complex ids were already taken
// so we'll try again; this could theoretially lead to an infinite loop,
// but the odds are incredibly low.
return $this->generate_id();
}
/**
* Make sure this item has a unique id. Should only be called for new items or the item will collide with itself.
* Make sure this item has a unique id.
*
* Should only be called for new items or the item will collide with itself.
*/
function unique_id() {
public function unique_id() {
$id = $this->get_id();
// Unset the autoincrement field so it can be regenerated.
foreach ((array)$this->get_primary_key() as $key) {
$this->{$key} = NULL;
foreach ((array) $this->get_primary_key() as $key) {
$this->{$key} = NULL;
}
// If the item doesn't have an ID or if it's id is already taken, generate random one.
// If the item doesn't have an ID or if it's id is already taken, generate
// random one.
if (!$id || $this->item($id)) {
$this->set_id($this->generate_id());
}
@@ -646,26 +651,24 @@ class backup_migrate_item {
/**
* Get the name of the item.
*/
function get_name() {
public function get_name() {
return @$this->name;
}
/**
* Get the member with the given key.
*/
function get($key) {
if (method_exists($this, 'get_'. $key)) {
return $this->{'get_'. $key}();
*/
public function get($key) {
if (method_exists($this, 'get_' . $key)) {
return $this->{'get_' . $key}();
}
return @$this->{$key};
}
/* UI Stuff */
/**
* Get the action links for a destination.
*/
function get_action_links() {
public function get_action_links() {
$out = array();
$item_id = $this->get_id();
@@ -675,13 +678,13 @@ class backup_migrate_item {
if (@$this->storage == BACKUP_MIGRATE_STORAGE_DB || @$this->storage == BACKUP_MIGRATE_STORAGE_OVERRIDEN) {
$out['edit'] = l(t("edit"), $path . "/edit/$item_id");
}
else if (@$this->storage == BACKUP_MIGRATE_STORAGE_NONE) {
elseif (@$this->storage == BACKUP_MIGRATE_STORAGE_NONE) {
$out['edit'] = l(t("override"), $path . "/edit/$item_id");
}
if (@$this->storage == BACKUP_MIGRATE_STORAGE_DB) {
$out['delete'] = l(t("delete"), $path . "/delete/$item_id");
}
else if (@$this->storage == BACKUP_MIGRATE_STORAGE_OVERRIDEN) {
elseif (@$this->storage == BACKUP_MIGRATE_STORAGE_OVERRIDEN) {
$out['delete'] = l(t("revert"), $path . "/delete/$item_id");
}
$out['export'] = l(t("export"), $path . "/export/$item_id");
@@ -691,11 +694,11 @@ class backup_migrate_item {
/**
* Get a table of all items of this type.
*/
function get_list() {
*/
public function get_list() {
$items = $this->all_items();
$rows = array();
foreach ((array)$items as $item) {
foreach ((array) $items as $item) {
if ($item->show_in_list()) {
if ($row = $item->get_list_row()) {
$rows[] = $row;
@@ -709,30 +712,29 @@ class backup_migrate_item {
$out = t('There are no !items to display.', array('!items' => $this->plural));
}
if (user_access('administer backup and migrate')) {
$out .= ' '. l(t('Create a new !item', array('!item' => $this->singular)), $this->get_settings_path() .'/add');
$out .= ' ' . l(t('Create a new !item', array('!item' => $this->singular)), $this->get_settings_path() . '/add');
}
return $out;
}
/**
* Get the columns needed to list the type.
*/
function show_in_list() {
*/
public function show_in_list() {
return $this->show_in_list;
}
/**
* Get the columns needed to list the type.
*/
function get_settings_path() {
*/
public function get_settings_path() {
return BACKUP_MIGRATE_MENU_PATH . $this->settings_path . $this->type_name;
}
/**
* Get the columns needed to list the type.
*/
function get_list_column_info() {
*/
public function get_list_column_info() {
return array(
'actions' => array('title' => t('Operations'), 'html' => TRUE),
);
@@ -740,8 +742,8 @@ class backup_migrate_item {
/**
* Get header for a lost of this type.
*/
function get_list_header() {
*/
public function get_list_header() {
$out = array();
foreach ($this->get_list_column_info() as $key => $col) {
$out[] = $col['title'];
@@ -751,8 +753,8 @@ class backup_migrate_item {
/**
* Get a row of data to be used in a list of items of this type.
*/
function get_list_row() {
*/
public function get_list_row() {
$out = array();
foreach ($this->get_list_column_info() as $key => $col) {
$out[$key] = empty($col['html']) ? check_plain($this->get($key)) : $this->get($key);
@@ -766,7 +768,7 @@ class backup_migrate_item {
/**
* Get the rendered action links for a destination.
*/
function get_actions() {
public function get_actions() {
$links = $this->get_action_links();
return implode(" &nbsp; ", $links);
}
@@ -774,7 +776,7 @@ class backup_migrate_item {
/**
* Get the edit form for the item.
*/
function edit_form() {
public function edit_form() {
$form = array();
$form['item'] = array(
'#type' => 'value',
@@ -811,37 +813,36 @@ class backup_migrate_item {
/**
* Validate the edit form for the item.
*/
function edit_form_validate($form, &$form_state) {
public function edit_form_validate($form, &$form_state) {
}
/**
* Submit the edit form for the item.
*/
function edit_form_submit($form, &$form_state) {
public function edit_form_submit($form, &$form_state) {
$this->from_array($form_state['values']);
$this->save();
_backup_migrate_message('Your !type was saved', array('!type' => t($this->singular)));
}
/**
* Get the message to send to the user when confirming the deletion of the item.
* The message to send to the user when confirming the deletion of the item.
*/
function delete_confirm_message() {
public function delete_confirm_message() {
return t('Are you sure you want to delete the !type %name?', array('!type' => t($this->singular), '%name' => $this->get('name')));
}
/**
* Get the message to send to the user when confirming the deletion of the item.
* The message to send to the user when confirming the deletion of the item.
*/
function revert_confirm_message() {
public function revert_confirm_message() {
return t('Are you sure you want to revert the !type %name back to the default settings?', array('!type' => t($this->singular), '%name' => $this->get('name')));
}
/* Static Functions */
/**
* Get the menu items for manipulating this type.
*/
function get_menu_items() {
public function get_menu_items() {
$path = $this->get_settings_path();
$type = $this->type_name;
@@ -853,13 +854,13 @@ class backup_migrate_item {
'weight' => 2,
'type' => MENU_LOCAL_TASK,
);
$items[$path .'/list'] = array(
$items[$path . '/list'] = array(
'title' => 'List !type',
'title arguments' => array('!type' => t($this->title_plural)),
'weight' => 1,
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items[$path .'/add'] = array(
$items[$path . '/add'] = array(
'title' => 'Add !type',
'title arguments' => array('!type' => t($this->title_singular)),
'page callback' => 'backup_migrate_menu_callback',
@@ -868,7 +869,7 @@ class backup_migrate_item {
'weight' => 2,
'type' => MENU_LOCAL_ACTION,
);
$items[$path .'/delete'] = array(
$items[$path . '/delete'] = array(
'title' => 'Delete !type',
'title arguments' => array('!type' => t($this->title_singular)),
'page callback' => 'backup_migrate_menu_callback',
@@ -876,7 +877,7 @@ class backup_migrate_item {
'access arguments' => array('administer backup and migrate'),
'type' => MENU_CALLBACK,
);
$items[$path .'/edit'] = array(
$items[$path . '/edit'] = array(
'title' => 'Edit !type',
'title arguments' => array('!type' => t($this->title_singular)),
'page callback' => 'backup_migrate_menu_callback',
@@ -884,7 +885,7 @@ class backup_migrate_item {
'access arguments' => array('administer backup and migrate'),
'type' => MENU_CALLBACK,
);
$items[$path .'/export'] = array(
$items[$path . '/export'] = array(
'title' => 'Export !type',
'title arguments' => array('!type' => t($this->title_singular)),
'page callback' => 'backup_migrate_menu_callback',
@@ -895,11 +896,13 @@ class backup_migrate_item {
return $items;
}
/**
* Create a new items with the given input. Doesn't load the parameters, but could use them to determine what type to create.
* Create a new items with the given input.
*
* Doesn't load the parameters, but could use them to determine what type to
* create.
*/
function create($params = array()) {
public function create($params = array()) {
$type = get_class($this);
return new $type($params);
}
@@ -907,12 +910,12 @@ class backup_migrate_item {
/**
* Get all of the given items.
*/
function all_items() {
static $cache = array();
public function all_items() {
$items = array();
// Get any items stored as a variable. This allows destinations to be defined in settings.php
$defaults = (array)variable_get($this->db_table . '_defaults', array());
// Get any items stored as a variable. This allows destinations to be
// defined in settings.php
$defaults = (array) variable_get($this->db_table . '_defaults', array());
foreach ($defaults as $info) {
if (is_array($info) && $item = $this->create($info)) {
$items[$item->get_id()] = $item;
@@ -932,27 +935,16 @@ class backup_migrate_item {
// Allow other modules to declare destinations programatically.
$default_items = module_invoke_all($this->db_table);
// Get CTools exported versions.
if (function_exists('ctools_include')) {
ctools_include('export');
$defaults = ctools_export_load_object($this->db_table);
foreach ($defaults as $info) {
$info = (array)$info;
if (!empty($info) && $item = $this->create($info)) {
$default_items[$item->get_id()] = $item;
}
}
}
// Get any items stored as a variable again to correctly mark overrides.
$defaults = (array)variable_get($this->db_table . '_defaults', array());
$defaults = (array) variable_get($this->db_table . '_defaults', array());
foreach ($defaults as $info) {
if (is_array($info) && $item = $this->create($info)) {
$default_items[] = $item;
}
}
// Add the default items to the array or set the storage flag if they've already been overridden.
// Add the default items to the array or set the storage flag if they've
// already been overridden.
foreach ($default_items as $item) {
if (isset($items[$item->get_id()])) {
$items[$item->get_id()]->storage = BACKUP_MIGRATE_STORAGE_OVERRIDEN;
@@ -963,9 +955,10 @@ class backup_migrate_item {
}
}
// Allow other modules to alter the items. This should maybe be before the db override code above
// but then the filters are not able to set defaults for missing values. Other modules should just
// be careful not to overwrite the user's UI changes in an unexpected way.
// Allow other modules to alter the items. This should maybe be before the
// db override code above but then the filters are not able to set defaults
// for missing values. Other modules should just be careful not to
// overwrite the user's UI changes in an unexpected way.
drupal_alter($this->db_table, $items);
return $items;
@@ -974,7 +967,7 @@ class backup_migrate_item {
/**
* A particular item.
*/
function item($item_id) {
public function item($item_id) {
$items = $this->all_items();
return !empty($items[$item_id]) ? $items[$item_id] : NULL;
}
@@ -982,8 +975,9 @@ class backup_migrate_item {
/**
* A particular item.
*/
function item_exists($item_id) {
public function item_exists($item_id) {
$items = $this->all_items();
return !empty($items[$item_id]);
}
}
@@ -1,6 +1,5 @@
<?php
/**
* @file
* Functions to handle the browser upload/download backup destination.
@@ -12,13 +11,15 @@
* @ingroup backup_migrate_destinations
*/
class backup_migrate_destination_browser extends backup_migrate_destination {
/**
* Get a row of data to be used in a list of items of this type.
*/
function get_list_row() {
*/
public function get_list_row() {
// Return none as this type should not be displayed.
return array();
}
}
/**
@@ -27,8 +28,16 @@ class backup_migrate_destination_browser extends backup_migrate_destination {
* @ingroup backup_migrate_destinations
*/
class backup_migrate_destination_browser_upload extends backup_migrate_destination_browser {
var $supported_ops = array('restore');
function __construct() {
/**
* {@inheritdoc}
*/
public $supported_ops = array('restore');
/**
* Constructor.
*/
public function __construct() {
$params = array();
$params['name'] = "Upload";
$params['machine_name'] = 'upload';
@@ -38,7 +47,7 @@ class backup_migrate_destination_browser_upload extends backup_migrate_destinati
/**
* File load destination callback.
*/
function load_file($file_id) {
public function load_file($file_id) {
if ($file = file_save_upload('backup_migrate_restore_upload')) {
$out = new backup_file(array('filepath' => $file->uri));
backup_migrate_temp_files_add($file->uri);
@@ -46,6 +55,7 @@ class backup_migrate_destination_browser_upload extends backup_migrate_destinati
}
return NULL;
}
}
/**
@@ -54,11 +64,22 @@ class backup_migrate_destination_browser_upload extends backup_migrate_destinati
* @ingroup backup_migrate_destinations
*/
class backup_migrate_destination_browser_download extends backup_migrate_destination_browser {
var $supported_ops = array('manual backup');
// Browser downloads must always be the last destination as they must end the current process when they are done.
var $weight = 1000;
function __construct() {
/**
* {@inheritdoc}
*/
public $supported_ops = array('manual backup');
/**
* Browser downloads must always be the last destination as they must end the
* current process when they are done.
*/
public $weight = 1000;
/**
* Constructor.
*/
public function __construct() {
$params = array();
$params['name'] = "Download";
$params['machine_name'] = 'download';
@@ -68,9 +89,9 @@ class backup_migrate_destination_browser_download extends backup_migrate_destina
/**
* File save destination callback.
*/
function save_file($file, $settings) {
public function save_file($file, $settings) {
backup_migrate_include('files');
$file->transfer();
}
}
}
@@ -1,6 +1,5 @@
<?php
/**
* @file
* Functions to handle the direct to database destination.
@@ -12,22 +11,22 @@
* @ingroup backup_migrate_destinations
*/
class backup_migrate_destination_db extends backup_migrate_destination_remote {
var $supported_ops = array('scheduled backup', 'manual backup', 'configure', 'source');
var $db_target = 'default';
var $connection = null;
public $supported_ops = array('scheduled backup', 'manual backup', 'configure', 'source');
public $db_target = 'default';
public $connection = NULL;
function type_name() {
public function type_name() {
return t("Database");
}
/**
* Save the info by importing it into the database.
*/
function save_file($file, $settings) {
public function save_file($file, $settings) {
backup_migrate_include('files');
// Set the source_id to the destination_id in the settings since for a restore, the source_id is the
// Set the source_id to the destination_id in the settings since for a restore, the source_id is the
// database that gets restored to.
$settings->set_source($this->get_id());
@@ -40,10 +39,10 @@ class backup_migrate_destination_db extends backup_migrate_destination_remote {
/**
* Destination configuration callback.
*/
function edit_form() {
public function edit_form() {
$form = parent::edit_form();
$form['scheme']['#title'] = t('Database type');
// $form['scheme']['#options'] = array($GLOBALS['db_type'] => $GLOBALS['db_type']);
// $form['scheme']['#options'] = array($GLOBALS['db_type'] => $GLOBALS['db_type']);
$form['scheme']['#description'] = t('The type of the database. Drupal only supports one database type at a time, so this must be the same as the current database type.');
$form['path']['#title'] = t('Database name');
$form['path']['#description'] = t('The name of the database. The database must exist, it will not be created for you.');
@@ -54,7 +53,7 @@ class backup_migrate_destination_db extends backup_migrate_destination_remote {
/**
* Validate the configuration form. Make sure the db info is valid.
*/
function edit_form_validate($form, &$form_state) {
public function edit_form_validate($form, &$form_state) {
if (!preg_match('/[a-zA-Z0-9_\$]+/', $form_state['values']['path'])) {
form_set_error('path', t('The database name is not valid.'));
}
@@ -62,56 +61,63 @@ class backup_migrate_destination_db extends backup_migrate_destination_remote {
}
/**
* Get the form for the settings for this destination.
* Get the default settings for this object.
*
* Return the default tables whose data can be ignored. These tables mostly contain
* info which can be easily reproducted (such as cache or search index)
* but also tables which can become quite bloated but are not necessarily extremely
* important to back up or migrate during development (such ass access log and watchdog)
* @return array
* The default tables whose data can be ignored. These tables mostly
* contain info which can be easily reproducted (such as cache or search
* index) but also tables which can become quite bloated but are not
* necessarily extremely important to back up or migrate during development
* (such as access log and watchdog).
*/
function backup_settings_default() {
$core = array(
'cache',
'cache_admin_menu',
'cache_browscap',
'cache_content',
'cache_filter',
'cache_calendar_ical',
'cache_location',
'cache_menu',
'cache_page',
'cache_reptag',
'cache_views',
'cache_views_data',
'cache_block',
'cache_update',
'cache_form',
'cache_bootstrap',
'cache_field',
'cache_image',
'cache_path',
'sessions',
'search_dataset',
'search_index',
'search_keywords_log',
'search_total',
'watchdog',
'accesslog',
'devel_queries',
'devel_times',
);
$nodata_tables = array_merge($core, module_invoke_all('devel_caches'));
return array(
'nodata_tables' => $nodata_tables,
'exclude_tables' => array(),
public function backup_settings_default() {
$all_tables = $this->_get_table_names();
// Basic modules that should be excluded.
$basic = array(
// Default core tables.
'accesslog',
'sessions',
'watchdog',
// Search module.
'search_dataset',
'search_index',
'search_keywords_log',
'search_total',
// Devel module.
'devel_queries',
'devel_times',
);
// Identify all cache tables.
$cache = array('cache');
foreach ($all_tables as $table_name) {
if (strpos($table_name, 'cache_') === 0) {
$cache[] = $table_name;
}
}
// Simpletest can create a lot of tables that do not need to be backed up,
// but all of them start with the string 'simpletest' so they can be easily
// excluded.
$simpletest = array();
foreach ($all_tables as $table_name) {
if (strpos($table_name, 'simpletest') === 0) {
$simpletest[] = $table_name;
}
}
return array(
'nodata_tables' => array_merge($basic, $cache, module_invoke_all('devel_caches')),
'exclude_tables' => $simpletest,
'utils_lock_tables' => FALSE,
);
);
}
/**
* Get the form for the backup settings for this destination.
*/
function backup_settings_form($settings) {
public function backup_settings_form($settings) {
$objects = $this->get_object_names();
$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(
@@ -143,16 +149,15 @@ class backup_migrate_destination_db extends backup_migrate_destination_remote {
/**
* Backup from this source.
*/
function backup_to_file($file, $settings) {
public function backup_to_file($file, $settings) {
$file->push_type($this->get_file_type_id());
backup_migrate_filters_invoke_all('pre_backup', $this, $file, $settings);
//$this->lock_tables($settings);
// $this->lock_tables($settings);
// Switch to a different db if specified.
$success = $this->_backup_db_to_file($file, $settings);
//$this->unlock_tables($settings);
// $this->unlock_tables($settings);
backup_migrate_filters_invoke_all('post_backup', $this, $file, $settings, $success);
return $success ? $file : FALSE;
@@ -161,7 +166,7 @@ class backup_migrate_destination_db extends backup_migrate_destination_remote {
/**
* Restore to this source.
*/
function restore_from_file($file, &$settings) {
public function restore_from_file($file, &$settings) {
$num = 0;
$type = $this->get_file_type_id();
// Open the file using the file wrapper. Check that the dump is of the right type (allow .sql for legacy reasons).
@@ -183,7 +188,7 @@ class backup_migrate_destination_db extends backup_migrate_destination_remote {
/**
* Get the db connection for the specified db.
*/
function _get_db_connection() {
public function _get_db_connection() {
if (!$this->connection) {
$target = $key = '';
$parts = explode(':', $this->get_id());
@@ -197,12 +202,12 @@ class backup_migrate_destination_db extends backup_migrate_destination_remote {
// If the url is specified build it into a connection info array.
if (!empty($this->dest_url)) {
$info = array(
'driver' => empty($this->dest_url['scheme']) ? NULL : $this->dest_url['scheme'],
'host' => empty($this->dest_url['host']) ? NULL : $this->dest_url['host'],
'port' => empty($this->dest_url['port']) ? NULL : $this->dest_url['port'],
'username' => empty($this->dest_url['user']) ? NULL : $this->dest_url['user'],
'password' => empty($this->dest_url['pass']) ? NULL : $this->dest_url['pass'],
'database' => empty($this->dest_url['path']) ? NULL : $this->dest_url['path'],
'driver' => empty($this->dest_url['scheme']) ? NULL : $this->dest_url['scheme'],
'host' => empty($this->dest_url['host']) ? NULL : $this->dest_url['host'],
'port' => empty($this->dest_url['port']) ? NULL : $this->dest_url['port'],
'username' => empty($this->dest_url['user']) ? NULL : $this->dest_url['user'],
'password' => empty($this->dest_url['pass']) ? NULL : $this->dest_url['pass'],
'database' => empty($this->dest_url['path']) ? NULL : $this->dest_url['path'],
);
$key = uniqid('backup_migrate_tmp_');
$target = 'default';
@@ -223,21 +228,21 @@ class backup_migrate_destination_db extends backup_migrate_destination_remote {
/**
* Backup the databases to a file.
*/
function _backup_db_to_file($file, $settings) {
public function _backup_db_to_file($file, $settings) {
// Must be overridden.
}
/**
* Backup the databases to a file.
*/
function _restore_db_from_file($file, $settings) {
public function _restore_db_from_file($file, $settings) {
// Must be overridden.
}
/**
* Get a list of objects in the database.
*/
function get_object_names() {
public function get_object_names() {
// Must be overridden.
$out = $this->_get_table_names();
if (method_exists($this, '_get_view_names')) {
@@ -249,7 +254,7 @@ class backup_migrate_destination_db extends backup_migrate_destination_remote {
/**
* Get a list of tables in the database.
*/
function get_table_names() {
public function get_table_names() {
// Must be overridden.
$out = $this->_get_table_names();
return $out;
@@ -258,7 +263,7 @@ class backup_migrate_destination_db extends backup_migrate_destination_remote {
/**
* Get a list of tables in the database.
*/
function _get_table_names() {
public function _get_table_names() {
// Must be overridden.
return array();
}
@@ -266,12 +271,12 @@ class backup_migrate_destination_db extends backup_migrate_destination_remote {
/**
* Lock the database in anticipation of a backup.
*/
function lock_tables($settings) {
public function lock_tables($settings) {
if ($settings->filters['utils_lock_tables']) {
$tables = array();
foreach ($this->get_table_names() as $table) {
// There's no need to lock excluded or structure only tables because it doesn't matter if they change.
if (empty($settings->filters['exclude_tables']) || !in_array($table, (array)$settings->filters['exclude_tables'])) {
if (empty($settings->filters['exclude_tables']) || !in_array($table, (array) $settings->filters['exclude_tables'])) {
$tables[] = $table;
}
}
@@ -282,14 +287,14 @@ class backup_migrate_destination_db extends backup_migrate_destination_remote {
/**
* Lock the list of given tables in the database.
*/
function _lock_tables($tables) {
public function _lock_tables($tables) {
// Must be overridden.
}
/**
* Unlock any tables that have been locked.
*/
function unlock_tables($settings) {
public function unlock_tables($settings) {
if ($settings->filters['utils_lock_tables']) {
$this->_unlock_tables();
}
@@ -298,14 +303,15 @@ class backup_migrate_destination_db extends backup_migrate_destination_remote {
/**
* Unlock the list of given tables in the database.
*/
function _unlock_tables($tables) {
public function _unlock_tables($tables) {
// Must be overridden.
}
/**
* Get the file type for to backup this destination to.
*/
function get_file_type_id() {
public function get_file_type_id() {
return 'sql';
}
}
@@ -1,5 +1,9 @@
<?php
/**
* @file
*/
backup_migrate_include('destinations.db');
/**
@@ -12,16 +16,15 @@ backup_migrate_include('destinations.db');
*
* @ingroup backup_migrate_destinations
*/
class backup_migrate_destination_db_mysql extends backup_migrate_destination_db {
function type_name() {
public function type_name() {
return t("MySQL Database");
}
/**
* Return a list of backup filetypes.
*/
function file_types() {
public function file_types() {
return array(
"sql" => array(
"extension" => "sql",
@@ -41,17 +44,27 @@ class backup_migrate_destination_db_mysql extends backup_migrate_destination_db
/**
* Declare any mysql databases defined in the settings.php file as a possible destination.
*/
function destinations() {
public function destinations() {
$out = array();
global $databases;
foreach ((array)$databases as $db_key => $target) {
foreach ((array)$target as $tgt_key => $info) {
foreach ((array) $databases as $db_key => $target) {
foreach ((array) $target as $tgt_key => $info) {
// Only mysql/mysqli supported by this destination.
$key = $db_key . ':' . $tgt_key;
if ($info['driver'] === 'mysql') {
$url = $info['driver'] . '://' . $info['username'] . ':' . $info['password'] . '@' . $info['host'] . (isset($info['port']) ? ':' . $info['port'] : '') . '/' . $info['database'];
// Compile the database connection string.
$url = 'mysql://';
$url .= urlencode($info['username']) . ':' . urlencode($info['password']);
$url .= '@';
$url .= urlencode($info['host']);
if (!empty($info['port'])) {
$url .= ':' . $info['port'];
}
$url .= '/' . urlencode($info['database']);
if ($destination = backup_migrate_create_destination('mysql', array('url' => $url))) {
// Treat the default database differently because it is probably the only one available.
// Treat the default database differently because it is probably
// the only one available.
if ($key == 'default:default') {
$destination->set_id('db');
$destination->set_name(t('Default Database'));
@@ -60,8 +73,8 @@ class backup_migrate_destination_db_mysql extends backup_migrate_destination_db
$destination->remove_op('manual backup');
}
else {
$destination->set_id('db:'. $key);
$destination->set_name($key .": ". $destination->get_display_location());
$destination->set_id('db:' . $key);
$destination->set_name($key . ": " . $destination->get_display_location());
}
$out[$destination->get_id()] = $destination;
}
@@ -74,14 +87,14 @@ class backup_migrate_destination_db_mysql extends backup_migrate_destination_db
/**
* Get the file type for to backup this destination to.
*/
function get_file_type_id() {
public function get_file_type_id() {
return 'mysql';
}
/**
* Get the form for the backup settings for this destination.
*/
function backup_settings_form($settings) {
public function backup_settings_form($settings) {
$form = parent::backup_settings_form($settings);
$form['use_mysqldump'] = array(
@@ -94,15 +107,14 @@ class backup_migrate_destination_db_mysql extends backup_migrate_destination_db
return $form;
}
/**
* Backup the databases to a file.
*
* Returns a list of sql commands, one command per line.
* That makes it easier to import without loading the whole file into memory.
* The files are a little harder to read, but human-readability is not a priority
* The files are a little harder to read, but human-readability is not a priority.
*/
function _backup_db_to_file($file, $settings) {
public function _backup_db_to_file($file, $settings) {
if (!empty($settings->filters['use_mysqldump']) && $this->_backup_db_to_file_mysqldump($file, $settings)) {
return TRUE;
}
@@ -145,16 +157,14 @@ class backup_migrate_destination_db_mysql extends backup_migrate_destination_db
}
}
/**
* Backup the databases to a file using the mysqldump command.
*/
function _backup_db_to_file_mysqldump($file, $settings) {
public function _backup_db_to_file_mysqldump($file, $settings) {
$success = FALSE;
$nodata_tables = array();
$alltables = $this->_get_tables();
$command = 'mysqldump --result-file=%file --opt -Q --host=%host --port=%port --user=%user --password=%pass %db';
$args = array(
'%file' => $file->filepath(),
@@ -168,17 +178,17 @@ class backup_migrate_destination_db_mysql extends backup_migrate_destination_db
// Ignore the excluded and no-data tables.
$db = $this->dest_url['path'];
if (!empty($settings->filters['exclude_tables'])) {
foreach ((array)$settings->filters['exclude_tables'] as $table) {
foreach ((array) $settings->filters['exclude_tables'] as $table) {
if (isset($alltables[$table])) {
$command .= ' --ignore-table='. $db .'.'. $table;
$command .= ' --ignore-table=' . $db . '.' . $table;
}
}
}
if (!empty($settings->filters['nodata_tables'])) {
foreach ((array)$settings->filters['nodata_tables'] as $table) {
foreach ((array) $settings->filters['nodata_tables'] as $table) {
if (isset($alltables[$table])) {
$nodata_tables[] = $table;
$command .= ' --ignore-table='. $db .'.'. $table;
$command .= ' --ignore-table=' . $db . '.' . $table;
}
}
}
@@ -196,10 +206,19 @@ class backup_migrate_destination_db_mysql extends backup_migrate_destination_db
/**
* Backup the databases to a file.
*/
function _restore_db_from_file($file, $settings) {
public function _restore_db_from_file($file, $settings) {
$num = 0;
if ($file->open() && $conn = $this->_get_db_connection()) {
// Optionally drop all existing tables.
if (!empty($settings->filters['utils_drop_all_tables'])) {
$all_tables = $this->_get_tables();
$table_names = array_map('backup_migrate_array_name_value', $all_tables);
$table_list = join(', ', $table_names);
$stmt = $conn->prepare("DROP TABLE IF EXISTS $table_list;\n");
$stmt->execute();
}
// Read one line at a time and run the query.
while ($line = $this->_read_sql_command_from_file($file)) {
if (_backup_migrate_check_timeout()) {
@@ -222,17 +241,16 @@ class backup_migrate_destination_db_mysql extends backup_migrate_destination_db
return $num;
}
/**
* Read a multiline sql command from a file.
*
* Supports the formatting created by mysqldump, but won't handle multiline comments.
*/
function _read_sql_command_from_file($file) {
public function _read_sql_command_from_file($file) {
$out = '';
while ($line = $file->read()) {
$first2 = substr($line, 0, 2);
$first3 = substr($line, 0, 2);
$first3 = substr($line, 0, 3);
// Ignore single line comments. This function doesn't support multiline comments or inline comments.
if ($first2 != '--' && ($first2 != '/*' || $first3 == '/*!')) {
@@ -249,7 +267,7 @@ class backup_migrate_destination_db_mysql extends backup_migrate_destination_db
/**
* Get a list of tables in the database.
*/
function _get_table_names() {
public function _get_table_names() {
$out = array();
foreach ($this->_get_tables() as $table) {
$out[$table['name']] = $table['name'];
@@ -260,7 +278,7 @@ class backup_migrate_destination_db_mysql extends backup_migrate_destination_db
/**
* Get a list of views in the database.
*/
function _get_view_names() {
public function _get_view_names() {
$out = array();
foreach ($this->_get_views() as $view) {
$out[$view['name']] = $view['name'];
@@ -271,29 +289,29 @@ class backup_migrate_destination_db_mysql extends backup_migrate_destination_db
/**
* Lock the list of given tables in the database.
*/
function _lock_tables($tables) {
public function _lock_tables($tables) {
if ($tables) {
$tables_escaped = array();
foreach ($tables as $table) {
$tables_escaped[] = '`'. db_escape_table($table) .'` WRITE';
$tables_escaped[] = '`' . db_escape_table($table) . '` WRITE';
}
$this->query('LOCK TABLES '. implode(', ', $tables_escaped));
$this->query('LOCK TABLES ' . implode(', ', $tables_escaped));
}
}
/**
* Unlock all tables in the database.
*/
function _unlock_tables($settings) {
public function _unlock_tables($settings) {
$this->query('UNLOCK TABLES');
}
/**
* Get a list of tables in the db.
*/
function _get_tables() {
public function _get_tables() {
$out = array();
// get auto_increment values and names of all tables
// get auto_increment values and names of all tables.
$tables = $this->query("show table status", array(), array('fetch' => PDO::FETCH_ASSOC));
foreach ($tables as $table) {
// Lowercase the keys because between Drupal 7.12 and 7.13/14 the default query behavior was changed.
@@ -309,9 +327,9 @@ class backup_migrate_destination_db_mysql extends backup_migrate_destination_db
/**
* Get a list of views in the db.
*/
function _get_views() {
public function _get_views() {
$out = array();
// get auto_increment values and names of all tables
// get auto_increment values and names of all tables.
$tables = $this->query("show table status", array(), array('fetch' => PDO::FETCH_ASSOC));
foreach ($tables as $table) {
// Lowercase the keys because between Drupal 7.12 and 7.13/14 the default query behavior was changed.
@@ -327,36 +345,36 @@ class backup_migrate_destination_db_mysql extends backup_migrate_destination_db
/**
* Get the sql for the structure of the given table.
*/
function _get_table_structure_sql($table) {
public function _get_table_structure_sql($table) {
$out = "";
$result = $this->query("SHOW CREATE TABLE `". $table['name'] ."`", array(), array('fetch' => PDO::FETCH_ASSOC));
$result = $this->query("SHOW CREATE TABLE `" . $table['name'] . "`", array(), array('fetch' => PDO::FETCH_ASSOC));
foreach ($result as $create) {
// Lowercase the keys because between Drupal 7.12 and 7.13/14 the default query behavior was changed.
// See: http://drupal.org/node/1171866
$create = array_change_key_case($create);
$out .= "DROP TABLE IF EXISTS `". $table['name'] ."`;\n";
$out .= "DROP TABLE IF EXISTS `" . $table['name'] . "`;\n";
// Remove newlines and convert " to ` because PDO seems to convert those for some reason.
$out .= strtr($create['create table'], array("\n" => ' ', '"' => '`'));
if ($table['auto_increment']) {
$out .= " AUTO_INCREMENT=". $table['auto_increment'];
$out .= " AUTO_INCREMENT=" . $table['auto_increment'];
}
$out .= ";\n";
}
return $out;
}
/**
* Get the sql for the structure of the given table.
*/
function _get_view_create_sql($view) {
public function _get_view_create_sql($view) {
$out = "";
// Switch SQL mode to get rid of "CREATE ALGORITHM..." what requires more permissions + troubles with the DEFINER user
// Switch SQL mode to get rid of "CREATE ALGORITHM..." what requires more permissions + troubles with the DEFINER user.
$sql_mode = $this->query("SELECT @@SESSION.sql_mode")->fetchField();
$this->query("SET sql_mode = 'ANSI'");
$result = $this->query("SHOW CREATE VIEW `" . $view['name'] . "`", array(), array('fetch' => PDO::FETCH_ASSOC));
$this->query("SET SQL_mode = :mode", array(':mode' => $sql_mode));
foreach ($result as $create) {
$out .= "DROP VIEW IF EXISTS `". $view['name'] ."`;\n";
$out .= "DROP VIEW IF EXISTS `" . $view['name'] . "`;\n";
$out .= "SET sql_mode = 'ANSI';\n";
$out .= strtr($create['Create View'], "\n", " ") . ";\n";
$out .= "SET sql_mode = '$sql_mode';\n";
@@ -365,67 +383,86 @@ class backup_migrate_destination_db_mysql extends backup_migrate_destination_db
}
/**
* Get the sql to insert the data for a given table
* Get the sql to insert the data for a given table.
*/
function _dump_table_data_sql_to_file($file, $table) {
public function _dump_table_data_sql_to_file($file, $table) {
$rows_per_query = variable_get('backup_migrate_data_rows_per_query', 1000);
$rows_per_line = variable_get('backup_migrate_data_rows_per_line', 30);
$bytes_per_line = variable_get('backup_migrate_data_bytes_per_line', 2000);
$lines = 0;
$data = $this->query("SELECT * FROM `". $table['name'] ."`", array(), array('fetch' => PDO::FETCH_ASSOC));
$rows = $bytes = 0;
// Escape backslashes, PHP code, special chars
if (variable_get('backup_migrate_verbose')) {
_backup_migrate_message('Table: %table', array('%table' => $table['name']), 'success');
}
// Escape backslashes, PHP code, special chars.
$search = array('\\', "'", "\x00", "\x0a", "\x0d", "\x1a");
$replace = array('\\\\', "''", '\0', '\n', '\r', '\Z');
$line = array();
foreach ($data as $row) {
// DB Escape the values.
$items = array();
foreach ($row as $key => $value) {
$items[] = is_null($value) ? "null" : "'". str_replace($search, $replace, $value) ."'";
$lines = 0;
$from = 0;
$args = array('fetch' => PDO::FETCH_ASSOC);
while ($data = $this->query("SELECT * FROM `" . $table['name'] . "`", array(), $args, $from, $rows_per_query)) {
if ($data->rowCount() == 0) {
break;
}
// If there is a row to be added.
if ($items) {
// Start a new line if we need to.
if ($rows == 0) {
$file->write("INSERT INTO `". $table['name'] ."` VALUES ");
$bytes = $rows = 0;
$rows = $bytes = 0;
$line = array();
foreach ($data as $row) {
$from++;
// DB Escape the values.
$items = array();
foreach ($row as $key => $value) {
$items[] = is_null($value) ? "null" : "'" . str_replace($search, $replace, $value) . "'";
}
// Otherwise add a comma to end the previous entry.
else {
$file->write(",");
}
// Write the data itself.
$sql = implode(',', $items);
$file->write('('. $sql .')');
$bytes += strlen($sql);
$rows++;
// Finish the last line if we've added enough items
if ($rows >= $rows_per_line || $bytes >= $bytes_per_line) {
$file->write(";\n");
$lines++;
$bytes = $rows = 0;
// If there is a row to be added.
if ($items) {
// Start a new line if we need to.
if ($rows == 0) {
$file->write("INSERT INTO `" . $table['name'] . "` VALUES ");
$bytes = $rows = 0;
}
// Otherwise add a comma to end the previous entry.
else {
$file->write(",");
}
// Write the data itself.
$sql = implode(',', $items);
$file->write('(' . $sql . ')');
$bytes += strlen($sql);
$rows++;
// Finish the last line if we've added enough items.
if ($rows >= $rows_per_line || $bytes >= $bytes_per_line) {
$file->write(";\n");
$lines++;
$bytes = $rows = 0;
}
}
}
// Finish any unfinished insert statements.
if ($rows > 0) {
$file->write(";\n");
$lines++;
}
}
// Finish any unfinished insert statements.
if ($rows > 0) {
$file->write(";\n");
$lines++;
if (variable_get('backup_migrate_verbose')) {
_backup_migrate_message('Peak memory usage: %mem', array('%mem' => backup_migrate_get_peak_memory_usage() . 'MB'), 'success');
}
return $lines;
}
/**
* Get the db connection for the specified db.
*/
function _get_db_connection() {
public function _get_db_connection() {
if (!$this->connection) {
$this->connection = parent::_get_db_connection();
// Set the sql mode because the default is ANSI,TRADITIONAL which is not aware of collation or storage engine.
@@ -435,11 +472,34 @@ class backup_migrate_destination_db_mysql extends backup_migrate_destination_db
}
/**
* Run a db query on this destination's db.
* Run a query on this destination's database using Drupal's MySQL engine.
*
* @param string $query
* The query string.
* @param array $args
* Arguments for the query.
* @param array $options
* Options to pass to the query.
* @param int|null $from
* The starting point for the query; when passed will perform a queryRange()
* method instead of a regular query().
* @param int|null $count
* The number of records to obtain from this query. Will be ignored if the
* $from argument is empty.
*
* @see DatabaseConnection_mysql::query()
* @see DatabaseConnection_mysql::queryRange()
*/
function query($query, $args = array(), $options = array()) {
public function query($query, array $args = array(), array $options = array(), $from = NULL, $count = NULL) {
if ($conn = $this->_get_db_connection()) {
return $conn->query($query, $args, $options);
// If no $from is passed in, just do a basic query.
if (is_null($from)) {
return $conn->query($query, $args, $options);
}
// The $from variable was passed in, so do a ranged query.
else {
return $conn->queryRange($query, $from, $count, $args, $options);
}
}
}
@@ -447,7 +507,7 @@ class backup_migrate_destination_db_mysql extends backup_migrate_destination_db
* The header for the top of the sql dump file. These commands set the connection
* character encoding to help prevent encoding conversion issues.
*/
function _get_sql_file_header() {
public function _get_sql_file_header() {
return "/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
@@ -459,11 +519,11 @@ SET NAMES utf8;
";
}
/**
* The footer of the sql dump file.
*/
function _get_sql_file_footer() {
public function _get_sql_file_footer() {
return "
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
@@ -474,4 +534,5 @@ SET NAMES utf8;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
";
}
}
@@ -1,6 +1,5 @@
<?php
/**
* @file
* Functions to handle the email backup destination.
@@ -12,12 +11,12 @@
* @ingroup backup_migrate_destinations
*/
class backup_migrate_destination_email extends backup_migrate_destination {
var $supported_ops = array('scheduled backup', 'manual backup', 'remote backup', 'configure');
public $supported_ops = array('scheduled backup', 'manual backup', 'remote backup', 'configure');
/**
* Save to (ie. email the file) to the email destination.
*/
function save_file($file, $settings) {
public function save_file($file, $settings) {
$size = filesize($file->filepath());
$max = variable_get('backup_migrate_max_email_size', 20971520);
if ($size > $max) {
@@ -34,14 +33,14 @@ class backup_migrate_destination_email extends backup_migrate_destination {
/**
* Get the form for the settings for this filter.
*/
function edit_form() {
public function edit_form() {
$form = parent::edit_form();
$form['location'] = array(
"#type" => "textfield",
"#title" => t("Email Address"),
"#default_value" => $this->get_location(),
"#required" => TRUE,
"#description" => t('Enter the email address to send the backup files to. Make sure the email sever can handle large file attachments'),
"#description" => t('Enter the email address to send the backup files to. Make sure the email server can handle large file attachments'),
);
return $form;
}
@@ -49,11 +48,12 @@ class backup_migrate_destination_email extends backup_migrate_destination {
/**
* Validate the configuration form. Make sure the email address is valid.
*/
function settings_form_validate($values) {
public function settings_form_validate($values) {
if (!valid_email_address($values['location'])) {
form_set_error('[location]', t('The e-mail address %mail is not valid.', array('%mail' => $form_state['values']['location'])));
}
}
}
/**
@@ -72,28 +72,30 @@ class backup_migrate_destination_email extends backup_migrate_destination {
* filename and "filename" which is just the filename.
*/
function _backup_migrate_destination_email_mail_backup($attachment, $to) {
// Send mail
// Send mail.
$attach = fread(fopen($attachment->path, "r"), filesize($attachment->path));
$mail = new mime_mail();
$mail->from = variable_get('site_mail', ini_get('sendmail_from'));
$mail->headers = 'Errors-To: [EMAIL='. $mail->from .']'. $mail->from .'[/EMAIL]';
$mail->headers = 'Errors-To: [EMAIL=' . $mail->from . ']' . $mail->from . '[/EMAIL]';
$mail->to = $to;
$mail->subject = t('Database backup from !site: !file', array('!site' => variable_get('site_name', 'drupal'), '!file' => $attachment->filename));
$mail->body = t('Database backup attached.') ."\n\n";
$mail->body = t('Database backup attached.') . "\n\n";
$mail->add_attachment("$attach", $attachment->filename, "Content-Transfer-Encoding: base64 /9j/4AAQSkZJRgABAgEASABIAAD/7QT+UGhvdG9zaG", NULL, TRUE);
$mail->send();
}
/**
*
*/
class mime_mail {
var $parts;
var $to;
var $from;
var $headers;
var $subject;
var $body;
public $parts;
public $to;
public $from;
public $headers;
public $subject;
public $body;
function mime_mail() {
public function __construct() {
$this->parts = array();
$this->to = "";
$this->from = "";
@@ -102,7 +104,7 @@ class mime_mail {
$this->body = "";
}
function add_attachment($message, $name = "", $ctype = "application/octet-stream", $encode = NULL, $attach = FALSE) {
public function add_attachment($message, $name = "", $ctype = "application/octet-stream", $encode = NULL, $attach = FALSE) {
$this->parts[] = array(
"ctype" => $ctype,
"message" => $message,
@@ -112,29 +114,36 @@ class mime_mail {
);
}
function build_message($part) {
public function build_message($part) {
$message = $part["message"];
$message = chunk_split(base64_encode($message));
$encoding = "base64";
$disposition = $part['attach'] ? "Content-Disposition: attachment; filename=$part[name]\n" : '';
return "Content-Type: ". $part["ctype"] . ($part["name"] ? "; name = \"". $part["name"] ."\"" : "") ."\nContent-Transfer-Encoding: $encoding\n$disposition\n$message\n";
return "Content-Type: " . $part["ctype"] . ($part["name"] ? "; name = \"" . $part["name"] . "\"" : "") . "\nContent-Transfer-Encoding: $encoding\n$disposition\n$message\n";
}
function build_multipart() {
$boundary = "b". md5(uniqid(time()));
public function build_multipart() {
$boundary = "b" . md5(uniqid(time()));
$multipart = "Content-Type: multipart/mixed; boundary = $boundary\n\nThis is a MIME encoded message.\n\n--$boundary";
for ($i = sizeof($this->parts) - 1; $i >= 0; $i--) {
$multipart .= "\n". $this->build_message($this->parts[$i]) ."--$boundary";
$multipart .= "\n" . $this->build_message($this->parts[$i]) . "--$boundary";
}
return $multipart .= "--\n";
}
function send() {
public function send() {
$mime = "";
if (!empty($this->from)) $mime .= "From: ". $this->from ."\n";
if (!empty($this->headers)) $mime .= $this->headers ."\n";
if (!empty($this->body)) $this->add_attachment($this->body, "", "text/plain");
$mime .= "MIME-Version: 1.0\n". $this->build_multipart();
if (!empty($this->from)) {
$mime .= "From: " . $this->from . "\n";
}
if (!empty($this->headers)) {
$mime .= $this->headers . "\n";
}
if (!empty($this->body)) {
$this->add_attachment($this->body, "", "text/plain");
}
$mime .= "MIME-Version: 1.0\n" . $this->build_multipart();
mail(trim($this->to), $this->subject, "", $mime);
}
}
@@ -1,6 +1,5 @@
<?php
/**
* @file
* A destination type for saving locally to the server.
@@ -11,34 +10,40 @@
*
* @ingroup backup_migrate_destinations
*/
class backup_migrate_destination_files extends backup_migrate_destination {
var $supported_ops = array('scheduled backup', 'manual backup', 'local backup', 'restore', 'list files', 'configure', 'delete');
public $supported_ops = array('scheduled backup', 'manual backup', 'local backup', 'restore', 'list files', 'configure', 'delete');
function type_name() {
public function type_name() {
return t("Server Directory");
}
/**
* Get the file location.
*/
function get_realpath() {
return drupal_realpath($this->get_location());
public function get_realpath() {
if ($realpath = drupal_realpath($this->get_location())) {
return $realpath;
}
return $this->get_location();
}
/**
* File save destination callback.
*/
function _save_file($file, $settings) {
public function _save_file($file, $settings) {
if ($this->confirm_destination() && $dir = $this->get_location()) {
$filepath = rtrim($dir, "/") ."/". $file->filename();
$filepath = rtrim($dir, "/") . "/" . $file->filename();
// Allow files to be overwritten by the filesystem.
$replace_method = $settings->append_timestamp == 2 ? FILE_EXISTS_REPLACE : FILE_EXISTS_RENAME;
// Copy the file if there are multiple destinations.
if (count($settings->get_destinations()) > 1) {
file_unmanaged_copy($file->filepath(), $filepath);
file_unmanaged_copy($file->filepath(), $filepath, $replace_method);
}
// Otherwise we can move it and save a delete.
else {
file_unmanaged_move($file->filepath(), $filepath);
file_unmanaged_move($file->filepath(), $filepath, $replace_method);
}
// chmod, chown and chgrp the file if needed.
@@ -59,14 +64,14 @@ class backup_migrate_destination_files extends backup_migrate_destination {
/**
* Determine if we can read the given file.
*/
function can_read_file($file_id) {
public function can_read_file($file_id) {
return $this->op('restore') && is_readable($this->get_filepath($file_id));
}
/**
* File load destination callback.
*/
function load_file($file_id) {
public function load_file($file_id) {
$filepath = $this->get_filepath($file_id);
if (file_exists($filepath)) {
backup_migrate_include('files');
@@ -77,7 +82,7 @@ class backup_migrate_destination_files extends backup_migrate_destination {
/**
* Get the file object for the given file.
*/
function get_file($file_id) {
public function get_file($file_id) {
$files = $this->list_files();
if (isset($files[$file_id])) {
isset($files[$file_id]);
@@ -88,15 +93,15 @@ class backup_migrate_destination_files extends backup_migrate_destination {
/**
* File list destination callback.
*/
function _list_files() {
public function _list_files() {
$files = array();
if ($dir = $this->get_realpath()) {
if ($handle = @opendir($dir)) {
backup_migrate_include('files');
while (FALSE !== ($file = readdir($handle))) {
if (substr($file, 0, 1) !== '.') {
$filepath = $dir ."/". $file;
$files[$file] = new backup_file(array('filepath' => $filepath));
$filepath = $dir . "/" . $file;
$files[$file] = new backup_file(array('filepath' => $filepath));
}
}
}
@@ -107,7 +112,7 @@ class backup_migrate_destination_files extends backup_migrate_destination {
/**
* File delete destination callback.
*/
function _delete_file($file_id) {
public function _delete_file($file_id) {
$filepath = $this->get_filepath($file_id);
file_unmanaged_delete($filepath);
}
@@ -115,9 +120,9 @@ class backup_migrate_destination_files extends backup_migrate_destination {
/**
* Get the filepath from the given file id.
*/
function get_filepath($file_id) {
public function get_filepath($file_id) {
if ($dir = $this->get_realpath()) {
$filepath = rtrim($dir, '/') .'/'. $file_id;
$filepath = rtrim($dir, '/') . '/' . $file_id;
return $filepath;
}
return FALSE;
@@ -126,7 +131,7 @@ class backup_migrate_destination_files extends backup_migrate_destination {
/**
* Get the form for the settings for the files destination.
*/
function edit_form() {
public function edit_form() {
$form = parent::edit_form();
$form['location'] = array(
"#type" => "textfield",
@@ -166,7 +171,7 @@ class backup_migrate_destination_files extends backup_migrate_destination {
/**
* Validate the form for the settings for the files destination.
*/
function edit_form_validate($form, &$form_state) {
public function edit_form_validate($form, &$form_state) {
$values = $form_state['values'];
if (isset($values['settings']['chmod']) && !empty($values['settings']['chmod']) && !preg_match('/0?[0-7]{3}/', $values['settings']['chmod'])) {
form_set_error('chmod', t('You must enter a valid chmod octal value (e.g. 644 or 0644) in the change mode field, or leave it blank.'));
@@ -177,7 +182,7 @@ class backup_migrate_destination_files extends backup_migrate_destination {
/**
* Submit the form for the settings for the files destination.
*/
function edit_form_submit($form, &$form_state) {
public function edit_form_submit($form, &$form_state) {
// Add a 0 to the start of a 3 digit file mode to make it proper PHP encoded octal.
if (strlen($form_state['values']['settings']['chmod']) == 3) {
$form_state['values']['settings']['chmod'] = '0' . $form_state['values']['settings']['chmod'];
@@ -188,7 +193,7 @@ class backup_migrate_destination_files extends backup_migrate_destination {
/**
* Check that a destination is valid.
*/
function confirm_destination() {
public function confirm_destination() {
if ($dir = $this->get_location()) {
return $this->check_dir($dir);
}
@@ -198,10 +203,10 @@ class backup_migrate_destination_files extends backup_migrate_destination {
/**
* Prepare the destination directory for the backups.
*/
function check_dir($directory) {
public function check_dir($directory) {
if (!file_prepare_directory($directory, FILE_CREATE_DIRECTORY)) {
// Unable to create destination directory.
_backup_migrate_message("Unable to create or write to the save directory '%directory'. Please check the file permissions that directory and try again.", array('%directory' => $directory), "error");
_backup_migrate_message("Unable to create or write to the save directory '%directory'. Please check the file permissions of that directory and try again.", array('%directory' => $directory), "error");
return FALSE;
}
@@ -216,25 +221,25 @@ class backup_migrate_destination_files extends backup_migrate_destination {
/**
* Check that a web accessible directory has been properly secured, othewise attempt to secure it.
*/
function check_web_dir($directory) {
public function check_web_dir($directory) {
// Check if the file has already been tested.
if (is_file($directory .'/tested.txt')) {
if (is_file($directory . '/tested.txt')) {
return $directory;
}
else {
file_create_htaccess($directory, TRUE);
// Check the user agent to make sure we're not responding to a request from drupal itself.
// That should prevent infinite loops which could be caused by poormanscron in some circumstances.
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Drupal') !== FALSE) {
return FALSE;
}
// Check to see if the destination is publicly accessible
// Check to see if the destination is publicly accessible.
$test_contents = "this file should not be publicly accessible";
// Create the the text.txt file if it's not already there.
if (!is_file($directory .'/test.txt') || file_get_contents($directory .'/test.txt') != $test_contents) {
if ($fp = fopen($directory .'/test.txt', 'w')) {
if (!is_file($directory . '/test.txt') || file_get_contents($directory . '/test.txt') != $test_contents) {
if ($fp = fopen($directory . '/test.txt', 'w')) {
@fputs($fp, $test_contents);
fclose($fp);
}
@@ -244,16 +249,16 @@ class backup_migrate_destination_files extends backup_migrate_destination {
return FALSE;
}
}
// Attempt to read the test file via http. This may fail for other reasons,
// so it's not a bullet-proof check.
if ($this->test_file_readable_remotely($directory .'/test.txt', $test_contents)) {
if ($this->test_file_readable_remotely($directory . '/test.txt', $test_contents)) {
$message = t("Security notice: Backup and Migrate will not save backup files to the server because the destination directory is publicly accessible. If you want to save files to the server, please secure the '%directory' directory", array('%directory' => $directory));
drupal_set_message($message, "error");
return FALSE;
}
// Directory tested OK, so we mark it as tested.
if ($fp = fopen($directory .'/tested.txt', 'w')) {
if ($fp = fopen($directory . '/tested.txt', 'w')) {
$contents = t('The presence of this file indicates that this directory has been tested as safe to use as a destination for Backup and Migrate. If you change the permissions of this directory or change your web server settings, please delete this file so that the directory can be checked again.');
@fputs($fp, $contents);
fclose($fp);
@@ -265,7 +270,7 @@ class backup_migrate_destination_files extends backup_migrate_destination {
/**
* Check if the given directory is within the webroot and is therefore web accessible.
*/
function dir_in_webroot($directory) {
public function dir_in_webroot($directory) {
$real_dir = drupal_realpath($directory);
$real_root = drupal_realpath(DRUPAL_ROOT);
if ($real_dir == $real_root || strpos($real_dir, $real_root . '/') === 0) {
@@ -274,10 +279,10 @@ class backup_migrate_destination_files extends backup_migrate_destination {
return FALSE;
}
/**
/**
* Check if a file can be read remotely via http.
*/
function test_file_readable_remotely($directory, $contents) {
public function test_file_readable_remotely($directory, $contents) {
$real_dir = drupal_realpath($directory);
$real_root = drupal_realpath(DRUPAL_ROOT);
if ($real_dir && $real_root) {
@@ -292,27 +297,29 @@ class backup_migrate_destination_files extends backup_migrate_destination {
}
return FALSE;
}
}
/**
* The manual files directory.
*/
class backup_migrate_destination_files_manual extends backup_migrate_destination_files {
var $supported_ops = array('manual backup', 'restore', 'list files', 'configure', 'delete');
function __construct($params = array()) {
public $supported_ops = array('manual backup', 'restore', 'list files', 'configure', 'delete');
public function __construct($params = array()) {
$dir = 'private://backup_migrate/manual';
parent::__construct($params + array('location' => $dir, 'name' => t('Manual Backups Directory')));
}
}
/**
* The scheduled files directory.
*/
class backup_migrate_destination_files_scheduled extends backup_migrate_destination_files {
var $supported_ops = array('scheduled backup', 'restore', 'list files', 'configure', 'delete');
function __construct($params = array()) {
public $supported_ops = array('scheduled backup', 'restore', 'list files', 'configure', 'delete');
public function __construct($params = array()) {
$dir = 'private://backup_migrate/scheduled';
parent::__construct($params + array('location' => $dir, 'name' => t('Scheduled Backups Directory')));
}
}
}
@@ -11,13 +11,13 @@
* @ingroup backup_migrate_destinations
*/
class backup_migrate_destination_ftp extends backup_migrate_destination_remote {
var $supported_ops = array('scheduled backup', 'manual backup', 'remote backup', 'restore', 'list files', 'configure', 'delete');
var $ftp = NULL;
public $supported_ops = array('scheduled backup', 'manual backup', 'remote backup', 'restore', 'list files', 'configure', 'delete');
public $ftp = NULL;
/**
* Save to the ftp destination.
*/
function _save_file($file, $settings) {
public function _save_file($file, $settings) {
$ftp = $this->ftp_object();
if (drupal_ftp_file_to_ftp($file->filepath(), $file->filename(), '.', $ftp)) {
return $file;
@@ -28,7 +28,7 @@ class backup_migrate_destination_ftp extends backup_migrate_destination_remote {
/**
* Load from the ftp destination.
*/
function load_file($file_id) {
public function load_file($file_id) {
backup_migrate_include('files');
$file = new backup_file(array('filename' => $file_id));
$this->ftp_object();
@@ -41,16 +41,16 @@ class backup_migrate_destination_ftp extends backup_migrate_destination_remote {
/**
* Delete from the ftp destination.
*/
function _delete_file($file_id) {
public function _delete_file($file_id) {
$this->ftp_object();
drupal_ftp_delete_file($file_id, $this->ftp);
}
function _list_files() {
public function _list_files() {
backup_migrate_include('files');
$files = array();
$this->ftp_object();
$ftp_files = (array)drupal_ftp_file_list('.', $this->ftp);
$ftp_files = (array) drupal_ftp_file_list('.', $this->ftp);
foreach ($ftp_files as $file) {
$files[$file['filename']] = new backup_file($file);
}
@@ -60,7 +60,7 @@ class backup_migrate_destination_ftp extends backup_migrate_destination_remote {
/**
* Get the form for the settings for this filter.
*/
function edit_form() {
public function edit_form() {
$form = parent::edit_form();
$form['scheme']['#type'] = 'value';
$form['scheme']['#value'] = 'ftp';
@@ -79,15 +79,15 @@ class backup_migrate_destination_ftp extends backup_migrate_destination_remote {
return $form;
}
function set_pasv($value) {
$this->settings['pasv'] = (bool)$value;
public function set_pasv($value) {
$this->settings['pasv'] = (bool) $value;
}
function get_pasv() {
public function get_pasv() {
return isset($this->settings['pasv']) ? $this->settings['pasv'] : FALSE;
}
function ftp_object() {
public function ftp_object() {
if (!$this->ftp) {
$this->dest_url['port'] = empty($this->dest_url['port']) ? '21' : $this->dest_url['port'];
$this->dest_url['pasv'] = $this->get_pasv();
@@ -95,19 +95,18 @@ class backup_migrate_destination_ftp extends backup_migrate_destination_remote {
}
return $this->ftp;
}
}
// The FTP code below was taken from the ftp module by Aaron Winborn.
// Inspired by http://www.devarticles.com/c/a/PHP/My-FTP-Wrapper-Class-for-PHP/
// It's been drupalized, however, and most of the bugs from that example have been fixed.
// - winborn 2007-06-22 - 2007-06-28
define('DRUPAL_FTP_FT_DIRECTORY', 0);
define('DRUPAL_FTP_FT_FILE', 1);
/**
* creates a new ftp object. if any elements of ftp_map are missing, they'll be filled with the server defaults.
* Creates a new ftp object. if any elements of ftp_map are missing, they'll be filled with the server defaults.
*/
function drupal_ftp_ftp_object($server, $port, $user, $pass, $dir, $pasv) {
$ftp = new stdClass();
@@ -123,17 +122,17 @@ function drupal_ftp_ftp_object($server, $port, $user, $pass, $dir, $pasv) {
}
/**
* The drupal_ftp_connect function
* The drupal_ftp_connect function
* This function connects to an FTP server and attempts to change into the directory specified by
* the fourth parameter, $directory.
*/
function drupal_ftp_connect(&$ftp) {
if (is_NULL($ftp)) {
if (is_null($ftp)) {
$ftp = drupal_ftp_ftp_object();
}
if (!$ftp->__conn && !drupal_ftp_connected($ftp)) {
// Attempt to connect to the remote server
// Attempt to connect to the remote server.
$ftp->__conn = @ftp_connect($ftp->__server, $ftp->__port);
if (!$ftp->__conn) {
@@ -141,7 +140,7 @@ function drupal_ftp_connect(&$ftp) {
return FALSE;
}
// Attempt to login to the remote server
// Attempt to login to the remote server.
$ftp->__login = @ftp_login($ftp->__conn, $ftp->__user, $ftp->__password);
if (!$ftp->__login) {
@@ -149,7 +148,7 @@ function drupal_ftp_connect(&$ftp) {
return FALSE;
}
// Attempt to change into the working directory
// Attempt to change into the working directory.
$chdir = @ftp_chdir($ftp->__conn, $ftp->__directory);
if (!$chdir) {
@@ -157,7 +156,7 @@ function drupal_ftp_connect(&$ftp) {
return FALSE;
}
// Set PASV - if needed
// Set PASV - if needed.
if ($ftp->__pasv) {
$pasv = @ftp_pasv($ftp->__conn, TRUE);
if (!$pasv) {
@@ -167,7 +166,7 @@ function drupal_ftp_connect(&$ftp) {
}
}
// Everything worked OK, return TRUE
// Everything worked OK, return TRUE.
return TRUE;
}
@@ -178,38 +177,36 @@ function drupal_ftp_connect(&$ftp) {
*/
function drupal_ftp_connected(&$ftp) {
// Attempt to call the ftp_systype to see if the connect
// to the FTP server is still alive and kicking
if (is_NULL($ftp)) {
// to the FTP server is still alive and kicking.
if (is_null($ftp)) {
$ftp = drupal_ftp_ftp_object();
return FALSE;
}
if (!@ftp_systype($ftp->__conn)) {
// The connection is dead
// The connection is dead.
return FALSE;
}
else {
// The connection is still alive
// The connection is still alive.
return TRUE;
}
}
/**
* This function tries to retrieve the contents of a file from the FTP server.
* This function tries to retrieve the contents of a file from the FTP server.
* Firstly it changes into the $directory directory, and then attempts to download the file $filename.
* The file is saved locally and its contents are returned to the caller of the function.
*/
function drupal_ftp_ftp_to_file($file, $filename, $directory, &$ftp) {
// Change into the remote directory and retrieve the content
// of a file. Once retrieve, return this value to the caller
// of a file. Once retrieve, return this value to the caller.
if (!@drupal_ftp_connect($ftp)) {
return FALSE;
}
// We are now connected, so let's retrieve the file contents.
// Firstly, we change into the directory
// Firstly, we change into the directory.
$chdir = @ftp_chdir($ftp->__conn, $directory);
if (!$chdir) {
@@ -217,7 +214,7 @@ function drupal_ftp_ftp_to_file($file, $filename, $directory, &$ftp) {
return FALSE;
}
// We have changed into the directory, let's attempt to get the file
// We have changed into the directory, let's attempt to get the file.
$fp = @fopen($file, 'wb');
$get_file = @ftp_fget($ftp->__conn, $fp, $filename, FTP_BINARY);
fclose($fp);
@@ -228,7 +225,7 @@ function drupal_ftp_ftp_to_file($file, $filename, $directory, &$ftp) {
_backup_migrate_message('FTP Error: Unable to download file: @filename from @directory', array('@filename' => $filename, '@directory' => $directory), 'error');
return FALSE;
}
return TRUE;
}
@@ -241,15 +238,15 @@ function drupal_ftp_file_to_ftp($file, $ftp_filename, $ftp_directory, &$ftp) {
}
if ($source = drupal_realpath($file)) {
// Now we can try to write to the remote file
$complete_filename = $ftp_directory .'/'. $ftp_filename;
// Now we can try to write to the remote file.
$complete_filename = $ftp_directory . '/' . $ftp_filename;
$put_file = @ftp_put($ftp->__conn, $complete_filename, $source, FTP_BINARY);
if (!$put_file) {
_backup_migrate_message('FTP Error: Couldn\'t write to @complete_filename when trying to save file on the ftp server.', array('@complete_filename' => $complete_filename), 'error');
return FALSE;
}
// Everything worked OK
// Everything worked OK.
return TRUE;
}
else {
@@ -259,19 +256,18 @@ function drupal_ftp_file_to_ftp($file, $ftp_filename, $ftp_directory, &$ftp) {
}
/**
* The drupal_ftp_change_directory Function
* The drupal_ftp_change_directory Function
* This function simply changes into the $directory folder on the FTP server.
* If a connection or permission error occurs then _backup_migrate_message() will contain the error message.
*/
function drupal_ftp_change_directory($directory, &$ftp) {
// Switch to another directory on the web server. If we don't
// have permissions then an error will occur
// have permissions then an error will occur.
if (!@drupal_ftp_connect($ftp)) {
return FALSE;
}
// Try and change into another directory
// Try and change into another directory.
$chdir = ftp_chdir($ftp->__conn, $directory);
if (!$chdir) {
@@ -279,21 +275,20 @@ function drupal_ftp_change_directory($directory, &$ftp) {
return FALSE;
}
else {
// Changing directories worked OK
// Changing directories worked OK.
return TRUE;
}
}
/**
* The drupal_ftp_file_list Function
* The drupal_ftp_file_list Function
* This function will change into the $directory folder and get a list of files and directories contained in that folder.
* This function still needs a lot of work, but should work in most cases.
*/
function drupal_ftp_file_list($directory, &$ftp) {
// This function will attempt to change into the specified
// directory and retrieve a list of files as an associative
// array. This list will include file name, size and date last modified
// array. This list will include file name, size and date last modified.
$file_array = array();
// Can we switch to the desired directory?
@@ -305,14 +300,14 @@ function drupal_ftp_file_list($directory, &$ftp) {
// This is slower than parsing the raw return values, but it is faster.
$file_list = ftp_nlist($ftp->__conn, $directory);
// Save the list of files
// Save the list of files.
if (@is_array($file_list)) {
// Interate through the array
// Interate through the array.
foreach ($file_list as $file) {
$file_array[] = array(
'filename' => $file,
'filesize' => ftp_size($ftp->__conn, $directory ."/". $file),
'filetime' => ftp_mdtm($ftp->__conn, $directory ."/". $file),
'filesize' => ftp_size($ftp->__conn, $directory . "/" . $file),
'filetime' => ftp_mdtm($ftp->__conn, $directory . "/" . $file),
);
}
}
@@ -321,13 +316,12 @@ function drupal_ftp_file_list($directory, &$ftp) {
}
/**
* The drupal_ftp_create_directory Function
* The drupal_ftp_create_directory Function
* This function tries to make a new directory called $folder_name on the FTP server.
* If it can create the folder, then the folder is given appropriate rights with the CHMOD command.
*/
function drupal_ftp_create_directory($folder_name, &$ftp) {
// Makes a new folder on the web server via FTP
// Makes a new folder on the web server via FTP.
if (!@drupal_ftp_connect($ftp)) {
return FALSE;
}
@@ -336,7 +330,7 @@ function drupal_ftp_create_directory($folder_name, &$ftp) {
if ($create_result == TRUE) {
// Can we change the files permissions?
$exec_result = @ftp_site($ftp->__conn, 'chmod 0777 '. $folder_name .'/');
$exec_result = @ftp_site($ftp->__conn, 'chmod 0777 ' . $folder_name . '/');
if ($exec_result == TRUE) {
return TRUE;
@@ -353,11 +347,11 @@ function drupal_ftp_create_directory($folder_name, &$ftp) {
}
/**
* The drupal_ftp_delete_file Function
* The drupal_ftp_delete_file Function
* This function attempts to delete a file called $filename from the FTP server.
*/
function drupal_ftp_delete_file($filename, &$ftp) {
// Remove the specified file from the FTP server
// Remove the specified file from the FTP server.
if (!@drupal_ftp_connect($ftp)) {
return FALSE;
}
@@ -365,18 +359,18 @@ function drupal_ftp_delete_file($filename, &$ftp) {
$delete_result = @ftp_delete($ftp->__conn, $filename);
if ($delete_result == TRUE) {
// The file/folder was renamed successfully
// The file/folder was renamed successfully.
return TRUE;
}
else {
// Couldn't delete the selected file
// Couldn't delete the selected file.
_backup_migrate_message('FTP Error: Couldn\'t delete the selected file: @filename', array('@filename' => $filename), 'error');
return FALSE;
}
}
/**
* The drupal_ftp_delete_folder Function
* The drupal_ftp_delete_folder Function
* This function was one of the hardest to write. It recursively deletes all files and folders from a directory called $folder_name.
*/
function drupal_ftp_delete_folder($folder_name, &$ftp) {
@@ -395,16 +389,16 @@ function drupal_ftp_delete_folder($folder_name, &$ftp) {
for ($i = 0; $i < sizeof($content); $i++) {
// If we can change into this then it's a directory.
// If not, it's a file
// If not, it's a file.
if ($content[$i] != "." && $content[$i] != "..") {
if (@ftp_chdir($ftp->__conn, $content[$i])) {
// We have a directory
// We have a directory.
$directories[] = $content[$i];
$dir_counter++;
@ftp_cdup($ftp->__conn);
}
else {
// We have a file
// We have a file.
$files[] = $content[$i];
$file_counter++;
}
@@ -419,7 +413,7 @@ function drupal_ftp_delete_folder($folder_name, &$ftp) {
if ($directories[$j] != "." OR $directories[$j] != "..") {
$location = ftp_pwd($ftp->__conn);
drupal_ftp_delete_folder($directories[$j], $ftp);
@ftp_cdup ($ftp->__conn);
@ftp_cdup($ftp->__conn);
@ftp_rmdir($ftp->__conn, $directories[$j]);
}
}
@@ -1,6 +1,5 @@
<?php
/**
* @file
* All of the destination handling code needed for Backup and Migrate.
@@ -26,19 +25,19 @@ function backup_migrate_backup_migrate_destination_subtypes() {
$out += array(
'file' => array(
'description' => t('Save the backup files to any directory on this server which the web-server can write to.'),
'file' => drupal_get_path('module', 'backup_migrate') .'/includes/destinations.file.inc',
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/destinations.file.inc',
'class' => 'backup_migrate_destination_files',
'type_name' => t('Server Directory'),
'local' => TRUE,
'can_create' => TRUE,
),
'file_manual' => array(
'file' => drupal_get_path('module', 'backup_migrate') .'/includes/destinations.file.inc',
'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',
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/destinations.file.inc',
'type_name' => t('Server Directory'),
'class' => 'backup_migrate_destination_files_scheduled',
),
@@ -46,16 +45,16 @@ function backup_migrate_backup_migrate_destination_subtypes() {
}
$out += array(
'browser_download' => array(
'file' => drupal_get_path('module', 'backup_migrate') .'/includes/destinations.browser.inc',
'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',
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/destinations.browser.inc',
'class' => 'backup_migrate_destination_browser_upload',
),
'nodesquirrel' => array(
'description' => t('Save the backup files to the NodeSquirrel.com backup service.'),
'file' => drupal_get_path('module', 'backup_migrate') .'/includes/destinations.nodesquirrel.inc',
'description' => t('Save the backup files to the <a href="@link" target="_blank">NodeSquirrel</a> backup service.', array('@link' => url('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,
@@ -63,15 +62,15 @@ function backup_migrate_backup_migrate_destination_subtypes() {
),
'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',
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/destinations.ftp.inc',
'class' => 'backup_migrate_destination_ftp',
'type_name' => t('FTP Directory'),
'can_create' => TRUE,
'remote' => TRUE,
),
's3' => array(
'description' => t('Save the backup files to a bucket on your !link.', array('!link' => l(t('Amazon S3 account'), 'http://aws.amazon.com/s3/'))),
'file' => drupal_get_path('module', 'backup_migrate') .'/includes/destinations.s3.inc',
'description' => t('Save the backup files to a bucket on your <a href="@link" target="_blank">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,
@@ -80,7 +79,7 @@ function backup_migrate_backup_migrate_destination_subtypes() {
'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',
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/destinations.email.inc',
'class' => 'backup_migrate_destination_email',
'can_create' => TRUE,
'remote' => TRUE,
@@ -134,7 +133,7 @@ function backup_migrate_backup_migrate_destinations() {
* 'all' - all available destinations should be returned
*/
function backup_migrate_get_destinations($op = 'all') {
static $destinations = NULL;
$destinations = &drupal_static('backup_migrate_get_destinations', NULL);
// Get the list of destinations and cache them locally.
if ($destinations === NULL) {
@@ -190,7 +189,7 @@ function backup_migrate_destination_get_latest_file($destination_id) {
if ($destination = backup_migrate_get_destination($destination_id)) {
$files = $destination->list_files();
$max = 0;
foreach ((array)$files as $file) {
foreach ((array) $files as $file) {
$info = $file->info();
// If there's a datestamp, it should override the filetime as it's probably more reliable.
@@ -276,7 +275,7 @@ 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) {
drupal_add_css(drupal_get_path('module', 'backup_migrate') .'/backup_migrate.css');
drupal_add_css(drupal_get_path('module', 'backup_migrate') . '/backup_migrate.css');
$rows = $sort = array();
if ($destination = backup_migrate_get_destination($destination_id)) {
@@ -302,7 +301,7 @@ function _backup_migrate_ui_destination_display_files($destination = NULL, $limi
// Get the fetch link.
if ($destination->cache_files && $destination->fetch_time) {
$fetch = '<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' => array('refresh' => 'true'))))) .'</div>';
$fetch = '<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' => array('refresh' => 'true'))))) . '</div>';
}
$out .= $fetch;
@@ -317,9 +316,9 @@ function _backup_migrate_ui_destination_display_files($destination = NULL, $limi
* List the backup files in the given destination.
*/
function _backup_migrate_ui_destination_display_file_list($files, $options = array()) {
drupal_add_css(drupal_get_path('module', 'backup_migrate') .'/backup_migrate.css');
drupal_add_css(drupal_get_path('module', 'backup_migrate') . '/backup_migrate.css');
// Set soem default options
// Set some default options.
$options += array(
'pager' => TRUE,
'more' => FALSE,
@@ -347,7 +346,7 @@ function _backup_migrate_ui_destination_display_file_list($files, $options = arr
$sort_dir = tablesort_get_sort($headers) == 'desc' ? SORT_DESC : SORT_ASC;
$i = 0;
foreach ((array)$files as $id => $file) {
foreach ((array) $files as $id => $file) {
$info = $file->info();
// If there's a datestamp, it should override the filetime as it's probably more reliable.
@@ -361,17 +360,17 @@ function _backup_migrate_ui_destination_display_file_list($files, $options = arr
}
// Add the backup source.
if (!empty($info['bam_sourcename'])) {
$description .= ' <div title="'. check_plain($info['bam_sourcename']) .'" class="backup-migrate-tags"><span class="backup-migrate-label">'. t('Source:') .' </span>' . check_plain($info['bam_sourcename']) . '</div>';
$description .= ' <div title="' . check_plain($info['bam_sourcename']) . '" class="backup-migrate-tags"><span class="backup-migrate-label">' . t('Source:') . ' </span>' . check_plain($info['bam_sourcename']) . '</div>';
}
// Add the tags as a new row.
if (!empty($info['tags'])) {
$tags = check_plain(implode(', ', (array)$info['tags']));
$tags = check_plain(implode(', ', (array) $info['tags']));
$description .= ' <div title="' . $tags . '" class="backup-migrate-tags"><span class="backup-migrate-label">' . t('Tags:') . ' </span>' . $tags . '</div>';
}
// Add the other info.
if (!empty($info['bam_other_safe'])) {
foreach ($info['bam_other_safe'] as $label => $data) {
$description .= ' <div class="backup-migrate-tags"><span class="backup-migrate-label">' . $label . ' </span>' . $data . '</div>';
$description .= ' <div class="backup-migrate-tags"><span class="backup-migrate-label">' . $label . ' </span>' . $data . '</div>';
}
}
@@ -404,7 +403,7 @@ function _backup_migrate_ui_destination_display_file_list($files, $options = arr
$start = 0;
if ($options['pager']) {
$page = isset($_GET['page']) ? $_GET['page'] : '';
$page = isset($_GET['page']) ? intval($_GET['page']) : 0;
$start = $page * $limit;
$element = 0;
@@ -416,15 +415,15 @@ function _backup_migrate_ui_destination_display_file_list($files, $options = arr
'',
t('older »'),
t('oldest »'),
);
$pager = theme('pager', $tags, $limit, $element, array(), ceil($total/$limit));
);
$pager = theme('pager', $tags, $limit, $element, array(), ceil($total / $limit));
$end = min($total - 1, $start + $limit);
$end = min($total, $start + $limit);
}
if ($total > $limit && $options['more']) {
$more = ' ' . l(t('view all'), $options['more']);
}
$showing = t('Showing @start to @end of @total files.', array('@start' => $start + 1, '@end' => $end + 1, '@total' => $total));
$showing = t('Showing @start to @end of @total files.', array('@start' => $start + 1, '@end' => $end, '@total' => $total));
// Limit the number of rows shown.
$rows = array_slice($rows, $start, $limit, TRUE);
@@ -445,7 +444,7 @@ function _backup_migrate_ui_destination_display_file_list($files, $options = arr
* List the backup files in the given destination.
*/
function _backup_migrate_ui_destination_display_file_list_options($files, $limit = NULL) {
drupal_add_css(drupal_get_path('module', 'backup_migrate') .'/backup_migrate.css');
drupal_add_css(drupal_get_path('module', 'backup_migrate') . '/backup_migrate.css');
$rows = $sort = array();
if ($files) {
@@ -461,7 +460,7 @@ function _backup_migrate_ui_destination_display_file_list_options($files, $limit
$sort_dir = tablesort_get_sort($headers) == 'desc' ? SORT_DESC : SORT_ASC;
$i = 0;
foreach ((array)$files as $file) {
foreach ((array) $files as $file) {
$info = $file->info();
// If there's a datestamp, it should override the filetime as it's probably more reliable.
@@ -475,17 +474,17 @@ function _backup_migrate_ui_destination_display_file_list_options($files, $limit
}
// Add the backup source.
if (!empty($info['bam_sourcename'])) {
$description .= ' <div title="'. check_plain($info['bam_sourcename']) .'" class="backup-migrate-tags"><span class="backup-migrate-label">'. t('Source:') .' </span>' . check_plain($info['bam_sourcename']) . '</div>';
$description .= ' <div title="' . check_plain($info['bam_sourcename']) . '" class="backup-migrate-tags"><span class="backup-migrate-label">' . t('Source:') . ' </span>' . check_plain($info['bam_sourcename']) . '</div>';
}
// Add the tags as a new row.
if (!empty($info['tags'])) {
$tags = check_plain(implode(', ', (array)$info['tags']));
$tags = check_plain(implode(', ', (array) $info['tags']));
$description .= ' <div title="' . $tags . '" class="backup-migrate-tags"><span class="backup-migrate-label">' . t('Tags:') . ' </span>' . $tags . '</div>';
}
// Add the other info.
if (!empty($info['bam_other_safe'])) {
foreach ($info['bam_other_safe'] as $label => $data) {
$description .= ' <div class="backup-migrate-tags"><span class="backup-migrate-label">' . $label . ' </span>' . $data . '</div>';
$description .= ' <div class="backup-migrate-tags"><span class="backup-migrate-label">' . $label . ' </span>' . $data . '</div>';
}
}
@@ -508,7 +507,6 @@ function _backup_migrate_ui_destination_display_file_list_options($files, $limit
$end = $limit;
$start = 0;
$showing = t('Showing @start to @end of @total files.', array('@start' => $start + 1, '@end' => $end + 1, '@total' => $total));
// Limit the number of rows shown.
@@ -573,7 +571,7 @@ function backup_migrate_ui_destination_restore_file_confirm($form, &$form_state,
$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'));
$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;
@@ -582,8 +580,8 @@ function backup_migrate_ui_destination_restore_file_confirm($form, &$form_state,
if (@$form['advanced']) {
$form['advanced']['#type'] = 'fieldset';
$form['advanced']['#title'] = t('Advanced Options');
$form['advanced']['#collapsed'] = true;
$form['advanced']['#collapsible'] = true;
$form['advanced']['#collapsed'] = TRUE;
$form['advanced']['#collapsible'] = TRUE;
}
return $form;
@@ -598,7 +596,7 @@ function backup_migrate_ui_destination_restore_file_confirm_submit($form, &$form
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;
$redir = user_access('access backup files') ? BACKUP_MIGRATE_MENU_PATH . "/destination/list/files/" . $destination_id : BACKUP_MIGRATE_MENU_PATH;
$form_state['redirect'] = $redir;
}
@@ -611,7 +609,7 @@ function backup_migrate_ui_destination_delete_file($destination_id = NULL, $file
}
_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 . '/destination/list/files/' . $destination_id);
}
drupal_goto(BACKUP_MIGRATE_MENU_PATH);
}
@@ -622,7 +620,7 @@ function backup_migrate_ui_destination_delete_file($destination_id = NULL, $file
function backup_migrate_ui_destination_delete_file_confirm($form, &$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'));
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'));
}
/**
@@ -635,7 +633,7 @@ function backup_migrate_ui_destination_delete_file_confirm_submit($form, &$form_
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;
$form_state['redirect'] = user_access('access backup files') ? BACKUP_MIGRATE_MENU_PATH . "/destination/list/files/" . $destination_id : BACKUP_MIGRATE_MENU_PATH;
}
/* Utilities */
@@ -644,7 +642,7 @@ function backup_migrate_ui_destination_delete_file_confirm_submit($form, &$form_
* Get pulldown to select existing source options.
*/
function _backup_migrate_get_destination_pulldown($op, $destination_id = NULL, $copy_destination_id = NULL) {
drupal_add_js(drupal_get_path('module', 'backup_migrate') .'/backup_migrate.js');
drupal_add_js(drupal_get_path('module', 'backup_migrate') . '/backup_migrate.js');
$destinations = _backup_migrate_get_destination_form_item_options($op);
$form = array(
@@ -656,10 +654,10 @@ function _backup_migrate_get_destination_pulldown($op, $destination_id = NULL, $
'#title' => t('Backup Destination'),
'#options' => $destinations,
'#default_value' => $destination_id,
//'#process' => array('_backup_migrate_process_destination_pulldown'),
// '#process' => array('_backup_migrate_process_destination_pulldown'),
);
if (user_access('administer backup and migrate')) {
$form['destination_id']['#description'] = l(t("Create new destination"), BACKUP_MIGRATE_MENU_PATH . "/destination/add");
$form['destination_id']['#description'] = l(t('Create new destination'), BACKUP_MIGRATE_MENU_PATH . '/settings/destination/add');
}
$form['copy'] = array(
'#type' => 'checkbox',
@@ -679,8 +677,6 @@ function _backup_migrate_get_destination_pulldown($op, $destination_id = NULL, $
'#default_value' => $copy_destination_id,
);
return $form;
}
@@ -693,16 +689,16 @@ function _backup_migrate_process_destination_pulldown($element) {
'backup_migrate' => array(
'destination_selectors' => array(
$id => array(
'destination_selector' => $id,
'destination_selector' => $id,
'copy_destination_selector' => $element['copy_destination']['copy_destination_id']['#id'],
'copy' => $element['copy']['#id'],
'labels' => array(
t('Local') => t('Save an offsite copy to'),
t('Offsite') => t('Save a local copy to'),
)
)
)
)
),
),
),
),
);
drupal_add_js($settings, 'setting');
@@ -750,7 +746,7 @@ function _backup_migrate_get_destination_form_item_options($op) {
t('Local') => $local,
t('Offsite') => $remote,
);
}
}
else {
$out = $remote + $local;
}
@@ -761,25 +757,26 @@ function _backup_migrate_get_destination_form_item_options($op) {
* A base class for creating destinations.
*/
class backup_migrate_destination extends backup_migrate_location {
var $db_table = "backup_migrate_destinations";
var $type_name = "destination";
var $default_values = array('settings' => array());
var $singular = 'destination';
var $plural = 'destinations';
var $title_plural = 'Destinations';
var $title_singular = 'Destination';
var $cache_files = FALSE;
var $fetch_time = NULL;
var $cache_expire = 86400; // 24 hours
var $weight = 0;
public $db_table = "backup_migrate_destinations";
public $type_name = "destination";
public $default_values = array('settings' => array());
public $singular = 'destination';
public $plural = 'destinations';
public $title_plural = 'Destinations';
public $title_singular = 'Destination';
public $cache_files = FALSE;
public $fetch_time = NULL;
public $cache_expire = 86400;
// 24 hours.
public $weight = 0;
var $destination_type = "";
var $supported_ops = array();
public $destination_type = "";
public $supported_ops = array();
/**
* This function is not supposed to be called. It is just here to help the po extractor out.
*/
function strings() {
public function strings() {
// Help the pot extractor find these strings.
t('Destination');
t('Destinations');
@@ -790,7 +787,7 @@ class backup_migrate_destination extends backup_migrate_location {
/**
* Save the given file to the destination.
*/
function save_file($file, $settings) {
public function save_file($file, $settings) {
$this->file_cache_clear();
// Save the file metadata if the destination supports it.
@@ -801,15 +798,15 @@ class backup_migrate_destination extends backup_migrate_location {
/**
* Save the given file to the destination.
*/
function _save_file($file, $settings) {
public function _save_file($file, $settings) {
// This must be overriden.
return $file;
}
/**
* Save the file metadata
* Save the file metadata.
*/
function save_file_info($file, $settings) {
public function save_file_info($file, $settings) {
$info = $this->create_info_file($file);
// Save the info file and the actual file.
return $this->_save_file($info, $settings);
@@ -818,7 +815,7 @@ class backup_migrate_destination extends backup_migrate_location {
/**
* Load the file with the given destination specific id and return as a backup_file object.
*/
function load_file($file_id) {
public function load_file($file_id) {
// This must be overriden.
return NULL;
}
@@ -826,7 +823,7 @@ class backup_migrate_destination extends backup_migrate_location {
/**
* Check if a file exists in the given destination.
*/
function file_exists($file_id) {
public function file_exists($file_id) {
// Check if the file exists in the list of available files. Actual destination types may have more efficient ways of doing this.
$files = $this->list_files();
return isset($files[$file_id]);
@@ -835,7 +832,7 @@ class backup_migrate_destination extends backup_migrate_location {
/**
* List all the available files in the given destination with their destination specific id.
*/
function list_files() {
public function list_files() {
$files = NULL;
if ($this->cache_files) {
$files = $this->file_cache_get();
@@ -846,6 +843,7 @@ class backup_migrate_destination extends backup_migrate_location {
if ($this->cache_files) {
$this->file_cache_set($files);
}
_backup_migrate_temp_files_delete();
}
$out = array();
@@ -863,22 +861,21 @@ class backup_migrate_destination extends backup_migrate_location {
/**
* List all the available files in the given destination with their destination specific id.
*/
function count_files() {
public function count_files() {
return count($this->list_files());
}
/**
* List all the available files in the given destination with their destination specific id.
*/
function _list_files() {
public function _list_files() {
return array();
}
/**
* Load up the file's metadata from the accompanying .info file if applicable.
*/
function load_files_info($files) {
public function load_files_info($files) {
foreach ($files as $key => $file) {
// See if there is an info file with the same name as the backup.
if (isset($files[$key . '.info'])) {
@@ -887,7 +884,7 @@ class backup_migrate_destination extends backup_migrate_location {
// Allow the stored metadata to override the detected metadata.
unset($info['filename']);
$file->file_info = $info + $file->file_info;
// Remove the metadata file from the list
// Remove the metadata file from the list.
unset($files[$key . '.info']);
}
@@ -896,14 +893,13 @@ class backup_migrate_destination extends backup_migrate_location {
$file->info_set('remote', $this->get('remote'));
}
return $files;
}
/**
* Create an ini file and write the meta data.
*/
function create_info_file($file) {
public function create_info_file($file) {
$info = $this->_file_info_file($file);
$data = _backup_migrate_array_to_ini($file->file_info);
$info->put_contents($data);
@@ -913,7 +909,7 @@ class backup_migrate_destination extends backup_migrate_location {
/**
* Create the info file object.
*/
function _file_info_file($file) {
public function _file_info_file($file) {
$info = new backup_file(array('filename' => $this->_file_info_filename($file->file_id())));
return $info;
}
@@ -921,24 +917,23 @@ class backup_migrate_destination extends backup_migrate_location {
/**
* Determine the file name of the info file for a file.
*/
function _file_info_filename($file_id) {
public function _file_info_filename($file_id) {
return $file_id . '.info';
}
/**
* Cache the file list.
*/
function file_cache_set($files) {
cache_set('backup_migrate_file_list:'. $this->get_id(), $files, 'cache', time() + $this->cache_expire);
public 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() {
public function file_cache_get() {
backup_migrate_include('files');
$cache = cache_get('backup_migrate_file_list:'. $this->get_id());
$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;
@@ -950,7 +945,7 @@ class backup_migrate_destination extends backup_migrate_location {
/**
* Retrieve the file list.
*/
function file_cache_clear() {
public function file_cache_clear() {
if ($this->cache_files) {
$this->file_cache_set(NULL);
}
@@ -959,7 +954,7 @@ class backup_migrate_destination extends backup_migrate_location {
/**
* Delete the file with the given destination specific id.
*/
function delete_file($file_id) {
public function delete_file($file_id) {
$this->file_cache_clear();
$this->_delete_file($file_id);
$this->_delete_file($this->_file_info_filename($file_id));
@@ -968,14 +963,14 @@ class backup_migrate_destination extends backup_migrate_location {
/**
* Delete the file with the given destination specific id.
*/
function _delete_file($file_id) {
public function _delete_file($file_id) {
// This must be overriden.
}
/**
* Get the edit form for the item.
*/
function edit_form() {
public function edit_form() {
if (get_class($this) !== 'backup_migrate_destination') {
$form = parent::edit_form();
$form['subtype'] = array(
@@ -990,17 +985,17 @@ class backup_migrate_destination extends backup_migrate_location {
'title' => t('Offsite Destinations'),
'description' => t('For the highest level of protection, set up an offsite backup destination in a location separate from your website.'),
'items' => array(),
),
),
'local' => array(
'title' => t('Local Destinations'),
'description' => t('Local backups are quick and convenient but do not provide the additional safety of offsite backups.'),
'items' => array(),
),
),
'other' => array(
'title' => t('Other Destinations'),
'description' => t('These destinations have not been classified because they were created for Backup and Migrate version 2. They may not work correctly with this version.'),
'items' => array(),
),
),
);
@@ -1009,8 +1004,8 @@ class backup_migrate_destination extends backup_migrate_location {
foreach ($types as $key => $type) {
if (@$type['can_create']) {
$type_url_str = str_replace('_', '-', $key);
$out = '<dt>'. l($type['type_name'], $path . "/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>';
$out = '<dt>' . l($type['type_name'], $path . "/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>';
if (!empty($type['local'])) {
$items['local']['items'][] = $out;
@@ -1027,7 +1022,7 @@ class backup_migrate_destination extends backup_migrate_location {
$output = '<p>' . t('Choose the type of destination you would like to create:') . '</p>';
foreach ($items as $group) {
if (count($group['items'])) {
$group['body'] = '<dl>'. implode('', $group['items']) .'</dl>';
$group['body'] = '<dl>' . implode('', $group['items']) . '</dl>';
$output .= theme('backup_migrate_group', $group);
}
}
@@ -1046,27 +1041,27 @@ class backup_migrate_destination extends backup_migrate_location {
/**
* Get the message to send to the user when confirming the deletion of the item.
*/
function delete_confirm_message() {
public 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()));
}
/**
* Get a boolean representing if the destination is remote or local.
*/
function get_remote() {
public function get_remote() {
return $this->op('remote backup');
}
/**
* Get the action links for a destination.
*/
function get_action_links() {
public function get_action_links() {
$out = parent::get_action_links();
$item_id = $this->get_id();
// Don't display the download/delete/restore ops if they are not available for this destination.
if ($this->op('list files') && user_access("access backup files")) {
$out = array('list files' => l(t("list files"), $this->get_settings_path() . '/list/files/'. $item_id)) + $out;
$out = array('list files' => l(t("list files"), $this->get_settings_path() . '/list/files/' . $item_id)) + $out;
}
if (!$this->op('configure') || !user_access('administer backup and migrate')) {
unset($out['edit']);
@@ -1077,7 +1072,7 @@ class backup_migrate_destination extends backup_migrate_location {
/**
* Get the action links for a file on a given destination.
*/
function get_file_links($file_id) {
public function get_file_links($file_id) {
$out = array();
// Don't display the download/delete/restore ops if they are not available for this destination.
@@ -1088,13 +1083,13 @@ class backup_migrate_destination extends backup_migrate_location {
$destination_id = $this->get_id();
if ($can_read && user_access("access backup files")) {
$out[] = l(t("download"), $path . '/downloadfile/'. $destination_id .'/'. $file_id);
$out[] = l(t("download"), $path . '/downloadfile/' . $destination_id . '/' . $file_id);
}
if ($can_read && user_access("restore from backup")) {
$out[] = l(t("restore"), $path . '/list/restorefile/' . $destination_id .'/'. $file_id);
$out[] = l(t("restore"), $path . '/list/restorefile/' . $destination_id . '/' . $file_id);
}
if ($can_delete && user_access("delete backup files")) {
$out[] = l(t("delete"), $path . '/list/deletefile/' . $destination_id .'/'. $file_id);
$out[] = l(t("delete"), $path . '/list/deletefile/' . $destination_id . '/' . $file_id);
}
return $out;
}
@@ -1102,55 +1097,55 @@ class backup_migrate_destination extends backup_migrate_location {
/**
* Determine if we can read the given file.
*/
function can_read_file($file_id) {
public function can_read_file($file_id) {
return $this->op('restore');
}
/**
* Determine if we can read the given file.
*/
function can_delete_file($file_id) {
public function can_delete_file($file_id) {
return $this->op('delete');
}
/**
* Get the form for the settings for this destination type.
*/
function settings_default() {
public function settings_default() {
return array();
}
/**
* Get the form for the settings for this destination.
*/
function settings_form($form) {
public function settings_form($form) {
return $form;
}
/**
* Validate the form for the settings for this destination.
*/
function settings_form_validate($form_values) {
public function settings_form_validate($form_values) {
}
/**
* Submit the settings form. Any values returned will be saved.
*/
function settings_form_submit($form_values) {
public function settings_form_submit($form_values) {
return $form_values;
}
/**
* Check that a destination is valid.
*/
function confirm_destination() {
return true;
public function confirm_destination() {
return TRUE;
}
/**
* Add the menu items specific to the destination type.
*/
function get_menu_items() {
public function get_menu_items() {
$items = parent::get_menu_items();
$path = $this->get_settings_path();
@@ -1189,7 +1184,6 @@ class backup_migrate_destination extends backup_migrate_location {
return $items;
}
}
/**
@@ -1199,21 +1193,21 @@ class backup_migrate_destination_remote extends backup_migrate_destination {
/**
* The location is a URI so parse it and store the parts.
*/
function get_location() {
public function get_location() {
return $this->url(FALSE);
}
/**
* The location to display is the url without the password.
*/
function get_display_location() {
public function get_display_location() {
return $this->url(TRUE);
}
/**
* Return the location with the password.
*/
function set_location($location) {
public function set_location($location) {
$this->location = $location;
$this->set_url($location);
}
@@ -1221,7 +1215,7 @@ class backup_migrate_destination_remote extends backup_migrate_destination {
/**
* Destination configuration callback.
*/
function edit_form() {
public function edit_form() {
$form = parent::edit_form();
$form['scheme'] = array(
"#type" => "textfield",
@@ -1271,10 +1265,10 @@ class backup_migrate_destination_remote extends backup_migrate_destination {
/**
* Submit the configuration form. Glue the url together and add the old password back if a new one was not specified.
*/
function edit_form_submit($form, &$form_state) {
public 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);
}
}
}
File diff suppressed because it is too large Load Diff
@@ -1,6 +1,5 @@
<?php
/**
* @file
* Functions to handle the s3 backup destination.
@@ -12,15 +11,14 @@
* @ingroup backup_migrate_destinations
*/
class backup_migrate_destination_s3 extends backup_migrate_destination_remote {
var $supported_ops = array('scheduled backup', 'manual backup', 'remote backup', 'restore', 'list files', 'configure', 'delete');
var $s3 = NULL;
var $cache_files = TRUE;
public $supported_ops = array('scheduled backup', 'manual backup', 'remote backup', 'restore', 'list files', 'configure', 'delete');
public $s3 = NULL;
public $cache_files = TRUE;
/**
* Save to to the s3 destination.
*/
function _save_file($file, $settings) {
public 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)) {
@@ -33,7 +31,7 @@ class backup_migrate_destination_s3 extends backup_migrate_destination_remote {
/**
* Load from the s3 destination.
*/
function load_file($file_id) {
public function load_file($file_id) {
backup_migrate_include('files');
$file = new backup_file(array('filename' => $file_id));
if ($s3 = $this->s3_object()) {
@@ -48,7 +46,7 @@ class backup_migrate_destination_s3 extends backup_migrate_destination_remote {
/**
* Delete from the s3 destination.
*/
function _delete_file($file_id) {
public function _delete_file($file_id) {
if ($s3 = $this->s3_object()) {
$s3->deleteObject($this->get_bucket(), $this->remote_path($file_id));
}
@@ -57,12 +55,12 @@ class backup_migrate_destination_s3 extends backup_migrate_destination_remote {
/**
* List all files from the s3 destination.
*/
function _list_files() {
public function _list_files() {
backup_migrate_include('files');
$files = array();
if ($s3 = $this->s3_object()) {
$s3_files = $s3->getBucket($this->get_bucket(), $this->get_subdir());
foreach ((array)$s3_files as $id => $file) {
foreach ((array) $s3_files as $id => $file) {
$info = array(
'filename' => $this->local_path($file['name']),
'filesize' => $file['size'],
@@ -77,15 +75,14 @@ class backup_migrate_destination_s3 extends backup_migrate_destination_remote {
/**
* Get the form for the settings for this filter.
*/
function edit_form() {
public function edit_form() {
// Check for the library.
$this->s3_object();
$form = parent::edit_form();
$form['scheme']['#type'] = 'value';
$form['scheme']['#value'] = 'https';
$form['host']['#type'] = 'value';
$form['host']['#value'] = 's3.amazonaws.com';
$form['host']['#default_value'] = @$this->dest_url['host'] ? $this->dest_url['host'] : 's3.amazonaws.com';
$form['path']['#title'] = 'S3 Bucket';
$form['path']['#default_value'] = $this->get_bucket();
@@ -98,7 +95,7 @@ class backup_migrate_destination_s3 extends backup_migrate_destination_remote {
'#type' => 'textfield',
'#title' => t('Subdirectory'),
'#default_value' => $this->get_subdir(),
'#weight' => 25
'#weight' => 25,
);
$form['settings']['#weight'] = 50;
@@ -108,11 +105,10 @@ class backup_migrate_destination_s3 extends backup_migrate_destination_remote {
/**
* Submit the form for the settings for the s3 destination.
*/
function edit_form_submit($form, &$form_state) {
public function edit_form_submit($form, &$form_state) {
// Append the subdir onto the path.
if (!empty($form_state['values']['subdir'])) {
$form_state['values']['path'] .= '/'. trim($form_state['values']['subdir'], '/');
$form_state['values']['path'] .= '/' . trim($form_state['values']['subdir'], '/');
}
parent::edit_form_submit($form, $form_state);
}
@@ -120,9 +116,9 @@ class backup_migrate_destination_s3 extends backup_migrate_destination_remote {
/**
* Generate a filepath with the correct prefix.
*/
function remote_path($path) {
public function remote_path($path) {
if ($subdir = $this->get_subdir()) {
$path = $subdir .'/'. $path;
$path = $subdir . '/' . $path;
}
return $path;
}
@@ -130,9 +126,9 @@ class backup_migrate_destination_s3 extends backup_migrate_destination_remote {
/**
* Generate a filepath with the correct prefix.
*/
function local_path($path) {
public function local_path($path) {
if ($subdir = $this->get_subdir()) {
$path = str_replace($subdir .'/', '', $path);
$path = str_replace($subdir . '/', '', $path);
}
return $path;
}
@@ -140,7 +136,7 @@ class backup_migrate_destination_s3 extends backup_migrate_destination_remote {
/**
* Get the bucket which is the first part of the path.
*/
function get_bucket() {
public function get_bucket() {
$parts = explode('/', @$this->dest_url['path']);
return $parts[0];
}
@@ -148,7 +144,7 @@ class backup_migrate_destination_s3 extends backup_migrate_destination_remote {
/**
* Get the bucket which is the first part of the path.
*/
function get_subdir() {
public function get_subdir() {
// Support the older style of subdir saving.
if ($subdir = $this->settings('subdir')) {
return $subdir;
@@ -158,7 +154,7 @@ class backup_migrate_destination_s3 extends backup_migrate_destination_remote {
return implode('/', array_filter($parts));
}
function s3_object() {
public function s3_object() {
// Try to use libraries module if available to find the path.
if (function_exists('libraries_get_path')) {
$library_paths[] = libraries_get_path('s3-php5-curl');
@@ -169,11 +165,16 @@ class backup_migrate_destination_s3 extends backup_migrate_destination_remote {
$library_paths[] = drupal_get_path('module', 'backup_migrate') . '/includes/s3-php5-curl';
$library_paths[] = drupal_get_path('module', 'backup_migrate') . '/includes';
foreach($library_paths as $path) {
foreach ($library_paths as $path) {
if (file_exists($path . '/S3.php')) {
require_once $path . '/S3.php';
if (!$this->s3 && !empty($this->dest_url['user'])) {
$this->s3 = new S3($this->dest_url['user'], $this->dest_url['pass']);
// The hostname can be overridden.
$host = 's3.amazonaws.com';
if (isset($this->dest_url['host'])) {
$host = $this->dest_url['host'];
}
$this->s3 = new S3($this->dest_url['user'], $this->dest_url['pass'], FALSE, $host);
}
return $this->s3;
}
@@ -181,4 +182,5 @@ class backup_migrate_destination_s3 extends backup_migrate_destination_remote {
drupal_set_message(t('Due to drupal.org code hosting policies, the S3 library needed to use an S3 destination is no longer distributed with this module. You must download the library from !link and place it in one of these locations: %locations.', array('%locations' => implode(', ', $library_paths), '!link' => l('http://undesigned.org.za/2007/10/22/amazon-s3-php-class', 'http://undesigned.org.za/2007/10/22/amazon-s3-php-class'))), 'error', FALSE);
return NULL;
}
}
@@ -1,6 +1,5 @@
<?php
/**
* @file
* General file handling code for Backup and Migrate.
@@ -12,7 +11,7 @@ define('BACKUP_MIGRATE_FILENAME_MAXLENGTH', 255);
* Add a file to the temporary files list for deletion when we're done.
*/
function backup_migrate_temp_files_add($filepath = NULL) {
static $files = array();
$files = &drupal_static('backup_migrate_temp_files_add', array());
if (!$filepath) {
return $files;
}
@@ -51,7 +50,7 @@ function _backup_migrate_temp_files_delete() {
}
/**
* Delete a temporary file or folder
* Delete a temporary file or folder.
*/
function _backup_migrate_temp_files_delete_file($file) {
if (file_exists($file) && (is_writable($file) || is_link($file))) {
@@ -62,6 +61,7 @@ function _backup_migrate_temp_files_delete_file($file) {
_backup_migrate_temp_files_delete_file("$dir/$file");
}
}
closedir($handle);
rmdir($dir);
}
else {
@@ -84,6 +84,7 @@ function _backup_migrate_move_files($from, $to) {
_backup_migrate_move_files("$from/$file", "$to/$file");
}
}
closedir($handle);
}
else {
rename($from, $to);
@@ -105,7 +106,7 @@ function backup_migrate_temp_directory() {
}
// Use a full path so that the files can be deleted during the shutdown function if needed.
$file = $tmp .'/'. uniqid('backup_migrate_');
$file = $tmp . '/' . uniqid('backup_migrate_');
mkdir($file);
backup_migrate_temp_files_add($file);
return $file;
@@ -136,7 +137,7 @@ function _backup_migrate_filename_append_prepare($filename, $append_str) {
}
return $filename;
}
/**
* Construct a filename using token and some cleaning.
*/
@@ -144,17 +145,17 @@ function _backup_migrate_construct_filename($settings) {
// Get the raw filename from the settings.
$filename = $settings->filename;
// Replace any tokens
// Replace any tokens.
if (module_exists('token') && function_exists('token_replace')) {
$filename = token_replace($filename);
}
// Remove illegal characters
// Remove illegal characters.
$filename = _backup_migrate_clean_filename($filename);
// Generate a timestamp if needed.
$timestamp = '';
if ($settings->append_timestamp && $settings->timestamp_format) {
if ($settings->append_timestamp == 1 && $settings->timestamp_format) {
$timestamp = format_date(time(), 'custom', $settings->timestamp_format);
}
@@ -178,7 +179,8 @@ function _backup_migrate_default_filename() {
return '[site:name]';
}
else {
// Cleaning the string isn't strictly necessary but it looks better in the settings field.
// Cleaning the string isn't strictly necessary but it looks better in the
// settings field.
return _backup_migrate_clean_filename(variable_get('site_name', "backup_migrate"));
}
}
@@ -203,17 +205,17 @@ function _backup_migrate_file_dispose_buffer($buffer) {
* A backup file which allows for saving to and reading from the server.
*/
class backup_file {
var $file_info = array();
var $type = array();
var $ext = array();
var $path = "";
var $name = "";
var $handle = NULL;
public $file_info = array();
public $type = array();
public $ext = array();
public $path = "";
public $name = "";
public $handle = NULL;
/**
* Construct a file object given a file path, or create a temp file for writing.
*/
function backup_file($params = array()) {
public function __construct($params = array()) {
if (isset($params['filepath']) && file_exists($params['filepath'])) {
$this->set_filepath($params['filepath']);
}
@@ -226,7 +228,7 @@ class backup_file {
/**
* Get the file_id if the file has been saved to a destination.
*/
function file_id() {
public function file_id() {
// The default file_id is the filename. Destinations can override the file_id if needed.
return isset($this->file_info['file_id']) ? $this->file_info['file_id'] : $this->filename();
}
@@ -234,14 +236,17 @@ class backup_file {
/**
* Get the current filepath.
*/
function filepath() {
return drupal_realpath($this->path);
public function filepath() {
if ($filepath = drupal_realpath($this->path)) {
return $filepath;
}
return $this->path;
}
/**
* Get the final filename.
*/
function filename($name = NULL) {
public function filename($name = NULL) {
if ($name) {
$this->name = $name;
}
@@ -253,11 +258,11 @@ class backup_file {
/**
* Set the current filepath.
*/
function set_filepath($path) {
public function set_filepath($path) {
$this->path = $path;
$params = array(
'filename' => basename($path),
'file_id' => basename($path)
'file_id' => basename($path),
);
if (file_exists($path)) {
$params['filesize'] = filesize($path);
@@ -269,56 +274,55 @@ class backup_file {
/**
* Get one or all pieces of info for the file.
*/
function info($key = NULL) {
public function info($key = NULL) {
if ($key) {
return @$this->file_info[$key];
}
return $this->file_info;
}
/**
* Get one or all pieces of info for the file.
*/
function info_set($key, $value) {
public function info_set($key, $value) {
$this->file_info[$key] = $value;
}
/**
* Get the file extension.
*/
function extension() {
public function extension() {
return implode(".", $this->ext);
}
/**
* Get the file type.
*/
function type() {
public function type() {
return $this->type;
}
/**
* Get the file mimetype.
*/
function mimetype() {
public function mimetype() {
return @$this->type['filemime'] ? $this->type['filemime'] : 'application/octet-stream';
}
/**
* Get the file mimetype.
*/
function type_id() {
public function type_id() {
return @$this->type['id'];
}
function filesize() {
public function filesize() {
if (empty($this->file_info['filesize'])) {
$this->calculate_filesize();
}
return $this->file_info['filesize'];
}
function calculate_filesize() {
public function calculate_filesize() {
$this->file_info['filesize'] = '';
if (!empty($this->path) && file_exists($this->path)) {
$this->file_info['filesize'] = filesize($this->path);
@@ -328,28 +332,28 @@ class backup_file {
/**
* Can this file be used to backup to.
*/
function can_backup() {
public function can_backup() {
return @$this->type['backup'];
}
/**
* Can this file be used to restore to.
*/
function can_restore() {
public function can_restore() {
return @$this->type['restore'];
}
/**
* Can this file be used to restore to.
*/
function is_recognized_type() {
public function is_recognized_type() {
return @$this->type['restore'] || @$this->type['backup'];
}
/**
* Open a file for reading or writing.
*/
function open($write = FALSE, $binary = FALSE) {
public function open($write = FALSE, $binary = FALSE) {
if (!$this->handle) {
$path = $this->filepath();
@@ -374,7 +378,7 @@ class backup_file {
/**
* Close a file when we're done reading/writing.
*/
function close() {
public function close() {
fclose($this->handle);
$this->handle = NULL;
}
@@ -382,7 +386,7 @@ class backup_file {
/**
* Write a line to the file.
*/
function write($data) {
public function write($data) {
if (!$this->handle) {
$this->handle = $this->open(TRUE);
}
@@ -394,7 +398,7 @@ class backup_file {
/**
* Read a line from the file.
*/
function read($size = NULL) {
public function read($size = NULL) {
if (!$this->handle) {
$this->handle = $this->open();
}
@@ -407,14 +411,14 @@ class backup_file {
/**
* Write data to the file.
*/
function put_contents($data) {
public function put_contents($data) {
file_put_contents($this->filepath(), $data);
}
/**
* Read data from the file.
*/
function get_contents() {
public function get_contents() {
return file_get_contents($this->filepath());
}
@@ -422,10 +426,10 @@ class backup_file {
* Transfer file using http to client. Similar to the built in file_transfer,
* but it calls module_invoke_all('exit') so that temp files can be deleted.
*/
function transfer() {
public function transfer() {
$headers = array(
array('key' => 'Content-Type', 'value' => $this->mimetype()),
array('key' => 'Content-Disposition', 'value' => 'attachment; filename="'. $this->filename() .'"'),
array('key' => 'Content-Disposition', 'value' => 'attachment; filename="' . $this->filename() . '"'),
);
// In some circumstances, web-servers will double compress gzipped files.
// This may help aleviate that issue by disabling mod-deflate.
@@ -470,7 +474,7 @@ class backup_file {
/**
* Push a file extension onto the file and return the previous file path.
*/
function push_type($extension) {
public function push_type($extension) {
$types = _backup_migrate_filetypes();
if ($type = @$types[$extension]) {
$this->push_filetype($type);
@@ -484,7 +488,7 @@ class backup_file {
/**
* Push a file extension onto the file and return the previous file path.
*/
function pop_type() {
public function pop_type() {
$out = new backup_file(array('filepath' => $this->filepath()));
$this->pop_filetype();
$this->temporary_file();
@@ -494,7 +498,7 @@ class backup_file {
/**
* Set the current file type.
*/
function set_filetype($type) {
public function set_filetype($type) {
$this->type = $type;
$this->ext = array($type['extension']);
}
@@ -502,7 +506,7 @@ class backup_file {
/**
* Set the current file type.
*/
function push_filetype($type) {
public function push_filetype($type) {
$this->ext[] = $type['extension'];
$this->type = $type;
}
@@ -510,7 +514,7 @@ class backup_file {
/**
* Pop the current file type.
*/
function pop_filetype() {
public function pop_filetype() {
array_pop($this->ext);
$this->detect_filetype_from_extension();
}
@@ -518,7 +522,7 @@ class backup_file {
/**
* Set the file info.
*/
function set_file_info($file_info) {
public function set_file_info($file_info) {
$this->file_info = $file_info;
$this->ext = explode('.', @$this->file_info['filename']);
@@ -533,7 +537,7 @@ class backup_file {
/**
* Get the filetype info of the given file, or false if the file is not a valid type.
*/
function detect_filetype_from_extension() {
public function detect_filetype_from_extension() {
$ext = end($this->ext);
$this->type = array();
$types = _backup_migrate_filetypes();
@@ -548,17 +552,17 @@ class backup_file {
/**
* Get a temporary file name with path.
*/
function temporary_file() {
public function temporary_file() {
$file = drupal_tempnam('temporary://', 'backup_migrate_');
// Add the version without the extension. The tempnam function creates this for us.
backup_migrate_temp_files_add($file);
if ($this->extension()) {
$file .= '.'. $this->extension();
$file .= '.' . $this->extension();
// Add the version with the extension. This is the one we will actually use.
backup_migrate_temp_files_add($file);
}
$this->path = $file;
}
}
}
@@ -1,9 +1,10 @@
<?php
/**
* @file
* This filter performs tha actual backup or restore operation. Not technically a filter per-se, but it does need to fit in the call chain.
* This filter performs tha actual backup or restore operation.
*
* Not technically a filter per-se, but it does need to fit in the call chain.
*/
/**
@@ -12,12 +13,12 @@
* @ingroup backup_migrate_filters
*/
class backup_migrate_filter_backup_restore extends backup_migrate_filter {
var $op_weights = array('backup' => 0, 'restore' => 0);
public $op_weights = array('backup' => 0, 'restore' => 0);
/**
* Get the default destinations for this filter.
*/
function destinations() {
public function destinations() {
$out = array();
foreach ($this->_get_destination_types() as $destination) {
if (method_exists($destination, 'destinations')) {
@@ -30,7 +31,7 @@ class backup_migrate_filter_backup_restore extends backup_migrate_filter {
/**
* Get the default sources for this filter.
*/
function sources() {
public function sources() {
$out = array();
foreach ($this->_get_source_types() as $type) {
if (method_exists($type, 'sources')) {
@@ -43,7 +44,7 @@ class backup_migrate_filter_backup_restore extends backup_migrate_filter {
/**
* Get the default backup settings for this filter.
*/
function backup_settings_default() {
public function backup_settings_default() {
backup_migrate_include('sources');
$out = array();
foreach (backup_migrate_get_sources() as $source) {
@@ -55,7 +56,7 @@ class backup_migrate_filter_backup_restore extends backup_migrate_filter {
/**
* Get the form for the settings for this filter.
*/
function backup_settings_form_validate($form, &$form_state) {
public function backup_settings_form_validate($form, &$form_state) {
foreach ($this->_get_destination_types() as $destination) {
$destination->backup_settings_form_validate($form, $form_state);
}
@@ -64,7 +65,7 @@ class backup_migrate_filter_backup_restore extends backup_migrate_filter {
/**
* Submit the settings form. Any values returned will be saved.
*/
function backup_settings_form_submit($form, &$form_state) {
public function backup_settings_form_submit($form, &$form_state) {
foreach ($this->_get_destination_types() as $destination) {
$destination->backup_settings_form_submit($form, $form_state);
}
@@ -73,7 +74,7 @@ class backup_migrate_filter_backup_restore extends backup_migrate_filter {
/**
* Get the default restore settings for this filter.
*/
function restore_settings_default() {
public function restore_settings_default() {
$out = array();
foreach ($this->_get_destination_types() as $destination) {
$out += $destination->restore_settings_default();
@@ -84,13 +85,15 @@ 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) {
public function backup_settings_form($settings) {
backup_migrate_include('sources');
$out = array('sources' => array(
'#tree' => TRUE,
));
foreach (backup_migrate_get_sources() as $source) {
$source_settings = (array)(@$settings['sources'][$source->get_id()]) + $settings;
$out = array(
'sources' => array(
'#tree' => TRUE,
),
);
foreach (backup_migrate_get_sources() as $source) {
$source_settings = (array) (@$settings['sources'][$source->get_id()]) + $settings;
if ($form = $source->backup_settings_form($source_settings)) {
$out['sources'][$source->get_id()] = array(
'#type' => 'fieldset',
@@ -108,7 +111,7 @@ class backup_migrate_filter_backup_restore extends backup_migrate_filter {
/**
* Get the form for the restore settings for this filter.
*/
function restore_settings_form($settings) {
public function restore_settings_form($settings) {
$form = array();
foreach ($this->_get_destination_types() as $destination) {
$destination->restore_settings_form($form, $settings);
@@ -119,7 +122,7 @@ class backup_migrate_filter_backup_restore extends backup_migrate_filter {
/**
* Get the before-backup form for the active sources and destinations.
*/
function before_action_form($op, $settings) {
public function before_action_form($op, $settings) {
$form = array();
$method = 'before_' . $op . '_form';
if ($source = $settings->get_source()) {
@@ -138,7 +141,7 @@ class backup_migrate_filter_backup_restore extends backup_migrate_filter {
/**
* Get the before-backup form for the active sources and destinations.
*/
function before_action_form_validate($op, $settings, $form, $form_state) {
public function before_action_form_validate($op, $settings, $form, $form_state) {
$method = 'before_' . $op . '_form_validate';
foreach ($settings->get_all_locations() as $location) {
if (method_exists($location, $method)) {
@@ -150,7 +153,7 @@ class backup_migrate_filter_backup_restore extends backup_migrate_filter {
/**
* Get the before-backup form for the active sources and destinations.
*/
function before_action_form_submit($op, $settings, $form, $form_state) {
public function before_action_form_submit($op, $settings, $form, $form_state) {
$method = 'before_' . $op . '_form_submit';
foreach ($settings->get_all_locations() as $location) {
if (method_exists($location, $method)) {
@@ -162,7 +165,7 @@ class backup_migrate_filter_backup_restore extends backup_migrate_filter {
/**
* Get the file types supported by this destination.
*/
function file_types() {
public function file_types() {
$types = array();
foreach ($this->_get_destination_types() as $destination) {
$types += $destination->file_types();
@@ -176,10 +179,10 @@ class backup_migrate_filter_backup_restore extends backup_migrate_filter {
/**
* Backup the data from the source specified in the settings.
*/
function backup($file, $settings) {
public function backup($file, $settings) {
if ($source = $settings->get_source()) {
if (!empty($settings->filters['sources'][$source->get_id()])) {
$settings->filters = (array)($settings->filters['sources'][$source->get_id()]) + $settings->filters;
$settings->filters = (array) ($settings->filters['sources'][$source->get_id()]) + $settings->filters;
}
$file = $source->backup_to_file($file, $settings);
@@ -192,10 +195,10 @@ class backup_migrate_filter_backup_restore extends backup_migrate_filter {
/**
* Restore the data from to source specified in the settings.
*/
function restore($file, $settings) {
public function restore($file, $settings) {
if ($source = $settings->get_source()) {
if (!empty($settings->filters['sources'][$source->get_id()])) {
$settings->filters = (array)($settings->filters['sources'][$source->get_id()]) + $settings->filters;
$settings->filters = (array) ($settings->filters['sources'][$source->get_id()]) + $settings->filters;
}
$num = $source->restore_from_file($file, $settings);
return $num ? $file : FALSE;
@@ -205,11 +208,14 @@ class backup_migrate_filter_backup_restore extends backup_migrate_filter {
}
/**
* Get a list of dummy destinations representing each of the available destination types.
* Dummy destinations representing each of the available destination types.
*
* @return array
* All of the available destination types.
*/
function _get_destination_types() {
public function _get_destination_types() {
backup_migrate_include('destinations');
static $destinations = NULL;
$destinations = &drupal_static('backup_migrate_filter_backup_restore::_get_destination_types', NULL);
if (!is_array($destinations)) {
$destinations = array();
$types = backup_migrate_get_destination_subtypes();
@@ -217,7 +223,7 @@ class backup_migrate_filter_backup_restore extends backup_migrate_filter {
foreach ($types as $key => $type) {
// Include the necessary file if specified by the type.
if (!empty($type['file'])) {
require_once './'. $type['file'];
require_once './' . $type['file'];
}
$destinations[] = new $type['class'](array());
}
@@ -226,19 +232,23 @@ class backup_migrate_filter_backup_restore extends backup_migrate_filter {
}
/**
* Get a list of dummy destinations representing each of the available source types.
* Dummy destinations representing each of the available source types.
*
* @return array
* All of the available source types.
*/
function _get_source_types() {
public function _get_source_types() {
backup_migrate_include('sources');
static $sources = NULL;
$sources = &drupal_static('backup_migrate_filter_backup_restore::_get_source_types', NULL);
if (!is_array($sources)) {
$sources = array();
$types = backup_migrate_get_source_subtypes();
// If no (valid) node type has been provided, display a node type overview.
// If no (valid) node type has been provided, display a node type
// overview.
foreach ($types as $key => $type) {
// Include the necessary file if specified by the type.
if (!empty($type['file'])) {
require_once './'. $type['file'];
require_once './' . $type['file'];
}
$sources[] = new $type['class'](array());
}
@@ -1,6 +1,5 @@
<?php
/**
* @file
* A filter for compressing bckups with zip, gz bzip etc.
@@ -12,26 +11,26 @@
* @ingroup backup_migrate_filters
*/
class backup_migrate_filter_compression extends backup_migrate_filter {
var $op_weights = array('backup' => 100, 'restore' => -100);
public $op_weights = array('backup' => 100, 'restore' => -100);
/**
* This function is called on a backup file after the backup has been completed.
*/
function backup($file, $settings) {
public function backup($file, $settings) {
return $this->_backup_migrate_file_compress($file, $settings);
}
/**
* This function is called on a backup file before importing it.
*/
function restore($file, $settings) {
public function restore($file, $settings) {
return $this->_backup_migrate_file_decompress($file, $settings);
}
/**
* Get the form for the settings for this filter.
*/
function backup_settings_default() {
public function backup_settings_default() {
$options = $this->_backup_migrate_get_compression_form_item_options();
return array('compression' => isset($options['gzip']) ? 'gzip' : 'none');
}
@@ -39,7 +38,7 @@ class backup_migrate_filter_compression extends backup_migrate_filter {
/**
* Get the form for the settings for this filter.
*/
function backup_settings_form($settings) {
public function backup_settings_form($settings) {
$form = array();
$compression_options = $this->_backup_migrate_get_compression_form_item_options();
$form['file']['compression'] = array(
@@ -54,7 +53,7 @@ class backup_migrate_filter_compression extends backup_migrate_filter {
/**
* Return a list of backup filetypes.
*/
function file_types() {
public function file_types() {
return array(
"gzip" => array(
"extension" => "gz",
@@ -86,7 +85,7 @@ class backup_migrate_filter_compression extends backup_migrate_filter {
/**
* Get the compression options as an options array for a form item.
*/
function _backup_migrate_get_compression_form_item_options() {
public function _backup_migrate_get_compression_form_item_options() {
$compression_options = array("none" => t("No Compression"));
if (@function_exists("gzencode")) {
$compression_options['gzip'] = t("GZip");
@@ -103,15 +102,14 @@ class backup_migrate_filter_compression extends backup_migrate_filter {
/**
* Gzip encode a file.
*/
function _backup_migrate_gzip_encode($source, $dest, $level = 9, $settings) {
public function _backup_migrate_gzip_encode($source, $dest, $level = 9, $settings) {
$success = FALSE;
// Try command line gzip first.
if (!empty($settings->filters['use_cli'])) {
$success = backup_migrate_exec("gzip -c -$level %input > %dest", array('%input' => $source, '%dest' => $dest, '%level' => $level));
}
if (!$success && @function_exists("gzopen")) {
if (($fp_out = gzopen($dest, 'wb'. $level)) && ($fp_in = fopen($source, 'rb'))) {
if (($fp_out = gzopen($dest, 'wb' . $level)) && ($fp_in = fopen($source, 'rb'))) {
while (!feof($fp_in)) {
gzwrite($fp_out, fread($fp_in, 1024 * 512));
}
@@ -126,7 +124,7 @@ class backup_migrate_filter_compression extends backup_migrate_filter {
/**
* Gzip decode a file.
*/
function _backup_migrate_gzip_decode($source, $dest, $settings) {
public function _backup_migrate_gzip_decode($source, $dest, $settings) {
$success = FALSE;
if (!empty($settings->filters['use_cli'])) {
@@ -149,7 +147,7 @@ class backup_migrate_filter_compression extends backup_migrate_filter {
/**
* Bzip encode a file.
*/
function _backup_migrate_bzip_encode($source, $dest) {
public function _backup_migrate_bzip_encode($source, $dest) {
$success = FALSE;
if (@function_exists("bzopen")) {
if (($fp_out = bzopen($dest, 'w')) && ($fp_in = fopen($source, 'rb'))) {
@@ -170,7 +168,7 @@ class backup_migrate_filter_compression extends backup_migrate_filter {
/**
* Bzip decode a file.
*/
function _backup_migrate_bzip_decode($source, $dest) {
public function _backup_migrate_bzip_decode($source, $dest) {
$success = FALSE;
if (@function_exists("bzopen")) {
if (($fp_out = fopen($dest, 'w')) && ($fp_in = bzopen($source, 'r'))) {
@@ -191,10 +189,10 @@ class backup_migrate_filter_compression extends backup_migrate_filter {
/**
* Zip encode a file.
*/
function _backup_migrate_zip_encode($source, $dest, $filename) {
public function _backup_migrate_zip_encode($source, $dest, $filename) {
$success = FALSE;
if (class_exists('ZipArchive')) {
$zip = new ZipArchive;
$zip = new ZipArchive();
$res = $zip->open($dest, constant("ZipArchive::CREATE"));
if ($res === TRUE) {
$zip->addFile($source, $filename);
@@ -207,10 +205,10 @@ class backup_migrate_filter_compression extends backup_migrate_filter {
/**
* Zip decode a file.
*/
function _backup_migrate_zip_decode($source, $dest) {
public function _backup_migrate_zip_decode($source, $dest) {
$success = FALSE;
if (class_exists('ZipArchive')) {
$zip = new ZipArchive;
$zip = new ZipArchive();
if (($fp_out = fopen($dest, "w")) && ($zip->open($source))) {
$filename = ($zip->getNameIndex(0));
if ($fp_in = $zip->getStream($filename)) {
@@ -230,7 +228,7 @@ class backup_migrate_filter_compression extends backup_migrate_filter {
* Compress a file with the given settings.
* Also updates settings to reflect new file mime and file extension.
*/
function _backup_migrate_file_compress($file, $settings) {
public function _backup_migrate_file_compress($file, $settings) {
switch ($settings->filters['compression']) {
case "gzip":
$from = $file->push_type('gzip');
@@ -264,7 +262,7 @@ class backup_migrate_filter_compression extends backup_migrate_filter {
* Decompress a file with the given settings.
* Also updates settings to reflect new file mime and file extension.
*/
function _backup_migrate_file_decompress($file, $settings) {
public function _backup_migrate_file_decompress($file, $settings) {
$success = FALSE;
switch ($file->type_id()) {
@@ -294,5 +292,5 @@ class backup_migrate_filter_compression extends backup_migrate_filter {
}
return $success ? $file : NULL;
}
}
}
@@ -1,6 +1,5 @@
<?php
/**
* @file
* A filter for encrypting bckups with AES.
@@ -12,33 +11,33 @@
* @ingroup backup_migrate_filters
*/
class backup_migrate_filter_encryption extends backup_migrate_filter {
var $op_weights = array('backup' => 170, 'restore' => -170);
public $op_weights = array('backup' => 170, 'restore' => -170);
/**
* This function is called on a backup file after the backup has been completed.
* Called on a backup file after the backup has been completed.
*/
function backup($file, $settings) {
public function backup($file, $settings) {
return $this->file_encrypt($file, $settings);
}
/**
* This function is called on a backup file before importing it.
* Called on a backup file before importing it.
*/
function restore($file, $settings) {
public function restore($file, $settings) {
return $this->file_decrypt($file);
}
/**
* Get the form for the settings for this filter.
* Gets the form for the settings for this filter.
*/
function backup_settings_default() {
public function backup_settings_default() {
return array('encryption' => 'none');
}
/**
* Get the form for the settings for this filter.
* Gets the form for the settings for this filter.
*/
function backup_settings_form($settings) {
public function backup_settings_form($settings) {
$form = array();
$options = $this->_backup_migrate_get_encryption_form_item_options();
if (count($options) > 1) {
@@ -62,9 +61,9 @@ class backup_migrate_filter_encryption extends backup_migrate_filter {
}
/**
* Return a list of backup filetypes.
* Returns a list of backup filetypes.
*/
function file_types() {
public function file_types() {
return array(
"aes" => array(
"extension" => "aes",
@@ -76,9 +75,9 @@ class backup_migrate_filter_encryption extends backup_migrate_filter {
}
/**
* Get the compression options as an options array for a form item.
* Gets the compression options as an options array for a form item.
*/
function _backup_migrate_get_encryption_form_item_options() {
public function _backup_migrate_get_encryption_form_item_options() {
$options = array();
$options = array('' => t('No Encryption'));
if (@function_exists("aes_encrypt")) {
@@ -88,13 +87,14 @@ class backup_migrate_filter_encryption extends backup_migrate_filter {
}
/**
* AES encrypt a file.
* AES encrypts a file.
*/
function aes_encrypt($source, $dest) {
public function aes_encrypt($source, $dest) {
$success = FALSE;
if (function_exists('aes_encrypt')) {
if ($data = $source->get_contents()) {
// Add a marker to the end of the data so we can trim the padding on decrpypt.
// Add a marker to the end of the data so we can trim the padding on
// decrpypt.
$data = pack("a*H2", $data, "80");
if ($data = aes_encrypt($data, FALSE)) {
$dest->put_contents($data);
@@ -106,9 +106,9 @@ class backup_migrate_filter_encryption extends backup_migrate_filter {
}
/**
* Gzip decode a file.
* AES decodes a file.
*/
function aes_decrypt($source, $dest) {
public function aes_decrypt($source, $dest) {
$success = FALSE;
if (function_exists('aes_decrypt')) {
if ($data = $source->get_contents()) {
@@ -124,10 +124,11 @@ class backup_migrate_filter_encryption extends backup_migrate_filter {
}
/**
* Compress a file with the given settings.
* Also updates settings to reflect new file mime and file extension.
* Compresses a file with the given settings.
*
* Also updates settings to reflect new file mime and file extension.
*/
function file_encrypt($file, $settings) {
public function file_encrypt($file, $settings) {
if (!empty($settings->filters['encryption'])) {
switch ($settings->filters['encryption']) {
case "aes":
@@ -146,10 +147,11 @@ class backup_migrate_filter_encryption extends backup_migrate_filter {
}
/**
* Decompress a file with the given settings.
* Also updates settings to reflect new file mime and file extension.
* Decompresses a file with the given settings.
*
* Also updates settings to reflect new file mime and file extension.
*/
function file_decrypt($file) {
public function file_decrypt($file) {
$success = FALSE;
if ($file) {
switch ($file->type_id()) {
@@ -157,11 +159,11 @@ class backup_migrate_filter_encryption extends backup_migrate_filter {
$from = $file->pop_type();
$success = $this->aes_decrypt($from, $file);
break;
default:
return $file;
break;
}
}
if (!$success) {
if (function_exists('aes_decrypt')) {
_backup_migrate_message("Could not decrpyt backup file. Please check that the file is valid and that the encryption key of the server matches the server that created the backup.", array(), 'error');
@@ -173,5 +175,5 @@ class backup_migrate_filter_encryption extends backup_migrate_filter {
}
return $success ? $file : NULL;
}
}
}
@@ -1,25 +1,24 @@
<?php
/**
* @file
* All of the filter handling code needed for Backup and Migrate.
*/
/**
* Get the available destination types.
* Gets the available destination types.
*/
function backup_migrate_get_filters($op = NULL) {
static $filters = NULL;
$filters = &drupal_static('backup_migrate_get_filters', NULL);
if ($filters === NULL) {
$filters = array();
$definitions = module_invoke_all('backup_migrate_filters');
foreach ($definitions as $definition) {
// Include the necessary file if specified by the filter.
if (!empty($definition['file'])) {
require_once './'. $definition['file'];
require_once './' . $definition['file'];
}
$filters[] = new $definition['class'];
$filters[] = new $definition['class']();
}
}
$sort = array();
@@ -32,37 +31,37 @@ function backup_migrate_get_filters($op = NULL) {
}
/**
* Implementation of hook_backup_migrate_filters().
* Implements hook_backup_migrate_filters().
*
* Get the built in Backup and Migrate filters.
*/
function backup_migrate_backup_migrate_filters() {
return array(
'backup_restore' => array(
'file' => drupal_get_path('module', 'backup_migrate') .'/includes/filters.backup_restore.inc',
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/filters.backup_restore.inc',
'class' => 'backup_migrate_filter_backup_restore',
),
'compression' => array(
'file' => drupal_get_path('module', 'backup_migrate') .'/includes/filters.compression.inc',
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/filters.compression.inc',
'class' => 'backup_migrate_filter_compression',
),
'encryption' => array(
'file' => drupal_get_path('module', 'backup_migrate') .'/includes/filters.encryption.inc',
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/filters.encryption.inc',
'class' => 'backup_migrate_filter_encryption',
),
'statusnotify' => array(
'file' => drupal_get_path('module', 'backup_migrate') .'/includes/filters.statusnotify.inc',
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/filters.statusnotify.inc',
'class' => 'backup_migrate_filter_statusnotify',
),
'utils' => array(
'file' => drupal_get_path('module', 'backup_migrate') .'/includes/filters.utils.inc',
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/filters.utils.inc',
'class' => 'backup_migrate_filter_utils',
),
);
}
/**
* Invoke the given method on all of the available filters.
* Invokes the given method on all of the available filters.
*/
function backup_migrate_filters_invoke_all() {
$args = func_get_args();
@@ -96,7 +95,7 @@ function backup_migrate_filters_invoke_all() {
}
/**
* Filter a backup file before sending it to the destination.
* Filters a backup file before sending it to the destination.
*/
function backup_migrate_filters_backup($file, &$settings) {
backup_migrate_filters_invoke_all('pre_backup', $file, $settings);
@@ -112,7 +111,7 @@ function backup_migrate_filters_backup($file, &$settings) {
}
/**
* Filter a backup file before sending it to the destination.
* Filters a backup file before sending it to the destination.
*/
function backup_migrate_filters_restore($file, &$settings) {
backup_migrate_filters_invoke_all('pre_restore', $file, $settings);
@@ -127,16 +126,16 @@ function backup_migrate_filters_restore($file, &$settings) {
}
/**
* Get the backup settings for all of the filters.
* Gets the backup settings for all of the filters.
*/
function backup_migrate_filters_settings_form($settings, $op) {
$out = backup_migrate_filters_invoke_all($op .'_settings_form', $settings);
$out = backup_migrate_filters_invoke_all($op . '_settings_form', $settings);
$out = backup_migrate_filters_settings_form_set_parents($out);
return $out;
}
/**
* Add a form parent to the filter settings so that the filter values are saved in the right table.
* Adds form parent to filter settings so the values are saved in correct table.
*/
function backup_migrate_filters_settings_form_set_parents($form) {
foreach (element_children($form) as $key) {
@@ -149,24 +148,24 @@ function backup_migrate_filters_settings_form_set_parents($form) {
}
/**
* Validate all the filters.
* Validates all the filters.
*/
function backup_migrate_filters_settings_form_validate($op, $form, &$form_state) {
backup_migrate_filters_invoke_all($op .'_settings_form_validate', $form, $form_state);
backup_migrate_filters_invoke_all($op . '_settings_form_validate', $form, $form_state);
}
/**
* Submit all of the filters.
* Submits all of the filters.
*/
function backup_migrate_filters_settings_form_submit($op, $form, &$form_state) {
backup_migrate_filters_invoke_all($op .'_settings_form_submit', $form, $form_state);
backup_migrate_filters_invoke_all($op . '_settings_form_submit', $form, $form_state);
}
/**
* Get the default settings for the filters.
* Gets the default settings for the filters.
*/
function backup_migrate_filters_settings_default($op) {
return backup_migrate_filters_invoke_all($op .'_settings_default');
return backup_migrate_filters_invoke_all($op . '_settings_default');
}
/**
@@ -175,7 +174,7 @@ function backup_migrate_filters_settings_default($op) {
function backup_migrate_filters_before_action_form($settings, $op) {
$out = array();
$out += backup_migrate_filters_invoke_all('before_action_form', $op, $settings);
$out += backup_migrate_filters_invoke_all('before_' . $op .'_form', $settings);
$out += backup_migrate_filters_invoke_all('before_' . $op . '_form', $settings);
return $out;
}
@@ -184,7 +183,7 @@ function backup_migrate_filters_before_action_form($settings, $op) {
*/
function backup_migrate_filters_before_action_form_validate($settings, $op, $form, &$form_state) {
backup_migrate_filters_invoke_all('before_action_form_validate', $op, $settings, $form, $form_state);
backup_migrate_filters_invoke_all('before_' . $op .'_form_validate', $settings, $form, $form_state);
backup_migrate_filters_invoke_all('before_' . $op . '_form_validate', $settings, $form, $form_state);
}
/**
@@ -192,7 +191,7 @@ function backup_migrate_filters_before_action_form_validate($settings, $op, $for
*/
function backup_migrate_filters_before_action_form_submit($settings, $op, $form, &$form_state) {
backup_migrate_filters_invoke_all('before_action_form_submit', $op, $settings, $form, $form_state);
backup_migrate_filters_invoke_all('before_' . $op .'_form_submit', $settings, $form, $form_state);
backup_migrate_filters_invoke_all('before_' . $op . '_form_submit', $settings, $form, $form_state);
}
/**
@@ -206,13 +205,13 @@ function backup_migrate_filters_file_types() {
* A base class for basing filters on.
*/
class backup_migrate_filter {
var $weight = 0;
var $op_weights = array();
public $weight = 0;
public $op_weights = array();
/**
* Get the weight of the filter for the given op.
*/
function weight($op = NULL) {
public function weight($op = NULL) {
if ($op && isset($this->op_weights[$op])) {
return $this->op_weights[$op];
}
@@ -222,111 +221,110 @@ class backup_migrate_filter {
/**
* Get the form for the settings for this filter.
*/
function backup_settings_default() {
public function backup_settings_default() {
return array();
}
/**
* Get the form for the settings for this filter.
*/
function backup_settings_form($settings) {
public function backup_settings_form($settings) {
return array();
}
/**
* Get the form for the settings for this filter.
*/
function backup_settings_form_validate($form, &$form_state) {
public function backup_settings_form_validate($form, &$form_state) {
}
/**
* Submit the settings form. Any values returned will be saved.
*/
function backup_settings_form_submit($form, &$form_state) {
public function backup_settings_form_submit($form, &$form_state) {
}
/**
* Get the form for the settings for this filter.
*/
function restore_settings_default() {
public function restore_settings_default() {
return array();
}
/**
* Get the form for the settings for this filter.
*/
function restore_settings_form($settings) {
public function restore_settings_form($settings) {
return array();
}
/**
* Get the form for the settings for this filter.
*/
function restore_settings_form_validate($form, &$form_state) {
public function restore_settings_form_validate($form, &$form_state) {
}
/**
* Submit the settings form. Any values returned will be saved.
*/
function restore_settings_form_submit($form, &$form_state) {
public function restore_settings_form_submit($form, &$form_state) {
return $form_state['values'];
}
/**
* Get a list of file types handled by this filter.
*/
function file_types() {
public function file_types() {
return array();
}
/**
* Declare any default destinations for this filter.
*/
function destinations() {
public function destinations() {
return array();
}
/**
* This function is called on a backup file after the backup has been completed.
* Called on a backup file after the backup has been completed.
*/
function backup($file, $settings) {
public function backup($file, $settings) {
return $file;
}
/**
* This function is called immediately prior to backup.
*/
function pre_backup($file, $settings) {
public function pre_backup($file, $settings) {
}
/**
* This function is called immediately post backup.
*/
function post_backup($file, $settings) {
public function post_backup($file, $settings) {
}
/**
* This function is called on a backup file before importing it.
*/
function restore($file, $settings) {
public function restore($file, $settings) {
return $file;
}
/**
* This function is called immediately prior to restore.
*/
function pre_restore($file, $settings) {
public function pre_restore($file, $settings) {
}
/**
* This function is called immediately post restore.
*/
function post_restore($file, $settings) {
public function post_restore($file, $settings) {
}
}
}
@@ -1,6 +1,5 @@
<?php
/**
* @file
* A filter for compressing bckups with zip, gz bzip etc.
@@ -12,11 +11,11 @@
* @ingroup backup_migrate_filters
*/
class backup_migrate_filter_statusnotify extends backup_migrate_filter {
/**
* Get the default backup settings for this filter.
*/
function backup_settings_default() {
public function backup_settings_default() {
return array(
'notify_success_enable' => FALSE,
'notify_failure_enable' => FALSE,
@@ -28,7 +27,7 @@ class backup_migrate_filter_statusnotify extends backup_migrate_filter {
/**
* Get the form for the settings for this filter.
*/
function backup_settings_form($settings) {
public function backup_settings_form($settings) {
$form = array();
$form['advanced']['notify_success_enable'] = array(
"#type" => 'checkbox',
@@ -68,41 +67,39 @@ class backup_migrate_filter_statusnotify extends backup_migrate_filter {
/**
* Send the success email.
*/
function backup_succeed($settings) {
public function backup_succeed($settings) {
if (@$settings->filters['notify_success_enable'] && $to = @$settings->filters['notify_success_email']) {
$messages = $this->get_messages();
$subject = t('!site backup succeeded', array('!site' => variable_get('site_name', 'Drupal site')));
if ($messages = $this->get_messages()) {
$body = t("The site backup has completed successfully with the following messages:\n!messages", array('!messages' => $messages));
}
else {
$body = t("The site backup has completed successfully.\n");
}
mail($settings->filters['notify_success_email'], $subject, $body);
drupal_mail('backup_migrate', 'backup_succeed', $settings->filters['notify_success_email'], language_default(), array('body' => $body));
}
}
/**
* Send the failure email.
*/
function backup_fail($settings) {
public function backup_fail($settings) {
if (@$settings->filters['notify_failure_enable'] && $to = @$settings->filters['notify_failure_email']) {
$messages = $this->get_messages();
$subject = t('!site backup failed', array('!site' => variable_get('site_name', 'Drupal site')));
if ($messages = $this->get_messages()) {
$body = t("The site backup has failed with the following messages:\n!messages", array('!messages' => $messages));
}
else {
$body = t("The site backup has failed for an unknown reason.");
}
mail($settings->filters['notify_failure_email'], $subject, $body);
drupal_mail('backup_migrate', 'backup_fail', $settings->filters['notify_failure_email'], language_default(), array('body' => $body));
}
}
/**
* Render the messages and errors for the email.
*/
function get_messages() {
public function get_messages() {
$out = "";
$messages = _backup_migrate_messages();
foreach ($messages as $message) {
@@ -110,5 +107,5 @@ class backup_migrate_filter_statusnotify extends backup_migrate_filter {
}
return $out;
}
}
}
@@ -1,6 +1,5 @@
<?php
/**
* @file
* A filter to run some basic utility functions. Basically any useful option not big enough to justify it's own class.
@@ -12,13 +11,13 @@
* @ingroup backup_migrate_filters
*/
class backup_migrate_filter_utils extends backup_migrate_filter {
var $op_weights = array('pre_backup' => -1000, 'post_backup' => 1000);
var $saved_devel_query = NULL;
public $op_weights = array('pre_backup' => -1000, 'post_backup' => 1000);
public $saved_devel_query = NULL;
/**
* Get the default backup settings for this filter.
*/
function backup_settings_default() {
public function backup_settings_default() {
return array(
'utils_disable_query_log' => TRUE,
'utils_site_offline' => FALSE,
@@ -29,7 +28,7 @@ class backup_migrate_filter_utils extends backup_migrate_filter {
/**
* Get the default restore settings for this filter.
*/
function restore_settings_default() {
public function restore_settings_default() {
return array(
'utils_disable_query_log' => TRUE,
'utils_site_offline' => FALSE,
@@ -39,7 +38,7 @@ class backup_migrate_filter_utils extends backup_migrate_filter {
/**
* Get the form for the backup settings for this filter.
*/
function backup_settings_form($settings) {
public function backup_settings_form($settings) {
$form = array();
if (module_exists('devel') && variable_get('dev_query', 0)) {
$form['database']['utils_disable_query_log'] = array(
@@ -65,7 +64,7 @@ class backup_migrate_filter_utils extends backup_migrate_filter {
'#type' => 'textarea',
'#title' => t('Site off-line message'),
'#default_value' => !empty($settings['utils_site_offline_message']) ? $settings['utils_site_offline_message'] : variable_get('site_offline_message', t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal')))),
'#description' => t('Message to show visitors when the site is in off-line mode.')
'#description' => t('Message to show visitors when the site is in off-line mode.'),
);
$form['advanced']['utils_description'] = array(
'#type' => 'textarea',
@@ -92,7 +91,7 @@ class backup_migrate_filter_utils extends backup_migrate_filter {
/**
* Get the form for the restore settings for this filter.
*/
function restore_settings_form($settings) {
public function restore_settings_form($settings) {
$form = array();
if (module_exists('devel') && variable_get('dev_query', 0)) {
$form['advanced']['utils_disable_query_log'] = array(
@@ -118,7 +117,13 @@ class backup_migrate_filter_utils extends backup_migrate_filter {
'#type' => 'textarea',
'#title' => t('Site off-line message'),
'#default_value' => !empty($settings['utils_site_offline_message']) ? $settings['utils_site_offline_message'] : variable_get('site_offline_message', t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal')))),
'#description' => t('Message to show visitors when the site is in off-line mode.')
'#description' => t('Message to show visitors when the site is in off-line mode.'),
);
$form['advanced']['utils_drop_all_tables'] = array(
'#type' => 'checkbox',
'#title' => t('Drop all tables before import (MySQL only)'),
'#default_value' => !empty($settings['utils_drop_all_tables']) ? $settings['utils_drop_all_tables'] : NULL,
'#description' => t('Drop all existing database tables before restoring the backup. This option is currently available on MySQL servers only.'),
);
$form['advanced']['use_cli'] = array(
"#type" => "checkbox",
@@ -135,25 +140,25 @@ class backup_migrate_filter_utils extends backup_migrate_filter {
return $form;
}
function pre_backup($file, $settings) {
public function pre_backup($file, $settings) {
$this->take_site_offline($settings);
$this->disable_devel_query($settings);
}
function post_backup($file, $settings) {
public function post_backup($file, $settings) {
$this->enable_devel_query($settings);
$this->take_site_online($settings);
if ($file) {
$this->add_file_info($file, $settings);
$this->add_file_info($file, $settings);
}
}
function pre_restore($file, $settings) {
public function pre_restore($file, $settings) {
$this->disable_devel_query($settings);
$this->take_site_offline($settings);
}
function post_restore($file, $settings) {
public function post_restore($file, $settings) {
$this->enable_devel_query($settings);
$this->take_site_online($settings);
}
@@ -161,7 +166,7 @@ class backup_migrate_filter_utils extends backup_migrate_filter {
/**
* Disable devel query logging if it's active and the user has chosen to do so.
*/
function disable_devel_query($settings) {
public function disable_devel_query($settings) {
$this->saved_devel_query = variable_get('dev_query', 0);
if (module_exists('devel') && variable_get('dev_query', 0) && !empty($settings->filters['utils_disable_query_log'])) {
variable_set('dev_query', 0);
@@ -171,7 +176,7 @@ class backup_migrate_filter_utils extends backup_migrate_filter {
/**
* Restore devel query to previous state.
*/
function enable_devel_query($settings) {
public function enable_devel_query($settings) {
if (module_exists('devel')) {
variable_set('dev_query', $this->saved_devel_query);
}
@@ -180,7 +185,7 @@ class backup_migrate_filter_utils extends backup_migrate_filter {
/**
* Add the backup metadata to the file.
*/
function add_file_info($file, $settings) {
public function add_file_info($file, $settings) {
$file->file_info['description'] = $settings->filters['utils_description'];
$file->file_info['datestamp'] = time();
$file->file_info['generator'] = 'Backup and Migrate (http://drupal.org/project/backup_migrate)';
@@ -204,31 +209,37 @@ class backup_migrate_filter_utils extends backup_migrate_filter {
/**
* Take the site offline if configured to do so.
*/
function take_site_offline($settings) {
// Save the current state of the site in case a restore overwrites it.
$this->saved_site_offline = variable_get('maintenance_mode', 0);
if (@$settings->filters['utils_site_offline']) {
$this->saved_site_offline_message = variable_get('maintenance_mode_message', NULL);
if (!empty($settings->filters['utils_site_offline_message'])) {
public function take_site_offline($settings) {
// If the site is already offline then don't do anything.
if (!variable_get('maintenance_mode', 0)) {
// Save the current state of the site in case a restore overwrites it.
if (!empty($settings->filters['utils_site_offline'])) {
$this->saved_site_offline = TRUE;
$this->saved_site_offline_message = variable_get('maintenance_mode_message', NULL);
variable_set('maintenance_mode_message', $settings->filters['utils_site_offline_message']);
if (!empty($settings->filters['utils_site_offline_message'])) {
$this->saved_site_offline_message = variable_get('maintenance_mode_message', NULL);
variable_set('maintenance_mode_message', $settings->filters['utils_site_offline_message']);
}
variable_set('maintenance_mode', 1);
_backup_migrate_message('Site was taken offline.');
}
variable_set('maintenance_mode', 1);
_backup_migrate_message('Site was taken offline.');
}
}
/**
* Take the site online again after backup or restore.
*/
function take_site_online($settings) {
public function take_site_online($settings) {
// Take the site back off/online because the restored db may have changed that setting.
variable_set('maintenance_mode', $this->saved_site_offline);
if ($settings->filters['utils_site_offline']) {
if (!empty($this->saved_site_offline_message)) {
variable_set('maintenance_mode_message', $this->saved_site_offline_message);
if (variable_get('maintenance_mode', 0) && !empty($this->saved_site_offline)) {
variable_set('maintenance_mode', 0);
if ($settings->filters['utils_site_offline']) {
if (!empty($this->saved_site_offline_message)) {
variable_set('maintenance_mode_message', $this->saved_site_offline_message);
}
_backup_migrate_message('Site was taken online.');
}
_backup_migrate_message('Site was taken online.');
}
}
}
@@ -1,6 +1,5 @@
<?php
/**
* @file
* All of the location handling code needed for Backup and Migrate.
@@ -45,7 +44,7 @@ function backup_migrate_backup_migrate_locations() {
* 'all' - all available locations should be returned
*/
function backup_migrate_get_locations($op = 'all') {
static $locations = NULL;
$locations = &drupal_static('backup_migrate_get_locations', NULL);
// Get the list of locations and cache them locally.
if ($locations === NULL) {
@@ -82,21 +81,21 @@ function backup_migrate_get_location($id) {
* A base class for creating locations.
*/
class backup_migrate_location extends backup_migrate_item {
var $db_table = "backup_migrate_destinations";
var $type_name = "location";
var $default_values = array('settings' => array());
var $singular = 'location';
var $plural = 'locations';
var $title_plural = 'Locations';
var $title_singular = 'Location';
public $db_table = "backup_migrate_destinations";
public $type_name = "location";
public $default_values = array('settings' => array());
public $singular = 'location';
public $plural = 'locations';
public $title_plural = 'Locations';
public $title_singular = 'Location';
var $subtype = "";
var $supported_ops = array();
public $subtype = "";
public $supported_ops = array();
/**
* This function is not supposed to be called. It is just here to help the po extractor out.
*/
function strings() {
public function strings() {
// Help the pot extractor find these strings.
t('location');
t('locations');
@@ -104,49 +103,49 @@ class backup_migrate_location extends backup_migrate_item {
t('Locations');
}
function ops() {
public function ops() {
return $this->supported_ops;
}
/**
* Does this location support the given operation.
*/
function op($op) {
$ops = (array)$this->ops();
public function op($op) {
$ops = (array) $this->ops();
return in_array($op, $ops);
}
/**
* Remove the given op from the support list.
*/
function remove_op($op) {
public function remove_op($op) {
$key = array_search($op, $this->supported_ops);
if ($key !== FALSE) {
unset($this->supported_ops[$key]);
}
}
function get_name() {
public function get_name() {
return @$this->name;
}
function set_name($name) {
public function set_name($name) {
return $this->name = $name;
}
function set_location($location) {
public function set_location($location) {
$this->location = $location;
}
function get_location() {
public function get_location() {
return @$this->location;
}
function get_display_location() {
public function get_display_location() {
return $this->get_location();
}
function settings($key = NULL) {
public function settings($key = NULL) {
$out = $this->settings;
if ($key) {
$out = isset($out[$key]) ? $out[$key] : NULL;
@@ -157,7 +156,7 @@ class backup_migrate_location extends backup_migrate_item {
/**
* Get the type name of this location for display to the user.
*/
function get_subtype_name() {
public function get_subtype_name() {
if ($type = $this->get('subtype')) {
$types = $this->location_types();
return isset($types[$type]['type_name']) ? $types[$type]['type_name'] : $type;
@@ -167,7 +166,7 @@ class backup_migrate_location extends backup_migrate_item {
/**
* Get the edit form for the item.
*/
function edit_form() {
public function edit_form() {
if (!empty($this->supported_ops)) {
$form = parent::edit_form();
$form['subtype'] = array(
@@ -182,13 +181,13 @@ class backup_migrate_location extends backup_migrate_item {
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 . "/settings/$this->type_name/add/$type_url_str", array('attributes' => array('title' => t('Add a new @s location.', array('@s' => $type['type_name']))))) .'</dt>';
$out .= '<dd>'. filter_xss_admin($type['description']) .'</dd>';
$out = '<dt>' . l($type['type_name'], BACKUP_MIGRATE_MENU_PATH . "/settings/$this->type_name/add/$type_url_str", array('attributes' => array('title' => t('Add a new @s location.', 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 location you would like to create:') .'<dl>'. implode('', $items) .'</dl>';
$output = t('Choose the type of location you would like to create:') . '<dl>' . implode('', $items) . '</dl>';
}
else {
$output = t('No types available.');
@@ -204,21 +203,21 @@ class backup_migrate_location extends backup_migrate_item {
/**
* Get the available location types.
*/
function location_types() {
public function location_types() {
return backup_migrate_get_location_subtypes();
}
/**
* Get the message to send to the user when confirming the deletion of the item.
*/
function delete_confirm_message() {
public function delete_confirm_message() {
return t('Are you sure you want to delete the %name?', array('%name' => $this->get_name()));
}
/**
* Get the columns needed to list the type.
*/
function get_list_column_info() {
*/
public function get_list_column_info() {
$out = parent::get_list_column_info();
$out = array(
'name' => array('title' => t('Name')),
@@ -230,11 +229,11 @@ class backup_migrate_location extends backup_migrate_item {
/**
* Get a row of data to be used in a list of items of this type.
*/
function get_list_row() {
*/
public function get_list_row() {
$out = parent::get_list_row();
// Supress locations with no actions as there's no value in showing them (and they may confuse new users).
// Suppress locations with no actions as there's no value in showing them (and they may confuse new users).
if (empty($out['actions'])) {
return NULL;
}
@@ -244,13 +243,13 @@ class backup_migrate_location extends backup_migrate_item {
/**
* Get the action links for a location.
*/
function get_action_links() {
public function get_action_links() {
$out = parent::get_action_links();
$item_id = $this->get_id();
// Don't display the download/delete/restore ops if they are not available for this location.
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;
$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']);
@@ -261,94 +260,94 @@ class backup_migrate_location extends backup_migrate_item {
/**
* Determine if we can read the given file.
*/
function can_read_file($file_id) {
public function can_read_file($file_id) {
return $this->op('restore');
}
/**
* Get the form for the settings for this location type.
*/
function settings_default() {
public function settings_default() {
return array();
}
/**
* Get the form for the settings for this location.
*/
function settings_form($form) {
public function settings_form($form) {
return $form;
}
/**
* Validate the form for the settings for this location.
*/
function settings_form_validate($form_values) {
public function settings_form_validate($form_values) {
}
/**
* Submit the settings form. Any values returned will be saved.
*/
function settings_form_submit($form_values) {
public function settings_form_submit($form_values) {
return $form_values;
}
/**
* Get the form for the settings for this filter.
*/
function backup_settings_default() {
public function backup_settings_default() {
return array();
}
/**
* Get the form for the settings for this filter.
*/
function backup_settings_form($settings) {
public function backup_settings_form($settings) {
return array();
}
/**
* Get the form for the settings for this filter.
*/
function backup_settings_form_validate($form, &$form_state) {
public function backup_settings_form_validate($form, &$form_state) {
}
/**
* Submit the settings form. Any values returned will be saved.
*/
function backup_settings_form_submit($form, &$form_state) {
public function backup_settings_form_submit($form, &$form_state) {
}
/**
* Get the form for the settings for this filter.
*/
function restore_settings_default() {
public function restore_settings_default() {
return array();
}
/**
* Get the form for the settings for this filter.
*/
function restore_settings_form($settings) {
public function restore_settings_form($settings) {
return array();
}
/**
* Get the form for the settings for this filter.
*/
function restore_settings_form_validate($form_values) {
public function restore_settings_form_validate($form_values) {
}
/**
* Submit the settings form. Any values returned will be saved.
*/
function restore_settings_form_submit($form_values) {
public function restore_settings_form_submit($form_values) {
return $form_values;
}
/**
* Create a new location of the correct type.
*/
function create($params = array()) {
public function create($params = array()) {
$out = NULL;
$types = backup_migrate_get_location_subtypes();
// Get the type passed in in the params, or if none, check the url for a valid type name.
@@ -358,7 +357,7 @@ class backup_migrate_location extends backup_migrate_item {
if ($location_type && ($type = @$types[$location_type])) {
// Include the necessary file if specified by the type.
if (!empty($type['file'])) {
require_once './'. $type['file'];
require_once './' . $type['file'];
}
$out = new $type['class']($params + array('subtype' => $location_type));
}
@@ -369,37 +368,37 @@ class backup_migrate_location extends backup_migrate_item {
return $out;
}
/**
/**
* Get a url from the parts.
*/
function url($hide_password = TRUE) {
public function url($hide_password = TRUE) {
return $this->glue_url($this->dest_url, $hide_password);
}
/**
* Glue a URLs component parts back into a URL.
*/
function glue_url($parts, $hide_password = TRUE) {
public function glue_url($parts, $hide_password = TRUE) {
// Obscure the password if we need to.
$parts['pass'] = $hide_password ? "" : $parts['pass'];
// Assemble the URL.
$out = "";
$out .= $parts['scheme'] .'://';
$out .= $parts['scheme'] . '://';
$out .= $parts['user'] ? urlencode($parts['user']) : '';
$out .= ($parts['user'] && $parts['pass']) ? ":". urlencode($parts['pass']) : '';
$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'];
$out .= !empty($parts['port']) ? ':' . $parts['port'] : '';
$out .= "/" . $parts['path'];
return $out;
}
/**
* Break a URL into it's component parts.
*/
function set_url($url) {
$parts = (array)parse_url($url);
public function set_url($url) {
$parts = (array) parse_url($url);
$parts['user'] = urldecode(@$parts['user']);
$parts['pass'] = urldecode(@$parts['pass']);
$parts['path'] = urldecode(@$parts['path']);
@@ -410,7 +409,7 @@ class backup_migrate_location extends backup_migrate_item {
/**
* Retrieve a list of filetypes supported by this source/destination.
*/
function file_types() {
public function file_types() {
return array();
}
@@ -423,67 +422,29 @@ class backup_migrate_location_remote extends backup_migrate_location {
/**
* The location is a URI so parse it and store the parts.
*/
function get_location() {
public function get_location() {
return $this->url(FALSE);
}
/**
* The location to display is the url without the password.
*/
function get_display_location() {
public function get_display_location() {
return $this->url(TRUE);
}
/**
* Return the location with the password.
*/
function set_location($location) {
public function set_location($location) {
$this->location = $location;
$this->set_url($location);
}
/**
* Get a url from the parts.
* Location configuration callback.
*/
function url($hide_password = TRUE) {
return $this->glue_url($this->dest_url, $hide_password);
}
/**
* Glue a URLs component parts back into a URL.
*/
function glue_url($parts, $hide_password = TRUE) {
// Obscure the password if we need to.
$parts['pass'] = $hide_password ? "" : $parts['pass'];
// Assemble the URL.
$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;
}
/**
* Break a URL into it's component parts.
*/
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;
}
/**
* location configuration callback.
*/
function edit_form() {
public function edit_form() {
$form = parent::edit_form();
$form['scheme'] = array(
"#type" => "select",
@@ -534,10 +495,10 @@ class backup_migrate_location_remote extends backup_migrate_location {
/**
* Submit the configuration form. Glue the url together and add the old password back if a new one was not specified.
*/
function edit_form_submit($form, &$form_state) {
public 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);
}
}
}
@@ -1,6 +1,5 @@
<?php
/**
* @file
* All of the settings profiles handling code for Backup and Migrate.
@@ -32,12 +31,7 @@ function backup_migrate_backup_migrate_profile_subtypes() {
*/
function backup_migrate_get_profiles() {
backup_migrate_include('filters');
static $profiles = NULL;
// Get the list of profiles and cache them locally.
if ($profiles === NULL) {
$profiles = backup_migrate_crud_get_items('profile');
}
$profiles = backup_migrate_crud_get_items('profile');
return $profiles;
}
@@ -49,7 +43,7 @@ function backup_migrate_get_profiles() {
function backup_migrate_backup_migrate_profiles_alter(&$profiles) {
foreach ($profiles as $id => $profile) {
// Set the default values for filter setting which don't exist in the profile.
$profiles[$id]->filters = (array)@$profile->filters + (array)backup_migrate_filters_settings_default('backup');
$profiles[$id]->filters = (array) @$profile->filters + (array) backup_migrate_filters_settings_default('backup');
}
}
@@ -80,7 +74,7 @@ function backup_migrate_backup_migrate_profiles() {
*/
function _backup_migrate_get_profile_form_item_options() {
$out = array();
foreach ((array)backup_migrate_get_profiles() as $key => $profile) {
foreach ((array) backup_migrate_get_profiles() as $key => $profile) {
$out[$key] = $profile->get('name');
}
return $out;
@@ -91,8 +85,8 @@ function _backup_migrate_get_profile_form_item_options() {
*/
function _backup_migrate_ui_backup_settings_form($profile) {
drupal_add_js(array('backup_migrate' => array('checkboxLinkText' => t('View as checkboxes'))), array('type' => 'setting'));
drupal_add_js(drupal_get_path('module', 'backup_migrate') .'/backup_migrate.js', array('type' => 'file', 'scope' => 'footer'));
drupal_add_css(drupal_get_path('module', 'backup_migrate') .'/backup_migrate.css');
drupal_add_js(drupal_get_path('module', 'backup_migrate') . '/backup_migrate.js', array('type' => 'file', 'scope' => 'footer'));
drupal_add_css(drupal_get_path('module', 'backup_migrate') . '/backup_migrate.css');
backup_migrate_include('files', 'destinations', 'filters');
@@ -126,14 +120,19 @@ function _backup_migrate_ui_backup_settings_form($profile) {
}
$form['file']['append_timestamp'] = array(
"#type" => "checkbox",
"#title" => t("Append a timestamp."),
"#type" => "radios",
'#options' => array(
0 => t('Create separate backups if `Backup file name` already exists'),
2 => t('Overwrite the existing backup file'),
1 => t('Append the timestamp'),
),
"#title" => t("Save mode"),
"#default_value" => $profile->append_timestamp,
);
$form['file']['timestamp_format_wrapper'] = array(
'#type' => 'backup_migrate_dependent',
'#dependencies' => array(
'append_timestamp' => TRUE,
'append_timestamp' => 1,
),
);
$form['file']['timestamp_format_wrapper']['timestamp_format'] = array(
@@ -150,8 +149,8 @@ function _backup_migrate_ui_backup_settings_form($profile) {
if ($form['advanced']) {
$form['advanced']['#type'] = 'fieldset';
$form['advanced']['#title'] = t('Advanced Options');
$form['advanced']['#collapsed'] = true;
$form['advanced']['#collapsible'] = true;
$form['advanced']['#collapsed'] = TRUE;
$form['advanced']['#collapsible'] = TRUE;
}
$form['#validate'][] = '_backup_migrate_ui_backup_settings_form_validate';
@@ -173,7 +172,7 @@ function _backup_migrate_ui_backup_settings_form_validate($form, &$form_state) {
function _backup_migrate_ui_backup_settings_form_submit($form, &$form_state) {
backup_migrate_filters_settings_form_submit('backup', $form, $form_state);
}
/**
* Get the default profile.
*/
@@ -207,17 +206,36 @@ function _backup_migrate_profile_saved_default_profile($profile_id = NULL) {
* A profile class for crud operations.
*/
class backup_migrate_profile extends backup_migrate_item {
var $db_table = "backup_migrate_profiles";
var $type_name = "profile";
var $singular = 'settings profile';
var $plural = 'settings profiles';
var $title_plural = 'Settings Profiles';
var $title_singular = 'Settings Profile';
public $db_table = "backup_migrate_profiles";
public $type_name = "profile";
public $singular = 'settings profile';
public $plural = 'settings profiles';
public $title_plural = 'Settings Profiles';
public $title_singular = 'Settings Profile';
/**
* Perform a shallow merge of the defaults and the parameters.
*
* This is needed because otherwise it will *combine* the nested arrays and
* make it impossible to deselect database tables from the 'nodata' setting.
*
* @param array $params
*/
public function __construct(array $params = array()) {
$params = (array) $params;
$defaults = (array) $this->get_default_values();
foreach ($defaults as $key => $val) {
if (!isset($params[$key])) {
$params[$key] = $val;
}
}
$this->from_array($params);
}
/**
* This function is not supposed to be called. It is just here to help the po extractor out.
*/
function strings() {
public function strings() {
// Help the pot extractor find these strings.
t('Settings Profile');
t('Settings Profiles');
@@ -228,22 +246,22 @@ class backup_migrate_profile extends backup_migrate_item {
/**
* Get the default values for standard parameters.
*/
function get_default_values() {
public function get_default_values() {
return _backup_migrate_profile_default_profile() + array('name' => t("Untitled Profile"));
}
/**
* Get a table of all items of this type.
*/
function get_list() {
drupal_add_css(drupal_get_path('module', 'backup_migrate') .'/backup_migrate.css');
*/
public function get_list() {
drupal_add_css(drupal_get_path('module', 'backup_migrate') . '/backup_migrate.css');
return parent::get_list();
}
/**
* Get the columns needed to list the type.
*/
function get_list_column_info() {
*/
public function get_list_column_info() {
$out = parent::get_list_column_info();
$out = array(
'name' => array('title' => t('Name')),
@@ -256,7 +274,7 @@ class backup_migrate_profile extends backup_migrate_item {
/**
* Set the source of this setings profile. Takes either a source object or source id.
*/
function set_source($source) {
public function set_source($source) {
if (is_object($source)) {
$this->source = $source;
$this->source_id = $source->get_id();
@@ -270,7 +288,7 @@ class backup_migrate_profile extends backup_migrate_item {
/**
* Get the source of the profile.
*/
function get_source() {
public function get_source() {
backup_migrate_include('locations');
if (!empty($this->source_id) && (empty($this->source) || $this->source->get_id() !== $this->source_id)) {
$this->source = backup_migrate_get_source($this->source_id);
@@ -281,7 +299,7 @@ class backup_migrate_profile extends backup_migrate_item {
/**
* Get the name of the source.
*/
function get_source_name() {
public function get_source_name() {
if ($source = $this->get_source()) {
return $source->get_name();
}
@@ -291,22 +309,22 @@ class backup_migrate_profile extends backup_migrate_item {
/**
* Get the destination of the profile.
*/
function get_destination() {
$destinations = (array)$this->get_destinations();
public function get_destination() {
$destinations = (array) $this->get_destinations();
return reset($destinations);
}
/**
* Get the destination of the profile.
*/
function get_destinations() {
public function get_destinations() {
backup_migrate_include('destinations');
if (empty($this->destinations)) {
$this->destinations = array();
$ids = $weights = array();
if (!empty($this->destination_id)) {
foreach ((array)$this->destination_id as $destination_id) {
if (!in_array($destination_id, $ids) && $destination = backup_migrate_get_destination($destination_id)) {
foreach ((array) $this->destination_id as $destination_id) {
if (!in_array($destination_id, $ids) && $destination = backup_migrate_get_destination($destination_id)) {
$this->destinations[] = $destination;
$weights[] = $destination->get('weight');
$ids[] = $destination_id;
@@ -323,7 +341,7 @@ class backup_migrate_profile extends backup_migrate_item {
/**
* Get the name of the destination.
*/
function get_destination_name() {
public function get_destination_name() {
$out = array();
foreach ($this->get_destinations() as $destination) {
$out[] = $destination->get_name();
@@ -335,9 +353,9 @@ class backup_migrate_profile extends backup_migrate_item {
}
/**
* Get the source and destinations specified in the given settings profile
* Get the source and destinations specified in the given settings profile.
*/
function get_all_locations() {
public function get_all_locations() {
$out = array();
$out += $this->get('destinations');
$out[] = $this->get('source');
@@ -347,7 +365,7 @@ class backup_migrate_profile extends backup_migrate_item {
/**
* Get the edit form.
*/
function edit_form() {
public function edit_form() {
$form = parent::edit_form();
$form['name'] = array(
"#type" => "textfield",
@@ -362,8 +380,8 @@ class backup_migrate_profile extends backup_migrate_item {
/**
* Get the message to send to the user when confirming the deletion of the item.
*/
function delete_confirm_message() {
public function delete_confirm_message() {
return t('Are you sure you want to delete the profile %name? Any schedules using this profile will be disabled.', array('%name' => $this->get('name')));
}
}
}
@@ -4,13 +4,13 @@
* @file
* All of the schedule handling code needed for Backup and Migrate.
*/
define('BACKUP_MIGRATE_KEEP_ALL', 0);
define('BACKUP_MIGRATE_STANDARD_DELETE', -1);
define('BACKUP_MIGRATE_SMART_DELETE', -2);
define('BACKUP_MIGRATE_CRON_BUILTIN', 'builtin');
define('BACKUP_MIGRATE_CRON_ELYSIA', 'elysia');
define('BACKUP_MIGRATE_CRON_ELYSIA', 'elysia');
define('BACKUP_MIGRATE_CRON_NONE', 'none');
@@ -67,7 +67,7 @@ function backup_migrate_schedules_run() {
*/
function backup_migrate_schedule_run($schedule_id) {
backup_migrate_include('profiles');
if ($schedule = backup_migrate_get_schedule($schedule_id)) {
if (($schedule = backup_migrate_get_schedule($schedule_id)) && $schedule->is_enabled()) {
$schedule->run();
}
backup_migrate_cleanup();
@@ -77,7 +77,7 @@ function backup_migrate_schedule_run($schedule_id) {
* Get all the available backup schedules.
*/
function backup_migrate_get_schedules() {
static $schedules = NULL;
$schedules = &drupal_static('backup_migrate_get_schedules');
// Get the list of schedules and cache them locally.
if ($schedules === NULL) {
$schedules = backup_migrate_crud_get_items('schedule');
@@ -97,18 +97,18 @@ function backup_migrate_get_schedule($schedule_id) {
* A schedule class for crud operations.
*/
class backup_migrate_schedule extends backup_migrate_item {
var $db_table = "backup_migrate_schedules";
var $type_name = 'schedule';
var $singular = 'schedule';
var $plural = 'schedules';
var $title_plural = 'Schedules';
var $title_singular = 'Schedule';
var $default_values = array();
public $db_table = "backup_migrate_schedules";
public $type_name = 'schedule';
public $singular = 'schedule';
public $plural = 'schedules';
public $title_plural = 'Schedules';
public $title_singular = 'Schedule';
public $default_values = array();
/**
* This function is not supposed to be called. It is just here to help the po extractor out.
*/
function strings() {
public function strings() {
// Help the pot extractor find these strings.
t('Schedule');
t('Schedules');
@@ -119,23 +119,23 @@ class backup_migrate_schedule extends backup_migrate_item {
/**
* Get the default values for this item.
*/
function get_default_values() {
public function get_default_values() {
return array(
'name' => t("Untitled Schedule"),
'source_id' => 'db',
'enabled' => 1,
'keep' => BACKUP_MIGRATE_KEEP_ALL,
'period' => 60 * 60 * 24,
'storage' => BACKUP_MIGRATE_STORAGE_NONE,
'cron' => BACKUP_MIGRATE_CRON_BUILTIN,
'cron_schedule' => '0 4 * * *',
);
'name' => t("Untitled Schedule"),
'source_id' => 'db',
'enabled' => 1,
'keep' => BACKUP_MIGRATE_KEEP_ALL,
'period' => 60 * 60 * 24,
'storage' => BACKUP_MIGRATE_STORAGE_NONE,
'cron' => BACKUP_MIGRATE_CRON_BUILTIN,
'cron_schedule' => '0 4 * * *',
);
}
/**
* Return as an array of values.
*/
function to_array() {
public function to_array() {
$out = parent::to_array();
unset($out['last_run']);
return $out;
@@ -143,8 +143,8 @@ class backup_migrate_schedule extends backup_migrate_item {
/**
* Get the columns needed to list the type.
*/
function get_list_column_info() {
*/
public function get_list_column_info() {
$out = parent::get_list_column_info();
$out = array(
'name' => array('title' => t('Name')),
@@ -160,8 +160,8 @@ class backup_migrate_schedule extends backup_migrate_item {
/**
* Get the columns needed to list the type.
*/
function get_settings_path() {
*/
public function get_settings_path() {
// Pull the schedules tab up a level to the top.
return BACKUP_MIGRATE_MENU_PATH . '/' . $this->type_name;
}
@@ -169,7 +169,7 @@ class backup_migrate_schedule extends backup_migrate_item {
/**
* Get the menu items for manipulating this type.
*/
function get_menu_items() {
public function get_menu_items() {
$items = parent::get_menu_items();
$path = $this->get_settings_path();
return $items;
@@ -178,15 +178,15 @@ class backup_migrate_schedule extends backup_migrate_item {
/**
* Get a row of data to be used in a list of items of this type.
*/
function get_list_row() {
drupal_add_css(drupal_get_path('module', 'backup_migrate') .'/backup_migrate.css');
public function get_list_row() {
drupal_add_css(drupal_get_path('module', 'backup_migrate') . '/backup_migrate.css');
$row = parent::get_list_row();
if (!$this->is_enabled()) {
foreach ($row as $key => $field) {
if (!is_array($field)) {
$row[$key] = array('data' => $field, 'class' => 'schedule-list-disabled');
}
else if (isset($row[$key]['class'])) {
elseif (isset($row[$key]['class'])) {
$row[$key]['class'] .= ' schedule-list-disabled';
}
else {
@@ -200,7 +200,7 @@ class backup_migrate_schedule extends backup_migrate_item {
/**
* Is the schedule enabled and valid.
*/
function is_enabled() {
public function is_enabled() {
$destination = $this->get_destination();
$profile = $this->get_profile();
return (!empty($this->enabled) && !empty($destination) && !empty($profile));
@@ -209,15 +209,15 @@ class backup_migrate_schedule extends backup_migrate_item {
/**
* Get the destination object of the schedule.
*/
function get_destination() {
$destinations = (array)$this->get_destinations();
public function get_destination() {
$destinations = (array) $this->get_destinations();
return reset($destinations);
}
/**
* Get the destination object of the schedule.
*/
function get_destination_ids() {
public function get_destination_ids() {
$out = array();
foreach (array('destination_id', 'copy_destination_id') as $key) {
if ($id = $this->get($key)) {
@@ -230,7 +230,7 @@ class backup_migrate_schedule extends backup_migrate_item {
/**
* Get the destination object of the schedule.
*/
function get_destinations() {
public function get_destinations() {
backup_migrate_include('destinations');
$out = array();
foreach ($this->get_destination_ids() as $id) {
@@ -244,14 +244,14 @@ class backup_migrate_schedule extends backup_migrate_item {
/**
* Get the destination object of the schedule.
*/
function get_destination_remote() {
public function get_destination_remote() {
backup_migrate_include('destinations');
return backup_migrate_get_destination($this->get('destination_remote_id'));
}
/**
/**
* Get the destination object of the schedule.
*/
function get_destination_local() {
public function get_destination_local() {
backup_migrate_include('destinations');
return backup_migrate_get_destination($this->get('destination_local_id'));
}
@@ -259,28 +259,28 @@ class backup_migrate_schedule extends backup_migrate_item {
/**
* Get the name of the destination.
*/
function get_destination_name() {
public function get_destination_name() {
if ($destinations = $this->get_destinations()) {
$out = array();
foreach ((array)$destinations as $destination) {
foreach ((array) $destinations as $destination) {
$out[] = check_plain($destination->get_name());
}
return implode(', ', $out);
}
return '<div class="row-error">'. t("Missing") .'</div>';
return '<div class="row-error">' . t("Missing") . '</div>';
}
/**
* Get the destination of the schedule.
*/
function get_profile() {
public function get_profile() {
backup_migrate_include('profiles');
if ($settings = backup_migrate_get_profile($this->get('profile_id'))) {
$settings->file_info = empty($settings->file_info) ? array() : $settings->file_info;
$settings->file_info += array(
'schedule_id' => $this->get_id(),
'schedule_name' => $this->get('name'),
);
);
}
return $settings;
@@ -289,23 +289,23 @@ class backup_migrate_schedule extends backup_migrate_item {
/**
* Get the name of the source.
*/
function get_profile_name() {
public function get_profile_name() {
if ($profile = $this->get_profile()) {
return check_plain($profile->get_name());
}
return '<div class="row-error">'. t("Missing") .'</div>';
return '<div class="row-error">' . t("Missing") . '</div>';
}
/**
* Format a frequency in human-readable form.
*/
function get_frequency_description() {
public function get_frequency_description() {
$period = $this->get_frequency_period();
$cron = $this->get('cron');
if ($cron == BACKUP_MIGRATE_CRON_BUILTIN) {
$out = format_plural(($this->period / $period['seconds']), $period['singular'], $period['plural']);
}
else if ($cron == BACKUP_MIGRATE_CRON_ELYSIA) {
elseif ($cron == BACKUP_MIGRATE_CRON_ELYSIA) {
$out = $this->get('cron_schedule');
}
else {
@@ -317,26 +317,26 @@ class backup_migrate_schedule extends backup_migrate_item {
/**
* Format the number to keep in human-readable form.
*/
function get_keep_description() {
public function get_keep_description() {
return $this->generate_keep_description($this->keep);
}
/**
* Format a number to keep in human readable from
* Format a number to keep in human readable from.
*/
function generate_keep_description($keep, $terse = TRUE) {
public function generate_keep_description($keep, $terse = TRUE) {
if ($keep == BACKUP_MIGRATE_KEEP_ALL) {
return t('all backups');
}
else if ($keep == BACKUP_MIGRATE_SMART_DELETE) {
elseif ($keep == BACKUP_MIGRATE_SMART_DELETE) {
$keep_hourly = variable_get('backup_migrate_smart_keep_hourly', BACKUP_MIGRATE_SMART_KEEP_HOURLY);
$keep_daily = variable_get('backup_migrate_smart_keep_daily', BACKUP_MIGRATE_SMART_KEEP_DAILY);
$keep_weekly = variable_get('backup_migrate_smart_keep_weekly', BACKUP_MIGRATE_SMART_KEEP_WEEKLY);
if ($terse) {
return t('!hours hourly, !days daily, !weeks weekly backups',
return t('!hours hourly, !days daily, !weeks weekly backups',
array(
'!hours' => $keep_hourly == PHP_INT_MAX ? t('all') : $keep_hourly,
'!days' => $keep_daily == PHP_INT_MAX ? t('all') : $keep_daily,
'!days' => $keep_daily == PHP_INT_MAX ? t('all') : $keep_daily,
'!weeks' => $keep_weekly == PHP_INT_MAX ? t('all') : $keep_weekly,
));
}
@@ -344,7 +344,7 @@ class backup_migrate_schedule extends backup_migrate_item {
return t('hourly backups !hours, daily backups !days and weekly backups !weeks',
array(
'!hours' => $keep_hourly == PHP_INT_MAX ? t('forever') : format_plural($keep_hourly, 'for 1 hour', 'for the past @count hours'),
'!days' => $keep_daily == PHP_INT_MAX ? t('forever') : format_plural($keep_daily, 'for 1 day', 'for the past @count days'),
'!days' => $keep_daily == PHP_INT_MAX ? t('forever') : format_plural($keep_daily, 'for 1 day', 'for the past @count days'),
'!weeks' => $keep_weekly == PHP_INT_MAX ? t('forever') : format_plural($keep_weekly, 'for 1 week', 'for the past @count weeks'),
)
);
@@ -357,14 +357,14 @@ class backup_migrate_schedule extends backup_migrate_item {
/**
* Format the enabled status in human-readable form.
*/
function get_enabled_description() {
public function get_enabled_description() {
return !empty($this->enabled) ? t('Enabled') : t('Disabled');
}
/**
* Format the enabled status in human-readable form.
*/
function get_last_run_description() {
public function get_last_run_description() {
$last_run = $this->get('last_run');
return !empty($last_run) ? format_date($last_run, 'small') : t('Never');
}
@@ -372,21 +372,21 @@ class backup_migrate_schedule extends backup_migrate_item {
/**
* Get the number of excluded tables.
*/
function get_exclude_tables_count() {
public function get_exclude_tables_count() {
return count($this->exclude_tables) ? count($this->exclude_tables) : t("No tables excluded");
}
/**
* Get the number of excluded tables.
*/
function get_nodata_tables_count() {
public function get_nodata_tables_count() {
return count($this->nodata_tables) ? count($this->nodata_tables) : t("No data omitted");
}
/**
* Get the edit form.
*/
function edit_form() {
public function edit_form() {
$form = parent::edit_form();
backup_migrate_include('destinations', 'sources', 'profiles');
@@ -404,7 +404,7 @@ class backup_migrate_schedule extends backup_migrate_item {
"#options" => _backup_migrate_get_profile_form_item_options(),
"#default_value" => $this->get('profile_id'),
);
$form['profile_id']['#description'] = ' '. l(t("Create new profile"), BACKUP_MIGRATE_MENU_PATH . "/profile/add");
$form['profile_id']['#description'] = ' ' . l(t('Create new profile'), BACKUP_MIGRATE_MENU_PATH . '/settings/profile/add');
if (!$form['profile_id']['#options']) {
$form['profile_id']['#options'] = array('0' => t('-- None Available --'));
}
@@ -437,7 +437,7 @@ class backup_migrate_schedule extends backup_migrate_item {
"#default_value" => $cron ? $cron : BACKUP_MIGRATE_CRON_BUILTIN,
'#parents' => array('cron'),
);
$form['cron_settings']['period_settings'] = array(
'#type' => 'backup_migrate_dependent',
'#dependencies' => array(
@@ -465,7 +465,6 @@ class backup_migrate_schedule extends backup_migrate_item {
'#parents' => array('period', 'type'),
);
$form['cron_settings']['cron_elysia'] = array(
"#type" => "radio",
"#title" => t('Run using Elysia cron'),
@@ -474,7 +473,7 @@ class backup_migrate_schedule extends backup_migrate_item {
"#default_value" => $cron ? $cron : BACKUP_MIGRATE_CRON_BUILTIN,
'#parents' => array('cron'),
);
if (!module_exists('elysia_cron')) {
if (!module_exists('elysia_cron') && !module_exists('ultimate_cron')) {
$form['cron_settings']['cron_elysia']['#disabled'] = TRUE;
$form['cron_settings']['cron_elysia']['#description'] .= ' ' . t('Install !elysia to enable this option.', array('!elysia' => l(t('Elysia Cron'), 'http://drupal.org/project/elysia_cron')));
}
@@ -488,7 +487,7 @@ class backup_migrate_schedule extends backup_migrate_item {
"#type" => "textfield",
"#title" => t('Cron Schedule'),
'#length' => 10,
"#description" => t('Specify the frequecy of the schedule using standard cron notation. For more information see the !elysiareadme.', array('!elysiareadme' => l(t('the Elysia Cron README'), 'http://drupalcode.org/project/elysia_cron.git/blob/refs/heads/7.x-1.x:/README.txt'))),
"#description" => t('Specify the frequency of the schedule using standard cron notation. For more information see the !elysiareadme.', array('!elysiareadme' => l(t('the Elysia Cron README'), 'http://drupalcode.org/project/elysia_cron.git/blob/refs/heads/7.x-1.x:/README.txt'))),
"#default_value" => $this->get('cron_schedule'),
'#parents' => array('cron_schedule'),
);
@@ -502,8 +501,6 @@ class backup_migrate_schedule extends backup_migrate_item {
'#parents' => array('cron'),
);
$keep = $this->get('keep');
$form['delete'] = array(
'#type' => 'checkbox',
@@ -558,7 +555,7 @@ class backup_migrate_schedule extends backup_migrate_item {
/**
* Submit the edit form.
*/
function edit_form_validate($form, &$form_state) {
public function edit_form_validate($form, &$form_state) {
if (!is_numeric($form_state['values']['period']['number']) || $form_state['values']['period']['number'] <= 0) {
form_set_error('period][number', t('Backup period must be a number greater than 0.'));
}
@@ -566,10 +563,10 @@ class backup_migrate_schedule extends backup_migrate_item {
if (!$form_state['values']['delete']) {
$form_state['values']['keep'] = 0;
}
else if ($form_state['values']['deletetype'] == BACKUP_MIGRATE_SMART_DELETE) {
elseif ($form_state['values']['deletetype'] == BACKUP_MIGRATE_SMART_DELETE) {
$form_state['values']['keep'] = BACKUP_MIGRATE_SMART_DELETE;
}
else if (!is_numeric($form_state['values']['keep']) || $form_state['values']['keep'] <= 0) {
elseif (!is_numeric($form_state['values']['keep']) || $form_state['values']['keep'] <= 0) {
form_set_error('keep', t('Number to keep must be a number greater than 0.'));
}
parent::edit_form_validate($form, $form_state);
@@ -578,7 +575,7 @@ class backup_migrate_schedule extends backup_migrate_item {
/**
* Submit the edit form.
*/
function edit_form_submit($form, &$form_state) {
public function edit_form_submit($form, &$form_state) {
$periods = $this->frequency_periods();
$period = $periods[$form_state['values']['period']['type']];
$form_state['values']['period'] = $form_state['values']['period']['number'] * $period['seconds'];
@@ -586,9 +583,9 @@ class backup_migrate_schedule extends backup_migrate_item {
}
/**
* Get the period of the frequency (ie: seconds, minutes etc.)
* Get the period of the frequency (ie: seconds, minutes etc.).
*/
function get_frequency_period() {
public function get_frequency_period() {
foreach (array_reverse($this->frequency_periods()) as $period) {
if ($period['seconds'] && ($this->period % $period['seconds']) === 0) {
return $period;
@@ -600,7 +597,7 @@ class backup_migrate_schedule extends backup_migrate_item {
* Get a list of available backup periods. Only returns time periods which have a
* (reasonably) consistent number of seconds (ie: no months).
*/
function frequency_periods() {
public function frequency_periods() {
return array(
'seconds' => array('type' => 'seconds', 'seconds' => 1, 'title' => t('Seconds'), 'singular' => t('Once a second'), 'plural' => t('Every @count seconds')),
'minutes' => array('type' => 'minutes', 'seconds' => 60, 'title' => t('Minutes'), 'singular' => t('Once a minute'), 'plural' => t('Every @count minutes')),
@@ -613,14 +610,14 @@ class backup_migrate_schedule extends backup_migrate_item {
/**
* Get the message to send to the user when confirming the deletion of the item.
*/
function delete_confirm_message() {
public function delete_confirm_message() {
return t('Are you sure you want to delete the schedule %name? Backups made with this schedule will not be deleted.', array('%name' => $this->get('name')));
}
/**
* Perform the cron action. Run the backup if enough time has elapsed.
*/
function cron() {
public function cron() {
$now = time();
// Add a small negative buffer (1% of the entire period) to the time to account for slight difference in cron run length.
@@ -635,13 +632,17 @@ class backup_migrate_schedule extends backup_migrate_item {
/**
* Run the actual schedule.
*/
function run() {
public function run() {
// Clear cached profile data which could have been altered by previous
// schedule run; see #2672478
drupal_static_reset('backup_migrate_get_profiles');
if ($settings = $this->get_profile()) {
$settings->source_id = $this->get('source_id');
$settings->destination_id = $this->get('destination_ids');
backup_migrate_perform_backup($settings);
$this->update_last_run(time());
backup_migrate_perform_backup($settings);
$this->remove_expired_backups();
}
else {
@@ -652,7 +653,7 @@ class backup_migrate_schedule extends backup_migrate_item {
/**
* Set the last run time of a schedule to the given timestamp, or now if none specified.
*/
function update_last_run($timestamp = NULL) {
public function update_last_run($timestamp = NULL) {
if ($timestamp === NULL) {
$timestamp = time();
}
@@ -662,31 +663,31 @@ class backup_migrate_schedule extends backup_migrate_item {
/**
* Set the last run time of a schedule to the given timestamp, or now if none specified.
*/
function get_last_run() {
public function get_last_run() {
return variable_get('backup_migrate_schedule_last_run_' . $this->get('id'), 0);
}
/**
* Remove older backups keeping only the number specified by the aministrator.
*/
function remove_expired_backups() {
public function remove_expired_backups() {
backup_migrate_include('destinations');
$num_to_keep = $this->keep;
// If num to keep is not 0 (0 is infinity).
foreach ((array)$this->get_destinations() as $destination) {
foreach ((array) $this->get_destinations() as $destination) {
if ($destination && $destination->op('delete') && $destination_files = $destination->list_files()) {
if ($num_to_keep == BACKUP_MIGRATE_SMART_DELETE) {
$this->smart_delete_backups(
$destination,
$destination,
$destination_files,
variable_get('backup_migrate_smart_keep_subhourly', BACKUP_MIGRATE_SMART_KEEP_SUBHOURLY),
variable_get('backup_migrate_smart_keep_hourly', BACKUP_MIGRATE_SMART_KEEP_HOURLY),
variable_get('backup_migrate_smart_keep_daily', BACKUP_MIGRATE_SMART_KEEP_DAILY),
variable_get('backup_migrate_smart_keep_weekly', BACKUP_MIGRATE_SMART_KEEP_WEEKLY)
variable_get('backup_migrate_smart_keep_hourly', BACKUP_MIGRATE_SMART_KEEP_HOURLY),
variable_get('backup_migrate_smart_keep_daily', BACKUP_MIGRATE_SMART_KEEP_DAILY),
variable_get('backup_migrate_smart_keep_weekly', BACKUP_MIGRATE_SMART_KEEP_WEEKLY)
);
}
else if ($num_to_keep != BACKUP_MIGRATE_KEEP_ALL) {
elseif ($num_to_keep != BACKUP_MIGRATE_KEEP_ALL) {
$this->delete_backups($destination, $destination_files, $num_to_keep);
}
}
@@ -696,7 +697,7 @@ class backup_migrate_schedule extends backup_migrate_item {
/**
* Remove older backups keeping only the number specified by the aministrator.
*/
function delete_backups($destination, $files, $num_to_keep) {
public function delete_backups($destination, $files, $num_to_keep) {
backup_migrate_include('destinations');
$num_to_keep = $this->keep;
@@ -729,7 +730,7 @@ class backup_migrate_schedule extends backup_migrate_item {
/**
* Delete files keeping the specified number of hourly, daily, weekly and monthly backups.
*/
function smart_delete_backups($destination, $files, $keep_subhourly = 3600, $keep_hourly = 24, $keep_daily = 14, $keep_weekly = PHP_INT_MAX, $keep_monthly = PHP_INT_MAX) {
public function smart_delete_backups($destination, $files, $keep_subhourly = 3600, $keep_hourly = 24, $keep_daily = 14, $keep_weekly = PHP_INT_MAX, $keep_monthly = PHP_INT_MAX) {
$now = time();
$periods = array(
'subhourly' => array(
@@ -739,19 +740,19 @@ class backup_migrate_schedule extends backup_migrate_item {
'files' => array(),
),
'hourly' => array(
'delta' => 60*60,
'delta' => 60 * 60,
'keep' => $keep_hourly,
'last_time' => 0,
'files' => array(),
),
'daily' => array(
'delta' => 60*60*24,
'delta' => 60 * 60 * 24,
'keep' => $keep_daily,
'last_time' => 0,
'files' => array(),
),
'weekly' => array(
'delta' => 60*60*24*7,
'delta' => 60 * 60 * 24 * 7,
'keep' => $keep_weekly,
'last_time' => 0,
'files' => array(),
@@ -786,7 +787,7 @@ class backup_migrate_schedule extends backup_migrate_item {
$keep_files[$id] = $id;
}
}
// Keep oldest backup or it will get deleted if it doesn't fall on an exact multiple of the period
// Keep oldest backup or it will get deleted if it doesn't fall on an exact multiple of the period.
if ($id) {
$keep_files[$id] = $id;
}
@@ -799,5 +800,5 @@ class backup_migrate_schedule extends backup_migrate_item {
}
}
}
}
}
+75 -49
View File
@@ -1,4 +1,9 @@
<?php
/**
* @file
*/
backup_migrate_include('sources.filesource');
/**
@@ -11,27 +16,31 @@ backup_migrate_include('sources.filesource');
*
* @ingroup backup_migrate_destinations
*/
class backup_migrate_files_destination_archivesource extends backup_migrate_destination_filesource {
var $supported_ops = array('source');
public $supported_ops = array('source');
function type_name() {
public function type_name() {
return t("Site Archive Source");
}
/**
* Declare the current files directory as a backup source..
* Declares the current files directory as a backup source..
*/
function sources() {
$out = array();
$out['archive'] = backup_migrate_create_destination('archive', array('machine_name' => 'archive', 'location' => '.', 'name' => t('Entire Site (code, files & DB)'), 'show_in_list' => FALSE));
public function sources() {
$out = array();
$out['archive'] = backup_migrate_create_destination('archive', array(
'machine_name' => 'archive',
'location' => '.',
'name' => t('Entire Site (code, files & DB)'),
'show_in_list' => FALSE,
));
return $out;
}
/**
* Return a list of backup filetypes.
* Returns a list of backup filetypes.
*/
function file_types() {
public function file_types() {
return array(
"sitearchive" => array(
"extension" => "sitearchive.tar",
@@ -43,14 +52,15 @@ class backup_migrate_files_destination_archivesource extends backup_migrate_dest
}
/**
* Get the form for the settings for this destination.
* Gets the form for the settings for this destination.
*/
function backup_settings_default() {
public function backup_settings_default() {
$out = parent::backup_settings_default();
$excludes = explode("\n", $out['exclude_filepaths']);
foreach ($excludes as $i => $exclude) {
$excludes[$i] = 'public://' . $exclude;
}
$excludes[] = 'private://backup_migrate';
$excludes[] = conf_path() . '/settings.php';
$excludes[] = file_directory_temp();
@@ -62,20 +72,22 @@ class backup_migrate_files_destination_archivesource extends backup_migrate_dest
/**
* Backup from this source.
*/
function _backup_to_file_php($file, $settings) {
public function _backup_to_file_php($file, $settings) {
if ($this->check_libs()) {
$base_dir = $this->get_realpath();
$excluded_paths = empty($settings->filters['exclude_filepaths']) ? '' : $settings->filters['exclude_filepaths'];
$exclude = $this->get_excluded_paths($excluded_paths);
$files = $this->get_files_to_backup($this->get_location(), $settings, $exclude, realpath('.') . '/');
$exclude = $this->get_excluded_paths($settings);
$files = $this->get_files_to_backup($this->get_realpath(), $settings, $exclude);
if ($files) {
$manifest = $this->generate_manifest();
$db = $this->get_db();
$file->push_type('sitearchive');
$gz = new Archive_Tar($file->filepath(), false);
$gz = new Archive_Tar($file->filepath(), FALSE);
$gz->addModify(array($manifest), $file->name .'/', dirname($manifest));
$gz->addModify($files, $file->name .'/docroot', $this->get_location());
$gz->addModify(array($manifest), $file->name . '/', dirname($manifest));
$gz->addModify($files, $file->name . '/docroot', $base_dir);
$gz->addModify($db, $file->name . '/', dirname($db));
unlink($manifest);
@@ -94,7 +106,7 @@ class backup_migrate_files_destination_archivesource extends backup_migrate_dest
/**
* Backup from this source.
*/
function _backup_to_file_cli($file, $settings) {
public function _backup_to_file_cli($file, $settings) {
if (!empty($settings->filters['use_cli']) && function_exists('backup_migrate_exec') && function_exists('escapeshellarg')) {
$excluded_paths = empty($settings->filters['exclude_filepaths']) ? '' : $settings->filters['exclude_filepaths'];
foreach ($this->get_excluded_paths($excluded_paths) as $path) {
@@ -102,7 +114,8 @@ class backup_migrate_files_destination_archivesource extends backup_migrate_dest
}
$exclude = implode(' ', $exclude);
// Create a symlink in a temp directory so we can rename the file in the archive.
// Create a symlink in a temp directory so we can rename the file in the
// archive.
$temp = backup_migrate_temp_directory();
$manifest = $this->generate_manifest();
@@ -113,7 +126,12 @@ class backup_migrate_files_destination_archivesource extends backup_migrate_dest
$file->push_type('sitearchive');
$link = $temp . '/docroot';
$input = realpath($this->get_location());
backup_migrate_exec("ln -s %input %link; tar --dereference -C %temp -rf %output $exclude .", array('%output' => $file->filepath(), '%input' => $input, '%temp' => $temp, '%link' => $link));
backup_migrate_exec("ln -s %input %link; tar --dereference -C %temp -rf %output $exclude .", array(
'%output' => $file->filepath(),
'%input' => $input,
'%temp' => $temp,
'%link' => $link,
));
return $file;
}
@@ -121,15 +139,15 @@ class backup_migrate_files_destination_archivesource extends backup_migrate_dest
}
/**
* Generate a manifest file.
* Generates a manifest file.
*/
function generate_manifest() {
public function generate_manifest() {
$info = array(
'Global' => array(
'datestamp' => time(),
'formatversion' => '2011-07-02',
'generator' => 'Backup and Migrate (http://drupal.org/project/backup_migrate)',
'generatorversion' => BACKUP_MIGRATE_VERSION,
'generatorversion' => BACKUP_MIGRATE_VERSION,
),
'Site 0' => array(
'version' => VERSION,
@@ -153,18 +171,23 @@ class backup_migrate_files_destination_archivesource extends backup_migrate_dest
}
/**
* Get a database dump to add to the archive.
* Gets a database dump to add to the archive.
*/
function get_db() {
public function get_db() {
backup_migrate_include('destinations', 'files', 'filters', 'profiles');
$file = new backup_file();
$settings = _backup_migrate_profile_saved_default_profile();
// Clone the default settings so we can make changes without them leaking
// out of this function.
$settings = clone _backup_migrate_profile_saved_default_profile();
$settings->source_id = 'db';
$settings->filters['compression'] = 'none';
// Execute the backup on the db with the default settings.
$file = backup_migrate_filters_backup($file, $settings);
// Generate a tmp file with the correct final title (because ArchiveTar doesn't seem to allow renaming).
// Generate a tmp file with the correct final title (because ArchiveTar
// doesn't seem to allow renaming).
$tmpdir = backup_migrate_temp_directory();
$filepath = $tmpdir . '/database.sql';
rename($file->filepath(), $filepath);
@@ -173,10 +196,10 @@ class backup_migrate_files_destination_archivesource extends backup_migrate_dest
}
/**
* Restore to this source.
* Restores to this source.
*/
function _restore_from_file_php($file, &$settings) {
$success = false;
public function _restore_from_file_php($file, &$settings) {
$success = FALSE;
if ($this->check_libs()) {
$from = $file->pop_type();
$temp = backup_migrate_temp_directory();
@@ -184,25 +207,25 @@ class backup_migrate_files_destination_archivesource extends backup_migrate_dest
$tar = new Archive_Tar($from->filepath());
$tar->extractModify($temp, $file->name);
// Parse the manifest
// Parse the manifest.
$manifest = $this->read_manifest($temp);
// Currently only the first site in the archive is supported.
$site = $manifest['Site 0'];
$docroot = $temp . '/' . $site['docroot'];
$sqlfile = $temp . '/' . $site['database-file-default'];
$docroot = $temp . '/' . $site['docroot'];
$sqlfile = $temp . '/' . $site['database-file-default'];
$filepath = NULL;
if (isset($site['files-private'])) {
$filepath = $temp . '/' . $site['files-private'];
}
else if (isset($site['files-public'])) {
elseif (isset($site['files-public'])) {
$filepath = $temp . '/' . $site['files-public'];
}
// Move the files from the temp directory.
if ($filepath && file_exists($filepath)) {
_backup_migrate_move_files($filepath, file_directory_path());
_backup_migrate_move_files($filepath, variable_get('file_public_path', conf_path() . '/files'));
}
else {
_backup_migrate_message('Files were not restored because the archive did not seem to contain a files directory or was in a format that Backup and Migrate couldn\'t read', array(), 'warning');
@@ -210,7 +233,7 @@ class backup_migrate_files_destination_archivesource extends backup_migrate_dest
// Restore the sql db.
if ($sqlfile && file_exists($sqlfile)) {
$db_settings = drupal_clone($settings);
$db_settings = clone $settings;
$db_settings->source_id = 'db';
$file = new backup_file(array('filepath' => $sqlfile));
$success = backup_migrate_filters_restore($file, $db_settings);
@@ -229,17 +252,17 @@ class backup_migrate_files_destination_archivesource extends backup_migrate_dest
}
/**
* Restore to this source.
* Restores to this source.
*/
function _restore_from_file_cli($file, &$settings) {
public function _restore_from_file_cli($file, &$settings) {
// @TODO: implement the cli version of the restore.
return FALSE;
}
/**
* Generate a manifest file.
* Generates a manifest file.
*/
function read_manifest($directory) {
public function read_manifest($directory) {
// Assume some defaults if values ore the manifest is missing.
$defaults = array(
'docroot' => 'docroot',
@@ -256,16 +279,17 @@ class backup_migrate_files_destination_archivesource extends backup_migrate_dest
return $out;
}
/**
* Convert an associated array to an ini format string. Only allows 2 levels of depth to allow parse_ini_file to parse.
* Converts an associated array to an ini format string.
*
* Only allows 2 levels of depth to allow parse_ini_file to parse.
*/
function _array_to_ini($sections) {
$content = "";
public function _array_to_ini($sections) {
$content = "";
foreach ($sections as $section => $data) {
$content .= '['. $section .']' . "\n";
$content .= '[' . $section . ']' . "\n";
foreach ($data as $key => $val) {
$content .= $key . " = \"". $val ."\"\n";
$content .= $key . " = \"" . $val . "\"\n";
}
$content .= "\n";
}
@@ -273,10 +297,12 @@ class backup_migrate_files_destination_archivesource extends backup_migrate_dest
}
/**
* Convert an associated array to an ini format string. Only allows 2 levels of depth to allow parse_ini_file to parse.
* Converts an associated array to an ini format string.
*
* Only allows 2 levels of depth to allow parse_ini_file to parse.
*/
function _ini_to_array($path) {
public function _ini_to_array($path) {
return parse_ini_file($path, TRUE);
}
}
}
@@ -1,6 +1,5 @@
<?php
/**
* @file
* Functions to handle the direct to database destination.
@@ -12,22 +11,22 @@
* @ingroup backup_migrate_destinations
*/
class backup_migrate_source_db extends backup_migrate_source_remote {
var $supported_ops = array('configure', 'source');
var $db_target = 'default';
var $connection = null;
public $supported_ops = array('configure', 'source');
public $db_target = 'default';
public $connection = NULL;
function type_name() {
public function type_name() {
return t("Database");
}
/**
* Save the info by importing it into the database.
*/
function save_file($file, $settings) {
public function save_file($file, $settings) {
backup_migrate_include('files');
// Set the source_id to the destination_id in the settings since for a restore, the source_id is the
// Set the source_id to the destination_id in the settings since for a restore, the source_id is the
// database that gets restored to.
$settings->set_source($this->get_id());
@@ -40,7 +39,7 @@ class backup_migrate_source_db extends backup_migrate_source_remote {
/**
* Destination configuration callback.
*/
function edit_form() {
public function edit_form() {
$form = parent::edit_form();
$form['scheme']['#default_value'] = $this->default_scheme();
$form['scheme']['#access'] = FALSE;
@@ -53,7 +52,7 @@ class backup_migrate_source_db extends backup_migrate_source_remote {
/**
* Validate the configuration form. Make sure the db info is valid.
*/
function edit_form_validate($form, &$form_state) {
public function edit_form_validate($form, &$form_state) {
if (!preg_match('/[a-zA-Z0-9_\$]+/', $form_state['values']['path'])) {
form_set_error('path', t('The database name is not valid.'));
}
@@ -61,56 +60,63 @@ class backup_migrate_source_db extends backup_migrate_source_remote {
}
/**
* Get the form for the settings for this destination.
* Get the default settings for this object.
*
* Return the default tables whose data can be ignored. These tables mostly contain
* info which can be easily reproducted (such as cache or search index)
* but also tables which can become quite bloated but are not necessarily extremely
* important to back up or migrate during development (such ass access log and watchdog)
* @return array
* The default tables whose data can be ignored. These tables mostly
* contain info which can be easily reproducted (such as cache or search
* index) but also tables which can become quite bloated but are not
* necessarily extremely important to back up or migrate during development
* (such as access log and watchdog).
*/
function backup_settings_default() {
$core = array(
'cache',
'cache_admin_menu',
'cache_browscap',
'cache_content',
'cache_filter',
'cache_calendar_ical',
'cache_location',
'cache_menu',
'cache_page',
'cache_reptag',
'cache_views',
'cache_views_data',
'cache_block',
'cache_update',
'cache_form',
'cache_bootstrap',
'cache_field',
'cache_image',
'cache_path',
'sessions',
'search_dataset',
'search_index',
'search_keywords_log',
'search_total',
'watchdog',
'accesslog',
'devel_queries',
'devel_times',
);
$nodata_tables = array_merge($core, module_invoke_all('devel_caches'));
return array(
'nodata_tables' => $nodata_tables,
'exclude_tables' => array(),
public function backup_settings_default() {
$all_tables = $this->_get_table_names();
// Basic modules that should be excluded.
$basic = array(
// Default core tables.
'accesslog',
'sessions',
'watchdog',
// Search module.
'search_dataset',
'search_index',
'search_keywords_log',
'search_total',
// Devel module.
'devel_queries',
'devel_times',
);
// Identify all cache tables.
$cache = array('cache');
foreach ($all_tables as $table_name) {
if (strpos($table_name, 'cache_') === 0) {
$cache[] = $table_name;
}
}
// Simpletest can create a lot of tables that do not need to be backed up,
// but all of them start with the string 'simpletest' so they can be easily
// excluded.
$simpletest = array();
foreach ($all_tables as $table_name) {
if (strpos($table_name, 'simpletest') === 0) {
$simpletest[] = $table_name;
}
}
return array(
'nodata_tables' => drupal_map_assoc(array_merge($basic, $cache, module_invoke_all('devel_caches'))),
'exclude_tables' => $simpletest,
'utils_lock_tables' => FALSE,
);
);
}
/**
* Get the form for the backup settings for this destination.
*/
function backup_settings_form($settings) {
public function backup_settings_form($settings) {
$objects = $this->get_object_names();
$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(
@@ -141,23 +147,27 @@ class backup_migrate_source_db extends backup_migrate_source_remote {
/**
* Backup from this source.
*/
function backup_to_file($file, $settings) {
public function backup_to_file($file, $settings) {
$file->push_type($this->get_file_type_id());
//$this->lock_tables($settings);
// $this->lock_tables($settings);
// Switch to a different db if specified.
if (variable_get('backup_migrate_verbose')) {
_backup_migrate_message('Start peak memory usage: %mem', array('%mem' => backup_migrate_get_peak_memory_usage() . 'MB'), 'success');
}
$success = $this->_backup_db_to_file($file, $settings);
if (variable_get('backup_migrate_verbose')) {
_backup_migrate_message('Finish peak memory usage: %mem', array('%mem' => backup_migrate_get_peak_memory_usage() . 'MB'), 'success');
}
//$this->unlock_tables($settings);
// $this->unlock_tables($settings);
return $success ? $file : FALSE;
}
/**
* Restore to this source.
*/
function restore_from_file($file, &$settings) {
public function restore_from_file($file, &$settings) {
$num = 0;
$type = $this->get_file_type_id();
// Open the file using the file wrapper. Check that the dump is of the right type (allow .sql for legacy reasons).
@@ -179,7 +189,7 @@ class backup_migrate_source_db extends backup_migrate_source_remote {
/**
* Get the db connection for the specified db.
*/
function _get_db_connection() {
public function _get_db_connection() {
if (!$this->connection) {
$target = $key = '';
$parts = explode(':', $this->get_id());
@@ -193,12 +203,12 @@ class backup_migrate_source_db extends backup_migrate_source_remote {
// If the url is specified build it into a connection info array.
if (!empty($this->dest_url)) {
$info = array(
'driver' => empty($this->dest_url['scheme']) ? NULL : $this->dest_url['scheme'],
'host' => empty($this->dest_url['host']) ? NULL : $this->dest_url['host'],
'port' => empty($this->dest_url['port']) ? NULL : $this->dest_url['port'],
'username' => empty($this->dest_url['user']) ? NULL : $this->dest_url['user'],
'password' => empty($this->dest_url['pass']) ? NULL : $this->dest_url['pass'],
'database' => empty($this->dest_url['path']) ? NULL : $this->dest_url['path'],
'driver' => empty($this->dest_url['scheme']) ? NULL : $this->dest_url['scheme'],
'host' => empty($this->dest_url['host']) ? NULL : $this->dest_url['host'],
'port' => empty($this->dest_url['port']) ? NULL : $this->dest_url['port'],
'username' => empty($this->dest_url['user']) ? NULL : $this->dest_url['user'],
'password' => empty($this->dest_url['pass']) ? NULL : $this->dest_url['pass'],
'database' => empty($this->dest_url['path']) ? NULL : $this->dest_url['path'],
);
$key = uniqid('backup_migrate_tmp_');
$target = 'default';
@@ -219,21 +229,21 @@ class backup_migrate_source_db extends backup_migrate_source_remote {
/**
* Backup the databases to a file.
*/
function _backup_db_to_file($file, $settings) {
public function _backup_db_to_file($file, $settings) {
// Must be overridden.
}
/**
* Backup the databases to a file.
*/
function _restore_db_from_file($file, $settings) {
public function _restore_db_from_file($file, $settings) {
// Must be overridden.
}
/**
* Get a list of objects in the database.
*/
function get_object_names() {
public function get_object_names() {
// Must be overridden.
$out = $this->_get_table_names();
if (method_exists($this, '_get_view_names')) {
@@ -245,7 +255,7 @@ class backup_migrate_source_db extends backup_migrate_source_remote {
/**
* Get a list of tables in the database.
*/
function get_table_names() {
public function get_table_names() {
// Must be overridden.
$out = $this->_get_table_names();
return $out;
@@ -254,7 +264,7 @@ class backup_migrate_source_db extends backup_migrate_source_remote {
/**
* Get a list of tables in the database.
*/
function _get_table_names() {
public function _get_table_names() {
// Must be overridden.
return array();
}
@@ -262,12 +272,12 @@ class backup_migrate_source_db extends backup_migrate_source_remote {
/**
* Lock the database in anticipation of a backup.
*/
function lock_tables($settings) {
public function lock_tables($settings) {
if ($settings->filters['utils_lock_tables']) {
$tables = array();
foreach ($this->get_table_names() as $table) {
// There's no need to lock excluded or structure only tables because it doesn't matter if they change.
if (empty($settings->filters['exclude_tables']) || !in_array($table, (array)$settings->filters['exclude_tables'])) {
if (empty($settings->filters['exclude_tables']) || !in_array($table, (array) $settings->filters['exclude_tables'])) {
$tables[] = $table;
}
}
@@ -278,14 +288,14 @@ class backup_migrate_source_db extends backup_migrate_source_remote {
/**
* Lock the list of given tables in the database.
*/
function _lock_tables($tables) {
public function _lock_tables($tables) {
// Must be overridden.
}
/**
* Unlock any tables that have been locked.
*/
function unlock_tables($settings) {
public function unlock_tables($settings) {
if ($settings->filters['utils_lock_tables']) {
$this->_unlock_tables();
}
@@ -294,21 +304,21 @@ class backup_migrate_source_db extends backup_migrate_source_remote {
/**
* Unlock the list of given tables in the database.
*/
function _unlock_tables($tables) {
public function _unlock_tables($tables) {
// Must be overridden.
}
/**
* Get the file type for to backup this destination to.
*/
function get_file_type_id() {
public function get_file_type_id() {
return 'sql';
}
/**
* Get the version info for the given DB.
*/
function _db_info() {
public function _db_info() {
return array(
'type' => FALSE,
'version' => t('Unknown'),
@@ -1,5 +1,9 @@
<?php
/**
* @file
*/
backup_migrate_include('sources.db');
/**
@@ -12,16 +16,15 @@ backup_migrate_include('sources.db');
*
* @ingroup backup_migrate_destinations
*/
class backup_migrate_source_db_mysql extends backup_migrate_source_db {
function type_name() {
public function type_name() {
return t("MySQL Database");
}
/**
* Return a list of backup filetypes.
*/
function file_types() {
public function file_types() {
return array(
"sql" => array(
"extension" => "sql",
@@ -41,25 +44,34 @@ class backup_migrate_source_db_mysql extends backup_migrate_source_db {
/**
* Return the scheme for this db type.
*/
function default_scheme() {
public function default_scheme() {
return 'mysql';
}
/**
/**
* Declare any mysql databases defined in the settings.php file as a possible source.
*/
function sources() {
public function sources() {
$out = array();
global $databases;
foreach ((array)$databases as $db_key => $target) {
foreach ((array)$target as $tgt_key => $info) {
foreach ((array) $databases as $db_key => $target) {
foreach ((array) $target as $tgt_key => $info) {
// Only mysql/mysqli supported by this source.
$key = $db_key . ':' . $tgt_key;
if ($info['driver'] === 'mysql') {
$url = $info['driver'] . '://' . $info['username'] . ':' . $info['password'] . '@' . $info['host'] . (isset($info['port']) ? ':' . $info['port'] : '') . '/' . $info['database'];
// Compile the database connection string.
$url = 'mysql://';
$url .= urlencode($info['username']) . ':' . urlencode($info['password']);
$url .= '@';
$url .= urlencode($info['host']);
if (!empty($info['port'])) {
$url .= ':' . $info['port'];
}
$url .= '/' . urlencode($info['database']);
if ($source = backup_migrate_create_destination('mysql', array('url' => $url))) {
// Treat the default database differently because it is probably the only one available.
// Treat the default database differently because it is probably
// the only one available.
if ($key == 'default:default') {
$source->set_id('db');
$source->set_name(t('Default Database'));
@@ -68,8 +80,8 @@ class backup_migrate_source_db_mysql extends backup_migrate_source_db {
$source->remove_op('manual backup');
}
else {
$source->set_id('db:'. $key);
$source->set_name($key .": ". $source->get_display_location());
$source->set_id('db:' . $key);
$source->set_name($key . ": " . $source->get_display_location());
}
$out[$source->get_id()] = $source;
}
@@ -82,7 +94,7 @@ class backup_migrate_source_db_mysql extends backup_migrate_source_db {
/**
* Get the file type for to backup this source to.
*/
function get_file_type_id() {
public function get_file_type_id() {
return 'mysql';
}
@@ -91,9 +103,9 @@ class backup_migrate_source_db_mysql extends backup_migrate_source_db {
*
* Returns a list of sql commands, one command per line.
* That makes it easier to import without loading the whole file into memory.
* The files are a little harder to read, but human-readability is not a priority
* The files are a little harder to read, but human-readability is not a priority.
*/
function _backup_db_to_file($file, $settings) {
public function _backup_db_to_file($file, $settings) {
if (!empty($settings->filters['use_cli']) && $this->_backup_db_to_file_mysqldump($file, $settings)) {
return TRUE;
}
@@ -135,16 +147,14 @@ class backup_migrate_source_db_mysql extends backup_migrate_source_db {
}
}
/**
* Backup the databases to a file using the mysqldump command.
*/
function _backup_db_to_file_mysqldump($file, $settings) {
public function _backup_db_to_file_mysqldump($file, $settings) {
$success = FALSE;
$nodata_tables = array();
$alltables = $this->_get_tables();
$command = 'mysqldump --result-file=%file --opt -Q --host=%host --port=%port --user=%user --password=%pass %db';
$args = array(
'%file' => $file->filepath(),
@@ -158,15 +168,15 @@ class backup_migrate_source_db_mysql extends backup_migrate_source_db {
// Ignore the excluded and no-data tables.
if (!empty($settings->filters['exclude_tables'])) {
$db = $this->dest_url['path'];
foreach ((array)$settings->filters['exclude_tables'] as $table) {
foreach ((array) $settings->filters['exclude_tables'] as $table) {
if (isset($alltables[$table])) {
$command .= ' --ignore-table='. $db .'.'. $table;
$command .= ' --ignore-table=' . $db . '.' . $table;
}
}
foreach ((array)$settings->filters['nodata_tables'] as $table) {
foreach ((array) $settings->filters['nodata_tables'] as $table) {
if (isset($alltables[$table])) {
$nodata_tables[] = $table;
$command .= ' --ignore-table='. $db .'.'. $table;
$command .= ' --ignore-table=' . $db . '.' . $table;
}
}
}
@@ -184,10 +194,19 @@ class backup_migrate_source_db_mysql extends backup_migrate_source_db {
/**
* Backup the databases to a file.
*/
function _restore_db_from_file($file, $settings) {
public function _restore_db_from_file($file, $settings) {
$num = 0;
if ($file->open() && $conn = $this->_get_db_connection()) {
// Optionally drop all existing tables.
if (!empty($settings->filters['utils_drop_all_tables'])) {
$all_tables = $this->_get_tables();
$table_names = array_map('backup_migrate_array_name_value', $all_tables);
$table_list = join(', ', $table_names);
$stmt = $conn->prepare("DROP TABLE IF EXISTS $table_list;\n");
$stmt->execute();
}
// Read one line at a time and run the query.
while ($line = $this->_read_sql_command_from_file($file)) {
if (_backup_migrate_check_timeout()) {
@@ -210,17 +229,16 @@ class backup_migrate_source_db_mysql extends backup_migrate_source_db {
return $num;
}
/**
* Read a multiline sql command from a file.
*
* Supports the formatting created by mysqldump, but won't handle multiline comments.
*/
function _read_sql_command_from_file($file) {
public function _read_sql_command_from_file($file) {
$out = '';
while ($line = $file->read()) {
$first2 = substr($line, 0, 2);
$first3 = substr($line, 0, 2);
$first3 = substr($line, 0, 3);
// Ignore single line comments. This function doesn't support multiline comments or inline comments.
if ($first2 != '--' && ($first2 != '/*' || $first3 == '/*!')) {
@@ -237,7 +255,7 @@ class backup_migrate_source_db_mysql extends backup_migrate_source_db {
/**
* Get a list of tables in the database.
*/
function _get_table_names() {
public function _get_table_names() {
$out = array();
foreach ($this->_get_tables() as $table) {
$out[$table['name']] = $table['name'];
@@ -248,7 +266,7 @@ class backup_migrate_source_db_mysql extends backup_migrate_source_db {
/**
* Get a list of views in the database.
*/
function _get_view_names() {
public function _get_view_names() {
$out = array();
foreach ($this->_get_views() as $view) {
$out[$view['name']] = $view['name'];
@@ -259,29 +277,29 @@ class backup_migrate_source_db_mysql extends backup_migrate_source_db {
/**
* Lock the list of given tables in the database.
*/
function _lock_tables($tables) {
public function _lock_tables($tables) {
if ($tables) {
$tables_escaped = array();
foreach ($tables as $table) {
$tables_escaped[] = '`'. db_escape_table($table) .'` WRITE';
$tables_escaped[] = '`' . db_escape_table($table) . '` WRITE';
}
$this->query('LOCK TABLES '. implode(', ', $tables_escaped));
$this->query('LOCK TABLES ' . implode(', ', $tables_escaped));
}
}
/**
* Unlock all tables in the database.
*/
function _unlock_tables($settings) {
public function _unlock_tables($settings) {
$this->query('UNLOCK TABLES');
}
/**
* Get a list of tables in the db.
*/
function _get_tables() {
public function _get_tables() {
$out = array();
// get auto_increment values and names of all tables
// get auto_increment values and names of all tables.
$tables = $this->query("show table status", array(), array('fetch' => PDO::FETCH_ASSOC));
foreach ($tables as $table) {
// Lowercase the keys because between Drupal 7.12 and 7.13/14 the default query behavior was changed.
@@ -297,9 +315,9 @@ class backup_migrate_source_db_mysql extends backup_migrate_source_db {
/**
* Get a list of views in the db.
*/
function _get_views() {
public function _get_views() {
$out = array();
// get auto_increment values and names of all tables
// get auto_increment values and names of all tables.
$tables = $this->query("show table status", array(), array('fetch' => PDO::FETCH_ASSOC));
foreach ($tables as $table) {
// Lowercase the keys because between Drupal 7.12 and 7.13/14 the default query behavior was changed.
@@ -312,12 +330,12 @@ class backup_migrate_source_db_mysql extends backup_migrate_source_db {
return $out;
}
/**
/**
* Get the sql for the structure of the given view.
*/
function _get_view_create_sql($view) {
public function _get_view_create_sql($view) {
$out = "";
// Switch SQL mode to get rid of "CREATE ALGORITHM..." what requires more permissions + troubles with the DEFINER user
// Switch SQL mode to get rid of "CREATE ALGORITHM..." what requires more permissions + troubles with the DEFINER user.
$sql_mode = $this->query("SELECT @@SESSION.sql_mode")->fetchField();
$this->query("SET sql_mode = 'ANSI'");
$result = $this->query("SHOW CREATE VIEW `" . $view['name'] . "`", array(), array('fetch' => PDO::FETCH_ASSOC));
@@ -326,7 +344,7 @@ class backup_migrate_source_db_mysql extends backup_migrate_source_db {
// Lowercase the keys because between Drupal 7.12 and 7.13/14 the default query behavior was changed.
// See: http://drupal.org/node/1171866
$create = array_change_key_case($create);
$out .= "DROP VIEW IF EXISTS `". $view['name'] ."`;\n";
$out .= "DROP VIEW IF EXISTS `" . $view['name'] . "`;\n";
$out .= "SET sql_mode = 'ANSI';\n";
$out .= strtr($create['create view'], "\n", " ") . ";\n";
$out .= "SET sql_mode = '$sql_mode';\n";
@@ -339,86 +357,105 @@ class backup_migrate_source_db_mysql extends backup_migrate_source_db {
/**
* Get the sql for the structure of the given table.
*/
function _get_table_structure_sql($table) {
public function _get_table_structure_sql($table) {
$out = "";
$result = $this->query("SHOW CREATE TABLE `". $table['name'] ."`", array(), array('fetch' => PDO::FETCH_ASSOC));
$result = $this->query("SHOW CREATE TABLE `" . $table['name'] . "`", array(), array('fetch' => PDO::FETCH_ASSOC));
foreach ($result as $create) {
// Lowercase the keys because between Drupal 7.12 and 7.13/14 the default query behavior was changed.
// See: http://drupal.org/node/1171866
$create = array_change_key_case($create);
$out .= "DROP TABLE IF EXISTS `". $table['name'] ."`;\n";
$out .= "DROP TABLE IF EXISTS `" . $table['name'] . "`;\n";
// Remove newlines and convert " to ` because PDO seems to convert those for some reason.
$out .= strtr($create['create table'], array("\n" => ' ', '"' => '`'));
if ($table['auto_increment']) {
$out .= " AUTO_INCREMENT=". $table['auto_increment'];
$out .= " AUTO_INCREMENT=" . $table['auto_increment'];
}
$out .= ";\n";
}
return $out;
}
/**
* Get the sql to insert the data for a given table
* Get the sql to insert the data for a given table.
*/
function _dump_table_data_sql_to_file($file, $table) {
public function _dump_table_data_sql_to_file($file, $table) {
$rows_per_query = variable_get('backup_migrate_data_rows_per_query', 1000);
$rows_per_line = variable_get('backup_migrate_data_rows_per_line', 30);
$bytes_per_line = variable_get('backup_migrate_data_bytes_per_line', 2000);
$lines = 0;
$data = $this->query("SELECT * FROM `". $table['name'] ."`", array(), array('fetch' => PDO::FETCH_ASSOC));
$rows = $bytes = 0;
// Escape backslashes, PHP code, special chars
if (variable_get('backup_migrate_verbose')) {
_backup_migrate_message('Table: %table', array('%table' => $table['name']), 'success');
}
// Escape backslashes, PHP code, special chars.
$search = array('\\', "'", "\x00", "\x0a", "\x0d", "\x1a");
$replace = array('\\\\', "''", '\0', '\n', '\r', '\Z');
$line = array();
foreach ($data as $row) {
// DB Escape the values.
$items = array();
foreach ($row as $key => $value) {
$items[] = is_null($value) ? "null" : "'". str_replace($search, $replace, $value) ."'";
$lines = 0;
$from = 0;
$args = array('fetch' => PDO::FETCH_ASSOC);
while ($data = $this->query("SELECT * FROM `" . $table['name'] . "`", array(), $args, $from, $rows_per_query)) {
if ($data->rowCount() == 0) {
break;
}
// If there is a row to be added.
if ($items) {
// Start a new line if we need to.
if ($rows == 0) {
$file->write("INSERT INTO `". $table['name'] ."` VALUES ");
$bytes = $rows = 0;
$rows = $bytes = 0;
$line = array();
foreach ($data as $row) {
$from++;
// DB Escape the values.
$items = array();
foreach ($row as $key => $value) {
$items[] = is_null($value) ? "null" : "'" . str_replace($search, $replace, $value) . "'";
}
// Otherwise add a comma to end the previous entry.
else {
$file->write(",");
}
// Write the data itself.
$sql = implode(',', $items);
$file->write('('. $sql .')');
$bytes += strlen($sql);
$rows++;
// Finish the last line if we've added enough items
if ($rows >= $rows_per_line || $bytes >= $bytes_per_line) {
$file->write(";\n");
$lines++;
$bytes = $rows = 0;
// If there is a row to be added.
if ($items) {
// Start a new line if we need to.
if ($rows == 0) {
$file->write("INSERT INTO `" . $table['name'] . "` VALUES ");
$bytes = $rows = 0;
}
// Otherwise add a comma to end the previous entry.
else {
$file->write(",");
}
// Write the data itself.
$sql = implode(',', $items);
$file->write('(' . $sql . ')');
$bytes += strlen($sql);
$rows++;
// Finish the last line if we've added enough items.
if ($rows >= $rows_per_line || $bytes >= $bytes_per_line) {
$file->write(";\n");
$lines++;
$bytes = $rows = 0;
}
}
}
// Finish any unfinished insert statements.
if ($rows > 0) {
$file->write(";\n");
$lines++;
}
}
// Finish any unfinished insert statements.
if ($rows > 0) {
$file->write(";\n");
$lines++;
if (variable_get('backup_migrate_verbose')) {
_backup_migrate_message('Peak memory usage: %mem', array('%mem' => backup_migrate_get_peak_memory_usage() . 'MB'), 'success');
}
return $lines;
}
/**
* Get the db connection for the specified db.
*/
function _get_db_connection() {
public function _get_db_connection() {
if (!$this->connection) {
$this->connection = parent::_get_db_connection();
// Set the sql mode because the default is ANSI,TRADITIONAL which is not aware of collation or storage engine.
@@ -428,11 +465,34 @@ class backup_migrate_source_db_mysql extends backup_migrate_source_db {
}
/**
* Run a db query on this destination's db.
* Run a query on this source's database using Drupal's MySQL engine.
*
* @param string $query
* The query string.
* @param array $args
* Arguments for the query.
* @param array $options
* Options to pass to the query.
* @param int|null $from
* The starting point for the query; when passed will perform a queryRange()
* method instead of a regular query().
* @param int|null $count
* The number of records to obtain from this query. Will be ignored if the
* $from argument is empty.
*
* @see DatabaseConnection_mysql::query()
* @see DatabaseConnection_mysql::queryRange()
*/
function query($query, $args = array(), $options = array()) {
public function query($query, array $args = array(), array $options = array(), $from = NULL, $count = NULL) {
if ($conn = $this->_get_db_connection()) {
return $conn->query($query, $args, $options);
// If no $from is passed in, just do a basic query.
if (is_null($from)) {
return $conn->query($query, $args, $options);
}
// The $from variable was passed in, so do a ranged query.
else {
return $conn->queryRange($query, $from, $count, $args, $options);
}
}
}
@@ -440,11 +500,11 @@ class backup_migrate_source_db_mysql extends backup_migrate_source_db {
* The header for the top of the sql dump file. These commands set the connection
* character encoding to help prevent encoding conversion issues.
*/
function _get_sql_file_header() {
public function _get_sql_file_header() {
$info = $this->_db_info();
return "-- Backup and Migrate (Drupal) MySQL Dump
-- Backup and Migrate Version: ". BACKUP_MIGRATE_VERSION ."
-- Backup and Migrate Version: " . BACKUP_MIGRATE_VERSION . "
-- http://drupal.org/project/backup_migrate
-- Drupal Version: " . VERSION . "
-- http://drupal.org/
@@ -466,11 +526,11 @@ SET NAMES utf8;
";
}
/**
* The footer of the sql dump file.
*/
function _get_sql_file_footer() {
public function _get_sql_file_footer() {
return "
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
@@ -485,7 +545,7 @@ SET NAMES utf8;
/**
* Get the version info for the given DB.
*/
function _db_info() {
public function _db_info() {
$db = $this->_get_db_connection();
return array(
'type' => 'mysql',
@@ -494,4 +554,3 @@ SET NAMES utf8;
}
}
@@ -1,6 +1,5 @@
<?php
/**
* @file
* A destination type for saving locally to the server.
@@ -11,45 +10,54 @@
*
* @ingroup backup_migrate_destinations
*/
class backup_migrate_destination_filesource extends backup_migrate_source {
var $supported_ops = array('restore', 'configure', 'delete', 'source');
public $supported_ops = array('restore', 'configure', 'delete', 'source');
function type_name() {
public function type_name() {
return t("Files Directory");
}
/**
* Declare the current files directory as a backup source..
* Declares the current files directory as a backup source..
*/
function sources() {
$out = array();
$out['files'] = backup_migrate_create_destination('filesource', array('machine_name' => 'files', 'location' => 'public://', 'name' => t('Public Files Directory'), 'show_in_list' => FALSE));
public function sources() {
$out = array();
$out['files'] = backup_migrate_create_destination('filesource', array(
'machine_name' => 'files',
'location' => 'public://',
'name' => t('Public Files Directory'),
'show_in_list' => FALSE,
));
if (variable_get('file_private_path', FALSE)) {
$out['files_private'] = backup_migrate_create_destination('filesource', array('machine_name' => 'files', 'location' => 'private://', 'name' => t('Private Files Directory'), 'show_in_list' => FALSE));
$out['files_private'] = backup_migrate_create_destination('filesource', array(
'machine_name' => 'files',
'location' => 'private://',
'name' => t('Private Files Directory'),
'show_in_list' => FALSE,
));
}
return $out;
}
/**
* Get the form for the settings for the files destination.
* Gets the form for the settings for the files destination.
*/
function edit_form() {
public function edit_form() {
$form = parent::edit_form();
$form['location'] = array(
"#type" => "textfield",
"#title" => t("Directory path"),
"#default_value" => $this->get_location(),
"#required" => TRUE,
"#description" => t('Enter the path to the directory to save the backups to. Use a relative path to pick a path relative to your Drupal root directory. The web server must be able to write to this path.'),
"#description" => t('Enter the path to the directory to back up. Use a relative path to pick a path relative to your Drupal root directory. The web server must be able to read from this path.'),
);
return $form;
}
/**
* Return a list of backup filetypes.
* Returns a list of backup filetypes.
*/
function file_types() {
public function file_types() {
return array(
"tar" => array(
"extension" => "tar",
@@ -61,27 +69,27 @@ class backup_migrate_destination_filesource extends backup_migrate_source {
}
/**
* Get the form for the settings for this destination.
* Gets the form for the settings for this destination.
*
* Return the default directories whose data can be ignored. These directories contain
* info which can be easily reproducted. Also exclude the backup and migrate folder
* to prevent exponential bloat.
* Return the default directories whose data can be ignored. These directories
* contain info which can be easily reproducted. Also exclude the backup and
* migrate folder to prevent exponential bloat.
*/
function backup_settings_default() {
return array(
'exclude_filepaths' => "backup_migrate\nstyles\ncss\njs\nctools\nless",
public function backup_settings_default() {
return array(
'exclude_filepaths' => "backup_migrate\nstyles\ncss\njs\nctools\nless\nlanguages",
);
}
/**
* Get the form for the backup settings for this destination.
*/
function backup_settings_form($settings) {
public function backup_settings_form($settings) {
$form['exclude_filepaths'] = array(
"#type" => "textarea",
"#multiple" => TRUE,
"#title" => t("Exclude the following files or directories"),
"#default_value" => $settings['exclude_filepaths'],
"#default_value" => isset($settings['exclude_filepaths']) ? $settings['exclude_filepaths'] : '',
"#description" => t("A list of files or directories to be excluded from backups. Add one path per line relative to the directory being backed up."),
);
return $form;
@@ -90,7 +98,7 @@ class backup_migrate_destination_filesource extends backup_migrate_source {
/**
* Backup from this source.
*/
function backup_to_file($file, $settings) {
public function backup_to_file($file, $settings) {
if ($out = $this->_backup_to_file_cli($file, $settings)) {
return $out;
}
@@ -102,13 +110,13 @@ class backup_migrate_destination_filesource extends backup_migrate_source {
/**
* Backup from this source.
*/
function _backup_to_file_php($file, $settings) {
public function _backup_to_file_php($file, $settings) {
if ($this->check_libs()) {
$excluded_paths = empty($settings->filters['exclude_filepaths']) ? '' : $settings->filters['exclude_filepaths'];
$files = $this->get_files_to_backup($this->get_realpath(), $settings, $this->get_excluded_paths($excluded_paths), DRUPAL_ROOT . '/');
$excluded = $this->get_excluded_paths($settings);
$files = $this->get_files_to_backup($this->get_realpath(), $settings, $excluded);
if ($files) {
$file->push_type('tar');
$gz = new Archive_Tar($file->filepath(), false);
$gz = new Archive_Tar($file->filepath(), FALSE);
$gz->addModify($files, '', $this->get_realpath());
return $file;
}
@@ -121,21 +129,25 @@ class backup_migrate_destination_filesource extends backup_migrate_source {
/**
* Backup from this source.
*/
function _backup_to_file_cli($file, $settings) {
public function _backup_to_file_cli($file, $settings) {
if (!empty($settings->filters['use_cli']) && function_exists('backup_migrate_exec') && function_exists('escapeshellarg')) {
$excluded_paths = empty($settings->filters['exclude_filepaths']) ? '' : $settings->filters['exclude_filepaths'];
$excluded = $this->get_excluded_paths($settings);
$exclude = array();
foreach ($this->get_excluded_paths($excluded_paths) as $path) {
foreach ($excluded as $path) {
$exclude[] = '--exclude=' . escapeshellarg($path);
}
$exclude = implode(' ', $exclude);
// Create a symlink in a temp directory so we can rename the file in the archive.
// Create a symlink in a temp directory so we can rename the file in the
// archive.
$temp = backup_migrate_temp_directory();
$file->push_type('tar');
backup_migrate_exec("tar --dereference -C %input -rf %output $exclude .", array('%output' => $file->filepath(), '%input' => $this->get_realpath(), '%temp' => $temp));
$file->push_type('tar');
backup_migrate_exec("tar --dereference -C %input -rf %output $exclude .", array(
'%output' => $file->filepath(),
'%input' => $this->get_realpath(),
'%temp' => $temp,
));
return $file;
}
return FALSE;
@@ -144,7 +156,7 @@ class backup_migrate_destination_filesource extends backup_migrate_source {
/**
* Restore to this source.
*/
function restore_from_file($file, &$settings) {
public function restore_from_file($file, &$settings) {
if ($out = $this->_restore_from_file_cli($file, $settings)) {
return $out;
}
@@ -156,7 +168,7 @@ class backup_migrate_destination_filesource extends backup_migrate_source {
/**
* Restore to this source.
*/
function _restore_from_file_php($file, &$settings) {
public function _restore_from_file_php($file, &$settings) {
if ($this->check_libs()) {
$from = $file->pop_type();
$temp = backup_migrate_temp_directory();
@@ -165,10 +177,10 @@ class backup_migrate_destination_filesource extends backup_migrate_source {
$tar->extractModify($temp, $file->name);
// Older B&M Files format included a base 'files' directory.
if (file_exists($temp .'/files')) {
if (file_exists($temp . '/files')) {
$temp = $temp . '/files';
}
if (file_exists($temp .'/'. $file->name .'/files')) {
if (file_exists($temp . '/' . $file->name . '/files')) {
$temp = $temp . '/files';
}
@@ -183,16 +195,16 @@ class backup_migrate_destination_filesource extends backup_migrate_source {
/**
* Restore to this source.
*/
function _restore_from_file_cli($file, &$settings) {
public function _restore_from_file_cli($file, &$settings) {
if (!empty($settings->filters['use_cli']) && function_exists('backup_migrate_exec')) {
$temp = backup_migrate_temp_directory();
backup_migrate_exec("tar -C %temp -xf %input", array('%input' => $file->filepath(), '%temp' => $temp));
// Older B&M Files format included a base 'files' directory.
if (file_exists($temp .'/files')) {
if (file_exists($temp . '/files')) {
$temp = $temp . '/files';
}
if (file_exists($temp .'/'. $file->name .'/files')) {
if (file_exists($temp . '/' . $file->name . '/files')) {
$temp = $temp . '/files';
}
@@ -204,10 +216,13 @@ class backup_migrate_destination_filesource extends backup_migrate_source {
}
/**
* Get a list of files to backup from the given set if dirs. Exclude any that match the array $exclude.
* Gets a list of files to backup from the given set if dirs.
*
* Exclude any that match the array $exclude.
*/
function get_files_to_backup($dir, $settings, $exclude = array(), $base_dir = '') {
public function get_files_to_backup($dir, $settings, $exclude = array()) {
$out = $errors = array();
if (!file_exists($dir)) {
backup_migrate_backup_fail('Directory %dir does not exist.', array('%dir' => $dir), $settings);
return FALSE;
@@ -216,25 +231,25 @@ class backup_migrate_destination_filesource extends backup_migrate_source {
while (($file = readdir($handle)) !== FALSE) {
if ($file != '.' && $file != '..' && !in_array($file, $exclude)) {
$real = realpath($dir . '/' . $file);
$path = str_replace($base_dir, '', $real);
// If the path is not excluded.
if (!in_array($path, $exclude)) {
if (!in_array($real, $exclude)) {
if (is_dir($real)) {
$subdir = $this->get_files_to_backup($real, $settings, $exclude, $base_dir);
// If there was an error reading the subdirectory then abort the backup.
$subdir = $this->get_files_to_backup($real, $settings, $exclude);
// If there was an error reading the subdirectory then abort the
// backup.
if ($subdir === FALSE) {
closedir($handle);
return FALSE;
}
// If the directory is empty, add an empty directory.
if (count($subdir) == 0) {
$out[] = $path;
$out[] = $real;
}
$out = array_merge($out, $subdir);
}
else {
if (is_readable($real)) {
$out[] = $path;
$out[] = $real;
}
else {
$errors[] = $dir . '/' . $file;
@@ -272,30 +287,46 @@ class backup_migrate_destination_filesource extends backup_migrate_source {
}
/**
* Break the excpluded paths string into a usable list of paths.
* Breaks the excluded paths string into a usable list of paths.
*/
function get_excluded_paths($paths) {
public function get_excluded_paths($settings) {
$base_dir = $this->get_realpath() . '/';
$paths = empty($settings->filters['exclude_filepaths']) ? '' : $settings->filters['exclude_filepaths'];
$out = explode("\n", $paths);
foreach ($out as $key => $val) {
$out[$key] = trim($val, "/ \t\r\n");
$path = trim($val, "/ \t\r\n");
// If the path specified is a stream url or absolute path add the
// normalized version.
if ($real = drupal_realpath($path)) {
$out[$key] = $real;
}
// If the path is a relative path add it.
elseif ($real = drupal_realpath($base_dir . $path)) {
$out[$key] = $real;
}
// Otherwise add it as is even though it probably won't match any files.
else {
$out[$key] = $path;
}
}
return $out;
}
/**
* Check that the required libraries are installed.
* Checks that the required libraries are installed.
*/
function check_libs() {
$result = true;
// Drupal 7 has Archive_Tar built in so there should be no need to include anything here.
public function check_libs() {
$result = TRUE;
// Drupal 7 has Archive_Tar built in so there should be no need to include
// anything here.
return $result;
}
/**
/**
* Get the file location.
*/
function get_realpath() {
public function get_realpath() {
return drupal_realpath($this->get_location());
}
}
}
@@ -1,6 +1,5 @@
<?php
/**
* @file
* All of the source handling code needed for Backup and Migrate.
@@ -39,7 +38,7 @@ function backup_migrate_create_source($subtype, $params = array()) {
}
/**
* Implementation of hook_backup_migrate_source_subtypes().
* Implements hook_backup_migrate_source_subtypes().
*
* Get the built in Backup and Migrate source types.
*/
@@ -49,27 +48,27 @@ function backup_migrate_backup_migrate_source_subtypes() {
'db' => array(
'type_name' => t('Database'),
'description' => t('Import the backup directly into another database. Database sources can also be used as a source to backup from.'),
'file' => drupal_get_path('module', 'backup_migrate') .'/includes/sources.db.inc',
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/sources.db.inc',
'class' => 'backup_migrate_source_db',
'can_create' => FALSE,
),
'mysql' => array(
'type_name' => t('MySQL Database'),
'description' => t('Import the backup directly into another MySQL database. Database sources can also be used as a source to backup from.'),
'file' => drupal_get_path('module', 'backup_migrate') .'/includes/sources.db.mysql.inc',
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/sources.db.mysql.inc',
'class' => 'backup_migrate_source_db_mysql',
'can_create' => TRUE,
),
'filesource' => array(
'description' => t('A files directory which can be backed up from.'),
'file' => drupal_get_path('module', 'backup_migrate') .'/includes/sources.filesource.inc',
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/sources.filesource.inc',
'class' => 'backup_migrate_destination_filesource',
'type_name' => t('File Directory'),
'can_create' => TRUE,
),
'archive' => array(
'description' => t('Create an archive of your entire site.'),
'file' => drupal_get_path('module', 'backup_migrate') .'/includes/sources.archivesource.inc',
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/sources.archivesource.inc',
'class' => 'backup_migrate_files_destination_archivesource',
'type_name' => t('Site Archive'),
'can_create' => FALSE,
@@ -80,12 +79,12 @@ function backup_migrate_backup_migrate_source_subtypes() {
}
/**
* Implementation of hook_backup_migrate_sources().
* Implements hook_backup_migrate_sources().
*
* Get the built in backup sources and those in the db.
*/
function backup_migrate_backup_migrate_sources() {
$out = array();
$out = array();
// Expose the configured databases as sources.
backup_migrate_include('filters');
@@ -153,17 +152,19 @@ function _backup_migrate_get_source_form_item_options() {
* A base class for creating sources.
*/
class backup_migrate_source extends backup_migrate_location {
var $db_table = "backup_migrate_sources";
var $type_name = 'source';
var $singular = 'source';
var $plural = 'sources';
var $title_plural = 'Sources';
var $title_singular = 'Source';
public $db_table = "backup_migrate_sources";
public $type_name = 'source';
public $singular = 'source';
public $plural = 'sources';
public $title_plural = 'Sources';
public $title_singular = 'Source';
/**
* This function is not supposed to be called. It is just here to help the po extractor out.
* This function is not supposed to be called.
*
* It is just here to help out the po extractor.
*/
function strings() {
public function strings() {
// Help the pot extractor find these strings.
t('source');
t('sources');
@@ -174,7 +175,7 @@ class backup_migrate_source extends backup_migrate_location {
/**
* Get the available location types.
*/
function location_types() {
public function location_types() {
return backup_migrate_get_source_subtypes();
}
@@ -184,32 +185,33 @@ class backup_migrate_source extends backup_migrate_location {
* A base class for creating sources.
*/
class backup_migrate_source_remote extends backup_migrate_source {
/**
* The location is a URI so parse it and store the parts.
*/
function get_location() {
public function get_location() {
return $this->url(FALSE);
}
/**
* The location to display is the url without the password.
*/
function get_display_location() {
public function get_display_location() {
return $this->url(TRUE);
}
/**
* Return the location with the password.
* Returns the location with the password.
*/
function set_location($location) {
public function set_location($location) {
$this->location = $location;
$this->set_url($location);
}
/**
* source configuration callback.
* Source configuration callback.
*/
function edit_form() {
public function edit_form() {
$form = parent::edit_form();
$form['scheme'] = array(
"#type" => "textfield",
@@ -251,18 +253,21 @@ class backup_migrate_source_remote extends backup_migrate_source {
"#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.');
$form['pass']["#description"] .= t('You do not need to enter a password unless you wish to change the currently saved password.');
}
return $form;
}
/**
* Submit the configuration form. Glue the url together and add the old password back if a new one was not specified.
* Submits the configuration form.
*
* Glue the url together and add the old password back if a new one was not
* specified.
*/
function edit_form_submit($form, &$form_state) {
public 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);
}
}
}