Browse Source

[up] Backup_migrate 7.x-3.6

opi 6 years ago
parent
commit
5d48817ac2
38 changed files with 3359 additions and 1867 deletions
  1. 240 0
      sites/all/modules/backup_migrate/CHANGELOG.txt
  2. 157 53
      sites/all/modules/backup_migrate/README.txt
  3. 7 4
      sites/all/modules/backup_migrate/backup_migrate.css
  4. 11 6
      sites/all/modules/backup_migrate/backup_migrate.info
  5. 221 103
      sites/all/modules/backup_migrate/backup_migrate.install
  6. 28 16
      sites/all/modules/backup_migrate/backup_migrate.js
  7. 411 231
      sites/all/modules/backup_migrate/backup_migrate.module
  8. 72 18
      sites/all/modules/backup_migrate/includes/backup_migrate.drush.inc
  9. 131 136
      sites/all/modules/backup_migrate/includes/crud.inc
  10. 33 12
      sites/all/modules/backup_migrate/includes/destinations.browser.inc
  11. 34 35
      sites/all/modules/backup_migrate/includes/destinations.db.inc
  12. 153 92
      sites/all/modules/backup_migrate/includes/destinations.db.mysql.inc
  13. 37 28
      sites/all/modules/backup_migrate/includes/destinations.email.inc
  14. 43 40
      sites/all/modules/backup_migrate/includes/destinations.file.inc
  15. 55 61
      sites/all/modules/backup_migrate/includes/destinations.ftp.inc
  16. 110 116
      sites/all/modules/backup_migrate/includes/destinations.inc
  17. 293 191
      sites/all/modules/backup_migrate/includes/destinations.nodesquirrel.inc
  18. 28 26
      sites/all/modules/backup_migrate/includes/destinations.s3.inc
  19. 54 50
      sites/all/modules/backup_migrate/includes/files.inc
  20. 41 31
      sites/all/modules/backup_migrate/includes/filters.backup_restore.inc
  21. 19 21
      sites/all/modules/backup_migrate/includes/filters.compression.inc
  22. 31 29
      sites/all/modules/backup_migrate/includes/filters.encryption.inc
  23. 46 48
      sites/all/modules/backup_migrate/includes/filters.inc
  24. 7 8
      sites/all/modules/backup_migrate/includes/filters.statusnotify.inc
  25. 25 19
      sites/all/modules/backup_migrate/includes/filters.utils.inc
  26. 64 65
      sites/all/modules/backup_migrate/includes/locations.inc
  27. 36 36
      sites/all/modules/backup_migrate/includes/profiles.inc
  28. 87 90
      sites/all/modules/backup_migrate/includes/schedules.inc
  29. 66 45
      sites/all/modules/backup_migrate/includes/sources.archivesource.inc
  30. 39 36
      sites/all/modules/backup_migrate/includes/sources.db.inc
  31. 156 96
      sites/all/modules/backup_migrate/includes/sources.db.mysql.inc
  32. 67 49
      sites/all/modules/backup_migrate/includes/sources.filesource.inc
  33. 32 27
      sites/all/modules/backup_migrate/includes/sources.inc
  34. 0 33
      sites/all/modules/backup_migrate/tests/BackupMigrateBasicsTest.test
  35. 0 16
      sites/all/modules/backup_migrate/tests/BackupMigrateHelper.test
  36. 246 0
      sites/all/modules/backup_migrate/tests/BmTestBase.test
  37. 111 0
      sites/all/modules/backup_migrate/tests/BmTestBasics.test
  38. 168 0
      sites/all/modules/backup_migrate/tests/BmTestProfiles.test

+ 240 - 0
sites/all/modules/backup_migrate/CHANGELOG.txt

@@ -0,0 +1,240 @@
+Backup and Migrate 7.x-3.6, 2018-12-15
+--------------------------------------
+#2293601 by KimNyholm, fastturtle: Errors shown because directory handles are
+  not closed when no longer needed.
+#2937023 by DamienMcKenna: Add a test for the basic UI functionality.
+#2945704 by DamienMcKenna: Write tests for each backup filename option.
+#2939277 by DamienMcKenna, baronmunchowsen: File mode change on
+  sources.archivesource.inc.
+#2935403 by DamienMcKenna, jacob.embree: Improve coding standards compliance.
+#2962822 by laryn: Spelling mistake: "frequecy".
+#2917959 by DamienMcKenna: Updated backup_migrate_update_7305() to fix schema
+  problems.
+#2996191 by mwnciau, DamienMcKenna: Special characters in database password
+  causes PHP notifications.
+#2949211 by gturnbull, DamienMcKenna, Alex Bukach, Eli.Stone, joelpittet:
+  Optional memory limit setting to work around out-of-memory errors during
+  backups.
+#2494757 by pbuyle, DamienMcKenna, Ives, Calystod: Allow running a scheduled
+  backup with Drush.
+#2404113 by DamienMcKenna, John Cook, danharper, salmino: Different host for
+  AWS type server.
+#2829492 by axel.rutz, RickJ, DamienMcKenna, devad, Kris77, pietrocap,
+  couturier: Big file backup breaks with "MySQL server has gone away".
+#3001702 by DamienMcKenna: Code cleanup on 7.x-3.x branch.
+#2831470 by snehal.addweb, bfodeke, jigish.addweb: Delete query in
+  hook_uninstall() can potentially remove unintended variables.
+#3004759 by Manthan.addweb, echoz: Notice: Undefined index: exclude_filepaths...
+  visiting Advanced Backup tab.
+#3013355 by jacob.embree: Syntax error in backup_migrate.js.
+#2415421 by ron_s, coredumperror, blake.thompson, John Bickar: Backup and
+  Migrate module and private file system.
+#3002975 by DamienMcKenna: Improve logging around the cron and backup processes.
+#2747197 by RickJ: Network errors writing to Nodesquirrel handled badly.
+#3014594 by DamienMcKenna: backup_migrate_uninstall() doesn't delete all.
+  variables; renamed "backup_migrate_backup_memory_limit" variable to
+  "backup_migrate_memory_limit".
+#3014601 by DamienMcKenna: Re-enable all tests.
+#3014143 by DamienMcKenna: Add master switch to turn off hook_cron.
+#3014603 by DamienMcKenna: Add a CHANGELOG.txt file.
+#3014596 by DamienMcKenna: Require PHP 5.4.
+#2943719 by DamienMcKenna: Reduce memory usage during MySQL database generation.
+#2338841 by catch, dasha_v, DamienMcKenna: Incorrect translated string +
+  menu_rebuild() performance issue.
+#1104012 by DamienMcKenna, axel.rutz, EmanueleQuinto, gisle, jacob.embree, Pere
+  Orga, frenkx: On restore, provide option to drop all tables.
+#2891272 by DamienMcKenna, webservant316: phpsnif 7.1 says Method name
+  \backup_migrate_destination_nodesquirrel::__xmlrpc\" is discouraged; PHP has
+  reserved all method names with a double underscore prefix for future use. 
+#3014597 by DamienMcKenna: Document the advanced backup options.
+#2382541 by sano, DamienMcKenna, couturier, dman, modulist: Updated
+  instructions for installing the S3 library.
+#3016278 by DamienMcKenna: Some debug messages aren't hidden behind
+  backup_migrate_verbose.
+#3016282 by DamienMcKenna: "Cannot add field
+  backup_migrate_profiles.machine_name: field already exists" error.
+#3017042 by DamienMcKenna, freelylw, gisle: Settings form field dependency
+  broken.
+#3018002 by DamienMcKenna: Improve the module's documentation.
+By DamienMcKenna: "server" not "sever" :-)
+#3018853 by RickJ: Temporary files not deleted.
+#2735337 by RickJ: Settings objects only offer Revert, not Delete.
+
+
+Backup and Migrate 7.x-3.5, 2018-02-05
+--------------------------------------
+#2941981 by DamienMcKenna, Rick J, camhoward: Backup files being overwritten
+  because of a change to the append_timestamp setting.
+#2940451 by Darren Oh: Unlimited max_execution_time treated as 0 seconds.
+
+
+Backup and Migrate 7.x-3.4, 2018-01-24
+--------------------------------------
+By DamienMcKenna, pere-orga, ikit-claw, cashwilliams: Make all permissions
+  restricted.
+#1058820 by kbasarab, sobi3ch, gbirch, avatxus: Add option to overwrite file.
+#2498191 by DamienMcKenna: Unable to backup to NodeSquirrel using PHP 5.6.9
+  (on Windows) due to changes in SSL validation rules.
+#2742855 by hanoii: Caching profile objects led to unwanted behaviors because of
+  stale data.
+#2703351 by DamienMcKenna, ultrabob: Redundant methods in
+  backup_migrate_location_remote.
+#2728345 by Rick J: Nodesquirrel destination class doesn't return its name.
+#2728331 by Rick J: Incorrect paging count in saved backup list.
+#2498179 by junaidpv: Use drupal_mail() for system notifications.
+#2920311 by DamienMcKenna: Check backup directory permissions / web
+  accessibility.
+#2912459 by DamienMcKenna: Add an initial test.
+#2880434 by DamienMcKenna, benqwerty: Minor changes to drush help output.
+#2914644 by DamienMcKenna, jacob.embree: List all files which contain classes in
+  the info file so other modules can use the classes.
+#2663928 by DamienMcKenna, fietserwin: public://languages should also be
+  excluded by default.
+#2388347 by DamienMcKenna: Nodequirrel destination class doesn't define $errno,
+  $errstr but assumes they're available.
+#2899586 by juankvillegas, DamienMcKenna: Ensure the page variable is numeric in
+  backup_migrate_nodesquirrel_status_form().
+
+
+Backup and Migrate 7.x-3.3, 2017-10-18
+--------------------------------------
+#2290707 by DamienMcKenna, mitsuroseba, Darren Oh: Exclude the data from the
+  following tables - does not work.
+#2830554 by axel.rutz: Support Ultimate Cron.
+#2728349 by Rick J: Disabled schedules still run under Elysia cron.
+
+
+Backup and Migrate 7.x-3.2, 2017-09-27
+--------------------------------------
+#2702229 by DamienMcKenna: Automatically add all cache tables to the 'nodata'
+  list, exclude simpletest tables.
+#2618516 by rocketeerbkw: Fatal error when restoring "Entire Site".
+#2839264 by wizonesolutions: Error: [] operator not supported for strings in
+  backup_migrate_crud_ui_list_all().
+#2633304 by adamelleston: 'clone' is a reserved keyword introduced in PHP
+  version 5.0 and cannot be invoked as a function.
+#2547065 by snehi: Description for filesource location is inaccurate.
+#2672478 by serverofworld, lklimek: Wrong destination when running multiple
+  schedules using the same profile.
+#1542274 by dale42, LGLC, AjitS: Restore fails with foreign key constraint error
+  (due to incorrect comment detection).
+#2623598 by SylvainM, joelstein: Deprecated: Methods with the same name as their
+  class will not be constructors in a future version of PHP.
+#2513720 by rrfegade: Code Spell errors.
+By ronan: Cleaned up use of manage url generator.
+#2495681 by DamienMcKenna: Secure all endpoint connections to NodeSquirrel
+  destination service.
+#2495677 by DamienMcKenna: Inconsistent use of https for manage.nodesquirrel.com
+  hostname.
+#2277383 by hswong3i: Fix schema mismatch after upgrade 7.x-3.x.
+
+
+Backup and Migrate 7.x-3.1, 2015-05-11
+--------------------------------------
+By ronan: Added pantheon notice and free notice to NodeSquirrel page.
+#2347637: Add a Note to Backup doesn't work with Jquery > 1.7.
+By ronan: Set Nodesquirrel schedule to use smart delete by default.
+#2477503: Error returned, but exit status is 0.
+#2369461: Scheduled Backups stopped working after 7.x-3.0?.
+#2390057: Site doesn't come out of maintenance mode when backing up entire site.
+#2455265: Update Version Number in README.TXT.
+By ronan: Updated NS messaging slightly.
+#2393615: Compression not running (only when backing up entire site).
+#2324949: Update #7303 Failing.
+#2421183: Stream URI - Not ignored (Recognized?) during backups.
+#2378739: "Exclude the data from the following tables" not respected when "Use
+  cli commands" is checked.
+#2307655 Fixed adding of full system path to site archive.
+#2290707 by marvoey Advanced Backup link on quick backup page goes to wrong
+  place.
+#2290707 Exclude the data from the following tables - does not work.
+By ronan: Moved run time check before scheduled backup attempt to fix too-
+  frequent schedule issue.
+#2280743: Files restore duplicating directory structure
+  (sites/default/files/sites/default/files).
+#2276663 Permissions - Access backup files.
+#2283701 by alarcombe. Restore not possible from archive.
+#2286835 by Fernando Vesga. Advanced backup page link error.
+#2287157 by topsitemakers. Links to "Create new destination" and "Create new
+  schedule" are invalid.
+#2287239 by topsitemakers. Minor typo in an error message.
+#2278865 by topsitemakers Undefined index: files in
+  theme_backup_migrate_file_list.
+
+
+Backup and Migrate 7.x-3.0, 2014-05-27
+--------------------------------------
+By ronan: Fixed comment on install hook.
+#2266381 Warning: Invalid argument supplied for foreach() in
+  backup_migrate_schedules_cron() on line 48.
+#1001654 Fixed ctools exportables.
+By ronan: Added nodesquirrel scheduling back. Fixed issue with restore from
+  previous radios. Added function to retrieve the most recent backup from the
+  given destination. This may be used in a drush command.
+By ronan: Removed link to help text when help module is off.
+By ronan: Removed confusing 'Quick Schedule' tab.
+#2225335 Drush commands not working.
+By ronan: Increased machine_name length in ui for compatibility with migrated
+  items.
+By ronan: Fixed a couple of php errors.
+By ronan: Minor wording tweaks.
+By ronan: Added better status for NodeSquirrel.
+By ronan: Removed dpm.
+By ronan: Added dependency to offline message on restore.
+By ronan: Removed stray console.log from the js.
+By ronan: Added most recent saved backups to the restore tab.
+By ronan: Ported MySQL views support.
+By ronan: Fixed some issues saving profiles.
+By ronan: Added a @TODO to remind me to fix saving on the advance backup page.
+#1974740 allow backup of codebase & files to skip unreadable files.
+By ronan: Merge branch 'refs/heads/NodeSquirrel-Language' into 7.x-3.x.
+By ronan: Fixed up some language and links to NodeSquirrel.
+By ronan: Cleaned up directory handling to support more directory structures.
+By ronan: Added some description language for NodeSquirrel.
+#2166813 Files backup fails when PEAR is not installed.
+#2155381 by JulienD Remove useless files[] directive from .info files.
+#1947206 by Les Lim. "No data" tables are exported even when they're in the
+  "Exclude the following tables altogether" list.
+#2031393 A debugging function call left behind.
+#2031777 Wrong function signature on form callback.
+#2065573 wrong default file token.
+#2039951 settings page gone for schedules.
+#2009392 Settings don't save for file or entire site sources.
+#1998788 missing i in NodeSquirrel.
+By ronan: Moved NodeSquirrel tab to match the 2.x branch.
+By ronan: Some d7 style cleanup.
+By ronan: Fixed nodesquirrel destination with new id structure.
+By ronan: Added checkplain to description on listing.
+By ronan: Fixed an issue with multiselect js invading other pages.
+#1564408 Gzip backups are compressed twice when downloaded.
+#1991686 thx morningtime. Undefined property: backup_migrate_schedule::$last_run
+By ronan: Switch to hourly default to align with smart delete default.
+#839254 Switched to using drupal_reapath to allow for stream wrapper schemas.
+#839254 Checking absolute paths within the docroot.
+#839254 check for access restriction ignores custom destination path.
+#1503202 Suhosin refuses sending mail because of to many new lines in mail
+  header (possible attacker).
+#1529174 Fatal Error when database name is longer than 21 characters.
+By ronan: Fixed 'Restore again' link.
+#1974720 error message on attempting to restore manual backup.
+#1974744 warning on creation of new settings profile.
+By ronan: Fixed inconsistent use of 'source' and 'destination'.
+By ronan: Changed destination_id to machine_name to fix issue with default file
+  destinations.
+By ronan: Fixed error noise caused by ftp not connecting.
+By ronan: Fixed error on file delete form.
+By ronan: Fixed fatal error in metadata util when a backup fails.
+#1968210 error message on attempting backup of entire site.
+By ronan: Improved error reporting when a non-existant file (such as a broken
+  symlink) cannot be backed up.
+#1968196 Error message on install in php 5.4.
+By ronan: Fixed checkboxes.
+By ronan: Fixed fatal error with token replace.
+By ronan: Created full upgrade path from 2.x. Fixed source settings.
+By ronan: Fixed db scheme issue. Fixed file source realpath issue.
+By ronan: Switched type to subtype for ctools compatibility.
+By ronan: Added machine_name js and ctools exportables.
+By ronan: Fixed source specific settings in backup.
+By ronan: Fixed issue with edit screen for source settings in profiles.
+By ronan: Fixed export.
+By ronan: Cleaned up more fatal errors. Better handling of translatable titles.

+ 157 - 53
sites/all/modules/backup_migrate/README.txt

@@ -1,93 +1,197 @@
+Backup and Migrate
+------------------
+This module makes the task of backing up a site's Drupal database, code and
+all uploaded files and of migrating data from one Drupal install to another
+easier.
 
--------------------------------------------------------------------------------
-Backup and Migrate 3 for Drupal 7.x
-  by Ronan Dowling, Gorton Studios - ronan (at) gortonstudios (dot) com
--------------------------------------------------------------------------------
-
-DESCRIPTION:
-This module makes the task of backing up your Drupal database, code and uploaded
-files and of migrating data from one Drupal install to another easier. 
+Database backup files are a list of SQL statements which can be executed with a
+tool such as phpMyAdmin or the command-line mysql client. File and code backup
+files are tarballs which can be restored by extracting them to the desired
+directory.
 
-Database backup files are a list of SQL statements which can be executed with a 
-tool such as phpMyAdmin or the command-line mysql client. File and code
-backup files are tarballs which can be restored by extracting them to the 
-desired directory.
 
+Installation
 -------------------------------------------------------------------------------
-
-INSTALLATION:
-* Put the module in your Drupal modules directory and enable it in 
-  admin/modules. 
-* Go to admin/people/permissions and grant permission to any roles that need to be 
-  able to backup or restore the database.
-* Configure and use the module at admin/config/system/backup_migrate
+* Put the module in the Drupal modules directory and enable it via
+  admin/modules.
+* Go to admin/people/permissions and grant permission to any roles that need to
+  be able to backup or restore the database.
+* Configure and use the module at admin/config/system/backup_migrate.
 
 OPTIONAL:
+* To drop all tables before import, expand "Advanced options" panel under the
+  "Restore" and "Saved backups" tabs and tick the option.
 * Enable token.module to allow token replacement in backup file names.
 * To Backup to Amazon S3:
-    - Download the S3 library from http://undesigned.org.za/2007/10/22/amazon-s3-php-class
-      and place the file 'S3.php' in the includes directory in this module.
-      The stable version (0.4.0 – 20th Jul 2009) works best with Backup and Migrate.
+  - Download the most recent version from:
+    https://github.com/tpyo/amazon-s3-php-class
+  - Or clone it with command:
+    git clone https://github.com/tpyo/amazon-s3-php-class.git s3-php5-curl
+  - Rename the unzipped folder to s3-php5-curl
+
+The most recent version of the library known to work is 0.5.1.
 
-LIGHTTPD USERS:
-Add the following code to your lighttp.conf to secure your backup directories:
+
+Additional requirements for LigHTTPd
+-------------------------------------------------------------------------------
+Add the following code to the lighttp.conf to secure the backup directories:
   $HTTP["url"] =~ "^/sites/default/files/backup_migrate/" {
-       url.access-deny = ( "" )
+    url.access-deny = ( "" )
   }
-You may need to adjust the path to reflect the actual path to the files.
+It may be necessary to adjust the path to reflect the actual path to the files.
 
-IIS 7 USERS:
-Add the following code to your web.config code to secure your backup directories:
+
+Additional requirements for IIS 7
+-------------------------------------------------------------------------------
+Add the following code to the web.config code to secure the backup
+directories:
 <rule name="postinst-redirect" stopProcessing="true">
    <match url="sites/default/files/backup_migrate" />
    <action type="Rewrite" url=""/>
 </rule>
-You may need to adjust the path to reflect the actual path to the files.
+It may also be necessary to adjust the path to reflect the actual path to the
+files.
 
--------------------------------------------------------------------------------
 
-VERY IMPORTANT SECURITY NOTE:
-Backup files may contain sensitive data and by default, are saved to your web
+VERY IMPORTANT SECURITY NOTE
+-------------------------------------------------------------------------------
+Backup files may contain sensitive data and, by default, are saved to the web
 server in a directory normally accessible by the public. This could lead to a
 very serious security vulnerability. Backup and Migrate attempts to protect
 backup files using a .htaccess file, but this is not guaranteed to work on all
-environments (and is guaranteed to fail on web servers that are not apache). You
-should test to see if your backup files are publicly accessible, and if in doubt
-do not save backups to the server, or use the destinations feature to save to a 
-folder outside of your webroot.
+environments (and is guaranteed to fail on web servers that are not Apache). It
+is imperitive to test to see if the site's backup files are publicly
+accessible, and if in doubt do not save backups to the server, or use the
+destinations feature to save to a folder outside of the site's webroot.
+
 
-OTHER WARNINGS:
-A failed restore can destroy your database and therefore your entire Drupal
+Other warnings
+-------------------------------------------------------------------------------
+A failed restore can destroy the database and therefore the entire Drupal
 installation. ALWAYS TEST BACKUP FILES ON A TEST ENVIRONMENT FIRST. If in doubt
 do not use this module.
 
-This module has only been tested with MySQL and does not work with any other dbms. 
-If you have experiences with Postgres or any other dbms and are willing to help 
-test and modify the module to work with it, please contact the developer at 
-ronan (at) gortonstudios (dot) com.
+This module has only been tested with MySQL and does not work with any other
+dbms. Assistance in adding support for other database systems would be
+appreciated, see the issue queue for further details.
 
-Make sure your php timeout is set high enough to complete a backup or restore
+Make sure the PHP timeout is set high enough to complete a backup or restore
 operation. Larger databases require more time. Also, while the module attempts
 to keep memory needs to a minimum, a backup or restore will require
-significantly more memory then most Drupal operations.
+significantly more memory than most Drupal operations.
 
-If your backup file contains the 'sessions' table all other users will be logged
-out after you run a restore. To avoid this, exclude the sessions table when 
-creating your backups. Be aware though that you will need to recreate the 
-sessions table if you use this backup on an empty database.
+If the backup file contains the 'sessions' table all other users will be logged
+out after running a restore. To avoid this, exclude the sessions table when
+creating the backups. Be aware though that this table is still required to run
+Drupal, so it will need to be recreated if the backup is restored onto an empty
+database.
 
 Do not change the file extension of backup files or the restore function will be
-unable to determine the compression type the file and will not function
+unable to determine the compression type of the file and will not function
 correctly.
 
 The module's permissions should only be given to trusted users due to the
 inherent security vulnerabilities in allowing people access to a site's database
 and/or files backups.
 
-IF A RESTORE FAILS:
-Don't panic, the restore file should work with phpMyAdmin's import function, or
-with the mysql command line tool. If it does not, then it is likely corrupt; you
-may panic now. MAKE SURE THAT THIS MODULE IS NOT YOUR ONLY FORM OF BACKUP.
 
+If a restore fails
 -------------------------------------------------------------------------------
+Don't panic!
+
+The restore file should still work with phpMyAdmin's import function or with
+the mysql command line tool.
 
+If the backup does not restore using either a graphical tool or the command line tools, then it is likely corrupt; you may panic now.
+
+MAKE SURE THAT THIS MODULE IS NOT THE ONLY FORM OF BACKUP.
+
+
+Known problems and workarounds
+-------------------------------------------------------------------------------
+* If backups fail due to an out-of-memory, try adjusting the memory limit using
+  the "backup_migrate_memory_limit" variable by adding one of these lines
+  to the site's settings.php file:
+
+  // Backup & Migrate: Use 512MB when generating backups.
+  $conf['backup_migrate_memory_limit'] = '512M';
+
+  // Backup & Migrate: Use 1GB when generating backups.
+  $conf['backup_migrate_memory_limit'] = '1G';
+
+* If backups fail due to a PHP timeout error, especially an error saying "MySQL
+  server has gone away", use the "backup_migrate_backup_max_time" variable to
+  adjust the timeout. Before doing this, check to see what PHP's
+  "max_execution_time" is set to, then set the "backup_migrate_backup_max_time"
+  variale to a higher number, e.g. if max_execution_time is 180 (seconds) try
+  setting backup_migrate_backup_max_time to 240 seconds / 4 minutes, or 300
+  seconds / 5 minutes
+
+  // Backup & Migrate: Adjust the PHP timeout to 5 minutes / 300 seconds.
+  $conf['backup_migrate_backup_max_time'] = 300;
+
+* A variable has been added which may help with problems. Setting the variable
+  'backup_migrate_verbose' to TRUE will make the module log additional messages
+  to watchdog as the module performs certain actions.
+
+  // Backup & Migrate: Log extra messages as the module is working.
+  $conf['backup_migrate_verbose'] = TRUE;
+
+* It can be frustrating working from a production database backup on non-prod
+  servers as schduled backups will automatically run via cron the same as they
+  run on production. The custom cron tasks may be disabled using the
+  "backup_migrate_disable_cron" variable. Note: this doesn't prevent people
+  from manually running backups via the UI or from the Drush commands, so it is
+  safe to hardcode to TRUE on all site instances and then hardcode to FALSE on
+  production environments.
+
+  // Backup & Migrate: Don't run backups via cron.
+  $conf['backup_migrate_disable_cron'] = TRUE;
+
+* There are three different variables that control how MySQL data is processed.
+  Should a site have problems with memory limits, it is worth testing these to
+  see which ones work the best.
+
+  - backup_migrate_data_rows_per_query
+    Controls how many records are loaded from the database at once. Defaults to
+    "1000", i.e. 1,000 rows. Note that setting this to a high number can cause
+    problems when exporting large data sets, e.g. cache tables can have huge
+    volumes of data per record.
+
+    // Backup & Migrate: Load 10,000 rows at once.
+    $conf['backup_migrate_data_rows_per_query'] = 10000;
+
+  - backup_migrate_data_rows_per_line
+    Controls how many records are included in a single INSERT statement.
+    Defaults to "30", i.e. 30 records.
+
+    // Backup & Migrate: Combine no more than five records in a single row.
+    $conf['backup_migrate_data_rows_per_line'] = 5;
+
+  - backup_migrate_data_bytes_per_line
+    Controls how much data will be inserted at once using a single INSERT
+    statement. This works with the "backup_migrate_data_rows_per_line" variable
+    to ensure that each INSERT statement doesn't end up being too large.
+    Defaults to "2000", i.e. 2,000 bytes.
+
+    // Backup & Migrate: Limit the output to 1000 bytes at a time.
+    $conf['backup_migrate_data_bytes_per_line'] = 1000;
+
+
+Credits / contact
+--------------------------------------------------------------------------------
+Currently maintained by Alex Andrascu [1], Damien McKenna [1] and Daniel Pickering [3]. All original development up through 2015 was by Ronan Dowling [4]
+with help by Drew Gorton [5].
+
+The best way to contact the authors is to submit an issue, be it a support
+request, a feature request or a bug report, in the project issue queue:
+  https://www.drupal.org/project/issues/backup_migrate
+
+
+References
+--------------------------------------------------------------------------------
+1: https://www.drupal.org/u/damienmckenna
+2: https://www.drupal.org/u/alex-andrascu
+3: https://www.drupal.org/u/ikit-claw
+4: https://www.drupal.org/u/ronan
+5: https://www.drupal.org/u/dgorton

+ 7 - 4
sites/all/modules/backup_migrate/backup_migrate.css

@@ -1,5 +1,9 @@
-.schedule-list-disabled
-{
+/**
+ * @file
+ * Custom CSS for the Backup Migrate module.
+ */
+
+.schedule-list-disabled {
   filter:alpha(opacity=50);
   -moz-opacity: .50;
   opacity: .50;
@@ -27,8 +31,7 @@ div.backup-migrate-tables-checkboxes {
 }
 div.backup-migrate-tags,
 div.backup-migrate-description,
-div.backup-migrate-date
-{
+div.backup-migrate-date {
   font-size: smaller;
 }
 span.backup-migrate-label {

+ 11 - 6
sites/all/modules/backup_migrate/backup_migrate.info

@@ -3,6 +3,11 @@ description = "Backup the Drupal database and files or migrate them to another e
 core = 7.x
 configure = admin/config/system/backup_migrate
 
+; Require PHP 5.4 so that some slightly more advanced PHP logic can be used.
+; This is for future usage; removing this will allow the module to continue
+; working fine for now.
+php = 5.4
+
 ; All of the class files used within the module.
 files[] = includes/crud.inc
 files[] = includes/destinations.inc
@@ -31,12 +36,12 @@ files[] = includes/sources.db.mysql.inc
 files[] = includes/sources.filesource.inc
 
 ; Test suite.
-files[] = tests/BackupMigrateHelper.test
-files[] = tests/BackupMigrateBasicsTest.test
+files[] = tests/BmTestBase.test
+files[] = tests/BmTestBasics.test
+files[] = tests/BmTestProfiles.test
 
-; Information added by Drupal.org packaging script on 2018-02-05
-version = "7.x-3.5"
+; Information added by Drupal.org packaging script on 2018-12-16
+version = "7.x-3.6"
 core = "7.x"
 project = "backup_migrate"
-datestamp = "1517871486"
-
+datestamp = "1544925486"

+ 221 - 103
sites/all/modules/backup_migrate/backup_migrate.install

@@ -1,14 +1,12 @@
 <?php
 
-
 /**
  * @file
  * Install hooks for Backup and Migrate.
  */
 
-
 /**
- * Implementation of hook_requirements().
+ * Implements hook_requirements().
  */
 function backup_migrate_requirements($phase) {
   $requirements = array();
@@ -109,6 +107,7 @@ function backup_migrate_requirements($phase) {
     }
     // Leave a note if there were no problems.
     // @todo No point in displaying this until the API has been expanded.
+    // @code
     // if (empty($requirements)) {
     //   $requirements['bmdest_' . $dest_name] = array(
     //     'severity' => REQUIREMENT_INFO,
@@ -117,13 +116,23 @@ function backup_migrate_requirements($phase) {
     //     'description' => $t('The backup destinations were all checked and none of them were exposing files to the public. This is a good thing.'),
     //   );
     // }
+    // @endcode
+
+    if (variable_get('backup_migrate_disable_cron', FALSE)) {
+      $requirements['bm_disable_cron'] = array(
+        'severity' => REQUIREMENT_INFO,
+        'title' => 'Backup Migrate',
+        'value' => $t('Cron tasks are disabled'),
+        'description' => $t('The cron tasks have been disabled, so scheduled backups will not run. See the Backup & Migrate module\'s README.txt file for further details.'),
+      );
+    }
   }
 
   return $requirements;
 }
 
 /**
- * Implementation of hook_schema().
+ * Implements hook_schema().
  */
 function backup_migrate_schema() {
   $schema['backup_migrate_profiles'] = array(
@@ -132,11 +141,14 @@ function backup_migrate_schema() {
       'key name' => 'Profile ID',
       'admin_title' => 'name',
       'primary key' => 'profile_id',
-      'identifier' => 'item', // Exports will be defined as $preset
-      'default hook' => 'exportables_backup_migrate_profiles',  // Function hook name.
+      // Exports will be defined as $preset.
+      'identifier' => 'item',
+      // Function hook name.
+      'default hook' => 'exportables_backup_migrate_profiles',
       'api' => array(
         'owner' => 'backup_migrate',
-        'api' => 'backup_migrate_exportables',  // Base name for api include files.
+        // Base name for api include files.
+        'api' => 'backup_migrate_exportables',
         'minimum_version' => 1,
         'current_version' => 1,
       ),
@@ -147,7 +159,8 @@ function backup_migrate_schema() {
         'unsigned' => TRUE,
         'not null' => TRUE,
         'description' => 'Primary ID field for the table. Not used for anything except internal lookups.',
-        'no export' => TRUE, // Do not export database-only keys.
+        // Do not export database-only keys.
+        'no export' => TRUE,
       ),
       'machine_name' => array(
         'type' => 'varchar',
@@ -160,13 +173,13 @@ function backup_migrate_schema() {
         'description' => 'The name of the profile.',
         'type' => 'varchar',
         'length' => 255,
-        'not null' => TRUE
+        'not null' => TRUE,
       ),
       'filename' => array(
         'description' => 'The name of the profile.',
         'type' => 'varchar',
         'length' => 255,
-        'not null' => TRUE
+        'not null' => TRUE,
       ),
       'append_timestamp' => array(
         'description' => 'Append a timestamp to the filename.',
@@ -174,13 +187,13 @@ function backup_migrate_schema() {
         'size' => 'tiny',
         'unsigned' => TRUE,
         'not null' => TRUE,
-        'default' => 0
+        'default' => 0,
       ),
       'timestamp_format' => array(
         'description' => 'The format of the timestamp.',
         'type' => 'varchar',
         'length' => 14,
-        'not null' => TRUE
+        'not null' => TRUE,
       ),
       'filters' => array(
         'description' => 'The filter settings for the profile.',
@@ -198,11 +211,14 @@ function backup_migrate_schema() {
       'key name' => 'Destination ID',
       'admin_title' => 'name',
       'primary key' => 'destination_id',
-      'identifier' => 'item', // Exports will be defined as $preset
-      'default hook' => 'exportables_backup_migrate_destinations',  // Function hook name.
+      // Exports will be defined as $preset.
+      'identifier' => 'item',
+      // Function hook name.
+      'default hook' => 'exportables_backup_migrate_destinations',
       'api' => array(
         'owner' => 'backup_migrate',
-        'api' => 'backup_migrate_exportables',  // Base name for api include files.
+        // Base name for api include files.
+        'api' => 'backup_migrate_exportables',
         'minimum_version' => 1,
         'current_version' => 1,
       ),
@@ -213,7 +229,8 @@ function backup_migrate_schema() {
         'unsigned' => TRUE,
         'not null' => TRUE,
         'description' => 'Primary ID field for the table. Not used for anything except internal lookups.',
-        'no export' => TRUE, // Do not export database-only keys.
+        // Do not export database-only keys.
+        'no export' => TRUE,
       ),
       'machine_name' => array(
         'type' => 'varchar',
@@ -226,18 +243,18 @@ function backup_migrate_schema() {
         'description' => 'The name of the destination.',
         'type' => 'varchar',
         'length' => 255,
-        'not null' => TRUE
+        'not null' => TRUE,
       ),
       'subtype' => array(
         'description' => 'The type of the destination.',
         'type' => 'varchar',
         'length' => 32,
-        'not null' => TRUE
+        'not null' => TRUE,
       ),
       'location' => array(
         'description' => 'The the location string of the destination.',
         'type' => 'text',
-        'not null' => TRUE
+        'not null' => TRUE,
       ),
       'settings' => array(
         'description' => 'Other settings for the destination.',
@@ -245,7 +262,7 @@ function backup_migrate_schema() {
         'not null' => TRUE,
         'serialize' => TRUE,
         'serialized default' => 'a:0:{}',
-     ),
+      ),
     ),
     'primary key' => array('destination_id'),
   );
@@ -255,11 +272,14 @@ function backup_migrate_schema() {
       'key name' => 'Source ID',
       'admin_title' => 'name',
       'primary key' => 'source_id',
-      'identifier' => 'item', // Exports will be defined as $preset
-      'default hook' => 'exportables_backup_migrate_sources',  // Function hook name.
+      // Exports will be defined as $preset.
+      'identifier' => 'item',
+      // Function hook name.
+      'default hook' => 'exportables_backup_migrate_sources',
       'api' => array(
         'owner' => 'backup_migrate',
-        'api' => 'backup_migrate_exportables',  // Base name for api include files.
+        // Base name for api include files.
+        'api' => 'backup_migrate_exportables',
         'minimum_version' => 1,
         'current_version' => 1,
       ),
@@ -270,7 +290,8 @@ function backup_migrate_schema() {
         'unsigned' => TRUE,
         'not null' => TRUE,
         'description' => 'Primary ID field for the table. Not used for anything except internal lookups.',
-        'no export' => TRUE, // Do not export database-only keys.
+        // Do not export database-only keys.
+        'no export' => TRUE,
       ),
       'machine_name' => array(
         'type' => 'varchar',
@@ -283,18 +304,18 @@ function backup_migrate_schema() {
         'description' => 'The name of the source.',
         'type' => 'varchar',
         'length' => 255,
-        'not null' => TRUE
+        'not null' => TRUE,
       ),
       'subtype' => array(
         'description' => 'The type of the source.',
         'type' => 'varchar',
         'length' => 32,
-        'not null' => TRUE
+        'not null' => TRUE,
       ),
       'location' => array(
         'description' => 'The the location string of the source.',
         'type' => 'text',
-        'not null' => TRUE
+        'not null' => TRUE,
       ),
       'settings' => array(
         'description' => 'Other settings for the source.',
@@ -302,7 +323,7 @@ function backup_migrate_schema() {
         'not null' => TRUE,
         'serialize' => TRUE,
         'serialized default' => 'a:0:{}',
-     ),
+      ),
     ),
     'primary key' => array('source_id'),
   );
@@ -313,11 +334,14 @@ function backup_migrate_schema() {
       'key name' => 'Source ID',
       'admin_title' => 'name',
       'primary key' => 'schedule_id',
-      'identifier' => 'item', // Exports will be defined as $preset
-      'default hook' => 'exportables_backup_migrate_schedules',  // Function hook name.
+      // Exports will be defined as $preset.
+      'identifier' => 'item',
+      // Function hook name.
+      'default hook' => 'exportables_backup_migrate_schedules',
       'api' => array(
         'owner' => 'backup_migrate',
-        'api' => 'backup_migrate_exportables',  // Base name for api include files.
+        // Base name for api include files.
+        'api' => 'backup_migrate_exportables',
         'minimum_version' => 1,
         'current_version' => 1,
       ),
@@ -328,7 +352,8 @@ function backup_migrate_schema() {
         'unsigned' => TRUE,
         'not null' => TRUE,
         'description' => 'Primary ID field for the table. Not used for anything except internal lookups.',
-        'no export' => TRUE, // Do not export database-only keys.
+        // Do not export database-only keys.
+        'no export' => TRUE,
       ),
       'machine_name' => array(
         'type' => 'varchar',
@@ -341,14 +366,14 @@ function backup_migrate_schema() {
         'description' => 'The name of the profile.',
         'type' => 'varchar',
         'length' => 255,
-        'not null' => TRUE
+        'not null' => TRUE,
       ),
       'source_id' => array(
         'description' => 'The {backup_migrate_destination}.destination_id of the source to backup from.',
         'type' => 'varchar',
         'length' => 255,
         'default' => 'db',
-        'not null' => TRUE
+        'not null' => TRUE,
       ),
       'destination_id' => array(
         'type' => 'varchar',
@@ -389,7 +414,7 @@ function backup_migrate_schema() {
         'size' => 'tiny',
         'unsigned' => TRUE,
         'not null' => TRUE,
-        'default' => 0
+        'default' => 0,
       ),
       'cron' => array(
         'description' => 'Whether the schedule should be run during cron.',
@@ -413,18 +438,27 @@ function backup_migrate_schema() {
 }
 
 /**
- * Implementation of hook_install().
- */
-function backup_migrate_install() {
-}
-
-/**
- * Remove variables on uninstall.
+ * Implements hook_uninstall().
  */
 function backup_migrate_uninstall() {
-  db_query("DELETE FROM {variable} WHERE name LIKE 'backup_migrate_%'");
-  db_query("DELETE FROM {variable} WHERE name LIKE 'nodesquirrel_%'");
-  cache_clear_all('variables', 'cache');
+  variable_del('backup_migrate_backup_max_time');
+  variable_del('backup_migrate_copy_destination_id');
+  variable_del('backup_migrate_data_bytes_per_line');
+  variable_del('backup_migrate_data_rows_per_line');
+  variable_del('backup_migrate_data_rows_per_query');
+  variable_del('backup_migrate_destination_id');
+  variable_del('backup_migrate_disable_cron');
+  variable_del('backup_migrate_memory_limit');
+  variable_del('backup_migrate_profile_id');
+  variable_del('backup_migrate_schedule_last_run_');
+  variable_del('backup_migrate_source_id');
+  variable_del('backup_migrate_timeout_buffer');
+  variable_del('backup_migrate_verbose');
+  variable_del('nodesquirrel_endpoint_urls');
+  variable_del('nodesquirrel_schedule');
+  variable_del('nodesquirrel_schedule_enabled');
+  variable_del('nodesquirrel_schedule_source_id');
+  variable_del('nodesquirrel_secret_key');
 }
 
 /**
@@ -436,7 +470,7 @@ function backup_migrate_update_2000() {
 }
 
 /**
- * Adding filter field for dev release of 2009-01-28
+ * Adding filter field for dev release of 2009-01-28.
  */
 function backup_migrate_update_2001() {
   $ret = array();
@@ -444,11 +478,21 @@ function backup_migrate_update_2001() {
 
   // Add the filters field to the db.
   if (!db_field_exists('backup_migrate_profiles', 'filters')) {
-    db_add_field('backup_migrate_profiles', 'filters', array('description' => t('The filter settings for the profile.'),'type' => 'text', 'not null' => TRUE));
+    db_add_field('backup_migrate_profiles', 'filters', array(
+      'description' => t('The filter settings for the profile.'),
+      'type' => 'text',
+      'not null' => TRUE,
+    ));
   }
-  // Add the source field
+  // Add the source field.
   if (!db_field_exists('backup_migrate_profiles', 'source_id')) {
-    db_add_field('backup_migrate_profiles', 'source_id', array('description' => t('The {backup_migrate_destination}.destination_id of the source to backup from.'), 'type' => 'varchar', 'length' => 255, 'default' => 'db', 'not null' => TRUE));
+    db_add_field('backup_migrate_profiles', 'source_id', array(
+      'description' => t('The {backup_migrate_destination}.destination_id of the source to backup from.'),
+      'type' => 'varchar',
+      'length' => 255,
+      'default' => 'db',
+      'not null' => TRUE,
+    ));
   }
   // Remove the compression field.
   if (db_field_exists('backup_migrate_profiles', 'compression')) {
@@ -458,7 +502,7 @@ function backup_migrate_update_2001() {
 }
 
 /**
- * Clearing the cache because there was a menu structure change in the dev of 2009-05-31
+ * Clear the cache because there was a menu structure change.
  */
 function backup_migrate_update_2002() {
   // Cache should clear automatically. Nothing to do here.
@@ -466,7 +510,7 @@ function backup_migrate_update_2002() {
 }
 
 /**
- * Allowing non-int profile ids in schedules 2009-05-31
+ * Allowing non-int profile ids in schedules 2009-05-31.
  */
 function backup_migrate_update_2003() {
   $ret = array();
@@ -483,7 +527,7 @@ function backup_migrate_update_2003() {
 }
 
 /**
- * Allowing non-int profile ids 2009-07-01
+ * Allowing non-int profile ids 2009-07-01.
  */
 function backup_migrate_update_2004() {
   $ret = array();
@@ -515,16 +559,16 @@ function backup_migrate_update_2004() {
 }
 
 /**
- * Change the default database id to something friendlier 2009-08-08
+ * Change the default database id to something friendlier 2009-08-08.
  */
 function backup_migrate_update_2005() {
-  require_once './'. drupal_get_path('module', 'backup_migrate') .'/includes/crud.inc';
-  require_once './'. drupal_get_path('module', 'backup_migrate') .'/includes/profiles.inc';
+  require_once './' . drupal_get_path('module', 'backup_migrate') . '/includes/crud.inc';
+  require_once './' . drupal_get_path('module', 'backup_migrate') . '/includes/profiles.inc';
 
   $ret = array();
-  // Change the destination ids of the defined database sources mostly to make using them with drush friendlier.
-
-  // Change the db_url:default id to simply 'db'
+  // Change the destination ids of the defined database sources mostly to make
+  // using them with drush friendlier.
+  // Change the db_url:default id to simply 'db'.
   $ret[] = db_query("UPDATE {backup_migrate_profiles} SET source_id = 'db' WHERE source_id = 'db_url:default'");
   $ret[] = db_query("UPDATE {backup_migrate_schedules} SET destination_id = 'db' WHERE destination_id = 'db_url:default'");
 
@@ -532,9 +576,15 @@ function backup_migrate_update_2005() {
   $ret[] = db_query("UPDATE {backup_migrate_profiles} SET source_id = REPLACE(source_id, 'db_url:', 'db:')");
   $ret[] = db_query("UPDATE {backup_migrate_schedules} SET destination_id = REPLACE(destination_id, 'db_url:', 'db:')");
 
-  // Add the source field to the schedule
+  // Add the source field to the schedule.
   if (!db_field_exists('backup_migrate_schedules', 'source_id')) {
-    db_add_field('backup_migrate_schedules', 'source_id', array('description' => t('The db source to backup from.'), 'type' => 'varchar', 'length' => 255, 'default' => 'db', 'not null' => TRUE));
+    db_add_field('backup_migrate_schedules', 'source_id', array(
+      'description' => t('The db source to backup from.'),
+      'type' => 'varchar',
+      'length' => 255,
+      'default' => 'db',
+      'not null' => TRUE,
+    ));
   }
 
   // Copy source data from profiles to schedules.
@@ -543,7 +593,7 @@ function backup_migrate_update_2005() {
     if (!$schedule['source_id']) {
       $schedule['source_id'] = 'db';
     }
-    $ret[] = db_query("UPDATE {backup_migrate_schedules} SET source_id = '". $schedule['source_id'] ."' WHERE schedule_id = '". $schedule['profile_id'] ."'");
+    $ret[] = db_query("UPDATE {backup_migrate_schedules} SET source_id = '" . $schedule['source_id'] . "' WHERE schedule_id = '" . $schedule['profile_id'] . "'");
   }
 
   if (db_field_exists('backup_migrate_profiles', 'source_id')) {
@@ -583,19 +633,21 @@ function backup_migrate_update_7200() {
   }
 }
 
-
 /**
  * Change the filename field to support 255 characters.
  */
 function backup_migrate_update_7202() {
   $ret = array();
-  db_change_field('backup_migrate_profiles', 'filename', 'filename', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE));
+  db_change_field('backup_migrate_profiles', 'filename', 'filename', array(
+    'type' => 'varchar',
+    'length' => 255,
+    'not null' => TRUE,
+  ));
   return $ret;
 }
 
-
 /**
- * Update the schedule last run times to use variables instead of saving with the schedule.
+ * Schedule last run times to use variables instead of saving with the schedule.
  */
 function backup_migrate_update_7203() {
   $result = db_query('SELECT * FROM {backup_migrate_schedules}', array(), array('fetch' => PDO::FETCH_ASSOC));
@@ -610,20 +662,20 @@ function backup_migrate_update_7203() {
 }
 
 /**
- * Uninstall backup migrate files if it's installed
+ * Uninstall backup migrate files if it's installed.
  */
 function backup_migrate_update_7300() {
   if (module_exists('backup_migrate_files')) {
     module_disable(array('backup_migrate_files'));
     $ret[] = array(
-      'success' => true,
+      'success' => TRUE,
       'query' => 'Disabled the Backup and Migrate Files module',
     );
   }
   if (module_exists('nodesquirrel')) {
     module_disable(array('nodesquirrel'));
     $ret[] = array(
-      'success' => true,
+      'success' => TRUE,
       'query' => 'Disabled the NodeSquirrel module',
     );
   }
@@ -642,18 +694,18 @@ function backup_migrate_update_7300() {
         'description' => t('The name of the source.'),
         'type' => 'varchar',
         'length' => 255,
-        'not null' => TRUE
+        'not null' => TRUE,
       ),
       'type' => array(
         'description' => t('The type of the source.'),
         'type' => 'varchar',
         'length' => 32,
-        'not null' => TRUE
+        'not null' => TRUE,
       ),
       'location' => array(
         'description' => t('The the location string of the source.'),
         'type' => 'text',
-        'not null' => TRUE
+        'not null' => TRUE,
       ),
       'settings' => array(
         'description' => t('Other settings for the source.'),
@@ -661,7 +713,7 @@ function backup_migrate_update_7300() {
         'not null' => TRUE,
         'serialize' => TRUE,
         'serialized default' => 'a:0:{}',
-     ),
+      ),
     ),
     'primary key' => array('source_id'),
   );
@@ -677,7 +729,7 @@ function backup_migrate_update_7300() {
     drupal_write_record('backup_migrate_source', $item);
   }
 
-  // Change 'destination' settings to 'source' settings
+  // Change 'destination' settings to 'source' settings.
   $result = db_query('SELECT * FROM {backup_migrate_profiles}', array(), array('fetch' => PDO::FETCH_ASSOC));
   foreach ($result as $item) {
     $item['filters'] = unserialize($item['filters']);
@@ -691,22 +743,33 @@ function backup_migrate_update_7300() {
  * Switch the cron switch to text.
  */
 function backup_migrate_update_7301() {
-  db_change_field('backup_migrate_schedules', 'cron', 'cron', array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => 'builtin'));
-  db_add_field('backup_migrate_schedules', 'cron_schedule', array('description' => 'The cron schedule to run on.', 'type' => 'varchar', 'length' => 255, 'default' => '0 4 * * *', 'not null' => TRUE));
+  db_change_field('backup_migrate_schedules', 'cron', 'cron', array(
+    'type' => 'varchar',
+    'length' => 32,
+    'not null' => TRUE,
+    'default' => 'builtin',
+  ));
+  db_add_field('backup_migrate_schedules', 'cron_schedule', array(
+    'description' => 'The cron schedule to run on.',
+    'type' => 'varchar',
+    'length' => 255,
+    'default' => '0 4 * * *',
+    'not null' => TRUE,
+  ));
 }
 
 /**
  * Add a second destination to schedules.
  */
 function backup_migrate_update_7302() {
-  db_add_field('backup_migrate_schedules', 'copy_destination_id', 
+  db_add_field('backup_migrate_schedules', 'copy_destination_id',
     array(
-        'type' => 'varchar',
-        'length' => 32,
-        'not null' => TRUE,
-        'default' => '0',
-        'description' => 'A second {backup_migrate_destination}.destination_id of the destination to copy the backup to.',
-      )
+      'type' => 'varchar',
+      'length' => 32,
+      'not null' => TRUE,
+      'default' => '0',
+      'description' => 'A second {backup_migrate_destination}.destination_id of the destination to copy the backup to.',
+    )
   );
 }
 
@@ -714,7 +777,12 @@ function backup_migrate_update_7302() {
  * Add a serial id field to all tables to allow them to be ctools exportable.
  */
 function backup_migrate_update_7303() {
-  foreach (array('backup_migrate_sources' => 'source_id', 'backup_migrate_destinations' => 'destination_id', 'backup_migrate_schedules' => 'schedule_id', 'backup_migrate_profiles' => 'profile_id') as $table => $id) {
+  foreach (array(
+    'backup_migrate_sources' => 'source_id',
+    'backup_migrate_destinations' => 'destination_id',
+    'backup_migrate_schedules' => 'schedule_id',
+    'backup_migrate_profiles' => 'profile_id',
+  ) as $table => $id) {
     // Take the primary key status from the machine name so it can be renamed
     // A serial field must be defined as a key, so make a temporary index.
     // See: https://www.drupal.org/node/190027
@@ -723,23 +791,32 @@ function backup_migrate_update_7303() {
     // Drop our temporary index.
     db_drop_index($table, 'temp');
 
-    // Switch the name of the id to 'machine_name' to be more ctools standard
-    db_change_field($table, $id, 'machine_name', array('type' => 'varchar', 'length' => 32, 'not null' => TRUE));
+    // Switch the name of the id to 'machine_name' to be more ctools standard.
+    db_change_field($table, $id, 'machine_name', array(
+      'type' => 'varchar',
+      'length' => 32,
+      'not null' => TRUE,
+    ));
 
-    // Add a serial ID
-    db_add_field($table, $id, 
+    // Add a serial ID.
+    db_add_field($table, $id,
       array(
-          'type' => 'serial',
-          'unsigned' => TRUE,
-          'not null' => TRUE,
-          'description' => 'Primary ID field for the table. Not used for anything except internal lookups.',
-          'no export' => TRUE, // Do not export database-only keys.
-        ),
+        'type' => 'serial',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'description' => 'Primary ID field for the table. Not used for anything except internal lookups.',
+        // Do not export database-only keys.
+        'no export' => TRUE,
+      ),
         array('primary key' => array($id))
     );
   }
   foreach (array('backup_migrate_sources', 'backup_migrate_destinations') as $table) {
-    db_change_field($table, 'type', 'subtype', array('type' => 'varchar', 'length' => 32, 'not null' => TRUE));
+    db_change_field($table, 'type', 'subtype', array(
+      'type' => 'varchar',
+      'length' => 32,
+      'not null' => TRUE,
+    ));
   }
 }
 
@@ -754,20 +831,50 @@ function backup_migrate_update_7304() {
  * Fix schema mismatch after upgrade.
  */
 function backup_migrate_update_7305() {
-  foreach (array('backup_migrate_profiles', 'backup_migrate_destinations', 'backup_migrate_sources', 'backup_migrate_schedules') as $table) {
-    db_change_field($table, 'machine_name', 'machine_name', array(
-      'type' => 'varchar',
-      'length' => 255,
-      'not null' => TRUE,
-      'default' => '0',
-    ));
+  // Fix the 'machine_name' table fields.
+  $field_spec = array(
+    'type' => 'varchar',
+    'length' => 255,
+    'not null' => TRUE,
+    'default' => '0',
+  );
+  foreach (array(
+    'backup_migrate_profiles',
+    'backup_migrate_destinations',
+    'backup_migrate_sources',
+    'backup_migrate_schedules',
+  ) as $table) {
+    if (!db_field_exists($table, $machine_name)) {
+      try {
+        db_add_field($table, 'machine_name', $field_spec);
+      }
+      catch (\Exception $e) {
+        db_change_field($table, 'machine_name', 'machine_name', $field_spec);
+      }
+    }
+    else {
+      db_change_field($table, 'machine_name', 'machine_name', $field_spec);
+    }
   }
-  db_change_field('backup_migrate_schedules', 'cron', 'cron', array(
+
+  // Fix the 'cron' table field.
+  $field_spec = array(
     'type' => 'varchar',
     'length' => 32,
     'not null' => TRUE,
     'default' => 'builtin',
-  ));
+  );
+  if (!db_field_exists('backup_migrate_schedules', 'cron')) {
+    try {
+      db_add_field('backup_migrate_schedules', 'cron', $field_spec);
+    }
+    catch (\Exception $e) {
+      db_change_field('backup_migrate_schedules', 'cron', 'cron', $field_spec);
+    }
+  }
+  else {
+    db_change_field('backup_migrate_schedules', 'cron', 'cron', $field_spec);
+  }
 }
 
 /**
@@ -776,3 +883,14 @@ function backup_migrate_update_7305() {
 function backup_migrate_update_7306() {
   drupal_set_message(t('Please note that release 7.x-3.4 had a bug which caused all backups to be overwritten instead of having a timestamp added. Please review all backup settings to ensure they work as intended.'), 'warning');
 }
+
+/**
+ * 'backup_migrate_backup_memory_limit' vs 'backup_migrate_memory_limit'.
+ */
+function backup_migrate_update_7307() {
+  $limit = variable_get('backup_migrate_backup_memory_limit');
+  if (!empty($limit)) {
+    variable_set('backup_migrate_memory_limit', $limit);
+    variable_del('backup_migrate_backup_memory_limit');
+  }
+}

+ 28 - 16
sites/all/modules/backup_migrate/backup_migrate.js

@@ -1,22 +1,32 @@
+/**
+ * @file
+ * Custom JS for the Backup and Migrate module.
+ */
+
 (function($) {
+  'use strict';
+
   Drupal.behaviors.backupMigrate = {
-    attach: function(context) {
-      if (Drupal.settings.backup_migrate !== undefined) { 
+    attach: function(context, settings) {
+      if (Drupal.settings.backup_migrate !== undefined) {
         if (Drupal.settings.backup_migrate.dependents !== undefined) {
+          var key;
           for (key in Drupal.settings.backup_migrate.dependents) {
             info = Drupal.settings.backup_migrate.dependents[key];
-            dependent = $('#edit-' + info['dependent']);
+            var dependent = $('#edit-' + info['dependent']);
             for (key in info['dependencies']) {
               $('[name="' + key + '"]').each(function() {
                 var dependentval = info['dependencies'][key];
                 var dependency = $(this);
                 (function(dependent, dependency) {
                   var checkval = function(inval) {
-                    if (dependency.attr('type') == 'radio') {
+                    // Do loose comparisons to support things like "true", "1",
+                    // etc.
+                    if (dependency.attr('type') === 'radio') {
                       var val = $('[name="' + dependency.attr('name') + '"]:checked').val();
                       return val == inval;
                     }
-                    else if (dependency.attr('type') == 'checkbox') {
+                    else if (dependency.attr('type') === 'checkbox') {
                       return dependency.is(':checked') && inval == dependency.val();
                     }
                     else {
@@ -53,12 +63,13 @@
                 var label = $(this).attr('label');
                 copy_selector_options[label] = [];
                 $(this).find('option').each(function() {
-                  copy_selector_options[label].push(this); 
+                  copy_selector_options[label].push(this);
                 });
                 $(this).remove();
               })
 
-              // Assign an action to the main selector to modify the secondary selector
+              // Assign an action to the main selector to modify the secondary
+              // selector.
               selector.each(function() {
                 $(this).bind('load change click keypress focus', function() {
                   var group = $(this).find('option[value=' + $(this).val() + ']').parents('optgroup').attr('label');
@@ -75,27 +86,28 @@
               });
             })(info);
           }
+
           // Add the convert to checkboxes functionality to all multiselects.
           $('#backup-migrate-ui-manual-backup-form select[multiple], #backup-migrate-crud-edit-form select[multiple]').each(function() {
             var self = this;
             $(self).after(
               $('<div class="description backup-migrate-checkbox-link"></div>').append(
-                $('<a>'+ Drupal.settings.backup_migrate.checkboxLinkText +'</a>').click(function() {
+                $('<a>' + Drupal.settings.backup_migrate.checkboxLinkText + '</a>').click(function() {
                   var $select = $(self);
                   var $checkboxes = $('<div></div>').addClass('backup-migrate-tables-checkboxes');
                   $('option', $select).each(function(i) {
                     $checkboxes.append(
                       $('<div class="form-item"></div>').append(
                         $('<label class="option backup-migrate-table-select">' + this.value + '</label>').prepend(
-                          $('<input type="checkbox" class="backup-migrate-tables-checkbox" name="'+ $select.attr('name') +'"'+ (this.selected ? 'checked="checked"' : '') +' value="'+ this.value +'"/>')
+                          $('<input type="checkbox" class="backup-migrate-tables-checkbox" name="' + $select.attr('name') + '"' + (this.selected ? 'checked="checked"' : '') + ' value="' + this.value + '"/>')
                             .bind('click change load', function() {
-                                if (this.checked) {
-                                  $(this).parent().addClass('checked');
-                                }
-                                else {
-                                  $(this).parent().removeClass('checked');
-                                }
-                              }).load()
+                              if (this.checked) {
+                                $(this).parent().addClass('checked');
+                              }
+                              else {
+                                $(this).parent().removeClass('checked');
+                              }
+                            }).load()
                         )
                       )
                     );

File diff suppressed because it is too large
+ 411 - 231
sites/all/modules/backup_migrate/backup_migrate.module


+ 72 - 18
sites/all/modules/backup_migrate/includes/backup_migrate.drush.inc

@@ -1,11 +1,10 @@
 <?php
 
-
 /**
  * @file
  * Drush commands for backup and migrate.
  */
- 
+
 /**
  * Implementation of hook_drush_command().
  */
@@ -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;
   }
@@ -108,10 +121,48 @@ function backup_migrate_drush_backup($source_id = 'db', $destination_id = 'manua
 }
 
 /**
+ * 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;
   }
@@ -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,7 +317,8 @@ function backup_migrate_drush_destination_files($destination_id = NULL) {
  * Send a message to the drush log.
  */
 function _backup_migrate_message_drush($message, $replace, $type) {
-  // If this is an error use drush_set_error to notify the end user and set the exit status
+  // 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)));
   }

+ 131 - 136
sites/all/modules/backup_migrate/includes/crud.inc

@@ -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;
@@ -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';
-
-  /**
-   * This function is not supposed to be called. It is just here to help the po extractor out.
+  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.
    */
-  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,11 +910,12 @@ class backup_migrate_item {
   /**
    * Get all of the given items.
    */
-  function all_items() {
+  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;
@@ -931,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;
@@ -962,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;
@@ -973,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;
   }
@@ -981,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]);
   }
+
 }

+ 33 - 12
sites/all/modules/backup_migrate/includes/destinations.browser.inc

@@ -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();
   }
-}
 
+}

+ 34 - 35
sites/all/modules/backup_migrate/includes/destinations.db.inc

@@ -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.'));
     }
@@ -71,7 +70,7 @@ class backup_migrate_destination_db extends backup_migrate_destination_remote {
    *   necessarily extremely important to back up or migrate during development
    *   (such as access log and watchdog).
    */
-  function backup_settings_default() {
+  public function backup_settings_default() {
     $all_tables = $this->_get_table_names();
 
     // Basic modules that should be excluded.
@@ -118,7 +117,7 @@ class backup_migrate_destination_db extends backup_migrate_destination_remote {
   /**
    * 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(
@@ -150,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;
@@ -168,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).
@@ -190,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());
@@ -204,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';
@@ -230,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')) {
@@ -256,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;
@@ -265,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();
   }
@@ -273,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;
         }
       }
@@ -289,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();
     }
@@ -305,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';
   }
+
 }

+ 153 - 92
sites/all/modules/backup_migrate/includes/destinations.db.mysql.inc

@@ -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,13 +241,12 @@ 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);
@@ -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;
-        }
-        // Otherwise add a comma to end the previous entry.
-        else {
-          $file->write(",");
+
+      $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) . "'";
         }
-  
-        // 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 */;
 ";
   }
+
 }

+ 37 - 28
sites/all/modules/backup_migrate/includes/destinations.email.inc

@@ -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 __construct() {
+  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);
   }
+
 }

+ 43 - 40
sites/all/modules/backup_migrate/includes/destinations.file.inc

@@ -1,6 +1,5 @@
 <?php
 
-
 /**
  * @file
  * A destination type for saving locally to the server.
@@ -11,27 +10,29 @@
  *
  * @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;
@@ -63,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');
@@ -81,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]);
@@ -92,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));
           }
         }
       }
@@ -111,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);
   }
@@ -119,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;
@@ -130,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",
@@ -170,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.'));
@@ -181,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'];
@@ -192,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);
     }
@@ -202,7 +203,7 @@ 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 of that directory and try again.", array('%directory' => $directory), "error");
@@ -220,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);
         }
@@ -248,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);
@@ -269,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) {
@@ -278,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) {
@@ -296,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')));
   }
-}
 
+}

+ 55 - 61
sites/all/modules/backup_migrate/includes/destinations.ftp.inc

@@ -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]);
     }
   }

+ 110 - 116
sites/all/modules/backup_migrate/includes/destinations.inc

@@ -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,
@@ -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 some 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>';
         }
       }
 
@@ -416,8 +415,8 @@ 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, $start + $limit);
       }
@@ -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,7 +654,7 @@ 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 . '/settings/destination/add');
@@ -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;
-
-  var $destination_type = "";
-  var $supported_ops = array();
+  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;
+
+  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
+ 293 - 191
sites/all/modules/backup_migrate/includes/destinations.nodesquirrel.inc


+ 28 - 26
sites/all/modules/backup_migrate/includes/destinations.s3.inc

@@ -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;
   }
+
 }

+ 54 - 50
sites/all/modules/backup_migrate/includes/files.inc

@@ -1,6 +1,5 @@
 <?php
 
-
 /**
  * @file
  * General file handling code for Backup and Migrate.
@@ -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,12 +145,12 @@ 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.
@@ -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 __construct($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;
   }
-}
 
+}

+ 41 - 31
sites/all/modules/backup_migrate/includes/filters.backup_restore.inc

@@ -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,9 +208,12 @@ 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');
     $destinations = &drupal_static('backup_migrate_filter_backup_restore::_get_destination_types', NULL);
     if (!is_array($destinations)) {
@@ -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');
     $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());
       }

+ 19 - 21
sites/all/modules/backup_migrate/includes/filters.compression.inc

@@ -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;
   }
-}
 
+}

+ 31 - 29
sites/all/modules/backup_migrate/includes/filters.encryption.inc

@@ -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;
   }
-}
 
+}

+ 46 - 48
sites/all/modules/backup_migrate/includes/filters.inc

@@ -1,13 +1,12 @@
 <?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) {
   $filters = &drupal_static('backup_migrate_get_filters', NULL);
@@ -17,9 +16,9 @@ function backup_migrate_get_filters($op = NULL) {
     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) {
 
   }
-}
 
+}

+ 7 - 8
sites/all/modules/backup_migrate/includes/filters.statusnotify.inc

@@ -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,7 +67,7 @@ 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();
       if ($messages = $this->get_messages()) {
@@ -84,7 +83,7 @@ class backup_migrate_filter_statusnotify extends backup_migrate_filter {
   /**
    * 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();
       if ($messages = $this->get_messages()) {
@@ -100,7 +99,7 @@ class backup_migrate_filter_statusnotify extends backup_migrate_filter {
   /**
    * Render the messages and errors for the email.
    */
-  function get_messages() {
+  public function get_messages() {
     $out = "";
     $messages = _backup_migrate_messages();
     foreach ($messages as $message) {
@@ -108,5 +107,5 @@ class backup_migrate_filter_statusnotify extends backup_migrate_filter {
     }
     return $out;
   }
-}
 
+}

+ 25 - 19
sites/all/modules/backup_migrate/includes/filters.utils.inc

@@ -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,7 +209,7 @@ class backup_migrate_filter_utils extends backup_migrate_filter {
   /**
    * Take the site offline if configured to do so.
    */
-  function take_site_offline($settings) {
+  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.
@@ -224,7 +229,7 @@ class backup_migrate_filter_utils extends backup_migrate_filter {
   /**
    * 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.
     if (variable_get('maintenance_mode', 0) && !empty($this->saved_site_offline)) {
       variable_set('maintenance_mode', 0);
@@ -236,4 +241,5 @@ class backup_migrate_filter_utils extends backup_migrate_filter {
       }
     }
   }
+
 }

+ 64 - 65
sites/all/modules/backup_migrate/includes/locations.inc

@@ -1,6 +1,5 @@
 <?php
 
-
 /**
  * @file
  * All of the location handling code needed for Backup and Migrate.
@@ -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,8 +229,8 @@ 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();
 
     // Suppress locations with no actions as there's no value in showing them (and they may confuse new users).
@@ -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));
     }
@@ -372,34 +371,34 @@ class backup_migrate_location extends backup_migrate_item {
   /**
    * 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,29 +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);
   }
 
   /**
-   * location configuration callback.
+   * Location configuration callback.
    */
-  function edit_form() {
+  public function edit_form() {
     $form = parent::edit_form();
     $form['scheme'] = array(
       "#type" => "select",
@@ -496,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);
   }
-}
 
+}

+ 36 - 36
sites/all/modules/backup_migrate/includes/profiles.inc

@@ -1,6 +1,5 @@
 <?php
 
-
 /**
  * @file
  * All of the settings profiles handling code for Backup and Migrate.
@@ -44,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');
   }
 }
 
@@ -75,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;
@@ -86,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');
 
@@ -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,12 +206,12 @@ 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.
@@ -223,8 +222,8 @@ class backup_migrate_profile extends backup_migrate_item {
    * @param array $params
    */
   public function __construct(array $params = array()) {
-    $params = (array)$params;
-    $defaults = (array)$this->get_default_values();
+    $params = (array) $params;
+    $defaults = (array) $this->get_default_values();
     foreach ($defaults as $key => $val) {
       if (!isset($params[$key])) {
         $params[$key] = $val;
@@ -236,7 +235,7 @@ class backup_migrate_profile extends backup_migrate_item {
   /**
    * 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');
@@ -247,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')),
@@ -275,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();
@@ -289,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);
@@ -300,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();
     }
@@ -310,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;
@@ -342,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();
@@ -354,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');
@@ -366,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",
@@ -381,7 +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')));
   }
+
 }

+ 87 - 90
sites/all/modules/backup_migrate/includes/schedules.inc

@@ -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');
 
 
@@ -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 . '/settings/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'),
@@ -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,7 +632,7 @@ 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');
@@ -656,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();
     }
@@ -666,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);
         }
       }
@@ -700,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;
@@ -733,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(
@@ -743,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(),
@@ -790,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;
       }
@@ -803,5 +800,5 @@ class backup_migrate_schedule extends backup_migrate_item {
       }
     }
   }
-}
 
+}

+ 66 - 45
sites/all/modules/backup_migrate/includes/sources.archivesource.inc

@@ -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,9 +52,9 @@ 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) {
@@ -63,7 +72,7 @@ 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();
 
@@ -75,10 +84,10 @@ class backup_migrate_files_destination_archivesource extends backup_migrate_dest
         $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', $base_dir);
+        $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);
@@ -97,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) {
@@ -105,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();
@@ -116,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;
     }
@@ -124,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,
@@ -156,13 +171,14 @@ 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();
-    // Clone the default settings so we can make changes without them leaking out of this function.
+    // 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';
@@ -170,7 +186,8 @@ class backup_migrate_files_destination_archivesource extends backup_migrate_dest
     // 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);
@@ -179,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();
@@ -190,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, variable_get('file_public_path', conf_path() . '/files') );
+        _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');
@@ -235,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',
@@ -263,14 +280,16 @@ 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 _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";
     }
@@ -278,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);
   }
-}
 
+}

+ 39 - 36
sites/all/modules/backup_migrate/includes/sources.db.inc

@@ -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.'));
     }
@@ -70,7 +69,7 @@ class backup_migrate_source_db extends backup_migrate_source_remote {
    *   necessarily extremely important to back up or migrate during development
    *   (such as access log and watchdog).
    */
-  function backup_settings_default() {
+  public function backup_settings_default() {
     $all_tables = $this->_get_table_names();
 
     // Basic modules that should be excluded.
@@ -117,7 +116,7 @@ class backup_migrate_source_db extends backup_migrate_source_remote {
   /**
    * 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(
@@ -148,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).
@@ -186,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());
@@ -200,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';
@@ -226,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')) {
@@ -252,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;
@@ -261,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();
   }
@@ -269,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;
         }
       }
@@ -285,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();
     }
@@ -301,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'),

+ 156 - 96
sites/all/modules/backup_migrate/includes/sources.db.mysql.inc

@@ -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,13 +229,12 @@ 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);
@@ -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;
-        }
-        // Otherwise add a comma to end the previous entry.
-        else {
-          $file->write(",");
+
+      $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) . "'";
         }
-  
-        // 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 . "
 -- 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;
   }
 
 }
-

+ 67 - 49
sites/all/modules/backup_migrate/includes/sources.filesource.inc

@@ -1,6 +1,5 @@
 <?php
 
-
 /**
  * @file
  * A destination type for saving locally to the server.
@@ -11,30 +10,39 @@
  *
  * @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",
@@ -47,9 +55,9 @@ class backup_migrate_destination_filesource extends backup_migrate_source {
   }
 
   /**
-   * 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,14 +69,14 @@ 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(
+  public function backup_settings_default() {
+    return array(
       'exclude_filepaths' => "backup_migrate\nstyles\ncss\njs\nctools\nless\nlanguages",
     );
   }
@@ -76,12 +84,12 @@ class backup_migrate_destination_filesource extends backup_migrate_source {
   /**
    * 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 = $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,7 +129,7 @@ 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 = $this->get_excluded_paths($settings);
       $exclude = array();
@@ -130,11 +138,16 @@ class backup_migrate_destination_filesource extends backup_migrate_source {
       }
       $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;
@@ -143,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;
     }
@@ -155,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();
@@ -164,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';
       }
 
@@ -182,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';
       }
 
@@ -203,9 +216,11 @@ 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()) {
+  public function get_files_to_backup($dir, $settings, $exclude = array()) {
     $out = $errors = array();
 
     if (!file_exists($dir)) {
@@ -220,7 +235,8 @@ class backup_migrate_destination_filesource extends backup_migrate_source {
           if (!in_array($real, $exclude)) {
             if (is_dir($real)) {
               $subdir = $this->get_files_to_backup($real, $settings, $exclude);
-              // If there was an error reading the subdirectory then abort the backup.
+              // If there was an error reading the subdirectory then abort the
+              // backup.
               if ($subdir === FALSE) {
                 closedir($handle);
                 return FALSE;
@@ -271,20 +287,21 @@ 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($settings) {
+  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) {
       $path = trim($val, "/ \t\r\n");
-      // If the path specified is a stream url or absolute path add the normalized version.
+      // 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.
-      else if ($real = drupal_realpath($base_dir . $path)) {
+      elseif ($real = drupal_realpath($base_dir . $path)) {
         $out[$key] = $real;
       }
       // Otherwise add it as is even though it probably won't match any files.
@@ -296,19 +313,20 @@ class backup_migrate_destination_filesource extends backup_migrate_source {
   }
 
   /**
-   * 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());
   }
-}
 
+}

+ 32 - 27
sites/all/modules/backup_migrate/includes/sources.inc

@@ -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);
   }
-}
 
+}

+ 0 - 33
sites/all/modules/backup_migrate/tests/BackupMigrateBasicsTest.test

@@ -1,33 +0,0 @@
-<?php
-
-/**
- * @file
- * Tests for different parts of the Backup Migrate system.
- */
-
-/**
- * Test that the front page still loads.
- */
-class BackupMigrateBasicsTest extends BackupMigrateBase {
-
-  /**
-   * Define this test class.
-   */
-  public static function getInfo() {
-    return array(
-      'name' => 'Basic test',
-      'description' => 'Ensure that the site was not blown up when the Backup & Migrate module was enabled.',
-      'group' => 'backup_migrate',
-    );
-  }
-
-  /**
-   * Verify the front page still loads.
-   */
-  public function testFrontPage() {
-    $this->drupalGet('<front>');
-    $this->assertResponse(200);
-    $this->assertText(t('No front page content has been created yet.'));
-  }
-
-}

+ 0 - 16
sites/all/modules/backup_migrate/tests/BackupMigrateHelper.test

@@ -1,16 +0,0 @@
-<?php
-
-/**
- * Base class for testing a module's custom tags.
- */
-abstract class BackupMigrateBase extends DrupalWebTestCase {
-
-  /**
-   * {@inheritdoc}
-   */
-  function setUp(array $modules = array()) {
-    $modules[] = 'backup_migrate';
-    parent::setUp($modules);
-  }
-  
-}

+ 246 - 0
sites/all/modules/backup_migrate/tests/BmTestBase.test

@@ -0,0 +1,246 @@
+<?php
+
+/**
+ * @file
+ * Shared functionality to make the rest of the tests simpler.
+ */
+
+/**
+ * Base class for testing a module's custom tags.
+ */
+abstract class BmTestBase extends DrupalWebTestCase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp(array $modules = array()) {
+    $modules[] = 'backup_migrate';
+    parent::setUp($modules);
+  }
+
+  /**
+   * Log in as user 1.
+   *
+   * The benefit of doing this is that it ignores permissions entirely, so the
+   * raw functionality can be tested.
+   */
+  protected function loginUser1() {
+    // Load user 1.
+    $account = user_load(1, TRUE);
+
+    // Reset the password.
+    $password = user_password();
+    $edit = array(
+      'pass' => $password,
+    );
+    user_save($account, $edit);
+    $account->pass_raw = $password;
+
+    // Login.
+    $this->drupalLogin($account);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function verbose($message, $title = NULL) {
+    // Handle arrays, objects, etc.
+    if (!is_string($message)) {
+      $message = "<pre>\n" . print_r($message, TRUE) . "\n</pre>\n";
+    }
+
+    // Optional title to go before the output.
+    if (!empty($title)) {
+      $title = '<h2>' . check_plain($title) . "</h2>\n";
+    }
+
+    parent::verbose($title . $message);
+  }
+
+  /**
+   * Confirm that a selector has the expected items.
+   */
+  protected function assertSelectOptions($select_id, array $options, $message = '') {
+    $elements = $this
+      ->xpath('//select[@id=:id]//option', array(
+        ':id' => $select_id,
+      ));
+    $results = $this->assertEqual(count($elements), count($options), t('The same number of items were found as were requested'));
+    $this->verbose($elements);
+
+    foreach ($options as $option) {
+      $elements = $this
+        ->xpath('//select[@id=:id]//option[@value=:option]', array(
+          ':id' => $select_id,
+          ':option' => $option,
+        ));
+      $this->verbose($elements);
+      $results *= $this->assertTrue(isset($elements[0]), $message ? $message : t('Option @option for field @id is present.', array(
+        '@option' => $option,
+        '@id' => $select_id,
+      )), t('Browser'));
+    }
+
+    return $results;
+  }
+
+  /**
+   * Confirm that a specific selector does not have items selected.
+   */
+  protected function assertNoOptionsSelected($id, $message = '') {
+    $elements = $this
+      ->xpath('//select[@id=:id]//option[@selected="selected"]', array(
+        ':id' => $id,
+      ));
+    return $this
+      ->assertTrue(!isset($elements[0]), $message ? $message : t('Field @id does not have any selected items.', array(
+        '@id' => $id,
+      )), t('Browser'));
+  }
+
+  /**
+   * Work out which compressor systems are supported by PHP.
+   *
+   * @return array
+   *   The list of supported compressors. Will always include the item 'none'.
+   */
+  protected function supportedCompressors() {
+    $items = array('none');
+
+    // Work out which systems are supported.
+    if (@function_exists("gzencode")) {
+      $items[] = 'gzip';
+    }
+    if (@function_exists("bzcompress")) {
+      $items[] = 'bzip';
+    }
+    if (class_exists('ZipArchive')) {
+      $items[] = 'zip';
+    }
+
+    return $items;
+  }
+
+  /**
+   * Get a list of the files in a specific destination.
+   *
+   * @param string $destination_id
+   *   The ID of the destination to check. Defaults to the manual file path.
+   *
+   * @return array
+   *   The backup files found in the requested backup destination.
+   */
+  protected function listBackupFiles($destination_id = 'manual') {
+    $items = array();
+
+    backup_migrate_include('destinations');
+
+    // Load the destination object.
+    $destination = backup_migrate_get_destination($destination_id);
+    if (!empty($destination)) {
+      $items = $destination->list_files();
+    }
+
+    return $items;
+  }
+
+  /**
+   * Run a specific backup.
+   *
+   * @param string $destination_id
+   *   The ID of the destination to check. Defaults to the manual file path.
+   */
+  protected function runBackup($destination_id = 'manual') {
+    $this->drupalGet(BACKUP_MIGRATE_MENU_PATH);
+    $this->assertResponse(200);
+    $edit = array(
+      'destination_id' => $destination_id,
+    );
+    $this->drupalPost(NULL, $edit, 'Backup now');
+    $this->assertResponse(200);
+    // Confirm the response is as expected. This is split up into separate
+    // pieces because it'd be more effort than is necessary right now to confirm
+    // what the exact filename is.
+    $this->assertText('Default Database backed up successfully');
+    $this->assertText('in destination');
+    $this->assertLink('download');
+    $this->assertLink('restore');
+    $this->assertLink('delete');
+  }
+
+  /**
+   * Delete all of the files in a specific backup destination.
+   *
+   * @param string $destination_id
+   *   The ID of the destination to check. Defaults to the manual file path.
+   */
+  protected function deleteBackups($destination_id = 'manual') {
+    $destination = backup_migrate_get_destination($destination_id);
+    $files = $this->listBackupFiles($destination_id);
+    if (!empty($files)) {
+      foreach ($files as $file_id => $file) {
+        $destination->delete_file($file_id);
+      }
+    }
+  }
+
+  /**
+   * Work out whether a backup filename includes a timestamp.
+   *
+   * @param object $file
+   *   The backup file to examine.
+   *
+   * @return mixed
+   *   Returns 1 if found, 0 if not found, FALSE if an error occurs.
+   */
+  protected function fileHasTimestamp($file) {
+    // Get the default filename, this is used later.
+    backup_migrate_include('files');
+    $default_filename = _backup_migrate_default_filename();
+    $ext = implode('.', $file->ext);
+    $pattern = "/{$default_filename}-(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d)-(\d\d)-(\d\d).{$ext}/";
+
+    return preg_match($pattern, $file->file_info['filename']);
+  }
+
+  /**
+   * Confirm that a backup filename includes a timestamp.
+   *
+   * @param object $file
+   *   The backup file to examine.
+   *
+   * @return bool
+   *   Indicates whether the file includes a timestamp.
+   */
+  protected function assertFileTimestamp($file) {
+    return $this->assertTrue($this->fileHasTimestamp($file));
+  }
+
+  /**
+   * Confirm that a backup filename does not include a timestamp.
+   *
+   * @param object $file
+   *   The backup file to examine.
+   *
+   * @return bool
+   *   Indicates whether the file does not include a timestamp.
+   */
+  protected function assertNoFileTimestamp($file) {
+    return !$this->assertFalse($this->fileHasTimestamp($file));
+  }
+
+  /**
+   * Get a profile.
+   *
+   * @param string $profile_id
+   *   The name of the profile to load. Defaults to 'default'.
+   *
+   * @return object
+   *   The profile object.
+   */
+  protected function getProfile($profile_id = 'default') {
+    backup_migrate_include('profiles');
+    return backup_migrate_get_profile($profile_id);
+  }
+
+}

+ 111 - 0
sites/all/modules/backup_migrate/tests/BmTestBasics.test

@@ -0,0 +1,111 @@
+<?php
+
+/**
+ * @file
+ * Tests for different parts of the Backup Migrate system.
+ */
+
+/**
+ * Test that the front page still loads.
+ */
+class BmTestBasics extends BmTestBase {
+
+  /**
+   * Define this test class.
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'Basic tests',
+      'description' => 'Run through basic scenarios and functionality.',
+      'group' => 'backup_migrate',
+    );
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp(array $modules = array()) {
+    parent::setUp($modules);
+
+    // Log in as user 1, so that permissions are irrelevant.
+    $this->loginUser1();
+  }
+
+  /**
+   * Verify the main page has the expected functionality available.
+   */
+  public function testMainPage() {
+    // Load the main B&M page.
+    $this->drupalGet(BACKUP_MIGRATE_MENU_PATH);
+    $this->assertResponse(200);
+
+    // @todo Confirm each of the tabs are present.
+    // @todo Confirm each of the local tasks are present.
+    // Confirm the form has the expected fields.
+    $this->assertFieldByName('source_id');
+    $this->assertFieldByName('destination_id');
+    $this->assertFieldByName('profile_id');
+    $this->assertFieldByName('copy');
+    $this->assertFieldByName('copy_destination_id');
+    $this->assertFieldByName('description_enabled');
+    // This item should not have a value "selected", it just defaults to the
+    // first item being the active item.
+    $items = array('db', 'files', 'archive');
+    $this->assertSelectOptions('edit-source-id', $items);
+    $this->assertNoOptionsSelected('edit-source-id');
+    // This item should have a value "selected", not just the first item.
+    $items = array('manual', 'download', 'nodesquirrel');
+    $this->assertSelectOptions('edit-destination-id', $items);
+    $this->assertOptionSelected('edit-destination-id', 'download');
+    // This item should not have a value "selected", it just defaults to the
+    // first item being the active item.
+    $items = array('default');
+    $this->assertSelectOptions('edit-profile-id', $items);
+    $this->assertNoOptionsSelected('edit-profile-id');
+    // This item should not have a value "selected", it just defaults to the
+    // first item being the active item.
+    $items = array('manual', 'download', 'nodesquirrel');
+    $this->assertSelectOptions('edit-copy-destination-id', $items);
+    $this->assertNoOptionsSelected('edit-copy-destination-id');
+  }
+
+  /**
+   * Confirm the initial backup process works.
+   */
+  public function testFirstBackup() {
+    // Load the main B&M page.
+    $this->drupalGet(BACKUP_MIGRATE_MENU_PATH);
+    $this->assertResponse(200);
+
+    // Generate a backup and confirm it was created correctly.
+    $edit = array(
+      'destination_id' => 'manual',
+    );
+    $this->drupalPost(NULL, $edit, 'Backup now');
+    $this->assertResponse(200);
+    // Confirm the response is as expected. This is split up into separate
+    // pieces because it'd be more effort than is necessary right now to confirm
+    // what the exact filename is.
+    $this->assertText('Default Database backed up successfully');
+    $this->assertText('in destination Manual Backups Directory');
+    $this->assertLink('download');
+    $this->assertLink('restore');
+    $this->assertLink('delete');
+
+    // Try requesting the backup file.
+    $xpath = $this
+      ->xpath('//a[normalize-space(text())=:label]', array(
+        ':label' => 'download',
+      ));
+    $this->verbose($xpath);
+    $this->assertTrue(isset($xpath[0]['href']));
+    $this->assertNotNull($xpath[0]['href']);
+    // @todo This doesn't work on drupalci, so work out how to fix it.
+    // $this->drupalGet($xpath[0]['href']);
+    $this->assertResponse(200);
+  }
+
+}
+
+// @todo Test permissions.
+// @todo Test admin forms.

+ 168 - 0
sites/all/modules/backup_migrate/tests/BmTestProfiles.test

@@ -0,0 +1,168 @@
+<?php
+
+/**
+ * @file
+ * Tests the profiles functionality.
+ */
+
+/**
+ * Test that the front page still loads.
+ */
+class BmTestProfiles extends BmTestBase {
+
+  /**
+   * Define this test class.
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'Destination tests',
+      'description' => 'Run through basic scenarios and functionality.',
+      'group' => 'backup_migrate',
+    );
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp(array $modules = array()) {
+    parent::setUp($modules);
+
+    // Log in as user 1, so that permissions are irrelevant.
+    $this->loginUser1();
+  }
+
+  /**
+   * Verify the profile page has the expected functionality available.
+   */
+  public function testProfilePage() {
+    // Load the main B&M page.
+    $this->drupalGet(BACKUP_MIGRATE_MENU_PATH . '/settings');
+    $this->assertResponse(200);
+
+    // Confirm the page has the expected settings details.
+    $this->assertText('Settings Profiles');
+    $this->assertText('Default Settings');
+    $this->assertLink('Create a new settings profile');
+  }
+
+  /**
+   * Confirm adding a new backup process works.
+   */
+  public function testAddDefaultProfile() {
+    // Load the main B&M page.
+    $this->drupalGet(BACKUP_MIGRATE_MENU_PATH . '/settings/profile/add');
+    $this->assertResponse(200);
+
+    backup_migrate_include('files', 'profiles');
+    $filename = _backup_migrate_default_filename();
+    $defaults = _backup_migrate_profile_default_profile();
+
+    // Verify all of the expected fields exist.
+    $this->assertFieldByName('name');
+    $this->assertFieldByName('name', 'Untitled Profile');
+    $this->assertFieldByName('machine_name');
+    $this->assertFieldByName('filename');
+    $this->assertFieldByName('filename', $filename);
+    // @todo Confirm all of the expected options are present.
+    $this->assertFieldByName('append_timestamp');
+    $this->assertFieldByName('timestamp_format');
+    $this->assertFieldByName('timestamp_format', $defaults['timestamp_format']);
+    $this->assertFieldByName('filters[compression]');
+    $items = $this->supportedCompressors();
+    $this->assertSelectOptions('edit-filters-compression', $items);
+    $this->assertOptionSelected('edit-filters-compression', 'gzip');
+    $this->assertFieldByName('filters[sources][db][exclude_tables][]');
+    $this->assertFieldByName('filters[sources][db][nodata_tables][]');
+    $this->assertFieldByName('filters[sources][db][utils_lock_tables]');
+    $this->assertFieldByName('filters[sources][files][exclude_filepaths]');
+    $this->assertFieldByName('filters[sources][archive][exclude_filepaths]');
+    $this->assertFieldByName('filters[utils_site_offline]');
+    $this->assertFieldByName('filters[utils_site_offline_message]');
+    $this->assertFieldByName('filters[utils_description]');
+    $this->assertFieldByName('filters[use_cli]');
+    $this->assertFieldByName('filters[ignore_errors]');
+    $this->assertFieldByName('filters[notify_success_enable]');
+    $this->assertFieldByName('filters[notify_success_email]');
+    $this->assertFieldByName('filters[notify_failure_enable]');
+    $this->assertFieldByName('filters[notify_failure_email]');
+  }
+
+  /**
+   * Confirm the backup filename processes work as expected.
+   */
+  public function testFilenameOptions() {
+    // Load the profile. This will be interacted with directly because otherwise
+    // the number of form fields will likely make it impossible to execute
+    // properly due to the max_input_vars setting defaulting to 1000.
+    $profile = $this->getProfile();
+
+    // Run a backup.
+    $this->runBackup();
+
+    // Confirm that there is only one file and it has a timestamp of some sort.
+    $files1 = $this->listBackupFiles();
+    $this->verbose($files1);
+    $this->assertTrue(count($files1) === 1, 'One backup file was found.');
+    $this->assertFileTimestamp(array_shift($files1));
+
+    // Run another backup.
+    $this->runBackup();
+
+    // Confirm that there are two backup files.
+    $files1b = $this->listBackupFiles();
+    $this->verbose($files1b);
+    $this->assertTrue(count($files1b) === 2, 'Two backup files were found.');
+
+    // Cleanup before the next test - purge existing backups.
+    $this->deleteBackups();
+
+    // Change settings to "create separate backups".
+    $profile->append_timestamp = 0;
+    $profile->save();
+
+    // Run a backup.
+    $this->runBackup();
+
+    // Confirm that separate files are retained.
+    $files2 = $this->listBackupFiles();
+    $this->verbose($files2);
+    $this->assertTrue(count($files2) === 1, 'One backup file was found.');
+    $this->assertNoFileTimestamp(array_shift($files2));
+
+    // Run another backup.
+    $this->runBackup();
+
+    // Confirm that separate files are retained.
+    $files2b = $this->listBackupFiles();
+    $this->verbose($files2b);
+    $this->assertTrue(count($files2b) === 2, 'Two backup files were found.');
+
+    // Cleanup before the next test - purge existing backups.
+    $this->deleteBackups();
+
+    // Change settings to "overwrite".
+    $profile->append_timestamp = 2;
+    $profile->save();
+
+    // Run a backup.
+    $this->runBackup();
+
+    // Confirm that a new file was created.
+    $files3 = $this->listBackupFiles();
+    $this->verbose($files3);
+    $this->assertTrue(count($files3) === 1, 'One backup file was found.');
+    $this->assertNoFileTimestamp(array_shift($files3));
+
+    // Run the backup again.
+    $this->runBackup();
+
+    // Confirm that a new file was not created.
+    $files3b = $this->listBackupFiles();
+    $this->verbose($files3b);
+    $this->assertTrue(count($files3b) === 1, 'One backup file was found.');
+
+    // Cleanup - purge all backups.
+    $this->deleteBackups();
+  }
+
+}