Index: CHANGELOG.txt
===================================================================
RCS file: CHANGELOG.txt
diff -N CHANGELOG.txt
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ CHANGELOG.txt	10 Nov 2009 05:02:11 -0000
@@ -0,0 +1,10 @@
+// $Id: CHANGELOG.txt,v 1.42 2009/11/10 00:13:07 sun Exp $
+
+Demo profile x.x-x.x, xxxx-xx-xx
+--------------------------------
+
+
+Demo profile 7.x-1.x, xxxx-xx-xx
+--------------------------------
+by sun: Updated for new install profile AWESOMENESS.
+
Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/profiles/demo_profile/README.txt,v
retrieving revision 1.2
diff -u -p -r1.2 README.txt
--- README.txt	27 Nov 2008 06:29:20 -0000	1.2
+++ README.txt	10 Nov 2009 05:11:43 -0000
@@ -1,31 +1,53 @@
-Demonstration Site Install Profile
-==================================
+/* $Id: README.txt,v 1.7 2009/11/09 18:21:28 sun Exp $ */
+
+-- SUMMARY --
 
 Allows restoration of the Demonstration Site module's database dumps
 during site installation.
 
-$Id: README.txt,v 1.2 2008/11/27 06:29:20 robloach Exp $
+For a full description visit the project page:
+  http://drupal.org/project/demo_profile
+Bug reports, feature suggestions and latest developments:
+  http://drupal.org/project/issues/demo_profile
+
+
+-- REQUIREMENTS --
+
+* Demonstration site module
+  http://drupal.org/project/demo
 
-Requirements
-------------
- 1) The Demonstration Site
-    http://drupal.org/project/demo
+* At least one demonstration site snapshot previously created with the module.
 
- 2) A database dump previously created with the module
 
+-- INSTALLATION --
 
-Usage
------
- 1) Install the Demonstration Site module on your site and make sure
-    you have some database snapshots saved.
+* Download and extract the Demonstration site profile (this package) into the
+  site's profiles directory (next to the "default" profile):
 
- 2) Install the Demonstation Site Install Profile into
     /profiles/demo_profile
 
- 3) During install, select the Demonstration Site install profile.
+* Download and extract the Demonstration site module into the site's modules
+  directory (as usual).
+
+* Copy the previously created snapshot(s) into the site's private files
+  directory, for example:
+
+    /sites/default/private/files/demo
+
+* Start the installation by pointing your browser to:
+
+    http://example.com/install.php
+
+* Select the "Demonstration site" profile.
+
+* REQUIRED: Use the same database prefix you were using for the original site.
+
+* Select the snapshot to restore.
+
+
+-- CONTACT --
 
- 4) REQUIRED: Use the same database prefix you were using for your
-    original site.
+Current maintainers:
+* Rob Loach - http://drupal.org/user/61114
+* Daniel F. Kudwien (sun) - http://drupal.org/user/54136
 
- 5) If needed, type in the correct dump path so that the database dumps
-    appear correctly.
Index: demo_profile.info
===================================================================
RCS file: demo_profile.info
diff -N demo_profile.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ demo_profile.info	10 Nov 2009 02:57:20 -0000
@@ -0,0 +1,6 @@
+; $Id$
+name = Demonstration site
+description = Create a pre-setup and pre-configured Drupal site from a snapshot.
+core = 7.x
+dependencies[] = demo
+files[] = demo_profile.profile
Index: demo_profile.profile
===================================================================
RCS file: /cvs/drupal-contrib/contributions/profiles/demo_profile/demo_profile.profile,v
retrieving revision 1.2
diff -u -p -r1.2 demo_profile.profile
--- demo_profile.profile	27 Nov 2008 06:29:20 -0000	1.2
+++ demo_profile.profile	10 Nov 2009 05:00:18 -0000
@@ -2,87 +2,170 @@
 // $Id: demo_profile.profile,v 1.2 2008/11/27 06:29:20 robloach Exp $
 
 /**
- * Return an array of the modules to be enabled when this profile is installed.
- *
- * @return
- *   An array of modules to enable.
+ * @file
+ * Demonstration site installation profile.
  */
-function demo_profile_profile_modules() {
-  return array('demo');
-}
 
 /**
- * Return a description of the profile for the initial installation screen.
- *
- * @return
- *   An array with keys 'name' and 'description' describing this profile,
- *   and optional 'language' to override the language selection for
- *   language-specific profiles.
+ * Implements hook_install_tasks_alter().
  */
-function demo_profile_profile_details() {
-  return array(
-    'name' => 'Demonstration site',
-    'description' => 'Select this profile to restore from a Database dump.',
+function demo_profile_install_tasks_alter(&$tasks, &$install_state) {
+  // Break references.
+  $finished_task = (array) $tasks['install_finished'];
+
+  // Regular tasks.
+  // @todo Not sure whether the simple unset() works too.
+  $tasks['install_system_module']['run'] = INSTALL_TASK_SKIP;
+  $tasks['install_bootstrap_full']['run'] = INSTALL_TASK_SKIP;
+  $tasks['install_profile_modules']['run'] = INSTALL_TASK_SKIP;
+  $tasks['install_import_locales']['run'] = INSTALL_TASK_SKIP;
+  $tasks['install_configure_form']['run'] = INSTALL_TASK_SKIP;
+  // Final tasks.
+  // We cannot implement hook_install_tasks(), because we want to intercept the
+  // installation process before it even begins (except database settings).
+  $tasks['install_import_locales_remaining']['run'] = INSTALL_TASK_SKIP;
+  $tasks['install_finished']['run'] = INSTALL_TASK_SKIP;
+
+  // Remove the tasks from the list and execution.
+  unset(
+    $tasks['install_system_module'],
+    $tasks['install_bootstrap_full'],
+    $tasks['install_profile_modules'],
+    $tasks['install_import_locales'],
+    $tasks['install_configure_form'],
+    $tasks['install_import_locales_remaining'],
+    $tasks['install_finished']
   );
+
+  // Add Demonstration site profile tasks.
+  // @todo Move dump path setting into separate step; store value in
+  //   $install_state.
+  $tasks['demo_profile_form'] = array(
+    'display_name' => st('Choose snapshot'),
+    'type' => 'form',
+    'run' => INSTALL_TASK_RUN_IF_NOT_COMPLETED,
+  );
+  $tasks['demo_profile_reset'] = array(
+    'display_name' => st('Install snapshot'),
+    'type' => 'batch',
+  );
+  $tasks['install_finished'] = $finished_task;
 }
 
 /**
  * Implementation of hook_form_alter().
- *
- * Allows the profile to alter the site-configuration form. This is
- * called through custom invocation, so $form_state is not populated.
  */
-function demo_profile_form_alter(&$form, $form_state, $form_id) {
-  if ($form_id == 'install_configure') {
+function demo_profile_form($form, &$form_state, &$install_state) {
+  drupal_set_title(st('Choose snapshot'));
 
-    // These settings arn't used, so add some default values and hide the elements.
-    $form['site_information']['site_name']['#value'] = 'Drupal';
-    $form['site_information']['site_mail']['#value'] = 'drupal@drupal.org';
-    $form['admin_account']['account']['name']['#value'] = 'Drupal';
-    $form['admin_account']['account']['mail']['#value'] = 'drupal@drupal.org';
-    $form['admin_account']['account']['pass']['#value'] = 'drupal';
-    $form['site_information']['#access'] = FALSE;
-    $form['admin_account']['#access'] = FALSE;
-    $form['server_settings']['#access'] = FALSE;
-
-    // Display the available database dumps.
-    module_load_include('inc', 'demo', 'demo.admin');
-    $fileconfig = demo_get_fileconfig();
-    $form['demo_dump_path'] = array(
-      '#required' => TRUE,
-      '#type' => 'textfield',
-      '#title' => t('Dump path'),
-      '#default_value' => $fileconfig['path'],
-      '#size' => 30,
-      '#description' => t('The path where the database dumps can be found.'),
-    );
-    $form['demo'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Demonstration site'),
-      '#description' => t('Which database dump would you like to restore from?'),
-      demo_get_dumps(),
-    );
-    $form['demo'][0]['dump']['filename']['#required']= FALSE;
-    $form['#submit'][] = 'demo_profile_form_submit';
-  }
+  // Display the available database dumps.
+  module_load_include('inc', 'demo', 'demo.admin');
+  $fileconfig = demo_get_fileconfig();
+
+  $form['demo'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Demonstration site settings'),
+  );
+  $form['demo']['demo_dump_path'] = array(
+    '#required' => TRUE,
+    '#type' => 'textfield',
+    '#title' => t('Dump path'),
+    '#default_value' => $fileconfig['path'],
+    '#description' => t('The path where the database dumps can be found.'),
+  );
+  // @todo Validate the given path to dumps.
+  // $form['#validate'][] = 'demo_admin_settings_validate';
+
+  $form['dump'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Snapshot'),
+    '#description' => t('Which snapshot would you like to restore?'),
+  );
+  $form['dump'] += demo_profile_get_dumps();
+
+  $form['submit'] = array('#type' => 'submit', '#value' => t('Restore'));
+  return $form;
 }
 
 /**
  * Submit handler for the "install_configure" form.
  */
 function demo_profile_form_submit($form, &$form_state) {
-  // Check if a database dump has been selected.
-  if (isset($form_state['clicked_button']['#post']['filename'])) {
-    // Restore the database dump and redirect to the homepage.
-    module_load_include('inc', 'demo', 'demo.admin');
-    demo_reset($form_state['clicked_button']['#post']['filename'], FALSE);
-    drupal_goto('<front>');
+  // Restore the database dump and redirect to the homepage.
+  drupal_load('module', 'demo');
+  demo_reset($form_state['values']['filename'], TRUE);
+
+  $form_state['redirect'] = '';
+
+//  // The dump path is being changed.
+//  variable_set('demo_dump_path', $form_state['values']['demo_dump_path']);
+//
+//  // Refresh the page so that the form refreshes.
+//  header('Location: '. base_path() . 'install.php?locale='. $_GET['locale'] .'&profile=demo_profile');
+}
+
+/**
+ * Half-bootstrap-aware fork of demo_get_dumps().
+ *
+ * @see demo_get_dumps()
+ */
+function demo_profile_get_dumps() {
+  $fileconfig = demo_get_fileconfig();
+
+  // Fetch list of available info files
+  $files = file_scan_directory($fileconfig['dumppath'], '/\.info$/');
+
+  foreach ($files as $file => $object) {
+    $files[$file]->filemtime = filemtime($file);
+    $files[$file]->filesize = filesize(substr($file, 0, -4) . 'sql');
   }
-  else {
-    // The dump path is being changed.
-    variable_set('demo_dump_path', $form_state['values']['demo_dump_path']);
-    
-    // Refresh the page so that the form refreshes.
-    header('Location: '. base_path() . 'install.php?locale='. $_GET['locale'] .'&profile=demo_profile');
+
+  // Sort snapshots by date (ascending file modification time)
+  uasort($files, create_function('$a, $b', 'return ($a->filemtime < $b->filemtime);'));
+
+  $options = array();
+  // Forms API does not pass selected value of individual radio buttons,
+  // so we manually insert an internal form value here.
+  $options['filename'] = array(
+    '#type' => 'value',
+    '#required' => TRUE,
+    '#title' => t('Snapshot'),
+  );
+  foreach ($files as $filename => $file) {
+    // Build basic file info
+    $files[$filename] = (array) $file;
+    $info = demo_get_info($filename);
+
+    // Convert file info for Forms API
+    $option = array(
+      '#type' => 'radio',
+      '#name' => 'filename',
+      // format_date() is not available during installation.
+      '#title' => check_plain($info['filename']) . ' (' . date('Y-m-d H:i:s', $file->filemtime) . ', ' . format_size($file->filesize) . ')',
+      '#description' => '',
+      '#return_value' => $info['filename'],
+      '#file' => $file,
+      '#info' => $info,
+      '#attributes' => array('onclick' => "jQuery('.description', this.parentNode.parentNode).slideToggle();"),
+    );
+    if (!empty($info['description'])) {
+      $option['#description'] .= '<p>' . $info['description'] . '</p>';
+    }
+
+    if (count($info['modules']) > 1) {
+      // Remove required core modules and obvious modules from module list.
+      $info['modules'] = array_diff($info['modules'], array('filter', 'node', 'system', 'user', 'watchdog', 'demo'));
+      // Sort module list alphabetically.
+      sort($info['modules']);
+      $option['#description'] .= t('Modules: ') . implode(', ', $info['modules']);
+    }
+
+    $options[$info['filename']] = $option;
   }
+
+  // Attach stylesheet to initially hide descriptions
+  drupal_add_js("jQuery('div.form-item div.description', jQuery('form')).hide();", array('type' => 'inline', 'scope' => 'footer'));
+
+  return $options;
 }
+
