bm_test.module 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * @file
  4. * Mock module to help and test hooks.
  5. */
  6. /**
  7. * A base class for mock exportables.
  8. */
  9. class BmTestItem {
  10. /**
  11. * Edit this to true to make a default item disabled initially.
  12. *
  13. * @var bool
  14. */
  15. public $disabled = FALSE;
  16. /**
  17. * Indicates the API version to use.
  18. *
  19. * @var int
  20. */
  21. public $api_version = 1;
  22. }
  23. /**
  24. * Implements hook_ctools_plugin_api().
  25. */
  26. function bm_test_ctools_plugin_api($module = NULL, $api = NULL) {
  27. if ($module == "backup_migrate" && $api == "backup_migrate_exportables") {
  28. return array("version" => "1");
  29. }
  30. }
  31. /**
  32. * Implements hook_exportables_backup_migrate_schedules().
  33. */
  34. function bm_test_exportables_backup_migrate_schedules() {
  35. $export = array();
  36. $item = new BmTestItem();
  37. $mock_record = _bm_test_get_mock_schedule();
  38. foreach ($mock_record as $key => $field) {
  39. $item->$key = $field;
  40. }
  41. $export['mock_db_weekly'] = $item;
  42. return $export;
  43. }
  44. /**
  45. * Helper function to create a mock schedule.
  46. */
  47. function _bm_test_get_mock_schedule() {
  48. return array(
  49. 'machine_name' => 'mock_db_weekly',
  50. 'name' => 'Mock weekly database schedule',
  51. 'source_id' => 'db',
  52. 'destination_id' => 'scheduled',
  53. 'copy_destination_id' => '',
  54. 'profile_id' => 'default',
  55. 'keep' => 4,
  56. 'period' => 604800,
  57. 'enabled' => TRUE,
  58. 'cron' => 'builtin',
  59. 'cron_schedule' => '0 4 * * *',
  60. );
  61. }
  62. /**
  63. * Implements hook_exportables_backup_migrate_sources().
  64. */
  65. function bm_test_exportables_backup_migrate_sources() {
  66. $export = array();
  67. $item = new BmTestItem();
  68. $mock_record = _bm_test_get_mock_source();
  69. foreach ($mock_record as $key => $field) {
  70. $item->$key = $field;
  71. }
  72. $export['mock_file_directory'] = $item;
  73. return $export;
  74. }
  75. /**
  76. * Helper function to create a mock source.
  77. */
  78. function _bm_test_get_mock_source() {
  79. return array(
  80. 'machine_name' => 'mock_file_directory',
  81. 'name' => 'Mock file directory',
  82. 'location' => '/dev/null',
  83. 'subtype' => 'filesource',
  84. );
  85. }
  86. /**
  87. * Implements hook_exportables_backup_migrate_destinations().
  88. */
  89. function bm_test_exportables_backup_migrate_destinations() {
  90. $export = array();
  91. $item = new BmTestItem();
  92. $mock_record = _bm_test_get_mock_destination();
  93. foreach ($mock_record as $key => $field) {
  94. $item->$key = $field;
  95. }
  96. $export['mock_email'] = $item;
  97. return $export;
  98. }
  99. /**
  100. * Helper function to create a mock destination.
  101. */
  102. function _bm_test_get_mock_destination() {
  103. return array(
  104. 'machine_name' => 'mock_email',
  105. 'name' => 'Mock e-mail destination',
  106. 'location' => 'test@example.com',
  107. 'subtype' => 'email',
  108. );
  109. }