destinations.browser.inc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * @file
  4. * Functions to handle the browser upload/download backup destination.
  5. */
  6. /**
  7. * A destination type for browser upload/download.
  8. *
  9. * @ingroup backup_migrate_destinations
  10. */
  11. class backup_migrate_destination_browser extends backup_migrate_destination {
  12. /**
  13. * Get a row of data to be used in a list of items of this type.
  14. */
  15. public function get_list_row() {
  16. // Return none as this type should not be displayed.
  17. return array();
  18. }
  19. }
  20. /**
  21. * A destination type for browser upload.
  22. *
  23. * @ingroup backup_migrate_destinations
  24. */
  25. class backup_migrate_destination_browser_upload extends backup_migrate_destination_browser {
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public $supported_ops = array('restore');
  30. /**
  31. * Constructor.
  32. */
  33. public function __construct() {
  34. $params = array();
  35. $params['name'] = "Upload";
  36. $params['machine_name'] = 'upload';
  37. parent::__construct($params);
  38. }
  39. /**
  40. * File load destination callback.
  41. */
  42. public function load_file($file_id) {
  43. if ($file = file_save_upload('backup_migrate_restore_upload')) {
  44. $out = new backup_file(array('filepath' => $file->uri));
  45. backup_migrate_temp_files_add($file->uri);
  46. return $out;
  47. }
  48. return NULL;
  49. }
  50. }
  51. /**
  52. * A destination type for browser download.
  53. *
  54. * @ingroup backup_migrate_destinations
  55. */
  56. class backup_migrate_destination_browser_download extends backup_migrate_destination_browser {
  57. /**
  58. * {@inheritdoc}
  59. */
  60. public $supported_ops = array('manual backup');
  61. /**
  62. * Browser downloads must always be the last destination as they must end the
  63. * current process when they are done.
  64. */
  65. public $weight = 1000;
  66. /**
  67. * Constructor.
  68. */
  69. public function __construct() {
  70. $params = array();
  71. $params['name'] = "Download";
  72. $params['machine_name'] = 'download';
  73. parent::__construct($params);
  74. }
  75. /**
  76. * File save destination callback.
  77. */
  78. public function save_file($file, $settings) {
  79. require_once dirname(__FILE__) . '/files.inc';
  80. $file->transfer();
  81. }
  82. }