demo.module 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. // $Id: demo.module,v 1.39 2010/09/25 17:06:05 sun Exp $
  3. /**
  4. * @file
  5. * Demonstration site API Drupal integration functions.
  6. */
  7. /**
  8. * Implements hook_perm().
  9. */
  10. function demo_permission() {
  11. return array(
  12. 'administer demo settings' => array(
  13. 'title' => t('Create snapshots and reset the site'),
  14. 'restrict access' => TRUE,
  15. ),
  16. );
  17. }
  18. /**
  19. * Implements hook_menu().
  20. */
  21. function demo_menu() {
  22. $admin_access = array('administer demo settings');
  23. $items['admin/structure/demo'] = array(
  24. 'title' => 'Snapshots',
  25. 'description' => 'Create snapshots and reset the site.',
  26. 'page callback' => 'drupal_get_form',
  27. 'page arguments' => array('demo_manage_form'),
  28. 'access arguments' => $admin_access,
  29. 'file' => 'demo.admin.inc',
  30. );
  31. $items['admin/structure/demo/list'] = array(
  32. 'title' => 'List',
  33. 'type' => MENU_DEFAULT_LOCAL_TASK,
  34. 'weight' => -10,
  35. );
  36. $items['admin/structure/demo/dump'] = array(
  37. 'title' => 'Create snapshot',
  38. 'page callback' => 'drupal_get_form',
  39. 'page arguments' => array('demo_dump_form'),
  40. 'access arguments' => $admin_access,
  41. 'file' => 'demo.admin.inc',
  42. 'type' => MENU_LOCAL_ACTION,
  43. );
  44. $items['admin/structure/demo/reset'] = array(
  45. 'title' => 'Reset',
  46. 'page callback' => 'drupal_get_form',
  47. 'page arguments' => array('demo_reset_confirm'),
  48. 'access arguments' => $admin_access,
  49. 'file' => 'demo.admin.inc',
  50. 'type' => MENU_LOCAL_TASK,
  51. 'weight' => 3,
  52. );
  53. $items['admin/structure/demo/delete/%'] = array(
  54. 'title' => 'Delete snapshot',
  55. 'page callback' => 'drupal_get_form',
  56. 'page arguments' => array('demo_delete_confirm', 4),
  57. 'access arguments' => $admin_access,
  58. 'file' => 'demo.admin.inc',
  59. 'type' => MENU_VISIBLE_IN_BREADCRUMB,
  60. );
  61. $items['admin/structure/demo/settings'] = array(
  62. 'title' => 'Settings',
  63. 'page callback' => 'drupal_get_form',
  64. 'page arguments' => array('demo_admin_settings'),
  65. 'access arguments' => $admin_access,
  66. 'file' => 'demo.admin.inc',
  67. 'type' => MENU_LOCAL_TASK,
  68. 'weight' => 10,
  69. );
  70. $items['demo/autocomplete'] = array(
  71. 'page callback' => 'demo_autocomplete',
  72. 'access arguments' => $admin_access,
  73. 'file' => 'demo.admin.inc',
  74. 'type' => MENU_CALLBACK,
  75. );
  76. $items['demo/download'] = array(
  77. 'page callback' => 'demo_download',
  78. 'access arguments' => $admin_access,
  79. 'file' => 'demo.admin.inc',
  80. 'type' => MENU_CALLBACK,
  81. );
  82. return $items;
  83. }
  84. /**
  85. * Create a new snapshot.
  86. *
  87. * @param $options
  88. * A structured array of snapshot options:
  89. * - filename: The base output filename, without extension.
  90. * - default: Whether to set this dump as new default snapshot.
  91. * - description: A description for the snapshot. If a snapshot with the same
  92. * name already exists and this is left blank, the new snapshot will reuse
  93. * the existing description.
  94. * - tables: An array of tables to dump, keyed by table name (including table
  95. * prefix, if any). The value is an array of dump options:
  96. * - schema: Whether to dump the table schema.
  97. * - data: Whether to dump the table data.
  98. */
  99. function demo_dump($options) {
  100. module_load_include('inc', 'demo', 'demo.admin');
  101. return _demo_dump($options);
  102. }
  103. /**
  104. * Reset site using snapshot.
  105. *
  106. * @param $filename
  107. * Base snapshot filename, without extension.
  108. * @param $verbose
  109. * Whether to output status messages.
  110. */
  111. function demo_reset($filename, $verbose = TRUE) {
  112. module_load_include('inc', 'demo', 'demo.admin');
  113. return _demo_reset($filename, $verbose);
  114. }