Index: modules/dashboard/dashboard.install
===================================================================
RCS file: modules/dashboard/dashboard.install
diff -N modules/dashboard/dashboard.install
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/dashboard/dashboard.install	28 Oct 2010 04:43:55 -0000
@@ -0,0 +1,72 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Install, update and uninstall functions for the dashboard module.
+ */
+
+/**
+ * Implements hook_disable().
+ *
+ * Stash a list of blocks enabled on the dashboard, so they can be re-enabled
+ * if the dashboard is re-enabled. Then disable those blocks, since the
+ * dashboard regions will no longer be defined.
+ */
+function dashboard_disable() {
+  // Stash a list of currently enabled blocks.
+  $stashed_blocks = array();
+
+  $result = db_select('block', 'b')
+    ->fields('b', array('module', 'delta', 'region'))
+    ->condition('b.region', dashboard_regions(), 'IN')
+    ->execute();
+
+  foreach ($result as $block) {
+    $stashed_blocks[] = array(
+      'module' => $block->module,
+      'delta' => $block->delta,
+      'region' => $block->region,
+    );
+  }
+  variable_set('dashboard_stashed_blocks', $stashed_blocks);
+
+  // Disable the dashboard blocks.
+  db_update('block')
+    ->fields(array(
+      'status' => 0,
+      'region' => BLOCK_REGION_NONE,
+    ))
+    ->condition('region', dashboard_regions(), 'IN')
+    ->execute();
+}
+
+/**
+ * Implements hook_enable().
+ *
+ * Restores blocks to the dashboard that were there when the dashboard module
+ * was disabled.
+ */
+function dashboard_enable() {
+  global $theme_key;
+  if (!$stashed_blocks = variable_get('dashboard_stashed_blocks')) {
+    return;
+  }
+  if (!$admin_theme = variable_get('admin_theme')) {
+    drupal_theme_initialize();
+    $admin_theme = $theme_key;
+  }
+  foreach ($stashed_blocks as $block) {
+    db_update('block')
+      ->fields(array(
+        'status' => 1,
+        'region' => $block['region']
+      ))
+      ->condition('module', $block['module'])
+      ->condition('delta', $block['delta'])
+      ->condition('theme', $admin_theme)
+      ->condition('status', 0)
+      ->execute();
+  }
+  variable_del('dashboard_stashed_blocks');
+}
Index: modules/dashboard/dashboard.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/dashboard/dashboard.test,v
retrieving revision 1.6
diff -u -p -r1.6 dashboard.test
--- modules/dashboard/dashboard.test	21 Oct 2010 11:55:09 -0000	1.6
+++ modules/dashboard/dashboard.test	28 Oct 2010 04:43:55 -0000
@@ -19,7 +19,7 @@ class DashboardBlocksTestCase extends Dr
     parent::setUp();
 
     // Create and log in an administrative user having access to the dashboard.
-    $admin_user = $this->drupalCreateUser(array('access dashboard', 'administer blocks'));
+    $admin_user = $this->drupalCreateUser(array('access dashboard', 'administer blocks', 'access administration pages', 'administer modules'));
     $this->drupalLogin($admin_user);
 
     // Make sure that the dashboard is using the same theme as the rest of the
@@ -79,4 +79,37 @@ class DashboardBlocksTestCase extends Dr
       $this->assertTrue(empty($elements), t('%region is not an available choice on the block configuration page.', array('%region' => $region)));
     }
   }
+
+  /**
+   * Test that the dashboard module can be disabled and enabled again,
+   * retaining its blocks.
+   */
+  function testDisableEnable() {
+    // Add a new custom block to a dashboard region.
+    $custom_block = array();
+    $custom_block['info'] = $this->randomName(8);
+    $custom_block['title'] = $this->randomName(8);
+    $custom_block['body[value]'] = $this->randomName(32);
+    $custom_block['regions[stark]'] = 'dashboard_main';
+    $this->drupalPost('admin/structure/block/add', $custom_block, t('Save block'));
+    $this->drupalGet('admin/dashboard');
+    $this->assertRaw($custom_block['title'], t('Block appears on the dashboard.'));
+
+    $edit = array();
+    $edit['modules[Core][dashboard][enable]'] = FALSE;
+    $this->drupalPost('admin/modules', $edit, t('Save configuration'));
+    $this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.'));
+    $this->assertNoRaw('assigned to the invalid region', t('Dashboard blocks gracefully disabled.'));
+    module_list(TRUE);
+    $this->assertFalse(module_exists('dashboard'), t('Dashboard disabled.'));
+
+    $edit['modules[Core][dashboard][enable]'] = 'dashboard';
+    $this->drupalPost('admin/modules', $edit, t('Save configuration'));
+    $this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.'));
+    module_list(TRUE);
+    $this->assertTrue(module_exists('dashboard'), t('Dashboard enabled.'));
+
+    $this->drupalGet('admin/dashboard');
+    $this->assertRaw($custom_block['title'], t('Block still appears on the dashboard.'));
+  }
 }
